-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
getitem support for standard_name (#39)
* Update pre-commit * Rework getitem for standard_name support * Add datasets.py
- Loading branch information
Showing
4 changed files
with
226 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import numpy as np | ||
import xarray as xr | ||
|
||
airds = xr.tutorial.open_dataset("air_temperature").isel(time=slice(4), lon=slice(50)) | ||
airds.air.attrs["cell_measures"] = "area: cell_area" | ||
airds.air.attrs["standard_name"] = "air_temperature" | ||
airds.coords["cell_area"] = ( | ||
xr.DataArray(np.cos(airds.lat * np.pi / 180)) | ||
* xr.ones_like(airds.lon) | ||
* 105e3 | ||
* 110e3 | ||
) | ||
|
||
ds_no_attrs = airds.copy(deep=True) | ||
for variable in ds_no_attrs.variables: | ||
ds_no_attrs[variable].attrs = {} | ||
|
||
|
||
popds = xr.Dataset() | ||
popds.coords["TLONG"] = ( | ||
("nlat", "nlon"), | ||
np.ones((20, 30)), | ||
{"axis": "X", "units": "degrees_east"}, | ||
) | ||
popds.coords["TLAT"] = ( | ||
("nlat", "nlon"), | ||
2 * np.ones((20, 30)), | ||
{"axis": "Y", "units": "degrees_north"}, | ||
) | ||
popds.coords["ULONG"] = ( | ||
("nlat", "nlon"), | ||
0.5 * np.ones((20, 30)), | ||
{"axis": "X", "units": "degrees_east"}, | ||
) | ||
popds.coords["ULAT"] = ( | ||
("nlat", "nlon"), | ||
2.5 * np.ones((20, 30)), | ||
{"axis": "Y", "units": "degrees_north"}, | ||
) | ||
popds["UVEL"] = ( | ||
("nlat", "nlon"), | ||
np.ones((20, 30)) * 15, | ||
{"coordinates": "ULONG ULAT", "standard_name": "sea_water_x_velocity"}, | ||
) | ||
popds["TEMP"] = ( | ||
("nlat", "nlon"), | ||
np.ones((20, 30)) * 15, | ||
{"coordinates": "TLONG TLAT", "standard_name": "sea_water_potential_temperature"}, | ||
) |
Oops, something went wrong.