diff --git a/nes/load_nes.py b/nes/load_nes.py index e9bdcb1f71abf39442560b5dfdf3c0f049ea033f..c5e824004905a1eb5ec3c34c78499cf7125442c2 100644 --- a/nes/load_nes.py +++ b/nes/load_nes.py @@ -9,8 +9,8 @@ from nes.nc_projections.rotated_nes import RotatedNes from nes.nc_projections.latlon_nes import LatLonNes -def open_netcdf(path, comm=None, xarray=False, info=False, - avoid_first_hours=0, avoid_last_hours=0, parallel_method='Y'): +def open_netcdf(path, comm=None, xarray=False, info=False, parallel_method='Y', + avoid_first_hours=0, avoid_last_hours=0, first_level=0, last_level=None): """ Open a netCDF file @@ -52,21 +52,14 @@ def open_netcdf(path, comm=None, xarray=False, info=False, # Rotated if __is_rotated(dataset): - nessy = RotatedNes(comm=comm, - dataset=dataset, - xarray=xarray, - info=info, - avoid_first_hours=avoid_first_hours, - avoid_last_hours=avoid_last_hours, - parallel_method=parallel_method) + nessy = RotatedNes(comm=comm, dataset=dataset, xarray=xarray, info=info, parallel_method=parallel_method, + avoid_first_hours=avoid_first_hours, avoid_last_hours=avoid_last_hours, + first_level=first_level, last_level=last_level + ) else: - nessy = LatLonNes(comm=comm, - dataset=dataset, - xarray=xarray, - info=info, - avoid_first_hours=avoid_first_hours, - avoid_last_hours=avoid_last_hours, - parallel_method=parallel_method) + nessy = LatLonNes(comm=comm, dataset=dataset, xarray=xarray, info=info, parallel_method=parallel_method, + avoid_first_hours=avoid_first_hours, avoid_last_hours=avoid_last_hours, + first_level=first_level, last_level=last_level) return nessy diff --git a/nes/nc_projections/default_nes.py b/nes/nc_projections/default_nes.py index 9ca9c5f07472bc8c8a404c8b7efc6b15a89f39f2..6e4163aecadd76160f063e4db6c1cca685eb3b09 100644 --- a/nes/nc_projections/default_nes.py +++ b/nes/nc_projections/default_nes.py @@ -80,8 +80,8 @@ class Nes(object): _lon_dim : None, tuple Tuple with the name of the dimensions of the Longitude values """ - def __init__(self, comm=None, path=None, info=False, dataset=None, xarray=False, avoid_first_hours=0, - avoid_last_hours=0, parallel_method='Y'): + def __init__(self, comm=None, path=None, info=False, dataset=None, xarray=False, parallel_method='Y', + avoid_first_hours=0, avoid_last_hours=0, first_level=0, last_level=None): """ Initialize the Nes class @@ -118,8 +118,12 @@ class Nes(object): self.print_info = info self.is_xarray = xarray self.__ini_path = path + + # Selecting info self.hours_start = avoid_first_hours self.hours_end = avoid_last_hours + self.first_level = first_level + self.last_level = last_level # NetCDF object if dataset is not None: @@ -358,6 +362,16 @@ class Nes(object): else: raise NotImplementedError("Parallel method '{meth}' is not implemented. Use one of these: {accept}".format( meth=self.parallel_method, accept=['Y'])) + + # Verical levels selection: + axis_limits['z_min'] = self.first_level + if self.last_level == -1 or self.last_level is None: + self.last_level = None + elif self.last_level +1 == len(self._lev['data']): + self.last_level = None + else: + self.last_level += 1 + axis_limits['z_max'] = self.last_level return axis_limits def set_write_axis_limits(self): @@ -780,7 +794,7 @@ class Nes(object): netcdf4-python opened Dataset """ netcdf.createDimension('time', None) - netcdf.createDimension('lev', len(self._lev['data'])) + netcdf.createDimension('lev', len(self.lev['data'])) if self._time_bnds is not None: netcdf.createDimension('time_nv', 2) diff --git a/nes/nc_projections/latlon_nes.py b/nes/nc_projections/latlon_nes.py index 609d80111db9186a21c878fd3a0458dcd53bf0d9..d5ec6fb6a92dbca49ff590d1186163cf15c83a95 100644 --- a/nes/nc_projections/latlon_nes.py +++ b/nes/nc_projections/latlon_nes.py @@ -18,8 +18,8 @@ class LatLonNes(Nes): Tuple with the name of the dimensions of the Longitude values. ('lon',) for a regular latitude-longitude projection. """ - def __init__(self, comm=None, path=None, info=False, dataset=None, xarray=False, - avoid_first_hours=0, avoid_last_hours=0, parallel_method='Y'): + def __init__(self, comm=None, path=None, info=False, dataset=None, xarray=False, parallel_method='Y', + avoid_first_hours=0, avoid_last_hours=0, first_level=0, last_level=None): """ Initialize the LatLonNes class @@ -43,14 +43,10 @@ class LatLonNes(Nes): Indicates the parallelization method that you want. Default over Y axis accepted values: ['Y', 'T'] """ - super(LatLonNes, self).__init__(comm=comm, - path=path, - info=info, - dataset=dataset, - xarray=xarray, - avoid_first_hours=avoid_first_hours, - avoid_last_hours=avoid_last_hours, - parallel_method=parallel_method) + super(LatLonNes, self).__init__(comm=comm, path=path, info=info, dataset=dataset, + xarray=xarray, parallel_method=parallel_method, + avoid_first_hours=avoid_first_hours, avoid_last_hours=avoid_last_hours, + first_level=first_level, last_level=last_level) self._var_dim = ('lat', 'lon') self._lat_dim = ('lat',) diff --git a/nes/nc_projections/rotated_nes.py b/nes/nc_projections/rotated_nes.py index 812d5218ff40f45d2be4885abbe2497a9c11fea1..06984059c937fa405d35203c31769edbbf75944a 100644 --- a/nes/nc_projections/rotated_nes.py +++ b/nes/nc_projections/rotated_nes.py @@ -30,8 +30,8 @@ class RotatedNes(Nes): Tuple with the name of the dimensions of the Longitude values. ('rlat', 'rlon') for a rotated projection. """ - def __init__(self, comm=None, path=None, info=False, dataset=None, xarray=False, - avoid_first_hours=0, avoid_last_hours=0, parallel_method='Y'): + def __init__(self, comm=None, path=None, info=False, dataset=None, xarray=False, parallel_method='Y', + avoid_first_hours=0, avoid_last_hours=0, first_level=0, last_level=None): """ Initialize the RotatedNes class @@ -57,8 +57,9 @@ class RotatedNes(Nes): """ super(RotatedNes, self).__init__(comm=comm, path=path, info=info, dataset=dataset, - xarray=xarray, avoid_first_hours=avoid_first_hours, - avoid_last_hours=avoid_last_hours, parallel_method=parallel_method) + xarray=xarray, parallel_method=parallel_method, + avoid_first_hours=avoid_first_hours, avoid_last_hours=avoid_last_hours, + first_level=first_level, last_level=last_level) self._rlat = self._get_coordinate_dimension('rlat') self._rlon = self._get_coordinate_dimension('rlon')