Skip to content

Commit

Permalink
Manage RotatedPole defaults, fix typing (#455)
Browse files Browse the repository at this point in the history
<!-- Please ensure the PR fulfills the following requirements! -->
<!-- If this is your first PR, make sure to add your details to the
AUTHORS.rst! -->
### Pull Request Checklist:
- [x] This PR addresses an already opened issue (for bug fixes /
features)
    - This PR fixes #xyz
- [x] (If applicable) Documentation has been added / updated (for bug
fixes / features).
- [x] (If applicable) Tests have been added.
- [x] This PR does not seem to break the templates.
- [x] CHANGELOG.rst has been updated (with summary of main changes).
- [x] Link to issue (:issue:`number`) and pull request (:pull:`number`)
has been added.

### What kind of change does this PR introduce?

* `central_rotated_longitude` is kept as None if it is not in the
dataset attributes.
* Attributes are cast as floats before `ccrs.RotatedPole`.

### Does this PR introduce a breaking change?


### Other information:
  • Loading branch information
RondeauG authored Sep 18, 2024
2 parents 89ba7bd + 47e42b8 commit be76344
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Bug fixes
* ``unstack_dates`` now works correctly for yearly datasets when `winter_starts_year=True`, as well as multi-year datasets. (:pull:`450`).
* Fix ``xs.catalog.concat_data_catalogs`` for catalogs that have not been search yet. (:pull:`431`).
* Fix indicator computation using ``freq=2Q*`` by assuming this means a semiannual frequency anchored at the given month (pandas assumes 2 quarter steps, any of them anchored at the given month). (:pull:`431`).
* ``create_bounds_rotated_pole`` now uses the default value if the dataset has no `north_pole_grid_longitude` attribute, instead of crashing. (:pull:`455`).

Breaking changes
^^^^^^^^^^^^^^^^
Expand Down
9 changes: 5 additions & 4 deletions src/xscen/regrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,12 +370,13 @@ def create_bounds_rotated_pole(ds: xr.Dataset):
rlonv = rlonv1D.expand_dims(rlat_vertices=rlatv1D).transpose(
"rlon_vertices", "rlat_vertices"
)

central = ds.rotated_pole.attrs.get("north_pole_grid_longitude")
central = float(central) if central is not None else None
# Get cartopy's crs for the projection
RP = ccrs.RotatedPole(
pole_longitude=ds.rotated_pole.grid_north_pole_longitude,
pole_latitude=ds.rotated_pole.grid_north_pole_latitude,
central_rotated_longitude=ds.rotated_pole.north_pole_grid_longitude,
pole_longitude=float(ds.rotated_pole.grid_north_pole_longitude),
pole_latitude=float(ds.rotated_pole.grid_north_pole_latitude),
central_rotated_longitude=central,
)
PC = ccrs.PlateCarree()

Expand Down

0 comments on commit be76344

Please sign in to comment.