Skip to content

Commit

Permalink
Fix geo_stack and geo_distances
Browse files Browse the repository at this point in the history
  • Loading branch information
stefraynaud committed Jul 17, 2023
1 parent 64129cf commit e150ce8
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
22 changes: 22 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,28 @@ What's new
##########


In development (XXX-XX-XX)
==========================

New features
------------
- Add support for not creating multi-indexes in :func:`xoa.coords.geo_stack`.

Breaking changes
----------------

Deprecations
------------

Bug fixes
---------
- Fix :func:`xoa.coords.geo_distance` that was not able to handle multi-indexes
from :func:`xoa.coords.geo_stack`.

Documentation
-------------


0.7.0 (2023-07-17)
==================

Expand Down
2 changes: 1 addition & 1 deletion examples/plot_hycom_gdp.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
# %%
# Since the sampling is not that nice, we resample it to 3-hour intervals.

drifter = drifter.resample("3H").mean(numeric_only=True)
drifter = drifter.resample("3H").mean()

# %%
# We convert it to and :class:`xarray.Dataset`, fix the time coordinate and decode it.
Expand Down
10 changes: 8 additions & 2 deletions xoa/coords.py
Original file line number Diff line number Diff line change
Expand Up @@ -901,7 +901,9 @@ def get_binding_data_vars(ds, coord, as_names=False):
return out


def geo_stack(obj, stack_dim="npts", rename=False, drop=False, reset_index=False):
def geo_stack(
obj, stack_dim="npts", rename=False, drop=False, reset_index=False, create_index=False
):
"""Stack the dimensions of longitude and latitude coordinates
.. note:: If already stacked or similar, a simple copy is returned,
Expand All @@ -918,6 +920,10 @@ def geo_stack(obj, stack_dim="npts", rename=False, drop=False, reset_index=False
If no need to stack, rename the single dimension to `stack_dim`.
drop: bool
Drop all variables and coordinates that does not contain final stack dimension
reset_index: bool
Remove MultiIndexes that contains lon and lat dimensions before any operations
create_index: bool
Create a MultiIndex when calling :meth:`~xarray.DataArray.stack`
Return
------
Expand Down Expand Up @@ -963,7 +969,7 @@ def geo_stack(obj, stack_dim="npts", rename=False, drop=False, reset_index=False
stack_dim = dims[0]
obj = obj.copy()
else:
obj = obj.stack({stack_dim: dims})
obj = obj.stack({stack_dim: dims}, create_index=create_index)

# No multiindex?
if not singleton and reset_index and lon.name not in obj.coords:
Expand Down
1 change: 1 addition & 0 deletions xoa/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ def plot_flow(
Example
------
.. ipython:: python
:okwarning:
@suppress
import numpy as np, xarray as xr
Expand Down

0 comments on commit e150ce8

Please sign in to comment.