Commit 79655a61 authored by PIOLLE's avatar PIOLLE
Browse files

property changed to constant in all feature classes

parent c187e6ed
...@@ -56,7 +56,8 @@ class CRACollection(Feature): ...@@ -56,7 +56,8 @@ class CRACollection(Feature):
@property @property
def _feature_geodimnames(self): def _feature_geodimnames(self):
return self.feature_class._instance_dimname, 'z', return (self.feature_class._instance_dimname,) + \
self.feature_class._feature_geodimnames
def get_geocoord_dimnames( def get_geocoord_dimnames(
self, fieldname: str, self, fieldname: str,
......
...@@ -81,6 +81,8 @@ class Grid(Feature): ...@@ -81,6 +81,8 @@ class Grid(Feature):
values of the existing attributes with the same name in the file). values of the existing attributes with the same name in the file).
Use with caution in this context. Use with caution in this context.
""" """
_feature_geodimnames = 'y', 'x',
def __init__(self, def __init__(self,
*args, *args,
projection: 'Projection' = Projection(), projection: 'Projection' = Projection(),
...@@ -103,10 +105,6 @@ class Grid(Feature): ...@@ -103,10 +105,6 @@ class Grid(Feature):
self._std_dataset = self._std_dataset.squeeze(dim='time') self._std_dataset = self._std_dataset.squeeze(dim='time')
self._std_dataset.coords['time'] = ctime self._std_dataset.coords['time'] = ctime
@property
def _feature_geodimnames(self) -> Tuple[str, ...]:
return 'y', 'x'
def get_geocoord_dimnames( def get_geocoord_dimnames(
self, fieldname: str, self, fieldname: str,
values: 'xr.DataArray') -> Tuple[str, ...]: values: 'xr.DataArray') -> Tuple[str, ...]:
......
...@@ -52,6 +52,8 @@ class GridTimeSeries(Feature): ...@@ -52,6 +52,8 @@ class GridTimeSeries(Feature):
values of the existing attributes with the same name in the file). values of the existing attributes with the same name in the file).
Use with caution in this context. Use with caution in this context.
""" """
_feature_geodimnames = 'time', 'y', 'x',
def __init__(self, def __init__(self,
*args, *args,
projection=Projection(), projection=Projection(),
...@@ -70,10 +72,6 @@ class GridTimeSeries(Feature): ...@@ -70,10 +72,6 @@ class GridTimeSeries(Feature):
"""Returns the iterator""" """Returns the iterator"""
return GridIterator(self) return GridIterator(self)
@property
def _feature_geodimnames(self) -> Tuple[str, ...]:
return 'time', 'y', 'x',
@property @property
def _grid_class(self): def _grid_class(self):
return Grid return Grid
......
...@@ -25,6 +25,8 @@ class Image(Feature): ...@@ -25,6 +25,8 @@ class Image(Feature):
that we don't need a time value for each pixel or even scan line. A single that we don't need a time value for each pixel or even scan line. A single
time value is enough to describe it, as if it was an instant snapshot. time value is enough to describe it, as if it was an instant snapshot.
""" """
_feature_geodimnames = 'row', 'cell',
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
# create feature # create feature
super(Image, self).__init__( super(Image, self).__init__(
...@@ -38,10 +40,6 @@ class Image(Feature): ...@@ -38,10 +40,6 @@ class Image(Feature):
self._std_dataset = self._std_dataset.squeeze(dim='time') self._std_dataset = self._std_dataset.squeeze(dim='time')
self._std_dataset.coords['time'] = ctime self._std_dataset.coords['time'] = ctime
@property
def _feature_geodimnames(self) -> Tuple[str, ...]:
return 'row', 'cell',
def get_geocoord_dimnames( def get_geocoord_dimnames(
self, fieldname: str, self, fieldname: str,
values: 'xr.DataArray') -> Tuple[str, ...]: values: 'xr.DataArray') -> Tuple[str, ...]:
......
...@@ -54,13 +54,15 @@ class IMDCollection(Feature): ...@@ -54,13 +54,15 @@ class IMDCollection(Feature):
@property @property
def _feature_geodimnames(self): def _feature_geodimnames(self):
return self.feature_class._instance_dimname, 'z', return (self.feature_class._instance_dimname,) + \
self.feature_class._feature_geodimnames
def get_geocoord_dimnames( def get_geocoord_dimnames(
self, fieldname: str, self, fieldname: str,
values: 'xr.DataArray') -> Tuple[str, ...]: values: 'xr.DataArray') -> Tuple[str, ...]:
if fieldname in ['depth', 'height']: if fieldname in ['depth', 'height']:
return self.feature_class._instance_dimname, 'z', return ((self.feature_class._instance_dimname,) +
self.feature_class._feature_geodimnames)
else: else:
return self.feature_class._instance_dimname return self.feature_class._instance_dimname
......
...@@ -54,12 +54,13 @@ class OMDCollection(Feature): ...@@ -54,12 +54,13 @@ class OMDCollection(Feature):
@property @property
def _feature_geodimnames(self): def _feature_geodimnames(self):
return self.feature_class._instance_dimname, 'z', return (self.feature_class._instance_dimname,) + \
self.feature_class._feature_geodimnames
def get_geocoord_dimnames( def get_geocoord_dimnames(
self, fieldname: str, self, fieldname: str,
values: 'xr.DataArray') -> Tuple[str, ...]: values: 'xr.DataArray') -> Tuple[str, ...]:
if fieldname in ['depth', 'height']: if fieldname in ['depth', 'height']:
return 'z', return self.feature_class._feature_geodimnames
else: else:
return self.feature_class._instance_dimname return self.feature_class._instance_dimname
...@@ -23,15 +23,12 @@ class Point(Feature): ...@@ -23,15 +23,12 @@ class Point(Feature):
dimension: ``obs``. dimension: ``obs``.
""" """
_instance_dimname = 'obs' _instance_dimname = 'obs'
_feature_geodimnames = ()
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super(Point, self).__init__(*args, **kwargs) super(Point, self).__init__(*args, **kwargs)
self._std_dataset.attrs['featureType'] = 'point' self._std_dataset.attrs['featureType'] = 'point'
@property
def _feature_geodimnames(self):
return 'obs',
def get_geocoord_dimnames(self, *args, **kwargs): def get_geocoord_dimnames(self, *args, **kwargs):
return 'obs', return ()
...@@ -26,6 +26,7 @@ class Profile(Feature): ...@@ -26,6 +26,7 @@ class Profile(Feature):
dimension: ``profile``. dimension: ``profile``.
""" """
_instance_dimname = 'profile' _instance_dimname = 'profile'
_feature_geodimnames = 'z',
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super(Feature, self).__init__(*args, **kwargs) super(Feature, self).__init__(*args, **kwargs)
...@@ -39,10 +40,6 @@ class Profile(Feature): ...@@ -39,10 +40,6 @@ class Profile(Feature):
for _, v in self._std_dataset.data_vars.items(): for _, v in self._std_dataset.data_vars.items():
v.attrs['coordinates'] = 'time lat lon z' v.attrs['coordinates'] = 'time lat lon z'
@property
def _feature_geodimnames(self):
return 'z',
def get_geocoord_dimnames( def get_geocoord_dimnames(
self, fieldname: str, self, fieldname: str,
values: 'xr.DataArray') -> Tuple[str, ...]: values: 'xr.DataArray') -> Tuple[str, ...]:
......
...@@ -20,6 +20,8 @@ class Swath(Feature): ...@@ -20,6 +20,8 @@ class Swath(Feature):
Feature class for representing a swath, a two-dimensional irregular grid Feature class for representing a swath, a two-dimensional irregular grid
along the satellite track. along the satellite track.
""" """
_feature_geodimnames = 'row', 'cell',
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
# create feature # create feature
super(Swath, self).__init__( super(Swath, self).__init__(
...@@ -27,10 +29,6 @@ class Swath(Feature): ...@@ -27,10 +29,6 @@ class Swath(Feature):
**kwargs **kwargs
) )
@property
def _feature_geodimnames(self):
return 'row', 'cell',
def get_geocoord_dimnames(self, fieldname, shape=None): def get_geocoord_dimnames(self, fieldname, shape=None):
if fieldname == 'depth': if fieldname == 'depth':
return 'depth', return 'depth',
......
...@@ -24,6 +24,7 @@ class TimeSeries(Feature): ...@@ -24,6 +24,7 @@ class TimeSeries(Feature):
(except ``time`` for T axis coordinate). (except ``time`` for T axis coordinate).
""" """
_instance_dimname = 'station' _instance_dimname = 'station'
_feature_geodimnames = 'time',
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super(TimeSeries, self).__init__(*args, **kwargs) super(TimeSeries, self).__init__(*args, **kwargs)
...@@ -35,10 +36,6 @@ class TimeSeries(Feature): ...@@ -35,10 +36,6 @@ class TimeSeries(Feature):
for _, v in self._std_dataset.data_vars.items(): for _, v in self._std_dataset.data_vars.items():
v.attrs['coordinates'] = 'time lat lon z' v.attrs['coordinates'] = 'time lat lon z'
@property
def _feature_geodimnames(self) -> Tuple[str, ...]:
return 'time'
def get_geocoord_dimnames( def get_geocoord_dimnames(
self, fieldname: str, *args, **kwargs) -> Tuple[str, ...]: self, fieldname: str, *args, **kwargs) -> Tuple[str, ...]:
if (fieldname in STANDARD_Z_FIELD + ['lat', 'lon'] or if (fieldname in STANDARD_Z_FIELD + ['lat', 'lon'] or
......
...@@ -24,6 +24,8 @@ class TimeSeriesProfile(Feature): ...@@ -24,6 +24,8 @@ class TimeSeriesProfile(Feature):
* ``time(profile)`` * ``time(profile)``
* ``depth/alt (profile, z)`` * ``depth/alt (profile, z)``
""" """
_feature_geodimnames = 'profile', 'z',
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super(TimeSeriesProfile, self).__init__(*args, **kwargs) super(TimeSeriesProfile, self).__init__(*args, **kwargs)
...@@ -34,10 +36,6 @@ class TimeSeriesProfile(Feature): ...@@ -34,10 +36,6 @@ class TimeSeriesProfile(Feature):
for _, v in self._std_dataset.data_vars.items(): for _, v in self._std_dataset.data_vars.items():
v.attrs['coordinates'] = 'time lat lon z' v.attrs['coordinates'] = 'time lat lon z'
@property
def _feature_geodimnames(self) -> Tuple[str, ...]:
return 'profile', 'z',
def get_geocoord_dimnames( def get_geocoord_dimnames(
self, fieldname: str, *args, **kwargs) -> Tuple[str, ...]: self, fieldname: str, *args, **kwargs) -> Tuple[str, ...]:
if fieldname in STANDARD_Z_FIELD or self.coords[fieldname].is_axis('Z'): if fieldname in STANDARD_Z_FIELD or self.coords[fieldname].is_axis('Z'):
...@@ -59,10 +57,6 @@ class UniZTimeSeriesProfile(Feature): ...@@ -59,10 +57,6 @@ class UniZTimeSeriesProfile(Feature):
* ``time(profile)`` * ``time(profile)``
* ``depth/alt (z)`` * ``depth/alt (z)``
""" """
@property
def _feature_geodimnames(self) -> Tuple[str, ...]:
return 'profile', 'z',
def get_geocoord_dimnames( def get_geocoord_dimnames(
self, fieldname: str, *args, **kwargs) -> Tuple[str, ...]: self, fieldname: str, *args, **kwargs) -> Tuple[str, ...]:
if fieldname in STANDARD_Z_FIELD or self.coords[fieldname].is_axis('Z'): if fieldname in STANDARD_Z_FIELD or self.coords[fieldname].is_axis('Z'):
......
...@@ -22,9 +22,8 @@ class Trajectory(Feature): ...@@ -22,9 +22,8 @@ class Trajectory(Feature):
``time(time)``, optionally ``z(time)``, all having a single geolocation ``time(time)``, optionally ``z(time)``, all having a single geolocation
dimension: ``time``. dimension: ``time``.
""" """
@property _instance_dimname = 'trajectory'
def _feature_geodimnames(self): _feature_geodimnames = 'time',
return 'time',
def get_geocoord_dimnames(self, *args, **kwargs): def get_geocoord_dimnames(self, *args, **kwargs):
return 'time', return 'time',
......
...@@ -22,6 +22,8 @@ class TrajectoryProfile(Feature): ...@@ -22,6 +22,8 @@ class TrajectoryProfile(Feature):
``time(profile)``, ``depth/alt (profile, z)``, all having a single ``time(profile)``, ``depth/alt (profile, z)``, all having a single
geolocation dimension: ``profile`` (except ``z`` for Z axis coordinate). geolocation dimension: ``profile`` (except ``z`` for Z axis coordinate).
""" """
_feature_geodimnames = 'profile', 'z',
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super(TrajectoryProfile, self).__init__(*args, **kwargs) super(TrajectoryProfile, self).__init__(*args, **kwargs)
...@@ -32,10 +34,6 @@ class TrajectoryProfile(Feature): ...@@ -32,10 +34,6 @@ class TrajectoryProfile(Feature):
for _, v in self._std_dataset.data_vars.items(): for _, v in self._std_dataset.data_vars.items():
v.attrs['coordinates'] = 'time lat lon z' v.attrs['coordinates'] = 'time lat lon z'
@property
def _feature_geodimnames(self) -> Tuple[str, ...]:
return 'profile', 'z',
def get_geocoord_dimnames( def get_geocoord_dimnames(
self, fieldname: str, *args, **kwargs) -> Tuple[str, ...]: self, fieldname: str, *args, **kwargs) -> Tuple[str, ...]:
if fieldname in ['lat', 'lon', 'time']: if fieldname in ['lat', 'lon', 'time']:
......
import numpy as np
import xarray as xr
from cerbere.feature.point import Point
from cerbere.feature.imdcollection import IMDCollection
from .test_feature import TestFeature
class TestIMDCollectionProfileFeature(TestFeature):
"""Test class for incomplete multidimensional collection of profile
features"""
def __init__(self, methodName="runTest"):
super().__init__(methodName)
def get_feature_class(self):
return IMDCollection
def get_feature(self, *args, **kwargs):
return self.get_feature_class()(
*args, feature_class=Point, **kwargs
)
def define_base_feature(self):
# creates a test xarray object
lon = xr.DataArray(data=[100., 100], dims=['obs'])
lat = xr.DataArray(data=[50., 50], dims=['obs'])
time = xr.DataArray(
[np.datetime64('2018-01-01 00:00:00'),
np.datetime64('2018-01-01 00:00:00')],
dims=['obs']
)
var = xr.DataArray(
data=np.ones(shape=(2,)),
dims=['obs',],
attrs={'myattr': 'test_attr_val'}
)
xrdataset = xr.Dataset(
coords={'lat': lat, 'lon': lon, 'time': time},
data_vars={'myvar': var},
attrs={'gattr1': 'gattr1_val', 'gattr2': 'gattr2_val'}
)
return IMDCollection(xrdataset, feature_class=Point)
def get_feature_dimnames(self):
return 'obs',
def get_feature_dimsizes(self):
return 2,
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment