Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated Notebooks 03 and 04 #319

Merged
merged 3 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions docs/notebooks/03_Extracting_forcing_data.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@
"Attributes:\n",
" long_name: Total precipitation\n",
" units: m\n",
" grid_mapping: crs</pre><div class='xr-wrap' style='display:none'><div class='xr-header'><div class='xr-obj-type'>xarray.DataArray</div><div class='xr-array-name'>'tp'</div><ul class='xr-dim-list'><li><span class='xr-has-index'>time</span>: 367</li><li><span class='xr-has-index'>latitude</span>: 1</li><li><span class='xr-has-index'>longitude</span>: 1</li></ul></div><ul class='xr-sections'><li class='xr-section-item'><div class='xr-array-wrap'><input id='section-d6169682-bc1c-461b-9464-ba5fa4c9b7ff' class='xr-array-in' type='checkbox' checked><label for='section-d6169682-bc1c-461b-9464-ba5fa4c9b7ff' title='Show/hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-array-preview xr-preview'><span>dask.array&lt;chunksize=(367, 1, 1), meta=np.ndarray&gt;</span></div><div class='xr-array-data'><table>\n",
" grid_mapping: crs</pre><div class='xr-wrap' style='display:none'><div class='xr-header'><div class='xr-obj-type'>xarray.DataArray</div><div class='xr-array-name'>'tp'</div><ul class='xr-dim-list'><li><span class='xr-has-index'>time</span>: 367</li><li><span class='xr-has-index'>latitude</span>: 1</li><li><span class='xr-has-index'>longitude</span>: 1</li></ul></div><ul class='xr-sections'><li class='xr-section-item'><div class='xr-array-wrap'><input id='section-8de94f0c-acbc-42e2-83e6-c01d5f99d79a' class='xr-array-in' type='checkbox' checked><label for='section-8de94f0c-acbc-42e2-83e6-c01d5f99d79a' title='Show/hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-array-preview xr-preview'><span>dask.array&lt;chunksize=(367, 1, 1), meta=np.ndarray&gt;</span></div><div class='xr-array-data'><table>\n",
" <tr>\n",
" <td>\n",
" <table style=\"border-collapse: collapse;\">\n",
Expand Down Expand Up @@ -563,17 +563,17 @@
"</svg>\n",
" </td>\n",
" </tr>\n",
"</table></div></div></li><li class='xr-section-item'><input id='section-b8000513-70a6-4f00-b4c6-c84b1c3b2197' class='xr-section-summary-in' type='checkbox' checked><label for='section-b8000513-70a6-4f00-b4c6-c84b1c3b2197' class='xr-section-summary' >Coordinates: <span>(3)</span></label><div class='xr-section-inline-details'></div><div class='xr-section-details'><ul class='xr-var-list'><li class='xr-var-item'><div class='xr-var-name'><span class='xr-has-index'>latitude</span></div><div class='xr-var-dims'>(latitude)</div><div class='xr-var-dtype'>float64</div><div class='xr-var-preview xr-preview'>48.5</div><input id='attrs-e4937338-9d7f-4fe1-ad88-f8a7b6145477' class='xr-var-attrs-in' type='checkbox' ><label for='attrs-e4937338-9d7f-4fe1-ad88-f8a7b6145477' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-1dacbe3d-fa44-4105-8285-43ab41e8c725' class='xr-var-data-in' type='checkbox'><label for='data-1dacbe3d-fa44-4105-8285-43ab41e8c725' title='Show/Hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-var-attrs'><dl class='xr-attrs'><dt><span>long_name :</span></dt><dd>latitude</dd><dt><span>standard_name :</span></dt><dd>latitude</dd><dt><span>stored_direction :</span></dt><dd>decreasing</dd><dt><span>units :</span></dt><dd>degrees_north</dd></dl></div><div class='xr-var-data'><pre>array([48.5])</pre></div></li><li class='xr-var-item'><div class='xr-var-name'><span class='xr-has-index'>longitude</span></div><div class='xr-var-dims'>(longitude)</div><div class='xr-var-dtype'>float64</div><div class='xr-var-preview xr-preview'>-71.5</div><input id='attrs-1294af79-e3b5-4b73-a46f-87ce67c8cf52' class='xr-var-attrs-in' type='checkbox' ><label for='attrs-1294af79-e3b5-4b73-a46f-87ce67c8cf52' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-eda5ea09-26b2-4fb6-b527-6b9e6e8d4923' class='xr-var-data-in' type='checkbox'><label for='data-eda5ea09-26b2-4fb6-b527-6b9e6e8d4923' title='Show/Hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-var-attrs'><dl class='xr-attrs'><dt><span>long_name :</span></dt><dd>longitude</dd><dt><span>standard_name :</span></dt><dd>longitude</dd><dt><span>units :</span></dt><dd>degrees_east</dd></dl></div><div class='xr-var-data'><pre>array([-71.5])</pre></div></li><li class='xr-var-item'><div class='xr-var-name'><span class='xr-has-index'>time</span></div><div class='xr-var-dims'>(time)</div><div class='xr-var-dtype'>datetime64[ns]</div><div class='xr-var-preview xr-preview'>1985-12-31 ... 1987-01-01</div><input id='attrs-09d8ad0b-4013-4c3b-b576-7290b8c927b7' class='xr-var-attrs-in' type='checkbox' disabled><label for='attrs-09d8ad0b-4013-4c3b-b576-7290b8c927b7' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-dc31aef6-37c2-49f9-a263-fd09be48b2e8' class='xr-var-data-in' type='checkbox'><label for='data-dc31aef6-37c2-49f9-a263-fd09be48b2e8' title='Show/Hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-var-attrs'><dl class='xr-attrs'></dl></div><div class='xr-var-data'><pre>array([&#x27;1985-12-31T00:00:00.000000000&#x27;, &#x27;1986-01-01T00:00:00.000000000&#x27;,\n",
"</table></div></div></li><li class='xr-section-item'><input id='section-6a214e36-daa8-4816-8550-093200852ef8' class='xr-section-summary-in' type='checkbox' checked><label for='section-6a214e36-daa8-4816-8550-093200852ef8' class='xr-section-summary' >Coordinates: <span>(3)</span></label><div class='xr-section-inline-details'></div><div class='xr-section-details'><ul class='xr-var-list'><li class='xr-var-item'><div class='xr-var-name'><span class='xr-has-index'>latitude</span></div><div class='xr-var-dims'>(latitude)</div><div class='xr-var-dtype'>float64</div><div class='xr-var-preview xr-preview'>48.5</div><input id='attrs-79956c5e-5685-49a6-a219-0c88486d2522' class='xr-var-attrs-in' type='checkbox' ><label for='attrs-79956c5e-5685-49a6-a219-0c88486d2522' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-b40c9524-7f1f-4b9e-a648-c2b7513e53ab' class='xr-var-data-in' type='checkbox'><label for='data-b40c9524-7f1f-4b9e-a648-c2b7513e53ab' title='Show/Hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-var-attrs'><dl class='xr-attrs'><dt><span>long_name :</span></dt><dd>latitude</dd><dt><span>standard_name :</span></dt><dd>latitude</dd><dt><span>stored_direction :</span></dt><dd>decreasing</dd><dt><span>units :</span></dt><dd>degrees_north</dd></dl></div><div class='xr-var-data'><pre>array([48.5])</pre></div></li><li class='xr-var-item'><div class='xr-var-name'><span class='xr-has-index'>longitude</span></div><div class='xr-var-dims'>(longitude)</div><div class='xr-var-dtype'>float64</div><div class='xr-var-preview xr-preview'>-71.5</div><input id='attrs-c66a132a-938f-4cdb-a914-1bba83be23f2' class='xr-var-attrs-in' type='checkbox' ><label for='attrs-c66a132a-938f-4cdb-a914-1bba83be23f2' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-27f3ac96-e048-427e-823c-f4cf9b98764c' class='xr-var-data-in' type='checkbox'><label for='data-27f3ac96-e048-427e-823c-f4cf9b98764c' title='Show/Hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-var-attrs'><dl class='xr-attrs'><dt><span>long_name :</span></dt><dd>longitude</dd><dt><span>standard_name :</span></dt><dd>longitude</dd><dt><span>units :</span></dt><dd>degrees_east</dd></dl></div><div class='xr-var-data'><pre>array([-71.5])</pre></div></li><li class='xr-var-item'><div class='xr-var-name'><span class='xr-has-index'>time</span></div><div class='xr-var-dims'>(time)</div><div class='xr-var-dtype'>datetime64[ns]</div><div class='xr-var-preview xr-preview'>1985-12-31 ... 1987-01-01</div><input id='attrs-9f7ce4e0-c6f4-486b-89f6-b48f8f0c9b9a' class='xr-var-attrs-in' type='checkbox' disabled><label for='attrs-9f7ce4e0-c6f4-486b-89f6-b48f8f0c9b9a' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-31636471-61f2-469d-a1a6-7024785edf36' class='xr-var-data-in' type='checkbox'><label for='data-31636471-61f2-469d-a1a6-7024785edf36' title='Show/Hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-var-attrs'><dl class='xr-attrs'></dl></div><div class='xr-var-data'><pre>array([&#x27;1985-12-31T00:00:00.000000000&#x27;, &#x27;1986-01-01T00:00:00.000000000&#x27;,\n",
" &#x27;1986-01-02T00:00:00.000000000&#x27;, ..., &#x27;1986-12-30T00:00:00.000000000&#x27;,\n",
" &#x27;1986-12-31T00:00:00.000000000&#x27;, &#x27;1987-01-01T00:00:00.000000000&#x27;],\n",
" dtype=&#x27;datetime64[ns]&#x27;)</pre></div></li></ul></div></li><li class='xr-section-item'><input id='section-0b7fadc9-beb8-401f-8709-2962edf0278b' class='xr-section-summary-in' type='checkbox' ><label for='section-0b7fadc9-beb8-401f-8709-2962edf0278b' class='xr-section-summary' >Indexes: <span>(3)</span></label><div class='xr-section-inline-details'></div><div class='xr-section-details'><ul class='xr-var-list'><li class='xr-var-item'><div class='xr-index-name'><div>latitude</div></div><div class='xr-index-preview'>PandasIndex</div><div></div><input id='index-b82b151d-2dd3-42b9-9e22-bc61aa213ea1' class='xr-index-data-in' type='checkbox'/><label for='index-b82b151d-2dd3-42b9-9e22-bc61aa213ea1' title='Show/Hide index repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-index-data'><pre>PandasIndex(Float64Index([48.5], dtype=&#x27;float64&#x27;, name=&#x27;latitude&#x27;))</pre></div></li><li class='xr-var-item'><div class='xr-index-name'><div>longitude</div></div><div class='xr-index-preview'>PandasIndex</div><div></div><input id='index-5fde8658-e71c-44e3-9452-d08dad6a2726' class='xr-index-data-in' type='checkbox'/><label for='index-5fde8658-e71c-44e3-9452-d08dad6a2726' title='Show/Hide index repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-index-data'><pre>PandasIndex(Float64Index([-71.5], dtype=&#x27;float64&#x27;, name=&#x27;longitude&#x27;))</pre></div></li><li class='xr-var-item'><div class='xr-index-name'><div>time</div></div><div class='xr-index-preview'>PandasIndex</div><div></div><input id='index-9022f398-18c3-4976-a6eb-9614516dcf49' class='xr-index-data-in' type='checkbox'/><label for='index-9022f398-18c3-4976-a6eb-9614516dcf49' title='Show/Hide index repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-index-data'><pre>PandasIndex(DatetimeIndex([&#x27;1985-12-31&#x27;, &#x27;1986-01-01&#x27;, &#x27;1986-01-02&#x27;, &#x27;1986-01-03&#x27;,\n",
" dtype=&#x27;datetime64[ns]&#x27;)</pre></div></li></ul></div></li><li class='xr-section-item'><input id='section-da74188b-af4e-4402-8269-aebd36881d1d' class='xr-section-summary-in' type='checkbox' ><label for='section-da74188b-af4e-4402-8269-aebd36881d1d' class='xr-section-summary' >Indexes: <span>(3)</span></label><div class='xr-section-inline-details'></div><div class='xr-section-details'><ul class='xr-var-list'><li class='xr-var-item'><div class='xr-index-name'><div>latitude</div></div><div class='xr-index-preview'>PandasIndex</div><div></div><input id='index-b7f2fce7-221b-4ad1-bd31-30677e950b5c' class='xr-index-data-in' type='checkbox'/><label for='index-b7f2fce7-221b-4ad1-bd31-30677e950b5c' title='Show/Hide index repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-index-data'><pre>PandasIndex(Float64Index([48.5], dtype=&#x27;float64&#x27;, name=&#x27;latitude&#x27;))</pre></div></li><li class='xr-var-item'><div class='xr-index-name'><div>longitude</div></div><div class='xr-index-preview'>PandasIndex</div><div></div><input id='index-56d79017-8132-4844-baa9-39ec5063d313' class='xr-index-data-in' type='checkbox'/><label for='index-56d79017-8132-4844-baa9-39ec5063d313' title='Show/Hide index repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-index-data'><pre>PandasIndex(Float64Index([-71.5], dtype=&#x27;float64&#x27;, name=&#x27;longitude&#x27;))</pre></div></li><li class='xr-var-item'><div class='xr-index-name'><div>time</div></div><div class='xr-index-preview'>PandasIndex</div><div></div><input id='index-e393a3e6-eec7-45cf-a452-d45f1afc38cc' class='xr-index-data-in' type='checkbox'/><label for='index-e393a3e6-eec7-45cf-a452-d45f1afc38cc' title='Show/Hide index repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-index-data'><pre>PandasIndex(DatetimeIndex([&#x27;1985-12-31&#x27;, &#x27;1986-01-01&#x27;, &#x27;1986-01-02&#x27;, &#x27;1986-01-03&#x27;,\n",
" &#x27;1986-01-04&#x27;, &#x27;1986-01-05&#x27;, &#x27;1986-01-06&#x27;, &#x27;1986-01-07&#x27;,\n",
" &#x27;1986-01-08&#x27;, &#x27;1986-01-09&#x27;,\n",
" ...\n",
" &#x27;1986-12-23&#x27;, &#x27;1986-12-24&#x27;, &#x27;1986-12-25&#x27;, &#x27;1986-12-26&#x27;,\n",
" &#x27;1986-12-27&#x27;, &#x27;1986-12-28&#x27;, &#x27;1986-12-29&#x27;, &#x27;1986-12-30&#x27;,\n",
" &#x27;1986-12-31&#x27;, &#x27;1987-01-01&#x27;],\n",
" dtype=&#x27;datetime64[ns]&#x27;, name=&#x27;time&#x27;, length=367, freq=None))</pre></div></li></ul></div></li><li class='xr-section-item'><input id='section-deb25bc5-d9b4-45ae-9c20-95ca34356cd3' class='xr-section-summary-in' type='checkbox' checked><label for='section-deb25bc5-d9b4-45ae-9c20-95ca34356cd3' class='xr-section-summary' >Attributes: <span>(3)</span></label><div class='xr-section-inline-details'></div><div class='xr-section-details'><dl class='xr-attrs'><dt><span>long_name :</span></dt><dd>Total precipitation</dd><dt><span>units :</span></dt><dd>m</dd><dt><span>grid_mapping :</span></dt><dd>crs</dd></dl></div></li></ul></div></div>"
" dtype=&#x27;datetime64[ns]&#x27;, name=&#x27;time&#x27;, length=367, freq=None))</pre></div></li></ul></div></li><li class='xr-section-item'><input id='section-b5387b36-9bd4-4a8b-b059-138c3f99a505' class='xr-section-summary-in' type='checkbox' checked><label for='section-b5387b36-9bd4-4a8b-b059-138c3f99a505' class='xr-section-summary' >Attributes: <span>(3)</span></label><div class='xr-section-inline-details'></div><div class='xr-section-details'><dl class='xr-attrs'><dt><span>long_name :</span></dt><dd>Total precipitation</dd><dt><span>units :</span></dt><dd>m</dd><dt><span>grid_mapping :</span></dt><dd>crs</dd></dl></div></li></ul></div></div>"
],
"text/plain": [
"<xarray.DataArray 'tp' (time: 367, latitude: 1, longitude: 1)>\n",
Expand Down Expand Up @@ -727,7 +727,7 @@
{
"data": {
"text/plain": [
"[<matplotlib.lines.Line2D at 0x7f0b917289a0>]"
"[<matplotlib.lines.Line2D at 0x7fd4e618da00>]"
]
},
"execution_count": 9,
Expand Down Expand Up @@ -755,7 +755,9 @@
"metadata": {},
"source": [
"### Here we will write the files to disk in a temporary folder since the root folder containing these notebooks is read-only.\n",
"You can change the path here to your own preferred path in your writable workspace. Alternatively, if you copy this notebook to your writable-workspace as shown in the introduction documentation, you can save just the filename (no absolute path) and the file will appear \"beside\" the notebooks, ready to be read by the next series of notebooks."
"You can change the path here to your own preferred path in your writable workspace. Alternatively, if you copy this notebook to your writable-workspace as shown in the introduction documentation, you can save just the filename (no absolute path) and the file will appear \"beside\" the notebooks, ready to be read by the next series of notebooks. \n",
"\n",
"For this case, you will want to use the second provided option in which all variables are stored in the same netcdf file. This will make the data much easier to find for Raven and prevent some errors, such as if Raven needs to calculate daily average temperature. This will be possible with all variables in the same file, but will cause an error if max and min temperature are in two seperate files."
]
},
{
Expand All @@ -764,6 +766,7 @@
"metadata": {},
"outputs": [],
"source": [
"# Option 1, which is not recommended to use in other notebooks but can be really useful in various other workflows:\n",
"with xr.set_options(keep_attrs=True):\n",
" # Write to disk.\n",
" tmp = Path(tempfile.mkdtemp())\n",
Expand All @@ -778,7 +781,7 @@
"metadata": {},
"outputs": [],
"source": [
"# We can also prepare a single file that merges all three variables into one netcdf file:\n",
"# Option 2, which is recommended, in which we prepare a single file that merges all three variables into one netcdf file:\n",
"with xr.set_options(keep_attrs=True):\n",
" xr.merge([ERA5_tmin, ERA5_tmax, ERA5_pr]).to_netcdf(tmp / \"ERA5_weather_data.nc\")"
]
Expand Down
Loading