Commit cacf1af9 authored by PIOLLE's avatar PIOLLE
Browse files

added class for SARAL data

parent 67d15839
# -*- coding: utf-8 -*-
"""
:mod:`~cerbere.dataset` class to read WHALES netCDF files
Cerbere Dataset class to read WHALES netCDF files
"""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import datetime
import logging
import xarray as xr
import numpy as np
from cerbere.dataset.dataset import Dataset
......@@ -30,6 +30,7 @@ class WHALESNCDataset(Dataset):
**kwargs)
def _transform(self):
self._std_dataset = self._std_dataset.squeeze('records')
self._std_dataset['time'].attrs['units'] = self.time_units
self._std_dataset = xr.decode_cf(self._std_dataset)
......@@ -37,3 +38,34 @@ class WHALESNCDataset(Dataset):
return super(WHALESNCDataset, self)._transform()
class SARALvTWHALESNCDataset(WHALESNCDataset):
def _transform(self):
# fix invalid times
self._std_dataset.time[:] = np.ma.masked_greater(
self._std_dataset.time.values, 1e19, copy=False)
# squeeze records dimension
self._std_dataset = self._std_dataset.rename_dims({'time': 'time_old'})
self._std_dataset = self._std_dataset.stack(
time_dim=('time_old', 'records'))
self._std_dataset = self._std_dataset.drop(['time_dim'])
self._std_dataset = self._std_dataset.swap_dims(
{'time_dim': 'time'})
# add time units
self._std_dataset['time'].attrs['units'] = self.time_units
self._std_dataset = xr.decode_cf(self._std_dataset)
return super(WHALESNCDataset, self)._transform()
def get_values(self, fieldname, *args, **kwargs):
"""fix fill values"""
values = super(WHALESNCDataset, self).get_values(
fieldname, *args, **kwargs)
if fieldname in ['lat', 'lon']:
values = np.ma.masked_greater_equal(values, 2147483647, copy=False)
elif fieldname != 'time':
values = np.ma.masked_greater(values, 1e19, copy=False)
return values
......@@ -33,6 +33,7 @@ setup(
entry_points={
'cerbere.plugins': [
'WHALESNCDataset = cerberecontrib_whales.dataset.whalesncdataset:WHALESNCDataset',
'SARALvTWHALESNCDataset = cerberecontrib_whales.dataset.whalesncdataset:SARALvTWHALESNCDataset',
]
},
platforms='any',
......
......@@ -23,7 +23,7 @@ class SARALvTWHALESNCDatasetChecker(Checker, unittest.TestCase):
@classmethod
def dataset(cls):
"""Return the mapper class name"""
return 'WHALESNCDataset'
return 'SARALvTWHALESNCDataset'
@classmethod
def feature(cls):
......@@ -33,7 +33,7 @@ class SARALvTWHALESNCDatasetChecker(Checker, unittest.TestCase):
@classmethod
def test_file(cls):
"""Return the name of the test file for this test"""
return "SRL_GPS_2PTP126_0015_20190101_042030_20190101_051048.CNES.nc.nc"
return "SRL_GPS_2PTP126_0015_20190101_042030_20190101_051048.CNES.nc"
@classmethod
def download_url(cls):
......
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