Skip to content

Commit 4f31499

Browse files
author
Christoph Paulik
committed
Add Documentation about reading the time series format.
1 parent 55c65ad commit 4f31499

File tree

3 files changed

+35
-4
lines changed

3 files changed

+35
-4
lines changed

Diff for: README.rst

+15
Original file line numberDiff line numberDiff line change
@@ -143,3 +143,18 @@ Conversion to time series is performed by the `repurpose package
143143
or other options see the `repurpose documentation
144144
<http://repurpose.readthedocs.io/en/latest/>`_ and the code in
145145
``ecmwf_models.reshuffle``.
146+
147+
Reading converted time series data
148+
----------------------------------
149+
150+
For reading the data the ``ecmwf_repurpose`` command produces the class
151+
``ERAInterimTs`` can be used:
152+
153+
.. code-block:: python
154+
155+
from ecmwf_models.interface import ERAinterimTs
156+
ds = ERAinterimTs(ts_path)
157+
# read_ts takes either lon, lat coordinates or a grid point indices.
158+
# and returns a pandas.DataFrame
159+
ts = ds.read_ts(45, 15)
160+

Diff for: ecmwf_models/interface.py

+18
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
Interface to reading ecmwf reanalysis data.
2727
'''
2828
import warnings
29+
import os
2930

3031
try:
3132
import pygrib
@@ -36,6 +37,12 @@
3637
from pygeobase.object_base import Image
3738
import numpy as np
3839
from datetime import timedelta
40+
try:
41+
from pynetcf.time_series import GriddedNcOrthoMultiTs
42+
import pygeogrids
43+
except ImportError:
44+
warnings.warn(
45+
"For reading converted time series the pynetcf package is necessary.")
3946

4047

4148
class ERAInterimImg(ImageBase):
@@ -160,3 +167,14 @@ def tstamps_for_daterange(self, start_date, end_date):
160167
timestamps.extend(daily_dates.tolist())
161168

162169
return timestamps
170+
171+
172+
class ERAinterimTs(GriddedNcOrthoMultiTs):
173+
174+
def __init__(self, ts_path, grid_path=None):
175+
176+
if grid_path is None:
177+
grid_path = os.path.join(ts_path, "grid.nc")
178+
179+
grid = pygeogrids.netcdf.load_grid(grid_path)
180+
super(ERAinterimTs, self).__init__(ts_path, grid)

Diff for: tests/test_reshuffle.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@
3232
import numpy.testing as nptest
3333

3434
from ecmwf_models.reshuffle import main
35-
import pygeogrids
36-
from pynetcf.time_series import GriddedNcOrthoMultiTs
35+
from ecmwf_models.interface import ERAinterimTs
3736

3837

3938
def test_reshuffle():
@@ -48,8 +47,7 @@ def test_reshuffle():
4847
args = [inpath, ts_path, startdate, enddate] + parameters
4948
main(args)
5049
assert len(glob.glob(os.path.join(ts_path, "*.nc"))) == 2589
51-
grid = pygeogrids.netcdf.load_grid(os.path.join(ts_path, 'grid.nc'))
52-
ds = GriddedNcOrthoMultiTs(ts_path, grid)
50+
ds = ERAinterimTs(ts_path)
5351
ts = ds.read_ts(45, 15)
5452
ts_39_values_should = np.array([0.17183685, 0.17189026, 0.17173004,
5553
0.17175293, 0.17183685, 0.17189026,

0 commit comments

Comments
 (0)