From cc3d294e1606633a05776ed92eebf9175f6d47a6 Mon Sep 17 00:00:00 2001 From: Ray Bell Date: Fri, 21 Jul 2017 06:48:00 -0400 Subject: [PATCH] Update for in xarray interface (#87) fixes #85 * Replaced deprecated xr.Coordinate with xr.IndexVariable. * Fixed #85. * Update xarray.py Update visual indent on xr.IndexVariable lines * Update reference.py Updated deprecated xr.Coordinate with xr.IndexVariable --- lib/eofs/tests/reference.py | 8 ++++---- lib/eofs/xarray.py | 38 ++++++++++++++++++------------------- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/lib/eofs/tests/reference.py b/lib/eofs/tests/reference.py index 3291250..0a45b03 100644 --- a/lib/eofs/tests/reference.py +++ b/lib/eofs/tests/reference.py @@ -194,10 +194,10 @@ def _wrap_xarray(solution, neofs, time_units): except ImportError: raise ValueError("cannot use container 'xarray' without " "the xarray/xray module") - time_dim = xr.Coordinate('time', solution['time']) - lat_dim = xr.Coordinate('latitude', solution['latitude']) - lon_dim = xr.Coordinate('longitude', solution['longitude']) - eof_dim = xr.Coordinate('eof', np.arange(1, neofs+1)) + time_dim = xr.IndexVariable('time', solution['time']) + lat_dim = xr.IndexVariable('latitude', solution['latitude']) + lon_dim = xr.IndexVariable('longitude', solution['longitude']) + eof_dim = xr.IndexVariable('eof', np.arange(1, neofs+1)) solution['sst'] = xr.DataArray(solution['sst'], coords=[time_dim, lat_dim, lon_dim]) solution['eigenvalues'] = xr.DataArray(solution['eigenvalues'], diff --git a/lib/eofs/xarray.py b/lib/eofs/xarray.py index d3a49ed..e893f61 100644 --- a/lib/eofs/xarray.py +++ b/lib/eofs/xarray.py @@ -174,8 +174,8 @@ def pcs(self, pcscaling=0, npcs=None): """ pcs = self._solver.pcs(pcscaling, npcs) - pcdim = xr.Coordinate('mode', range(pcs.shape[1]), - attrs={'long_name': 'eof_mode_number'}) + pcdim = xr.IndexVariable('mode', range(pcs.shape[1]), + attrs={'long_name': 'eof_mode_number'}) coords = [self._time, pcdim] pcs = xr.DataArray(pcs, coords=coords, name='pcs') pcs.coords.update({coord.name: ('time', coord) @@ -220,8 +220,8 @@ def eofs(self, eofscaling=0, neofs=None): """ eofs = self._solver.eofs(eofscaling, neofs) - eofdim = xr.Coordinate('mode', range(eofs.shape[0]), - attrs={'long_name': 'eof_mode_number'}) + eofdim = xr.IndexVariable('mode', range(eofs.shape[0]), + attrs={'long_name': 'eof_mode_number'}) coords = [eofdim] + self._coords long_name = 'empirical_orthogonal_functions' eofs = xr.DataArray(eofs, coords=coords, name='eofs', @@ -267,8 +267,8 @@ def eofsAsCorrelation(self, neofs=None): """ eofs = self._solver.eofsAsCorrelation(neofs) - eofdim = xr.Coordinate('mode', range(eofs.shape[0]), - attrs={'long_name': 'eof_mode_number'}) + eofdim = xr.IndexVariable('mode', range(eofs.shape[0]), + attrs={'long_name': 'eof_mode_number'}) coords = [eofdim] + self._coords long_name = 'correlation_between_pcs_and_{!s}'.format(self._name) eofs = xr.DataArray(eofs, coords=coords, name='eofs', @@ -327,8 +327,8 @@ def eofsAsCovariance(self, neofs=None, pcscaling=1): """ eofs = self._solver.eofsAsCovariance(neofs, pcscaling) - eofdim = xr.Coordinate('mode', range(eofs.shape[0]), - attrs={'long_name': 'eof_mode_number'}) + eofdim = xr.IndexVariable('mode', range(eofs.shape[0]), + attrs={'long_name': 'eof_mode_number'}) coords = [eofdim] + self._coords long_name = 'covariance_between_pcs_and_{!s}'.format(self._name) eofs = xr.DataArray(eofs, coords=coords, name='eofs', @@ -367,8 +367,8 @@ def eigenvalues(self, neigs=None): """ lambdas = self._solver.eigenvalues(neigs=neigs) - eofdim = xr.Coordinate('mode', range(lambdas.shape[0]), - attrs={'long_name': 'eof_mode_number'}) + eofdim = xr.IndexVariable('mode', range(lambdas.shape[0]), + attrs={'long_name': 'eof_mode_number'}) coords = [eofdim] long_name = 'eigenvalues' lambdas = xr.DataArray(lambdas, coords=coords, name='eigenvalues', @@ -409,8 +409,8 @@ def varianceFraction(self, neigs=None): """ vf = self._solver.varianceFraction(neigs=neigs) - eofdim = xr.Coordinate('mode', range(vf.shape[0]), - attrs={'long_name': 'eof_mode_number'}) + eofdim = xr.IndexVariable('mode', range(vf.shape[0]), + attrs={'long_name': 'eof_mode_number'}) coords = [eofdim] long_name = 'variance_fractions' vf = xr.DataArray(vf, coords=coords, name='variance_fractions', @@ -483,8 +483,8 @@ def northTest(self, neigs=None, vfscaled=False): """ typerrs = self._solver.northTest(neigs=neigs, vfscaled=vfscaled) - eofdim = xr.Coordinate('mode', range(typerrs.shape[0]), - attrs={'long_name': 'eof_mode_number'}) + eofdim = xr.IndexVariable('mode', range(typerrs.shape[0]), + attrs={'long_name': 'eof_mode_number'}) coords = [eofdim] long_name = 'typical_errors' typerrs = xr.DataArray(typerrs, coords=coords, name='typical_errors', @@ -621,15 +621,15 @@ def projectField(self, array, neofs=None, eofscaling=0, weighted=True): weighted=weighted) # Create the PCs DataArray. if pcs.ndim == 2: - pcdim = xr.Coordinate('mode', range(pcs.shape[1]), - attrs={'long_name': 'eof_mode_number'}) + pcdim = xr.IndexVariable('mode', range(pcs.shape[1]), + attrs={'long_name': 'eof_mode_number'}) pcs = xr.DataArray( pcs, coords=[time_coord, pcdim], name='pseudo_pcs', attrs={'long_name': '{}_pseudo_pcs'.format(array_name)}) else: - pcdim = xr.Coordinate('mode', range(pcs.shape[0]), - attrs={'long_name': 'eof_mode_number'}) + pcdim = xr.IndexVariable('mode', range(pcs.shape[0]), + attrs={'long_name': 'eof_mode_number'}) pcs = xr.DataArray( pcs, coords=[pcdim], name='pseudo_pcs', @@ -637,7 +637,7 @@ def projectField(self, array, neofs=None, eofscaling=0, weighted=True): if has_time: # Add non-dimension coordinates. pcs.coords.update({coord.name: (coord.dims, coord) - for coord in self._time_ndcoords}) + for coord in time_ndcoords}) return pcs def getWeights(self):