Skip to content

Commit

Permalink
Update for in xarray interface (ajdawson#87) fixes ajdawson#85
Browse files Browse the repository at this point in the history
* Replaced deprecated xr.Coordinate with xr.IndexVariable.
* Fixed ajdawson#85.

* Update xarray.py

Update visual indent on xr.IndexVariable lines

* Update reference.py

Updated deprecated xr.Coordinate with xr.IndexVariable
  • Loading branch information
Ray Bell authored and ajdawson committed Jul 21, 2017
1 parent a00c4e9 commit cc3d294
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 23 deletions.
8 changes: 4 additions & 4 deletions lib/eofs/tests/reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down
38 changes: 19 additions & 19 deletions lib/eofs/xarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -621,23 +621,23 @@ 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',
attrs={'long_name': '{}_pseudo_pcs'.format(array_name)})
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):
Expand Down

0 comments on commit cc3d294

Please sign in to comment.