Skip to content

Commit

Permalink
Merge pull request #4 from ecmwf-projects/feature/harmonise_with_cgul
Browse files Browse the repository at this point in the history
cgul harmonise method
  • Loading branch information
JamesVarndell authored Dec 16, 2022
2 parents d5f37d2 + b9ddc30 commit a7b84fe
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 7 deletions.
10 changes: 9 additions & 1 deletion emohawk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,17 @@ def to_numpy(self, *args, **kwargs):
def to_pandas(self, *args, **kwargs):
self._not_implemented()

def to_xarray(self, *args, **kwargs):
def _to_xarray(self, *args, **kwargs):
self._not_implemented()

def to_xarray(self, *args, harmonise=False, **kwargs):
xarray_object = self._to_xarray(self, *args, **kwargs)
if harmonise:
import cgul

xarray_object = cgul.harmonise(xarray_object)
return xarray_object

def to_netcdf(self, *args, **kwargs):
self._not_implemented()

Expand Down
4 changes: 2 additions & 2 deletions emohawk/readers/grib.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,15 +154,15 @@ def to_pandas(self, **kwargs):
"""
return self._xarray_wrapper(**self.__xarray_kwargs).to_pandas(**kwargs)

def to_xarray(self, **kwargs):
def _to_xarray(self, *args, **kwargs):
"""
Return an xarray representation of the data.
Returns
-------
xarray.core.dataarray.DataArray
"""
return self._xarray_wrapper(**self.__xarray_kwargs).to_xarray()
return self._xarray_wrapper(**self.__xarray_kwargs)._to_xarray()


def reader(path, magic=None, deeper_check=False):
Expand Down
4 changes: 2 additions & 2 deletions emohawk/readers/netcdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,15 @@ def to_pandas(self, **kwargs):
"""
return self._xarray_wrapper(**self.__xarray_kwargs).to_pandas(**kwargs)

def to_xarray(self, **kwargs):
def _to_xarray(self, *args, **kwargs):
"""
Return an xarray representation of the data.
Returns
-------
xarray.core.dataarray.DataArray
"""
return self._xarray_wrapper(**self.__xarray_kwargs).to_xarray()
return self._xarray_wrapper(**self.__xarray_kwargs)._to_xarray()

@classmethod
def to_xarray_multi_from_paths(cls, paths, **kwargs):
Expand Down
2 changes: 1 addition & 1 deletion emohawk/wrappers/pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def to_numpy(self, *args, **kwargs):
"""
return self.source.to_numpy(*args, **kwargs)

def to_xarray(self, *args, **kwargs):
def _to_xarray(self, *args, **kwargs):
"""
Return an xarray representation of the data.
Expand Down
2 changes: 1 addition & 1 deletion emohawk/wrappers/xarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def axis(self, axis):
raise ValueError(f"No coordinate found with axis '{axis}'")
return self.source.coords[coord]

def to_xarray(self):
def _to_xarray(self, *args, **kwargs):
"""
Return an xarray representation of the data.
Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ packages = find:
install_requires =
numpy
xarray
cgul


[flake8]
Expand Down

0 comments on commit a7b84fe

Please sign in to comment.