Skip to content

updated monthly mean averaging example using new virtual variable syntax #357

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

Merged
merged 1 commit into from
Mar 3, 2015
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
76 changes: 38 additions & 38 deletions doc/examples/monthly-means.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ different number of days.

numpy version : 1.9.1
pandas version : 0.15.2
xray version : 0.3.2
xray version : 0.4rc1-20-g52bbca3


Some calendar information so we can support any netCDF calendar.
Expand Down Expand Up @@ -99,7 +99,7 @@ Open the ``Dataset``
* depth (depth) int64 0 1 2
* x (x) int64 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 ...
* y (y) int64 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 ...
Variables:
Data variables:
Precipitation (time, y, x) float64 nan nan nan nan nan nan nan nan nan nan nan nan nan ...
Evap (time, y, x) float64 nan nan nan nan nan nan nan nan nan nan nan nan nan ...
Runoff (time, y, x) float64 nan nan nan nan nan nan nan nan nan nan nan nan nan ...
Expand Down Expand Up @@ -165,35 +165,35 @@ allong the time dimension.
.. parsed-literal::

<xray.Dataset>
Dimensions: (depth: 3, time.season: 4, x: 275, y: 205)
Dimensions: (depth: 3, season: 4, x: 275, y: 205)
Coordinates:
* depth (depth) int64 0 1 2
* x (x) int64 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 ...
* y (y) int64 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 ...
* time.season (time.season) int32 1 2 3 4
Variables:
Lwnet (time.season, y, x) float64 nan nan nan nan nan nan nan nan nan nan nan ...
Tair (time.season, y, x) float64 nan nan nan nan nan nan nan nan nan nan nan ...
Surft (time.season, y, x) float64 nan nan nan nan nan nan nan nan nan nan nan ...
Senht (time.season, y, x) float64 nan nan nan nan nan nan nan nan nan nan nan ...
Tsoil (time.season, depth, y, x) float64 nan nan nan nan nan nan nan nan nan ...
Netrad (time.season, y, x) float64 nan nan nan nan nan nan nan nan nan nan nan ...
Evap (time.season, y, x) float64 nan nan nan nan nan nan nan nan nan nan nan ...
Latht (time.season, y, x) float64 nan nan nan nan nan nan nan nan nan nan nan ...
Wind (time.season, y, x) float64 nan nan nan nan nan nan nan nan nan nan nan ...
Precipitation (time.season, y, x) float64 nan nan nan nan nan nan nan nan nan nan nan ...
Soilw (time.season, depth, y, x) float64 nan nan nan nan nan nan nan nan nan ...
Relhum (time.season, y, x) float64 nan nan nan nan nan nan nan nan nan nan nan ...
Swd (time.season, y, x) float64 nan nan nan nan nan nan nan nan nan nan nan ...
Swnet (time.season, y, x) float64 nan nan nan nan nan nan nan nan nan nan nan ...
Swq (time.season, y, x) float64 nan nan nan nan nan nan nan nan nan nan nan ...
Swin (time.season, y, x) float64 nan nan nan nan nan nan nan nan nan nan nan ...
Albedo (time.season, y, x) float64 nan nan nan nan nan nan nan nan nan nan nan ...
Lwin (time.season, y, x) float64 nan nan nan nan nan nan nan nan nan nan nan ...
Radt (time.season, y, x) float64 nan nan nan nan nan nan nan nan nan nan nan ...
Runoff (time.season, y, x) float64 nan nan nan nan nan nan nan nan nan nan nan ...
Grdht (time.season, y, x) float64 nan nan nan nan nan nan nan nan nan nan nan ...
Baseflow (time.season, y, x) float64 nan nan nan nan nan nan nan nan nan nan nan ...
* x (x) int64 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 ...
* depth (depth) int64 0 1 2
* season (season) object 'DJF' 'JJA' 'MAM' 'SON'
Data variables:
Baseflow (season, y, x) float64 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ...
Tsoil (season, depth, y, x) float64 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ...
Wind (season, y, x) float64 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ...
Swin (season, y, x) float64 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ...
Swq (season, y, x) float64 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ...
Netrad (season, y, x) float64 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ...
Albedo (season, y, x) float64 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ...
Evap (season, y, x) float64 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ...
Swd (season, y, x) float64 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ...
Radt (season, y, x) float64 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ...
Lwin (season, y, x) float64 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ...
Relhum (season, y, x) float64 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ...
Soilw (season, depth, y, x) float64 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ...
Lwnet (season, y, x) float64 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ...
Senht (season, y, x) float64 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ...
Surft (season, y, x) float64 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ...
Latht (season, y, x) float64 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ...
Runoff (season, y, x) float64 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ...
Tair (season, y, x) float64 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ...
Grdht (season, y, x) float64 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ...
Swnet (season, y, x) float64 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ...
Precipitation (season, y, x) float64 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ...


.. code:: python
Expand All @@ -204,23 +204,23 @@ allong the time dimension.
.. code:: python

# Quick plot to show the results
is_null = np.isnan(ds_weighted['Tair'][0].values)
is_null = np.isnan(ds_unweighted['Tair'][0].values)

fig, axes = plt.subplots(nrows=4, ncols=3, figsize=(14,12))
for i, season in enumerate(('DJF', 'MAM', 'JJA', 'SON')):
plt.sca(axes[i, 0])
plt.pcolormesh(np.ma.masked_where(is_null, ds_weighted['Tair'][i].values),
vmin=-30, vmax=30, cmap='Spectral_r')
plt.pcolormesh(np.ma.masked_where(is_null, ds_weighted['Tair'].sel(season=season).values),
vmin=-30, vmax=30, cmap='Spectral_r')
plt.colorbar(extend='both')

plt.sca(axes[i, 1])
plt.pcolormesh(np.ma.masked_where(is_null, ds_unweighted['Tair'][i].values),
vmin=-30, vmax=30, cmap='Spectral_r')
plt.pcolormesh(np.ma.masked_where(is_null, ds_unweighted['Tair'].sel(season=season).values),
vmin=-30, vmax=30, cmap='Spectral_r')
plt.colorbar(extend='both')

plt.sca(axes[i, 2])
plt.pcolormesh(np.ma.masked_where(is_null, ds_diff['Tair'][i].values),
vmin=-0.1, vmax=.1, cmap='RdBu_r')
plt.pcolormesh(np.ma.masked_where(is_null, ds_diff['Tair'].sel(season=season).values),
vmin=-0.1, vmax=.1, cmap='RdBu_r')
plt.colorbar(extend='both')
for j in range(3):
axes[i, j].axes.get_xaxis().set_ticklabels([])
Expand All @@ -230,7 +230,7 @@ allong the time dimension.
axes[i, 0].set_ylabel(season)

axes[0, 0].set_title('Weighted by DPM')
axes[0, 1].set_title('No Weighting')
axes[0, 1].set_title('Equal Weighting')
axes[0, 2].set_title('Difference')

plt.tight_layout()
Expand Down Expand Up @@ -259,4 +259,4 @@ allong the time dimension.
np.testing.assert_allclose(weights.groupby('time.season').sum().values, np.ones(4))

# Calculate the weighted average
return (ds * weights).groupby('time.season').sum(dim='time')
return (ds * weights).groupby('time.season').sum(dim='time')
Binary file modified doc/examples/monthly_means_output.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.