<jupyter_start><jupyter_text>4. Creating forcing data netCDF<jupyter_code>from netCDF4 import Dataset, default_fillvals
import numpy as np
# Create a netCDF file
forcing_data = Dataset("forcing_above_aspen.nc", "w", format="NETCDF3_CLASSIC")
# Create attributes in a netCDF file
forcing_data.dataset_orig_path = "/d2/anewman/summa/summaTestCases/testCases_data/inputData/fieldData/reynolds"
forcing_data.history = "Tue Sep 27 21:53:08 2016: ncrename -d nHRU,hru ./inputData/fieldData/reynolds/forcing_above_aspen.nc"
forcing_data.NCO = "4.6.0"
# Create Dimension in a netCDF file
hru = forcing_data.createDimension("hru", 1)
time = forcing_data.createDimension("time", None)
forcing_data<jupyter_output><empty_output><jupyter_text>Create variables in a netCDF file  for figure07 in wrrPaperTestCases (Clark et al., 2015b)<jupyter_code>hruId = forcing_data.createVariable("hruId", "i4", ("hru",))
hruId[:] = '1001'
latitude = forcing_data.createVariable("latitude", "f8", ("hru",))
latitude[:] = '43.2'
longitude = forcing_data.createVariable("longitude", "f8", ("hru",))
longitude[:] = '243.2'
data_step = forcing_data.createVariable("data_step", "f8", )
data_step.units = 'seconds'
data_step.long_name = "data step length in seconds"
data_step[:] = '3600.0'
import pandas as pd 
filename = '/media/sf_pysumma/input/Forcing_data/forcing2.csv'
myFile = pd.read_csv(filename, sep=',')
time = forcing_data.createVariable("time", "f8", ("time"))
time.units = 'days since 1990-01-01 00:00:00'
time.long_name = "Observation time"
time.calendar = "standard"
time[:] = np.arange(87672)
time[:] = myFile[['time2']].values
LWRadAtm = forcing_data.createVariable("LWRadAtm", "f8", ("time", "hru",), fill_value=-999.0)
LWRadAtm.units = 'W m-2'
LWRadAtm.long_name = "downward longwave radiation at the upper boundary"
LWRadAtm.v_type = 'scalarv'
LWRadAtm[:] = myFile[['LWRadAtm']].values
SWRadAtm = forcing_data.createVariable("SWRadAtm", "f8", ("time", "hru",), fill_value=-999.0)
SWRadAtm.units = 'W m-2'
SWRadAtm.long_name = "downward shortwave radiation at the upper boundary"
SWRadAtm.v_type = 'scalarv'
SWRadAtm[:] = myFile[['SWRadAtm']].values
airpres = forcing_data.createVariable("airpres", "f8", ("time", "hru",), fill_value=-999.0)
airpres.units = 'Pa'
airpres.long_name = "air pressure at the measurement height"
airpres.v_type = 'scalarv'
airpres[:] = myFile[['airpres']].values
airtemp = forcing_data.createVariable("airtemp", "f8", ("time", "hru",), fill_value=-999.0)
airtemp.units = 'K'
airtemp.long_name = "air temperature at the measurement height"
airtemp.v_type = 'scalarv'
airtemp[:] = myFile[['airtemp']].values
pptrate = forcing_data.createVariable("pptrate", "f8", ("time", "hru",), fill_value=-999.0)
pptrate.units = 'kg m-2 s-1'
pptrate.long_name = "Precipitation rate"
pptrate.v_type = 'scalarv'
pptrate[:] = myFile[['pptrate']].values
spechum = forcing_data.createVariable("spechum", "f8", ("time", "hru",), fill_value=-999.0)
spechum.units = 'g g-1'
spechum.long_name = "specific humidity at the measurement heigh"
spechum.v_type = 'scalarv'
spechum[:] = myFile[['spechum']].values
windspd = forcing_data.createVariable("windspd", "f8", ("time", "hru",), fill_value=-999.0)
windspd.units = 'm s-1'
windspd.long_name = "wind speed at the measurement height"
windspd.v_type = 'scalarv'
windspd[:] = myFile[['windspd']].values
# Check variables in a netCDF file
forcing_data.variables
# Check Dimension in a netCDF file
forcing_data.dimensions
# Check a netCDF file
forcing_data
# close a netCDF file
forcing_data.close()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16072931276297336, 'fraction_numerical': 0.030575035063113605, 'mean_word_length': 6.735357917570499, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '185655', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 1433, 'n_tokens_neox': 1362, 'n_words': 285, 'path': 'notebooks/4_Creating_Input_of_SUMMA_forcing_data.ipynb', 'repo_name': 'samarthsing/pysumma', 'size': '3565'}