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):
@property
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(
self, fieldname: str,
......
......@@ -81,6 +81,8 @@ class Grid(Feature):
values of the existing attributes with the same name in the file).
Use with caution in this context.
"""
_feature_geodimnames = 'y', 'x',
def __init__(self,
*args,
projection: 'Projection' = Projection(),
......@@ -103,10 +105,6 @@ class Grid(Feature):
self._std_dataset = self._std_dataset.squeeze(dim='time')
self._std_dataset.coords['time'] = ctime
@property
def _feature_geodimnames(self) -> Tuple[str, ...]:
return 'y', 'x'
def get_geocoord_dimnames(
self, fieldname: str,
values: 'xr.DataArray') -> Tuple[str, ...]:
......
......@@ -52,6 +52,8 @@ class GridTimeSeries(Feature):
values of the existing attributes with the same name in the file).
Use with caution in this context.
"""
_feature_geodimnames = 'time', 'y', 'x',
def __init__(self,
*args,
projection=Projection(),
......@@ -70,10 +72,6 @@ class GridTimeSeries(Feature):
"""Returns the iterator"""
return GridIterator(self)
@property
def _feature_geodimnames(self) -> Tuple[str, ...]:
return 'time', 'y', 'x',
@property
def _grid_class(self):
return Grid
......
......@@ -25,6 +25,8 @@ class Image(Feature):
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.
"""
_feature_geodimnames = 'row', 'cell',
def __init__(self, *args, **kwargs):
# create feature
super(Image, self).__init__(
......@@ -38,10 +40,6 @@ class Image(Feature):
self._std_dataset = self._std_dataset.squeeze(dim='time')
self._std_dataset.coords['time'] = ctime
@property
def _feature_geodimnames(self) -> Tuple[str, ...]:
return 'row', 'cell',
def get_geocoord_dimnames(
self, fieldname: str,
values: 'xr.DataArray') -> Tuple[str, ...]:
......
......@@ -54,13 +54,15 @@ class IMDCollection(Feature):
@property
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(
self, fieldname: str,
values: 'xr.DataArray') -> Tuple[str, ...]:
if fieldname in ['depth', 'height']:
return self.feature_class._instance_dimname, 'z',
return ((self.feature_class._instance_dimname,) +
self.feature_class._feature_geodimnames)
else:
return self.feature_class._instance_dimname
......
......@@ -54,12 +54,13 @@ class OMDCollection(Feature):
@property
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(
self, fieldname: str,
values: 'xr.DataArray') -> Tuple[str, ...]:
if fieldname in ['depth', 'height']:
return 'z',
return self.feature_class._feature_geodimnames
else:
return self.feature_class._instance_dimname
......@@ -23,15 +23,12 @@ class Point(Feature):
dimension: ``obs``.
"""
_instance_dimname = 'obs'
_feature_geodimnames = ()
def __init__(self, *args, **kwargs):
super(Point, self).__init__(*args, **kwargs)
self._std_dataset.attrs['featureType'] = 'point'
@property
def _feature_geodimnames(self):
return 'obs',
def get_geocoord_dimnames(self, *args, **kwargs):
return 'obs',
return ()
......@@ -26,6 +26,7 @@ class Profile(Feature):
dimension: ``profile``.
"""
_instance_dimname = 'profile'
_feature_geodimnames = 'z',
def __init__(self, *args, **kwargs):
super(Feature, self).__init__(*args, **kwargs)
......@@ -39,10 +40,6 @@ class Profile(Feature):
for _, v in self._std_dataset.data_vars.items():
v.attrs['coordinates'] = 'time lat lon z'
@property
def _feature_geodimnames(self):
return 'z',
def get_geocoord_dimnames(
self, fieldname: str,
values: 'xr.DataArray') -> Tuple[str, ...]:
......
......@@ -20,6 +20,8 @@ class Swath(Feature):
Feature class for representing a swath, a two-dimensional irregular grid
along the satellite track.
"""
_feature_geodimnames = 'row', 'cell',
def __init__(self, *args, **kwargs):
# create feature
super(Swath, self).__init__(
......@@ -27,10 +29,6 @@ class Swath(Feature):
**kwargs
)
@property
def _feature_geodimnames(self):
return 'row', 'cell',
def get_geocoord_dimnames(self, fieldname, shape=None):
if fieldname == 'depth':
return 'depth',
......
......@@ -24,6 +24,7 @@ class TimeSeries(Feature):
(except ``time`` for T axis coordinate).
"""
_instance_dimname = 'station'
_feature_geodimnames = 'time',
def __init__(self, *args, **kwargs):
super(TimeSeries, self).__init__(*args, **kwargs)
......@@ -35,10 +36,6 @@ class TimeSeries(Feature):
for _, v in self._std_dataset.data_vars.items():
v.attrs['coordinates'] = 'time lat lon z'
@property
def _feature_geodimnames(self) -> Tuple[str, ...]:
return 'time'
def get_geocoord_dimnames(
self, fieldname: str, *args, **kwargs) -> Tuple[str, ...]:
if (fieldname in STANDARD_Z_FIELD + ['lat', 'lon'] or
......
......@@ -24,6 +24,8 @@ class TimeSeriesProfile(Feature):
* ``time(profile)``
* ``depth/alt (profile, z)``
"""
_feature_geodimnames = 'profile', 'z',
def __init__(self, *args, **kwargs):
super(TimeSeriesProfile, self).__init__(*args, **kwargs)
......@@ -34,10 +36,6 @@ class TimeSeriesProfile(Feature):
for _, v in self._std_dataset.data_vars.items():
v.attrs['coordinates'] = 'time lat lon z'
@property
def _feature_geodimnames(self) -> Tuple[str, ...]:
return 'profile', 'z',
def get_geocoord_dimnames(
self, fieldname: str, *args, **kwargs) -> Tuple[str, ...]:
if fieldname in STANDARD_Z_FIELD or self.coords[fieldname].is_axis('Z'):
......@@ -59,10 +57,6 @@ class UniZTimeSeriesProfile(Feature):
* ``time(profile)``
* ``depth/alt (z)``
"""
@property
def _feature_geodimnames(self) -> Tuple[str, ...]:
return 'profile', 'z',
def get_geocoord_dimnames(
self, fieldname: str, *args, **kwargs) -> Tuple[str, ...]:
if fieldname in STANDARD_Z_FIELD or self.coords[fieldname].is_axis('Z'):
......
......@@ -22,9 +22,8 @@ class Trajectory(Feature):
``time(time)``, optionally ``z(time)``, all having a single geolocation
dimension: ``time``.
"""
@property
def _feature_geodimnames(self):
return 'time',
_instance_dimname = 'trajectory'
_feature_geodimnames = 'time',
def get_geocoord_dimnames(self, *args, **kwargs):
return 'time',
......
......@@ -22,6 +22,8 @@ class TrajectoryProfile(Feature):
``time(profile)``, ``depth/alt (profile, z)``, all having a single
geolocation dimension: ``profile`` (except ``z`` for Z axis coordinate).
"""
_feature_geodimnames = 'profile', 'z',
def __init__(self, *args, **kwargs):
super(TrajectoryProfile, self).__init__(*args, **kwargs)
......@@ -32,10 +34,6 @@ class TrajectoryProfile(Feature):
for _, v in self._std_dataset.data_vars.items():
v.attrs['coordinates'] = 'time lat lon z'
@property
def _feature_geodimnames(self) -> Tuple[str, ...]:
return 'profile', 'z',
def get_geocoord_dimnames(
self, fieldname: str, *args, **kwargs) -> Tuple[str, ...]:
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