diff --git a/nes/nc_projections/default_nes.py b/nes/nc_projections/default_nes.py index 8edaa24a9643cdd6286326c075c3600a64bcd75e..aac531c4272abf692649944ce9aef7342becc72e 100644 --- a/nes/nc_projections/default_nes.py +++ b/nes/nc_projections/default_nes.py @@ -157,6 +157,7 @@ class Nes(object): # Complete dimensions self._time = times self._time_bnds = self.__get_time_bnds(create_nes) + self._lat_bnds, self._lon_bnds = self.__get_coordinates_bnds(create_nes) self._lev = {'data': np.array([0]), 'units': '', 'positive': 'up'} @@ -169,6 +170,7 @@ class Nes(object): self.time = self._time[self.read_axis_limits['t_min']:self.read_axis_limits['t_max']] self.time_bnds = self._time_bnds self.lev = deepcopy(self._lev) + self.lat_bnds, self.lon_bnds = self._lat_bnds, self._lon_bnds # Set NetCDF attributes self.global_attrs = self.__get_global_attributes(create_nes) @@ -199,6 +201,7 @@ class Nes(object): self._lev = self._get_coordinate_dimension(['lev', 'level', 'lm', 'plev']) self._lat = self._get_coordinate_dimension(['lat', 'latitude']) self._lon = self._get_coordinate_dimension(['lon', 'longitude']) + self._lat_bnds, self._lon_bnds = self.__get_coordinates_bnds() # Set axis limits for parallel reading self.read_axis_limits = self.get_read_axis_limits() @@ -209,6 +212,7 @@ class Nes(object): self.lev = self._get_coordinate_values(self._lev, 'Z') self.lat = self._get_coordinate_values(self._lat, 'Y') self.lon = self._get_coordinate_values(self._lon, 'X') + self.lat_bnds, self.lon_bnds = self._lat_bnds, self._lon_bnds # Set axis limits for parallel writing self.write_axis_limits = self.get_write_axis_limits() @@ -288,6 +292,10 @@ class Nes(object): del self._lat del self.lon del self._lon + del self._lat_bnds + del self.lat_bnds + del self._lon_bnds + del self.lon_bnds except AttributeError: pass @@ -433,6 +441,36 @@ class Nes(object): return None + def set_lat_bnds(self, lat_bnds): + """ + Modify the original latitude bounds values with new ones. + + Parameters + ---------- + lat_bnds : list + List with the new latitude bounds information to be set. + """ + + self._lat_bnds = deepcopy(lat_bnds) + self.lat_bnds = deepcopy(lat_bnds) + + return None + + def set_lon_bnds(self, lon_bnds): + """ + Modify the original longitude bounds values with new ones. + + Parameters + ---------- + lon_bnds : list + List with the new longitude bounds information to be set. + """ + + self._lon_bnds = deepcopy(lon_bnds) + self.lon_bnds = deepcopy(lon_bnds) + + return None + def create_bounds(self, coordinates, inc, spatial_nv=2, inverse=False): """ Calculate the vertices coordinates. @@ -1122,7 +1160,7 @@ class Nes(object): Returns ------- - time : list + time_bnds : list List of time bounds (datetime) of the NetCDF data. """ @@ -1142,10 +1180,55 @@ class Nes(object): else: time_bnds = None time_bnds = self.comm.bcast(time_bnds, root=0) + self.free_vars('time_bnds') return time_bnds + def __get_coordinates_bnds(self, create_nes=False): + """ + Get the NetCDF coordinates bounds values. + + Parameters + ---------- + create_nes : bool + Indicates if you want to create the object from scratch (True) or through an existing file. + + Returns + ------- + lat_bnds : list + List of latitude bounds of the NetCDF data. + lon_bnds : list + List of longitude bounds of the NetCDF data. + """ + + if self.is_xarray: + lat_bnds = self.variables['lat_bnds'] + lon_bnds = self.variables['lon_bnds'] + else: + if self.master: + if not create_nes: + if 'lat_bnds' in self.netcdf.variables.keys(): + lat_bnds = self.netcdf.variables['lat_bnds'][:] + else: + lat_bnds = None + if 'lon_bnds' in self.netcdf.variables.keys(): + lon_bnds = self.netcdf.variables['lon_bnds'][:] + else: + lon_bnds = None + else: + lat_bnds = None + lon_bnds = None + else: + lat_bnds = None + lon_bnds = None + lat_bnds = self.comm.bcast(lat_bnds, root=0) + lon_bnds = self.comm.bcast(lon_bnds, root=0) + + self.free_vars(['lat_bnds', 'lon_bnds']) + + return lat_bnds, lon_bnds + def _get_coordinate_dimension(self, possible_names): """ Read the coordinate dimension data. @@ -1547,7 +1630,7 @@ class Nes(object): def _create_dimensions(self, netcdf): """ - Create the 'lev' and 'time' dimension. + Create 'time', 'time_bnds', 'lev', 'lon' and 'lat' dimensions. Parameters ---------- @@ -1555,9 +1638,14 @@ class Nes(object): netcdf4-python opened Dataset. """ + # Create time dimension netcdf.createDimension('time', None) + + # Create time_nv (number of vertices) dimension if self._time_bnds is not None: netcdf.createDimension('time_nv', 2) + + # Create lev, lon and lat dimensions netcdf.createDimension('lev', len(self.lev['data'])) netcdf.createDimension('lon', len(self._lon['data'])) netcdf.createDimension('lat', len(self._lat['data'])) @@ -1566,7 +1654,7 @@ class Nes(object): def _create_dimension_variables(self, netcdf): """ - Create the 'lev' and 'time' variables. + Create the 'time', 'time_bnds', 'lev', 'lat', 'lat_bnds', 'lon' and 'lon_bnds' variables. Parameters ---------- @@ -1614,20 +1702,40 @@ class Nes(object): lat.axis = 'Y' lat.long_name = 'latitude coordinate' lat.standard_name = 'latitude' + if self._lat_bnds is not None: + lat.bounds = 'lat_bnds' if self.size > 1: lat.set_collective(True) lat[:] = self._lat['data'] + # LATITUDES BOUNDS + if self._lat_bnds is not None: + lat_bnds_var = netcdf.createVariable('lat_bnds', np.float64, self._var_dim + ('spatial_nv',), + zlib=self.zip_lvl, complevel=self.zip_lvl) + if self.size > 1: + lat_bnds_var.set_collective(True) + lat_bnds_var[:] = self._lat_bnds[:] + # LONGITUDES lon = netcdf.createVariable('lon', np.float64, self._lon_dim, zlib=self.zip_lvl > 0, complevel=self.zip_lvl) lon.units = 'degrees_east' lon.axis = 'X' lon.long_name = 'longitude coordinate' lon.standard_name = 'longitude' + if self._lon_bnds is not None: + lon.bounds = 'lon_bnds' if self.size > 1: lon.set_collective(True) lon[:] = self._lon['data'] + # LONGITUDES BOUNDS + if self._lon_bnds is not None: + lon_bnds_var = netcdf.createVariable('lon_bnds', np.float64, self._var_dim + ('spatial_nv',), + zlib=self.zip_lvl, complevel=self.zip_lvl) + if self.size > 1: + lon_bnds_var.set_collective(True) + lon_bnds_var[:] = self._lon_bnds[:] + return None def _create_variables(self, netcdf, chunking=False): diff --git a/nes/nc_projections/latlon_nes.py b/nes/nc_projections/latlon_nes.py index c31b06d89a6945ce1c59c9301c437ee4912135f7..d8f05eea59c29ad128353768563a93c8c429c27e 100644 --- a/nes/nc_projections/latlon_nes.py +++ b/nes/nc_projections/latlon_nes.py @@ -96,6 +96,24 @@ class LatLonNes(Nes): avoid_last_hours=avoid_last_hours, first_level=first_level, last_level=last_level) return new + def _create_dimensions(self, netcdf): + """ + Create 'spatial_nv' dimension and the super dimensions ('time', 'time_nv', 'lev', 'lat', 'lon'). + + Parameters + ---------- + netcdf : Dataset + NetCDF object. + """ + + super(LatLonNes, self)._create_dimensions(netcdf) + + # Create spatial_nv (number of vertices) dimension + if (self._lat_bnds is not None) and (self._lon_bnds is not None): + netcdf.createDimension('spatial_nv', 2) + + return None + def _create_centre_coordinates(self, **kwargs): """ Calculate centre latitudes and longitudes from grid details. diff --git a/nes/nc_projections/lcc_nes.py b/nes/nc_projections/lcc_nes.py index 235d1be2a9f36d25c021e0cac2f468cadd35e949..db92c9bee963994331e0123eac40cfd68da9363e 100644 --- a/nes/nc_projections/lcc_nes.py +++ b/nes/nc_projections/lcc_nes.py @@ -144,7 +144,7 @@ class LCCNes(Nes): def _create_dimensions(self, netcdf): """ - Create the 'y', 'x' dimensions and the super dimensions ('lev', 'time'). + Create 'y', 'x' and 'spatial_nv' dimensions and the super dimensions ('lev', 'time'). Parameters ---------- @@ -153,9 +153,14 @@ class LCCNes(Nes): """ super(LCCNes, self)._create_dimensions(netcdf) + # Create y and x dimensions netcdf.createDimension('y', len(self._y['data'])) netcdf.createDimension('x', len(self._x['data'])) + # Create spatial_nv (number of vertices) dimension + if (self._lat_bnds is not None) and (self._lon_bnds is not None): + netcdf.createDimension('spatial_nv', 4) + return None def _create_dimension_variables(self, netcdf): diff --git a/nes/nc_projections/mercator_nes.py b/nes/nc_projections/mercator_nes.py index a6e640c3d8506f9a0feb39403e4b52ba958d27f4..50e2a691da6f07a419d377796f4b4fb1ac310e77 100644 --- a/nes/nc_projections/mercator_nes.py +++ b/nes/nc_projections/mercator_nes.py @@ -144,18 +144,24 @@ class MercatorNes(Nes): def _create_dimensions(self, netcdf): """ - Create the 'y', 'x' dimensions and the super dimensions ('lev', 'time'). + Create 'y', 'x' and 'spatial_nv' dimensions and the super dimensions ('lev', 'time'). Parameters ---------- netcdf : Dataset NetCDF object. """ + super(MercatorNes, self)._create_dimensions(netcdf) + # Create y and x dimensions netcdf.createDimension('y', len(self._y['data'])) netcdf.createDimension('x', len(self._x['data'])) + # Create spatial_nv (number of vertices) dimension + if (self._lat_bnds is not None) and (self._lon_bnds is not None): + netcdf.createDimension('spatial_nv', 4) + return None def _create_dimension_variables(self, netcdf): diff --git a/nes/nc_projections/points_nes.py b/nes/nc_projections/points_nes.py index a17e297c660ccf62b44f13fafaa6281c35c0eb0b..8136d6ce487347364890926ab598b2fc6a6d4622 100644 --- a/nes/nc_projections/points_nes.py +++ b/nes/nc_projections/points_nes.py @@ -117,7 +117,7 @@ class PointsNes(Nes): def _create_dimensions(self, netcdf): """ - Create the 'lev', 'time_nv', 'station' dimensions. + Create 'lev', 'time_nv', 'station', 'spatial_nv' and 'strlen' dimensions. Parameters ---------- @@ -127,9 +127,16 @@ class PointsNes(Nes): # Create time dimension netcdf.createDimension('time', None) + + # Create time_nv (number of vertices) dimension if self._time_bnds is not None: netcdf.createDimension('time_nv', 2) + # Create spatial_nv (number of vertices) dimension + if (self._lat_bnds is not None) and (self._lon_bnds is not None): + netcdf.createDimension('spatial_nv', 2) + + # Create station dimension # The number of longitudes is equal to the number of stations netcdf.createDimension('station', len(self._lon['data'])) @@ -142,7 +149,7 @@ class PointsNes(Nes): def _create_dimension_variables(self, netcdf): """ - Create the 'time', 'time_bnds' and 'station' variables. + Create the 'time', 'time_bnds', 'station', 'lat', 'lat_bnds', 'lon' and 'lon_bnds' variables. Parameters ---------- @@ -191,10 +198,20 @@ class PointsNes(Nes): lat.axis = 'Y' lat.long_name = 'latitude coordinate' lat.standard_name = 'latitude' + if self._lat_bnds is not None: + lat.bounds = 'lat_bnds' if self.size > 1: lat.set_collective(True) lat[:] = self._lat['data'] + # LATITUDES BOUNDS + if self._lat_bnds is not None: + lat_bnds_var = netcdf.createVariable('lat_bnds', np.float64, self._var_dim + ('spatial_nv',), + zlib=self.zip_lvl, complevel=self.zip_lvl) + if self.size > 1: + lat_bnds_var.set_collective(True) + lat_bnds_var[:] = self._lat_bnds[:] + # LONGITUDES lon = netcdf.createVariable('lon', np.float64, self._lon_dim, zlib=self.zip_lvl > 0, complevel=self.zip_lvl) @@ -202,10 +219,20 @@ class PointsNes(Nes): lon.axis = 'X' lon.long_name = 'longitude coordinate' lon.standard_name = 'longitude' + if self._lon_bnds is not None: + lon.bounds = 'lon_bnds' if self.size > 1: lon.set_collective(True) lon[:] = self._lon['data'] + # LONGITUDES BOUNDS + if self._lon_bnds is not None: + lon_bnds_var = netcdf.createVariable('lon_bnds', np.float64, self._var_dim + ('spatial_nv',), + zlib=self.zip_lvl, complevel=self.zip_lvl) + if self.size > 1: + lon_bnds_var.set_collective(True) + lon_bnds_var[:] = self._lon_bnds[:] + return None def _get_coordinate_values(self, coordinate_info, coordinate_axis): diff --git a/nes/nc_projections/points_nes_ghost.py b/nes/nc_projections/points_nes_ghost.py index a90158ae89a5e77027e7850bf4853ad3a4d2bc93..b8fc489a115f35c23fb1b22593aa05039dbd759a 100644 --- a/nes/nc_projections/points_nes_ghost.py +++ b/nes/nc_projections/points_nes_ghost.py @@ -127,7 +127,8 @@ class PointsNesGHOST(PointsNes): def _create_dimensions(self, netcdf): """ - Create the 'N_flag_codes' and 'N_qa_codes' dimensions and the super dimensions ('time', 'station'). + Create 'N_flag_codes' and 'N_qa_codes' dimensions and the super dimensions + ('lev', 'time_nv', 'station', 'spatial_nv' and 'strlen'). Parameters ---------- @@ -137,6 +138,7 @@ class PointsNesGHOST(PointsNes): super(PointsNesGHOST, self)._create_dimensions(netcdf) + # Create N_flag_codes and N_qa_codes dimensions netcdf.createDimension('N_flag_codes', self._flag['data'].shape[2]) netcdf.createDimension('N_qa_codes', self._qa['data'].shape[2]) @@ -144,7 +146,7 @@ class PointsNesGHOST(PointsNes): def _create_dimension_variables(self, netcdf): """ - Create the 'station' variables. + Create the 'time', 'time_bnds', 'station', 'lat', 'lat_bnds', 'lon' and 'lon_bnds' variables. Parameters ---------- @@ -193,10 +195,20 @@ class PointsNesGHOST(PointsNes): lat.axis = 'Y' lat.long_name = 'latitude coordinate' lat.standard_name = 'latitude' + if self._lat_bnds is not None: + lat.bounds = 'lat_bnds' if self.size > 1: lat.set_collective(True) lat[:] = self._lat['data'] + # LATITUDES BOUNDS + if self._lat_bnds is not None: + lat_bnds_var = netcdf.createVariable('lat_bnds', np.float64, self._var_dim + ('spatial_nv',), + zlib=self.zip_lvl, complevel=self.zip_lvl) + if self.size > 1: + lat_bnds_var.set_collective(True) + lat_bnds_var[:] = self._lat_bnds[:] + # LONGITUDES lon = netcdf.createVariable('longitude', np.float64, self._lon_dim, zlib=self.zip_lvl > 0, complevel=self.zip_lvl) @@ -204,10 +216,20 @@ class PointsNesGHOST(PointsNes): lon.axis = 'X' lon.long_name = 'longitude coordinate' lon.standard_name = 'longitude' + if self._lon_bnds is not None: + lon.bounds = 'lon_bnds' if self.size > 1: lon.set_collective(True) lon[:] = self._lon['data'] + # LONGITUDES BOUNDS + if self._lon_bnds is not None: + lon_bnds_var = netcdf.createVariable('lon_bnds', np.float64, self._var_dim + ('spatial_nv',), + zlib=self.zip_lvl, complevel=self.zip_lvl) + if self.size > 1: + lon_bnds_var.set_collective(True) + lon_bnds_var[:] = self._lon_bnds[:] + def erase_flags(self): first_time_idx = self.get_time_id(self.hours_start, first=True) last_time_idx = self.get_time_id(self.hours_end, first=False) diff --git a/nes/nc_projections/points_nes_providentia.py b/nes/nc_projections/points_nes_providentia.py index d45f8269a0be879d1272dcd82925e61523e60826..347bf31626d0029ac6f989f5aedfc326e8e80027 100644 --- a/nes/nc_projections/points_nes_providentia.py +++ b/nes/nc_projections/points_nes_providentia.py @@ -169,7 +169,8 @@ class PointsNesProvidentia(PointsNes): def _create_dimensions(self, netcdf): """ - Create the 'grid_edge', 'model_latitude', 'model_longitude' dimensions. + Create 'grid_edge', 'model_latitude' and 'model_longitude' dimensions and the super dimensions + ('lev', 'time_nv', 'station', 'spatial_nv', 'strlen'). Parameters ---------- @@ -179,6 +180,7 @@ class PointsNesProvidentia(PointsNes): super(PointsNesProvidentia, self)._create_dimensions(netcdf) + # Create grid_edge, model_latitude and model_longitude dimensions netcdf.createDimension('grid_edge', len(self._grid_edge_lon['data'])) netcdf.createDimension('model_latitude', self._model_centre_lon['data'].shape[0]) netcdf.createDimension('model_longitude', self._model_centre_lon['data'].shape[1]) diff --git a/nes/nc_projections/rotated_nes.py b/nes/nc_projections/rotated_nes.py index ae3abb2a394fb6b24d10614ec77a2036ac37d092..697921e36855b89623d0305fafc9e4f718a2eddb 100644 --- a/nes/nc_projections/rotated_nes.py +++ b/nes/nc_projections/rotated_nes.py @@ -145,7 +145,7 @@ class RotatedNes(Nes): def _create_dimensions(self, netcdf): """ - Create the 'rlat', 'rlon' dimensions and the super dimensions ('lev', 'time'). + Create 'rlat', 'rlon' and 'spatial_nv' dimensions and the super dimensions ('lev', 'time'). Parameters ---------- @@ -154,9 +154,14 @@ class RotatedNes(Nes): """ super(RotatedNes, self)._create_dimensions(netcdf) + # Create rlat and rlon dimensions netcdf.createDimension('rlon', len(self._rlon['data'])) netcdf.createDimension('rlat', len(self._rlat['data'])) + # Create spatial_nv (number of vertices) dimension + if (self._lat_bnds is not None) and (self._lon_bnds is not None): + netcdf.createDimension('spatial_nv', 4) + return None def _create_dimension_variables(self, netcdf): @@ -259,14 +264,14 @@ class RotatedNes(Nes): stph = np.sin(tph) ctph = np.cos(tph) - # Latitudes + # LATITUDES sph = (ctph0 * stph) + (stph0 * ctph * ctlm) sph[sph > 1.] = 1. sph[sph < -1.] = -1. aph = np.arcsin(sph) aphd = aph / degrees_to_radians - # Longitudes + # LONGITUDES anum = ctph * stlm denom = (ctlm * ctph - stph0 * sph) / ctph0 relm = np.arctan2(anum, denom) - math.pi diff --git a/tutorials/1.Introduction/1.5.Read_Write_Mercator.ipynb b/tutorials/1.Introduction/1.5.Read_Write_Mercator.ipynb index ec31ac656aa0a887efb6a91322133907f74e3800..67f9bb479f4f32d46bc68c8ff0f816ca3bd1d204 100644 --- a/tutorials/1.Introduction/1.5.Read_Write_Mercator.ipynb +++ b/tutorials/1.Introduction/1.5.Read_Write_Mercator.ipynb @@ -44,15 +44,6 @@ "cell_type": "code", "execution_count": 3, "metadata": {}, - "outputs": [], - "source": [ - "# xr.open_dataset(nc_path_1, decode_times=False).drop(['lat_bnds', 'lon_bnds']).to_netcdf('input/mercator_grid_example.nc')" - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "metadata": {}, "outputs": [ { "data": { @@ -409,17 +400,20 @@ " fill: currentColor;\n", "}\n", "
<xarray.Dataset>\n",
-       "Dimensions:    (time: 1, y: 236, x: 210)\n",
+       "Dimensions:    (time: 1, y: 236, x: 210, nv: 4)\n",
        "Coordinates:\n",
        "  * time       (time) float64 0.0\n",
        "    lat        (y, x) float32 -43.52 -43.52 -43.52 -43.52 ... 49.6 49.6 49.6\n",
        "    lon        (y, x) float32 -18.91 -18.46 -18.01 -17.56 ... 74.22 74.67 75.12\n",
        "  * x          (x) float64 -1.01e+05 -5.101e+04 ... 1.03e+07 1.035e+07\n",
        "  * y          (y) float64 -5.382e+06 -5.332e+06 ... 6.318e+06 6.368e+06\n",
+       "Dimensions without coordinates: nv\n",
        "Data variables:\n",
+       "    lat_bnds   (y, x, nv) float32 ...\n",
+       "    lon_bnds   (y, x, nv) float32 ...\n",
        "    var_aux    (time, y, x) float32 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0\n",
        "    mercator   int32 -2147483647\n",
-       "    cell_area  (y, x) float32 1.316e+09 1.316e+09 ... 1.051e+09 1.051e+09
  • " ], "text/plain": [ "\n", - "Dimensions: (time: 1, y: 236, x: 210)\n", + "Dimensions: (time: 1, y: 236, x: 210, nv: 4)\n", "Coordinates:\n", " * time (time) float64 0.0\n", " lat (y, x) float32 ...\n", " lon (y, x) float32 ...\n", " * x (x) float64 -1.01e+05 -5.101e+04 ... 1.03e+07 1.035e+07\n", " * y (y) float64 -5.382e+06 -5.332e+06 ... 6.318e+06 6.368e+06\n", + "Dimensions without coordinates: nv\n", "Data variables:\n", + " lat_bnds (y, x, nv) float32 ...\n", + " lon_bnds (y, x, nv) float32 ...\n", " var_aux (time, y, x) float32 ...\n", " mercator int32 ...\n", " cell_area (y, x) float32 ..." ] }, - "execution_count": 4, + "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "xr.open_dataset('input/mercator_grid_example.nc', decode_times=False)" + "xr.open_dataset(nc_path_1, decode_times=False)" ] }, { @@ -495,28 +492,28 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "" + "" ] }, - "execution_count": 5, + "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "nessy_1 = open_netcdf(path='input/mercator_grid_example.nc', info=True)\n", + "nessy_1 = open_netcdf(nc_path_1, info=True)\n", "nessy_1" ] }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 5, "metadata": {}, "outputs": [ { @@ -525,7 +522,7 @@ "[datetime.datetime(2000, 1, 1, 0, 0)]" ] }, - "execution_count": 6, + "execution_count": 5, "metadata": {}, "output_type": "execute_result" } @@ -536,7 +533,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 6, "metadata": {}, "outputs": [ { @@ -545,7 +542,7 @@ "{'data': array([0]), 'units': ''}" ] }, - "execution_count": 7, + "execution_count": 6, "metadata": {}, "output_type": "execute_result" } @@ -556,7 +553,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 7, "metadata": {}, "outputs": [ { @@ -640,7 +637,7 @@ " 'standard_name': 'projection_x_coordinate'}" ] }, - "execution_count": 8, + "execution_count": 7, "metadata": {}, "output_type": "execute_result" } @@ -651,7 +648,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 8, "metadata": {}, "outputs": [ { @@ -713,7 +710,7 @@ " 'standard_name': 'projection_y_coordinate'}" ] }, - "execution_count": 9, + "execution_count": 8, "metadata": {}, "output_type": "execute_result" } @@ -724,7 +721,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 9, "metadata": {}, "outputs": [ { @@ -755,7 +752,7 @@ " 'bounds': 'lat_bnds'}" ] }, - "execution_count": 10, + "execution_count": 9, "metadata": {}, "output_type": "execute_result" } @@ -766,7 +763,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 10, "metadata": {}, "outputs": [ { @@ -797,7 +794,7 @@ " 'bounds': 'lon_bnds'}" ] }, - "execution_count": 11, + "execution_count": 10, "metadata": {}, "output_type": "execute_result" } @@ -806,10 +803,322 @@ "nessy_1.lon" ] }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "masked_array(\n", + " data=[[[-43.68109893798828, -43.68109893798828, -43.354862213134766,\n", + " -43.354862213134766],\n", + " [-43.68109893798828, -43.68109893798828, -43.354862213134766,\n", + " -43.354862213134766],\n", + " [-43.68109893798828, -43.68109893798828, -43.354862213134766,\n", + " -43.354862213134766],\n", + " ...,\n", + " [-43.68109893798828, -43.68109893798828, -43.354862213134766,\n", + " -43.354862213134766],\n", + " [-43.68109893798828, -43.68109893798828, -43.354862213134766,\n", + " -43.354862213134766],\n", + " [-43.68109893798828, -43.68109893798828, -43.354862213134766,\n", + " -43.354862213134766]],\n", + "\n", + " [[-43.354862213134766, -43.354862213134766, -43.02686309814453,\n", + " -43.02686309814453],\n", + " [-43.354862213134766, -43.354862213134766, -43.02686309814453,\n", + " -43.02686309814453],\n", + " [-43.354862213134766, -43.354862213134766, -43.02686309814453,\n", + " -43.02686309814453],\n", + " ...,\n", + " [-43.354862213134766, -43.354862213134766, -43.02686309814453,\n", + " -43.02686309814453],\n", + " [-43.354862213134766, -43.354862213134766, -43.02686309814453,\n", + " -43.02686309814453],\n", + " [-43.354862213134766, -43.354862213134766, -43.02686309814453,\n", + " -43.02686309814453]],\n", + "\n", + " [[-43.02686309814453, -43.02686309814453, -42.69709777832031,\n", + " -42.69709777832031],\n", + " [-43.02686309814453, -43.02686309814453, -42.69709777832031,\n", + " -42.69709777832031],\n", + " [-43.02686309814453, -43.02686309814453, -42.69709777832031,\n", + " -42.69709777832031],\n", + " ...,\n", + " [-43.02686309814453, -43.02686309814453, -42.69709777832031,\n", + " -42.69709777832031],\n", + " [-43.02686309814453, -43.02686309814453, -42.69709777832031,\n", + " -42.69709777832031],\n", + " [-43.02686309814453, -43.02686309814453, -42.69709777832031,\n", + " -42.69709777832031]],\n", + "\n", + " ...,\n", + "\n", + " [[48.86896514892578, 48.86896514892578, 49.16401672363281,\n", + " 49.16401672363281],\n", + " [48.86896514892578, 48.86896514892578, 49.16401672363281,\n", + " 49.16401672363281],\n", + " [48.86896514892578, 48.86896514892578, 49.16401672363281,\n", + " 49.16401672363281],\n", + " ...,\n", + " [48.86896514892578, 48.86896514892578, 49.16401672363281,\n", + " 49.16401672363281],\n", + " [48.86896514892578, 48.86896514892578, 49.16401672363281,\n", + " 49.16401672363281],\n", + " [48.86896514892578, 48.86896514892578, 49.16401672363281,\n", + " 49.16401672363281]],\n", + "\n", + " [[49.16401672363281, 49.16401672363281, 49.45732498168945,\n", + " 49.45732498168945],\n", + " [49.16401672363281, 49.16401672363281, 49.45732498168945,\n", + " 49.45732498168945],\n", + " [49.16401672363281, 49.16401672363281, 49.45732498168945,\n", + " 49.45732498168945],\n", + " ...,\n", + " [49.16401672363281, 49.16401672363281, 49.45732498168945,\n", + " 49.45732498168945],\n", + " [49.16401672363281, 49.16401672363281, 49.45732498168945,\n", + " 49.45732498168945],\n", + " [49.16401672363281, 49.16401672363281, 49.45732498168945,\n", + " 49.45732498168945]],\n", + "\n", + " [[49.45732498168945, 49.45732498168945, 49.74888229370117,\n", + " 49.74888229370117],\n", + " [49.45732498168945, 49.45732498168945, 49.74888229370117,\n", + " 49.74888229370117],\n", + " [49.45732498168945, 49.45732498168945, 49.74888229370117,\n", + " 49.74888229370117],\n", + " ...,\n", + " [49.45732498168945, 49.45732498168945, 49.74888229370117,\n", + " 49.74888229370117],\n", + " [49.45732498168945, 49.45732498168945, 49.74888229370117,\n", + " 49.74888229370117],\n", + " [49.45732498168945, 49.45732498168945, 49.74888229370117,\n", + " 49.74888229370117]]],\n", + " mask=[[[False, False, False, False],\n", + " [False, False, False, False],\n", + " [False, False, False, False],\n", + " ...,\n", + " [False, False, False, False],\n", + " [False, False, False, False],\n", + " [False, False, False, False]],\n", + "\n", + " [[False, False, False, False],\n", + " [False, False, False, False],\n", + " [False, False, False, False],\n", + " ...,\n", + " [False, False, False, False],\n", + " [False, False, False, False],\n", + " [False, False, False, False]],\n", + "\n", + " [[False, False, False, False],\n", + " [False, False, False, False],\n", + " [False, False, False, False],\n", + " ...,\n", + " [False, False, False, False],\n", + " [False, False, False, False],\n", + " [False, False, False, False]],\n", + "\n", + " ...,\n", + "\n", + " [[False, False, False, False],\n", + " [False, False, False, False],\n", + " [False, False, False, False],\n", + " ...,\n", + " [False, False, False, False],\n", + " [False, False, False, False],\n", + " [False, False, False, False]],\n", + "\n", + " [[False, False, False, False],\n", + " [False, False, False, False],\n", + " [False, False, False, False],\n", + " ...,\n", + " [False, False, False, False],\n", + " [False, False, False, False],\n", + " [False, False, False, False]],\n", + "\n", + " [[False, False, False, False],\n", + " [False, False, False, False],\n", + " [False, False, False, False],\n", + " ...,\n", + " [False, False, False, False],\n", + " [False, False, False, False],\n", + " [False, False, False, False]]],\n", + " fill_value=1e+20,\n", + " dtype=float32)" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "nessy_1.lat_bnds" + ] + }, { "cell_type": "code", "execution_count": 12, "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "masked_array(\n", + " data=[[[-19.13384246826172, -18.683956146240234, -18.683956146240234,\n", + " -19.13384246826172],\n", + " [-18.683956146240234, -18.234071731567383, -18.234071731567383,\n", + " -18.683956146240234],\n", + " [-18.234071731567383, -17.7841854095459, -17.7841854095459,\n", + " -18.234071731567383],\n", + " ...,\n", + " [73.99246978759766, 74.44235229492188, 74.44235229492188,\n", + " 73.99246978759766],\n", + " [74.44235229492188, 74.89224243164062, 74.89224243164062,\n", + " 74.44235229492188],\n", + " [74.89224243164062, 75.34212493896484, 75.34212493896484,\n", + " 74.89224243164062]],\n", + "\n", + " [[-19.13384246826172, -18.683956146240234, -18.683956146240234,\n", + " -19.13384246826172],\n", + " [-18.683956146240234, -18.234071731567383, -18.234071731567383,\n", + " -18.683956146240234],\n", + " [-18.234071731567383, -17.7841854095459, -17.7841854095459,\n", + " -18.234071731567383],\n", + " ...,\n", + " [73.99246978759766, 74.44235229492188, 74.44235229492188,\n", + " 73.99246978759766],\n", + " [74.44235229492188, 74.89224243164062, 74.89224243164062,\n", + " 74.44235229492188],\n", + " [74.89224243164062, 75.34212493896484, 75.34212493896484,\n", + " 74.89224243164062]],\n", + "\n", + " [[-19.13384246826172, -18.683956146240234, -18.683956146240234,\n", + " -19.13384246826172],\n", + " [-18.683956146240234, -18.234071731567383, -18.234071731567383,\n", + " -18.683956146240234],\n", + " [-18.234071731567383, -17.7841854095459, -17.7841854095459,\n", + " -18.234071731567383],\n", + " ...,\n", + " [73.99246978759766, 74.44235229492188, 74.44235229492188,\n", + " 73.99246978759766],\n", + " [74.44235229492188, 74.89224243164062, 74.89224243164062,\n", + " 74.44235229492188],\n", + " [74.89224243164062, 75.34212493896484, 75.34212493896484,\n", + " 74.89224243164062]],\n", + "\n", + " ...,\n", + "\n", + " [[-19.13384246826172, -18.683956146240234, -18.683956146240234,\n", + " -19.13384246826172],\n", + " [-18.683956146240234, -18.234071731567383, -18.234071731567383,\n", + " -18.683956146240234],\n", + " [-18.234071731567383, -17.7841854095459, -17.7841854095459,\n", + " -18.234071731567383],\n", + " ...,\n", + " [73.99246978759766, 74.44235229492188, 74.44235229492188,\n", + " 73.99246978759766],\n", + " [74.44235229492188, 74.89224243164062, 74.89224243164062,\n", + " 74.44235229492188],\n", + " [74.89224243164062, 75.34212493896484, 75.34212493896484,\n", + " 74.89224243164062]],\n", + "\n", + " [[-19.13384246826172, -18.683956146240234, -18.683956146240234,\n", + " -19.13384246826172],\n", + " [-18.683956146240234, -18.234071731567383, -18.234071731567383,\n", + " -18.683956146240234],\n", + " [-18.234071731567383, -17.7841854095459, -17.7841854095459,\n", + " -18.234071731567383],\n", + " ...,\n", + " [73.99246978759766, 74.44235229492188, 74.44235229492188,\n", + " 73.99246978759766],\n", + " [74.44235229492188, 74.89224243164062, 74.89224243164062,\n", + " 74.44235229492188],\n", + " [74.89224243164062, 75.34212493896484, 75.34212493896484,\n", + " 74.89224243164062]],\n", + "\n", + " [[-19.13384246826172, -18.683956146240234, -18.683956146240234,\n", + " -19.13384246826172],\n", + " [-18.683956146240234, -18.234071731567383, -18.234071731567383,\n", + " -18.683956146240234],\n", + " [-18.234071731567383, -17.7841854095459, -17.7841854095459,\n", + " -18.234071731567383],\n", + " ...,\n", + " [73.99246978759766, 74.44235229492188, 74.44235229492188,\n", + " 73.99246978759766],\n", + " [74.44235229492188, 74.89224243164062, 74.89224243164062,\n", + " 74.44235229492188],\n", + " [74.89224243164062, 75.34212493896484, 75.34212493896484,\n", + " 74.89224243164062]]],\n", + " mask=[[[False, False, False, False],\n", + " [False, False, False, False],\n", + " [False, False, False, False],\n", + " ...,\n", + " [False, False, False, False],\n", + " [False, False, False, False],\n", + " [False, False, False, False]],\n", + "\n", + " [[False, False, False, False],\n", + " [False, False, False, False],\n", + " [False, False, False, False],\n", + " ...,\n", + " [False, False, False, False],\n", + " [False, False, False, False],\n", + " [False, False, False, False]],\n", + "\n", + " [[False, False, False, False],\n", + " [False, False, False, False],\n", + " [False, False, False, False],\n", + " ...,\n", + " [False, False, False, False],\n", + " [False, False, False, False],\n", + " [False, False, False, False]],\n", + "\n", + " ...,\n", + "\n", + " [[False, False, False, False],\n", + " [False, False, False, False],\n", + " [False, False, False, False],\n", + " ...,\n", + " [False, False, False, False],\n", + " [False, False, False, False],\n", + " [False, False, False, False]],\n", + "\n", + " [[False, False, False, False],\n", + " [False, False, False, False],\n", + " [False, False, False, False],\n", + " ...,\n", + " [False, False, False, False],\n", + " [False, False, False, False],\n", + " [False, False, False, False]],\n", + "\n", + " [[False, False, False, False],\n", + " [False, False, False, False],\n", + " [False, False, False, False],\n", + " ...,\n", + " [False, False, False, False],\n", + " [False, False, False, False],\n", + " [False, False, False, False]]],\n", + " fill_value=1e+20,\n", + " dtype=float32)" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "nessy_1.lon_bnds" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, "outputs": [ { "name": "stdout", @@ -828,7 +1137,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 14, "metadata": {}, "outputs": [ { @@ -847,9 +1156,9 @@ " dtype=float32),\n", " 'dimensions': ('time', 'y', 'x'),\n", " 'units': '?',\n", + " 'coordinates': 'lat lon',\n", " 'cell_measures': 'area: cell_area',\n", - " 'grid_mapping': 'mercator',\n", - " 'coordinates': 'lat lon'},\n", + " 'grid_mapping': 'mercator'},\n", " 'cell_area': {'data': masked_array(\n", " data=[[[[1.31594240e+09, 1.31593690e+09, 1.31594240e+09, ...,\n", " 1.31593126e+09, 1.31595354e+09, 1.31593126e+09],\n", @@ -870,11 +1179,10 @@ " 'dimensions': ('y', 'x'),\n", " 'long_name': 'area of the grid cell',\n", " 'standard_name': 'cell_area',\n", - " 'units': 'm2',\n", - " 'coordinates': 'lat lon'}}" + " 'units': 'm2'}}" ] }, - "execution_count": 13, + "execution_count": 14, "metadata": {}, "output_type": "execute_result" } @@ -885,7 +1193,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 15, "metadata": {}, "outputs": [ { @@ -894,6 +1202,91 @@ "text": [ "Rank 000: Creating mercator_file_1.nc\n", "Rank 000: NetCDF ready to write\n", + "[[[-43.68109893798828 -43.68109893798828 -43.354862213134766\n", + " -43.354862213134766]\n", + " [-43.68109893798828 -43.68109893798828 -43.354862213134766\n", + " -43.354862213134766]\n", + " [-43.68109893798828 -43.68109893798828 -43.354862213134766\n", + " -43.354862213134766]\n", + " ...\n", + " [-43.68109893798828 -43.68109893798828 -43.354862213134766\n", + " -43.354862213134766]\n", + " [-43.68109893798828 -43.68109893798828 -43.354862213134766\n", + " -43.354862213134766]\n", + " [-43.68109893798828 -43.68109893798828 -43.354862213134766\n", + " -43.354862213134766]]\n", + "\n", + " [[-43.354862213134766 -43.354862213134766 -43.02686309814453\n", + " -43.02686309814453]\n", + " [-43.354862213134766 -43.354862213134766 -43.02686309814453\n", + " -43.02686309814453]\n", + " [-43.354862213134766 -43.354862213134766 -43.02686309814453\n", + " -43.02686309814453]\n", + " ...\n", + " [-43.354862213134766 -43.354862213134766 -43.02686309814453\n", + " -43.02686309814453]\n", + " [-43.354862213134766 -43.354862213134766 -43.02686309814453\n", + " -43.02686309814453]\n", + " [-43.354862213134766 -43.354862213134766 -43.02686309814453\n", + " -43.02686309814453]]\n", + "\n", + " [[-43.02686309814453 -43.02686309814453 -42.69709777832031\n", + " -42.69709777832031]\n", + " [-43.02686309814453 -43.02686309814453 -42.69709777832031\n", + " -42.69709777832031]\n", + " [-43.02686309814453 -43.02686309814453 -42.69709777832031\n", + " -42.69709777832031]\n", + " ...\n", + " [-43.02686309814453 -43.02686309814453 -42.69709777832031\n", + " -42.69709777832031]\n", + " [-43.02686309814453 -43.02686309814453 -42.69709777832031\n", + " -42.69709777832031]\n", + " [-43.02686309814453 -43.02686309814453 -42.69709777832031\n", + " -42.69709777832031]]\n", + "\n", + " ...\n", + "\n", + " [[48.86896514892578 48.86896514892578 49.16401672363281\n", + " 49.16401672363281]\n", + " [48.86896514892578 48.86896514892578 49.16401672363281\n", + " 49.16401672363281]\n", + " [48.86896514892578 48.86896514892578 49.16401672363281\n", + " 49.16401672363281]\n", + " ...\n", + " [48.86896514892578 48.86896514892578 49.16401672363281\n", + " 49.16401672363281]\n", + " [48.86896514892578 48.86896514892578 49.16401672363281\n", + " 49.16401672363281]\n", + " [48.86896514892578 48.86896514892578 49.16401672363281\n", + " 49.16401672363281]]\n", + "\n", + " [[49.16401672363281 49.16401672363281 49.45732498168945\n", + " 49.45732498168945]\n", + " [49.16401672363281 49.16401672363281 49.45732498168945\n", + " 49.45732498168945]\n", + " [49.16401672363281 49.16401672363281 49.45732498168945\n", + " 49.45732498168945]\n", + " ...\n", + " [49.16401672363281 49.16401672363281 49.45732498168945\n", + " 49.45732498168945]\n", + " [49.16401672363281 49.16401672363281 49.45732498168945\n", + " 49.45732498168945]\n", + " [49.16401672363281 49.16401672363281 49.45732498168945\n", + " 49.45732498168945]]\n", + "\n", + " [[49.45732498168945 49.45732498168945 49.74888229370117\n", + " 49.74888229370117]\n", + " [49.45732498168945 49.45732498168945 49.74888229370117\n", + " 49.74888229370117]\n", + " [49.45732498168945 49.45732498168945 49.74888229370117\n", + " 49.74888229370117]\n", + " ...\n", + " [49.45732498168945 49.45732498168945 49.74888229370117\n", + " 49.74888229370117]\n", + " [49.45732498168945 49.45732498168945 49.74888229370117\n", + " 49.74888229370117]\n", + " [49.45732498168945 49.45732498168945 49.74888229370117\n", + " 49.74888229370117]]]\n", "Rank 000: Dimensions done\n", "Rank 000: Writing var_aux var (1/2)\n", "Rank 000: Var var_aux created (1/2)\n", @@ -921,16 +1314,16 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 16, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "" + "" ] }, - "execution_count": 15, + "execution_count": 16, "metadata": {}, "output_type": "execute_result" } @@ -949,7 +1342,7 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 17, "metadata": {}, "outputs": [ { @@ -1307,7 +1700,7 @@ " fill: currentColor;\n", "}\n", "
    <xarray.Dataset>\n",
    -       "Dimensions:    (time: 1, lev: 1, y: 236, x: 210)\n",
    +       "Dimensions:    (time: 1, lev: 1, y: 236, x: 210, spatial_nv: 4)\n",
            "Coordinates:\n",
            "  * time       (time) datetime64[ns] 2000-01-01\n",
            "  * lev        (lev) float64 0.0\n",
    @@ -1315,12 +1708,15 @@
            "    lon        (y, x) float64 -18.91 -18.46 -18.01 -17.56 ... 74.22 74.67 75.12\n",
            "  * y          (y) float64 -5.382e+06 -5.332e+06 ... 6.318e+06 6.368e+06\n",
            "  * x          (x) float64 -1.01e+05 -5.101e+04 ... 1.03e+07 1.035e+07\n",
    +       "Dimensions without coordinates: spatial_nv\n",
            "Data variables:\n",
    +       "    lat_bnds   (y, x, spatial_nv) float64 ...\n",
    +       "    lon_bnds   (y, x, spatial_nv) float64 ...\n",
            "    var_aux    (time, lev, y, x) float32 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0\n",
            "    cell_area  (time, lev, y, x) float32 1.316e+09 1.316e+09 ... 1.051e+09\n",
            "    mercator   |S1 b''\n",
            "Attributes:\n",
    -       "    Conventions:  CF-1.7
  • Conventions :
    CF-1.7
  • " ], "text/plain": [ "\n", - "Dimensions: (time: 1, lev: 1, y: 236, x: 210)\n", + "Dimensions: (time: 1, lev: 1, y: 236, x: 210, spatial_nv: 4)\n", "Coordinates:\n", " * time (time) datetime64[ns] 2000-01-01\n", " * lev (lev) float64 0.0\n", @@ -1361,7 +1757,10 @@ " lon (y, x) float64 ...\n", " * y (y) float64 -5.382e+06 -5.332e+06 ... 6.318e+06 6.368e+06\n", " * x (x) float64 -1.01e+05 -5.101e+04 ... 1.03e+07 1.035e+07\n", + "Dimensions without coordinates: spatial_nv\n", "Data variables:\n", + " lat_bnds (y, x, spatial_nv) float64 ...\n", + " lon_bnds (y, x, spatial_nv) float64 ...\n", " var_aux (time, lev, y, x) float32 ...\n", " cell_area (time, lev, y, x) float32 ...\n", " mercator |S1 ...\n", @@ -1369,7 +1768,7 @@ " Conventions: CF-1.7" ] }, - "execution_count": 16, + "execution_count": 17, "metadata": {}, "output_type": "execute_result" } diff --git a/tutorials/4.Interpolation/4.3.Providentia_Interpolation.ipynb b/tutorials/4.Interpolation/4.3.Providentia_Interpolation.ipynb index 070e36d09d51b21e085e8674daf519251d7d73db..683bba0e3fa998b0e1387d5db139897624dd597b 100644 --- a/tutorials/4.Interpolation/4.3.Providentia_Interpolation.ipynb +++ b/tutorials/4.Interpolation/4.3.Providentia_Interpolation.ipynb @@ -422,7 +422,9 @@ "source": [ "interpolated_source_grid = source_grid.interpolate_horizontal(dst_grid, weight_matrix_path=None, \n", " kind='NearestNeighbour', n_neighbours=4,\n", - " info=True, to_providentia=True)" + " info=True, to_providentia=True)\n", + "# Bilinear to use n_neighbours (weighted average)\n", + "# n_neighbours = 1 for kind='NearestNeighbour'" ] }, { diff --git a/tutorials/5.Others/5.1.Add_Time_Bounds.ipynb b/tutorials/5.Others/5.1.Add_Time_Bounds.ipynb index 9c08016b91387c8db5d3efaeef8d56d2edbd04be..1ed4e2f29a02d9a7b08cc645a9cb39a2d8606e5a 100644 --- a/tutorials/5.Others/5.1.Add_Time_Bounds.ipynb +++ b/tutorials/5.Others/5.1.Add_Time_Bounds.ipynb @@ -40,24 +40,11 @@ "cell_type": "code", "execution_count": 3, "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "array([[datetime.datetime(2020, 2, 20, 0, 0),\n", - " datetime.datetime(2020, 2, 15, 0, 0)]], dtype=object)" - ] - }, - "execution_count": 3, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "array = np.array([[datetime.datetime(year=2020, month=2, day=20), \n", " datetime.datetime(year=2020, month=2, day=15)]])\n", - "nessy.set_time_bnds(array)\n", - "nessy.time_bnds" + "nessy.set_time_bnds(array)" ] }, { @@ -78,15 +65,6 @@ "nessy.load()" ] }, - { - "cell_type": "code", - "execution_count": 5, - "metadata": {}, - "outputs": [], - "source": [ - "nessy.to_netcdf('nc_serial_test.nc')" - ] - }, { "cell_type": "markdown", "metadata": {}, diff --git a/tutorials/5.Others/5.2.Add_Coordinates_Bounds.ipynb b/tutorials/5.Others/5.2.Add_Coordinates_Bounds.ipynb new file mode 100644 index 0000000000000000000000000000000000000000..5b70186d28465713d58c475f85af2e62e4a51f77 --- /dev/null +++ b/tutorials/5.Others/5.2.Add_Coordinates_Bounds.ipynb @@ -0,0 +1,250 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# How to add time bounds" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "import xarray as xr\n", + "import datetime\n", + "import numpy as np\n", + "from nes import *" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 1. Set time bounds" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "test_path = \"/gpfs/scratch/bsc32/bsc32538/mr_multiplyby/OUT/stats_bnds/monarch/a45g/regional/daily_max/O3_all/O3_all-000_2021080300.nc\"\n", + "nessy = open_netcdf(path=test_path, info=True)" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "inc_lat = np.abs(np.mean(np.diff(nessy.lat['data'])))\n", + "lat_bnds = nessy.create_bounds(nessy.lat['data'], inc_lat, spatial_nv=4)\n", + "nessy.set_lat_bnds(lat_bnds)" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [], + "source": [ + "inc_lon = np.abs(np.mean(np.diff(nessy.lon['data'])))\n", + "lon_bnds = nessy.create_bounds(nessy.lon['data'], inc_lon, spatial_nv=4)\n", + "nessy.set_lon_bnds(lon_bnds)" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Rank 000: Loading O3_all var (1/1)\n", + "Rank 000: Loaded O3_all var ((1, 24, 271, 351))\n" + ] + } + ], + "source": [ + "nessy.load()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 2. Explore variables" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "masked_array(\n", + " data=[[[16.35033798, 16.35033798, 16.35033798, 16.35033798],\n", + " [16.43292999, 16.43292999, 16.43292999, 16.43292999],\n", + " [16.51514626, 16.51514626, 16.51514626, 16.51514626],\n", + " ...,\n", + " [16.51514626, 16.51514626, 16.51514626, 16.51514626],\n", + " [16.43292999, 16.43292999, 16.43292999, 16.43292999],\n", + " [16.35033798, 16.35033798, 16.35033798, 16.35033798]],\n", + "\n", + " [[16.52742577, 16.52742577, 16.52742577, 16.52742577],\n", + " [16.61023903, 16.61023903, 16.61023903, 16.61023903],\n", + " [16.69267654, 16.69267654, 16.69267654, 16.69267654],\n", + " ...,\n", + " [16.69267654, 16.69267654, 16.69267654, 16.69267654],\n", + " [16.61024284, 16.61024284, 16.61024284, 16.61024284],\n", + " [16.52742577, 16.52742577, 16.52742577, 16.52742577]],\n", + "\n", + " [[16.70447159, 16.70447159, 16.70447159, 16.70447159],\n", + " [16.78750801, 16.78750801, 16.78750801, 16.78750801],\n", + " [16.87016678, 16.87016678, 16.87016678, 16.87016678],\n", + " ...,\n", + " [16.87016678, 16.87016678, 16.87016678, 16.87016678],\n", + " [16.78750992, 16.78750992, 16.78750992, 16.78750992],\n", + " [16.70447159, 16.70447159, 16.70447159, 16.70447159]],\n", + "\n", + " ...,\n", + "\n", + " [[58.32094955, 58.32094955, 58.32094955, 58.32094955],\n", + " [58.47268295, 58.47268295, 58.47268295, 58.47268295],\n", + " [58.62430954, 58.62430954, 58.62430954, 58.62430954],\n", + " ...,\n", + " [58.62430954, 58.62430954, 58.62430954, 58.62430954],\n", + " [58.47268295, 58.47268295, 58.47268295, 58.47268295],\n", + " [58.32094955, 58.32094955, 58.32094955, 58.32094955]],\n", + "\n", + " [[58.42628479, 58.42628479, 58.42628479, 58.42628479],\n", + " [58.57820129, 58.57820129, 58.57820129, 58.57820129],\n", + " [58.73002625, 58.73002625, 58.73002625, 58.73002625],\n", + " ...,\n", + " [58.73002625, 58.73002625, 58.73002625, 58.73002625],\n", + " [58.57820129, 58.57820129, 58.57820129, 58.57820129],\n", + " [58.42628479, 58.42628479, 58.42628479, 58.42628479]],\n", + "\n", + " [[58.53079224, 58.53079224, 58.53079224, 58.53079224],\n", + " [58.68289948, 58.68289948, 58.68289948, 58.68289948],\n", + " [58.83491898, 58.83491898, 58.83491898, 58.83491898],\n", + " ...,\n", + " [58.83491898, 58.83491898, 58.83491898, 58.83491898],\n", + " [58.68290329, 58.68290329, 58.68290329, 58.68290329],\n", + " [58.53079224, 58.53079224, 58.53079224, 58.53079224]]],\n", + " mask=False,\n", + " fill_value=1e+20)" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "nessy.lat_bnds" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "masked_array(\n", + " data=[[[-22.32515679, -22.03737297, -22.03737297, -22.32515679],\n", + " [-22.16056404, -21.87278023, -21.87278023, -22.16056404],\n", + " [-21.99569092, -21.7079071 , -21.7079071 , -21.99569092],\n", + " ...,\n", + " [ 41.70790329, 41.99568711, 41.99568711, 41.70790329],\n", + " [ 41.8727745 , 42.16055832, 42.16055832, 41.8727745 ],\n", + " [ 42.03736725, 42.32515106, 42.32515106, 42.03736725]],\n", + "\n", + " [[-22.42207108, -22.13428726, -22.13428726, -22.42207108],\n", + " [-22.25707779, -21.96929397, -21.96929397, -22.25707779],\n", + " [-22.0917965 , -21.80401268, -21.80401268, -22.0917965 ],\n", + " ...,\n", + " [ 41.80400696, 42.09179077, 42.09179077, 41.80400696],\n", + " [ 41.96928253, 42.25706635, 42.25706635, 41.96928253],\n", + " [ 42.13427963, 42.42206345, 42.42206345, 42.13427963]],\n", + "\n", + " [[-22.51915894, -22.23137512, -22.23137512, -22.51915894],\n", + " [-22.35376511, -22.06598129, -22.06598129, -22.35376511],\n", + " [-22.18808136, -21.90029754, -21.90029754, -22.18808136],\n", + " ...,\n", + " [ 41.90029373, 42.18807755, 42.18807755, 41.90029373],\n", + " [ 42.06598129, 42.35376511, 42.35376511, 42.06598129],\n", + " [ 42.23137131, 42.51915512, 42.51915512, 42.23137131]],\n", + "\n", + " ...,\n", + "\n", + " [[-67.72155914, -67.43377533, -67.43377533, -67.72155914],\n", + " [-67.54095612, -67.2531723 , -67.2531723 , -67.54095612],\n", + " [-67.3592392 , -67.07145538, -67.07145538, -67.3592392 ],\n", + " ...,\n", + " [ 87.07144775, 87.35923157, 87.35923157, 87.07144775],\n", + " [ 87.25316467, 87.54094849, 87.54094849, 87.25316467],\n", + " [ 87.4337677 , 87.72155152, 87.72155152, 87.4337677 ]],\n", + "\n", + " [[-68.04577027, -67.75798645, -67.75798645, -68.04577027],\n", + " [-67.86636505, -67.57858124, -67.57858124, -67.86636505],\n", + " [-67.68583069, -67.39804687, -67.39804687, -67.68583069],\n", + " ...,\n", + " [ 87.39804687, 87.68583069, 87.68583069, 87.39804687],\n", + " [ 87.57856598, 87.86634979, 87.86634979, 87.57856598],\n", + " [ 87.75797882, 88.04576264, 88.04576264, 87.75797882]],\n", + "\n", + " [[-68.37192688, -68.08414306, -68.08414306, -68.37192688],\n", + " [-68.19371185, -67.90592804, -67.90592804, -68.19371185],\n", + " [-68.01440582, -67.72662201, -67.72662201, -68.01440582],\n", + " ...,\n", + " [ 87.72661438, 88.0143982 , 88.0143982 , 87.72661438],\n", + " [ 87.90592804, 88.19371185, 88.19371185, 87.90592804],\n", + " [ 88.08414306, 88.37192688, 88.37192688, 88.08414306]]],\n", + " mask=False,\n", + " fill_value=1e+20)" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "nessy.lon_bnds" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.7.4" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +}