Skip to content

Commit

Permalink
Prepare for new release (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
wpreimes authored Sep 20, 2019
1 parent d8702ee commit c5519ec
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 58 deletions.
7 changes: 6 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@ Changelog

Unreleased
==========
-

Version 0.6
===========

- Add support for downloading, reading, reshuffling era5-land
- Add support for reading, reshuffling points over land only
- Add support for reading, reshuffling points over land only (era5 and era5-land)
- Add function to create land definition files
- Test with pinned environments

Expand Down
2 changes: 1 addition & 1 deletion docs/ts_read.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ can be passed as well:

.. code-block:: python
from ecmwf_models.interface import ERATs
from ecmwf_models import ERATs
ds = ERATs(ts_path, ioclass_kws={'read_bulk':True}) # read_bulk reads full files into memory
# read_ts takes either lon, lat coordinates to perform a nearest neighbour search
# or a grid point index (from the grid.nc file) and returns a pandas.DataFrame.
Expand Down
4 changes: 3 additions & 1 deletion ecmwf_models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@
try:
__version__ = pkg_resources.get_distribution(__name__).version
except:
__version__ = 'unknown'
__version__ = 'unknown'

from ecmwf_models.interface import ERATs
13 changes: 7 additions & 6 deletions ecmwf_models/era5/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,20 +244,21 @@ def parse_args(args):
help=("Enddate in format YYYY-MM-DD. "
"If not given then the current date is used."))
parser.add_argument("-p", "--product", type=str, default='ERA5',
help=("Choose either ERA5 or ERA5-Land. Default is ERA5."))
help=("The ERA5 product to download. Choose either ERA5 or ERA5-Land. Default is ERA5."))
parser.add_argument("-var", "--variables", metavar="variables", type=str, default=None,
nargs="+",
help=("Name of variables to download. If None are passed, we use the default ones from the"
"era5_lut.csv and era5-land_lut.csv files."
help=("Name of variables to download. If None are passed, we use the default ones from the "
"era5_lut.csv resp. era5-land_lut.csv files in this package. "
"See the ERA5/ERA5-LAND documentation for more variable names: "
" https://confluence.ecmwf.int/display/CKB/ERA5+data+documentation "
" https://confluence.ecmwf.int/display/CKB/ERA5-Land+data+documentation"))
parser.add_argument("-keep", "--keep_original", type=str2bool, default='False',
help=("Keep the originally, temporally downloaded file as it is instread of deleting it afterwards"))
help=("Also keep the originally, temporarily downloaded image stack instead of deleting it "
"after extracting single images. Default is False."))
parser.add_argument("-grb", "--as_grib", type=str2bool, default='False',
help=("Download data in grib format, instead of the default netcdf format"))
help=("Download data in grib format instead of netcdf. Default is False."))
parser.add_argument("--h_steps", type=int, default=[0,6,12,18], nargs='+',
help=("Manually change the temporal resolution of downloaded images."
help=("Temporal resolution of downloaded images. "
"Pass a set of full hours here, like '--h_steps 0 12'. "
"By default 6H images (starting at 0:00 UTC, i.e. 0 6 12 18) will be downloaded"))

Expand Down
8 changes: 4 additions & 4 deletions ecmwf_models/era5/reshuffle.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,14 +161,14 @@ def parse_args(args):
"See documentation on image download for resp. ERA products, "
"for more information on variable names of the product. "))
parser.add_argument("--land_points", type=str2bool, default='False',
help=("Store only time series for points that are over land"))
help=("Store only time series for points that are over land. Default is False."))
parser.add_argument("--h_steps", type=int, default=None, nargs='+',
help=("Time steps (full hours) of images that will be reshuffled (must be in the images). "
"By default 6H images (starting at 0:00 UTC) will be reshuffled."))
"By default 6H images (starting at 0:00 UTC) will be reshuffled: 0 6 12 18"))
parser.add_argument("--imgbuffer", type=int, default=50,
help=("How many images to read at once. Bigger numbers make the "
"conversion faster but consume more memory. Choose this according to your "
"system and the size of a single image."))
"system and the size of a single image. Default is 50."))
args = parser.parse_args(args)

print("Converting ERA5/ERA5-Land data from {} to {} into {}."
Expand All @@ -191,4 +191,4 @@ def main(args):


def run():
main(sys.argv[1:])
main(sys.argv[1:])
86 changes: 43 additions & 43 deletions ecmwf_models/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@
except ImportError:
warnings.warn("pygrib has not been imported")

'''
Base classes for reading downloaded ERA netcdf and grib images and 6H image stacks
'''
"""
Base classes for reading downloaded ERA netcdf and grib images and stacks
"""


class ERANcImg(ImageBase):
"""
Expand All @@ -54,7 +55,7 @@ class ERANcImg(ImageBase):
'era5' or 'era5-land' or 'eraint'
parameter: list or str, optional (default: ['swvl1', 'swvl2'])
Name of parameters to read from the image file.
subgrid: pygeogrids.CellGrid, optional (default:None)
subgrid: pygeogrids.CellGrid, optional (default: None)
Read only data for points of this grid and not global values.
mask_seapoints : bool, optional (default: False)
Read the land-sea mask to mask points over water and set them to nan.
Expand Down Expand Up @@ -86,14 +87,14 @@ def __init__(self, filename, product, parameter=['swvl1', 'swvl2'],
"equal number of points in each line")

def read(self, timestamp=None):
'''
"""
Read data from the loaded image file.
Parameters
---------
timestamp : datetime, optional (default: None)
Specific date (time) to read the data for.
'''
"""
return_img = {}
return_metadata = {}

Expand Down Expand Up @@ -186,7 +187,7 @@ class ERANcDs(MultiTemporalImageBase):
Read only data for points of this grid and not global values.
mask_seapoints : bool, optional (default: False)
Use the land-sea-mask parameter in the file to mask points over water.
h_step : list, optional (default: [0,6,12,18])
h_steps : list, optional (default: [0,6,12,18])
List of full hours for which images exist.
array_1D: bool, optional (default: False)
Read data as list, instead of 2D array, used for reshuffling.
Expand Down Expand Up @@ -439,42 +440,41 @@ def tstamps_for_daterange(self, start_date, end_date):
return timestamps

class ERATs(GriddedNcOrthoMultiTs):
'''
Time series reader for all reshuffled ERA reanalysis products in time
series format.
Use the read_ts(lon, lat) resp. read_ts(gpi) function of this class
to read data for locations (gpi or latlon)!
Parameters
----------
ts_path : str
Directory where the netcdf time series files are stored
grid_path : str, optional (default: None)
Path to grid file, that is used to organize the location of time
series to read. If None is passed, grid.nc is searched for in the
ts_path.
Optional keyword arguments that are passed to the Gridded Base when used:
------------------------------------------------------------------------
parameters : list, optional (default: None)
Specific variable names to read, if None are selected, all are read.
offsets : dict, optional (default: None)
Offsets (values) that are added to the parameters (keys)
scale_factors : dict, optional (default: None)
Offset (value) that the parameters (key) is multiplied with
ioclass_kws: dict, (optional)
Optional keyword arguments, passed to the OrthoMultiTs class when used:
----------------------------------------------------------------
read_bulk : boolean, optional (default: False)
If set to True, the data of all locations is read into memory,
and subsequent calls to read_ts then read from cache and
not from disk. This makes reading complete files faster.
read_dates : boolean, optional (default: False)
If false, dates will not be read automatically but only on
specific request useable for bulk reading because currently
the netCDF num2date routine is very slow for big datasets.
'''
"""
Time series reader for all reshuffled ERA reanalysis products in time
series format.
Use the read_ts(lon, lat) resp. read_ts(gpi) function of this class
to read data for locations!
Parameters
----------
ts_path : str
Directory where the netcdf time series files are stored
grid_path : str, optional (default: None)
Path to grid file, that is used to organize the location of time
series to read. If None is passed, grid.nc is searched for in the
ts_path.
Optional keyword arguments that are passed to the Gridded Base when used:
------------------------------------------------------------------------
parameters : list, optional (default: None)
Specific variable names to read, if None are selected, all are read.
offsets : dict, optional (default: None)
Offsets (values) that are added to the parameters (keys)
scale_factors : dict, optional (default: None)
Offset (value) that the parameters (key) is multiplied with
ioclass_kws: dict, (optional)
Optional keyword arguments, passed to the OrthoMultiTs class when used:
----------------------------------------------------------------
read_bulk : boolean, optional (default: False)
If set to True, the data of all locations is read into memory,
and subsequent calls to read_ts then read from cache and
not from disk. This makes reading complete files faster.
read_dates : boolean, optional (default: False)
If false, dates will not be read automatically but only on
specific request useable for bulk reading because currently
the netCDF num2date routine is very slow for big datasets.
"""
def __init__(self, ts_path, grid_path=None, **kwargs):

if grid_path is None:
Expand Down
2 changes: 1 addition & 1 deletion tests/tests_era5/test_era5_reshuffle.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import numpy.testing as nptest

from ecmwf_models.era5.reshuffle import main
from ecmwf_models.interface import ERATs
from ecmwf_models import ERATs
import shutil

def test_ERA5_reshuffle_nc():
Expand Down
2 changes: 1 addition & 1 deletion tests/tests_eraint/test_eraint_reshuffle.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import numpy.testing as nptest

from ecmwf_models.erainterim.reshuffle import main
from ecmwf_models.interface import ERATs
from ecmwf_models import ERATs
import shutil

def test_ERAInterim_reshuffle_grb():
Expand Down

0 comments on commit c5519ec

Please sign in to comment.