Skip to content

Commit 8e4e5b1

Browse files
committed
update notebooks to use module save
1 parent 948417a commit 8e4e5b1

2 files changed

Lines changed: 51 additions & 70 deletions

File tree

notebooks/run_model_in_notebook.ipynb

Lines changed: 45 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
"outputs": [],
1616
"source": [
1717
"import os\n",
18-
"from PyStemmusScope import StemmusScope"
18+
"from PyStemmusScope import StemmusScope\n",
19+
"from PyStemmusScope import save"
1920
]
2021
},
2122
{
@@ -87,7 +88,7 @@
8788
},
8889
{
8990
"cell_type": "code",
90-
"execution_count": 4,
91+
"execution_count": 9,
9192
"metadata": {},
9293
"outputs": [
9394
{
@@ -96,20 +97,20 @@
9697
"{'WorkDir': '/home/sarah/temp/ecoextreml/test/',\n",
9798
" 'SoilPropertyPath': '/home/sarah/temp/ecoextreml/data/model_parameters/soil_property/',\n",
9899
" 'ForcingPath': '/home/sarah/temp/ecoextreml/data/forcing/plumber2_data/',\n",
99-
" 'ForcingFileName': 'AU-DaS_2010-2017_OzFlux_Met.nc',\n",
100+
" 'ForcingFileName': 'AR-SLu_2010-2010_FLUXNET2015_Met.nc',\n",
100101
" 'directional': '/home/sarah/temp/ecoextreml/data/model_parameters/vegetation_property/directional/',\n",
101102
" 'fluspect_parameters': '/home/sarah/temp/ecoextreml/data/model_parameters/vegetation_property/fluspect_parameters/',\n",
102103
" 'leafangles': '/home/sarah/temp/ecoextreml/data/model_parameters/vegetation_property/leafangles/',\n",
103104
" 'radiationdata': '/home/sarah/temp/ecoextreml/data/model_parameters/vegetation_property/radiationdata/',\n",
104105
" 'soil_spectrum': '/home/sarah/temp/ecoextreml/data/model_parameters/vegetation_property/soil_spectrum/',\n",
105106
" 'InitialConditionPath': '/home/sarah/temp/ecoextreml/soil_initialcondition/',\n",
106107
" 'input_data': '/home/sarah/temp/ecoextreml/data/model_parameters/vegetation_property/input_data.xlsx',\n",
107-
" 'NumberOfTimeSteps': 'NA',\n",
108+
" 'NumberOfTimeSteps': '5',\n",
108109
" 'InputPath': '/will_be_created_under_WorkDir/input/AU-DaS_2022-05-11-1705/',\n",
109-
" 'OutputPath': '/will_be_created_under_WorkDir/output/AU-DaS_2022-05-11-1705/'}"
110+
" 'OutputPath': '/home/sarah/temp/ecoextreml/output/AR-SLu_2022-07-29-1451/'}"
110111
]
111112
},
112-
"execution_count": 4,
113+
"execution_count": 9,
113114
"metadata": {},
114115
"output_type": "execute_result"
115116
}
@@ -124,14 +125,14 @@
124125
},
125126
{
126127
"cell_type": "code",
127-
"execution_count": 6,
128+
"execution_count": 10,
128129
"metadata": {},
129130
"outputs": [
130131
{
131132
"name": "stdout",
132133
"output_type": "stream",
133134
"text": [
134-
"/home/sarah/temp/ecoextreml/test/input/ZA-Kru_2022-07-18-1630/ZA-Kru_2022-07-18-1630_config.txt\n"
135+
"/home/sarah/temp/ecoextreml/test/input/ZA-Kru_2022-08-03-1537/ZA-Kru_2022-08-03-1537_config.txt\n"
135136
]
136137
}
137138
],
@@ -146,7 +147,7 @@
146147
},
147148
{
148149
"cell_type": "code",
149-
"execution_count": 7,
150+
"execution_count": 11,
150151
"metadata": {},
151152
"outputs": [
152153
{
@@ -164,11 +165,11 @@
164165
" 'InitialConditionPath': '/home/sarah/temp/ecoextreml/soil_initialcondition/',\n",
165166
" 'input_data': '/home/sarah/temp/ecoextreml/data/model_parameters/vegetation_property/input_data.xlsx',\n",
166167
" 'NumberOfTimeSteps': '10',\n",
167-
" 'InputPath': '/home/sarah/temp/ecoextreml/test/input/ZA-Kru_2022-07-18-1630/',\n",
168-
" 'OutputPath': '/home/sarah/temp/ecoextreml/test/output/ZA-Kru_2022-07-18-1630/'}"
168+
" 'InputPath': '/home/sarah/temp/ecoextreml/test/input/ZA-Kru_2022-08-03-1537/',\n",
169+
" 'OutputPath': '/home/sarah/temp/ecoextreml/test/output/ZA-Kru_2022-08-03-1537/'}"
169170
]
170171
},
171-
"execution_count": 7,
172+
"execution_count": 11,
172173
"metadata": {},
173174
"output_type": "execute_result"
174175
}
@@ -180,16 +181,16 @@
180181
},
181182
{
182183
"cell_type": "code",
183-
"execution_count": 8,
184+
"execution_count": 12,
184185
"metadata": {},
185186
"outputs": [
186187
{
187188
"data": {
188189
"text/plain": [
189-
"b'Reading config from /home/sarah/temp/ecoextreml/test/input/ZA-Kru_2022-07-18-1630/ZA-Kru_2022-07-18-1630_config.txt\\n\\n The calculations start now \\r\\n The calculations end now \\r'"
190+
"b'Reading config from /home/sarah/temp/ecoextreml/test/input/ZA-Kru_2022-08-03-1537/ZA-Kru_2022-08-03-1537_config.txt\\n\\n The calculations start now \\r\\n The calculations end now \\r'"
190191
]
191192
},
192-
"execution_count": 8,
193+
"execution_count": 12,
193194
"metadata": {},
194195
"output_type": "execute_result"
195196
}
@@ -200,6 +201,26 @@
200201
"result"
201202
]
202203
},
204+
{
205+
"cell_type": "code",
206+
"execution_count": 14,
207+
"metadata": {},
208+
"outputs": [
209+
{
210+
"name": "stdout",
211+
"output_type": "stream",
212+
"text": [
213+
"/home/sarah/temp/ecoextreml/test/output/ZA-Kru_2022-08-03-1537/ZA-Kru_2022-08-03-1537_STEMMUS_SCOPE.nc\n"
214+
]
215+
}
216+
],
217+
"source": [
218+
"# save output in nercdf format\n",
219+
"variables_will_be_in_NetCDF_file = \"./STEMMUS_SCOPE/utils/csv_to_nc/Variables_will_be_in_NetCDF_file.csv\"\n",
220+
"nc_file_name = save.to_netcdf(model.config, variables_will_be_in_NetCDF_file)\n",
221+
"print(nc_file_name)"
222+
]
223+
},
203224
{
204225
"cell_type": "markdown",
205226
"metadata": {},
@@ -209,15 +230,17 @@
209230
},
210231
{
211232
"cell_type": "code",
212-
"execution_count": 9,
233+
"execution_count": 15,
213234
"metadata": {},
214235
"outputs": [
215236
{
216237
"name": "stdout",
217238
"output_type": "stream",
218239
"text": [
219-
"b'Reading config from /home/sarah/temp/ecoextreml/test/input/ZA-Kru_2022-07-18-1631/ZA-Kru_2022-07-18-1631_config.txt\\n\\n The calculations start now \\r\\n The calculations end now \\r'\n",
220-
"b'Reading config from /home/sarah/temp/ecoextreml/test/input/AR-SLu_2022-07-18-1631/AR-SLu_2022-07-18-1631_config.txt\\n\\n The calculations start now \\r\\n The calculations end now \\r'\n"
240+
"b'Reading config from /home/sarah/temp/ecoextreml/test/input/ZA-Kru_2022-08-03-1541/ZA-Kru_2022-08-03-1541_config.txt\\n\\n The calculations start now \\r\\n The calculations end now \\r'\n",
241+
"/home/sarah/temp/ecoextreml/test/output/ZA-Kru_2022-08-03-1541/ZA-Kru_2022-08-03-1541_STEMMUS_SCOPE.nc\n",
242+
"b'Reading config from /home/sarah/temp/ecoextreml/test/input/AR-SLu_2022-08-03-1541/AR-SLu_2022-08-03-1541_config.txt\\n\\n The calculations start now \\r\\n The calculations end now \\r'\n",
243+
"/home/sarah/temp/ecoextreml/test/output/AR-SLu_2022-08-03-1541/AR-SLu_2022-08-03-1541_STEMMUS_SCOPE.nc\n"
221244
]
222245
}
223246
],
@@ -241,32 +264,12 @@
241264
" # run the model\n",
242265
" result = model.run()\n",
243266
" print(result)\n",
267+
" \n",
268+
" # save results in a netcdf file\n",
269+
" nc_file_name = save.to_netcdf(model.config, variables_will_be_in_NetCDF_file)\n",
270+
" print(nc_file_name)\n",
244271
" "
245272
]
246-
},
247-
{
248-
"cell_type": "markdown",
249-
"metadata": {},
250-
"source": [
251-
"#### TODO: Create output directories, prepare output files"
252-
]
253-
},
254-
{
255-
"cell_type": "code",
256-
"execution_count": 7,
257-
"metadata": {},
258-
"outputs": [],
259-
"source": [
260-
"# convert csv files to nc files\n",
261-
"# path_to_generate_netcdf_script = \"path_to_generate_netcdf_script\"\n",
262-
"# path_to_Variables_will_be_in_NetCDF_file = \"path_to_Variables_will_be_in_NetCDF_file\"\n",
263-
"# for ncfile in forcing_filenames_list:\n",
264-
"# path_to_config = config_path_dict[ncfile]\n",
265-
"# result = subprocess.run([\"python\", path_to_generate_netcdf_script,\n",
266-
"# \"--config_file\", path_to_config, \"--variable_file\",\n",
267-
"# path_to_Variables_will_be_in_NetCDF_file])\n",
268-
"# result.check_returncode()"
269-
]
270273
}
271274
],
272275
"metadata": {

notebooks/run_model_in_notebook_dev.ipynb

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -239,40 +239,18 @@
239239
"cell_type": "markdown",
240240
"metadata": {},
241241
"source": [
242-
"#### Create output directories, prepare output files"
242+
"#### save results in a netcdf file"
243243
]
244244
},
245245
{
246246
"cell_type": "code",
247-
"execution_count": 10,
247+
"execution_count": null,
248248
"metadata": {},
249-
"outputs": [
250-
{
251-
"name": "stdout",
252-
"output_type": "stream",
253-
"text": [
254-
"/scratch-shared/ecoextreml/stemmus_scope/output/FI-Hyy_20220621_1415/ECdata.csv\n",
255-
"Reading variable metadata from /home/yangl/STEMMUS_SCOPE/utils/csv_to_nc/Variables_will_be_in_NetCDF_file.csv\n",
256-
"Creating /scratch-shared/ecoextreml/stemmus_scope/output/FI-Hyy_20220621_1415/FI-Hyy_20220621_1415_STEMMUS_SCOPE.nc \n",
257-
"Reading data from file: radiation.csv\n",
258-
"Reading data from file: fluxes.csv\n",
259-
"Reading data from file: surftemp.csv\n",
260-
"Reading data from file: Sim_Temp.csv\n",
261-
"Reading data from file: Sim_Theta.csv\n",
262-
"Reading data from file: aerodyn.csv\n",
263-
"Reading data from file: ECdata.csv\n",
264-
"Done writing /scratch-shared/ecoextreml/stemmus_scope/output/FI-Hyy_20220621_1415/FI-Hyy_20220621_1415_STEMMUS_SCOPE.nc\n"
265-
]
266-
}
267-
],
249+
"outputs": [],
268250
"source": [
269-
"# convert csv files to nc files\n",
270-
"path_to_generate_netcdf_script = \"path_to_generate_netcdf_script\"\n",
271-
"path_to_Variables_will_be_in_NetCDF_file = \"path_to_Variables_will_be_in_NetCDF_file\"\n",
272-
"result = subprocess.run([\"python\", path_to_generate_netcdf_script,\n",
273-
" \"--config_file\", config_path, \"--variable_file\",\n",
274-
" path_to_Variables_will_be_in_NetCDF_file])\n",
275-
"result.check_returncode()"
251+
"variables_will_be_in_NetCDF_file = path_to_model / \"utils\" / \"csv_to_nc\" / \"Variables_will_be_in_NetCDF_file.csv\"\n",
252+
"nc_file_name = save.to_netcdf(model.config, variables_will_be_in_NetCDF_file)\n",
253+
"print(nc_file_name)"
276254
]
277255
},
278256
{

0 commit comments

Comments
 (0)