diff --git a/nes/nc_projections/latlon_nes.py b/nes/nc_projections/latlon_nes.py index 35d68c8ee3e75b9b3483f953a882c021c2cb368f..d7902f8e9cd29ba8e3d3046b816f472eb49019c8 100644 --- a/nes/nc_projections/latlon_nes.py +++ b/nes/nc_projections/latlon_nes.py @@ -50,12 +50,12 @@ class LatLonNes(Nes): create_nes : bool Indicates if you want to create the object from scratch (True) or through an existing file. balanced : bool - Indicates if you want a balanced parallelization or not. + Indicates if you want a balanced parallelization or not. Balanced dataset cannot be written in chunking mode. times : list, None List of times to substitute the current ones while creation. """ - + super(LatLonNes, self).__init__(comm=comm, path=path, info=info, dataset=dataset, parallel_method=parallel_method, balanced=balanced, avoid_first_hours=avoid_first_hours, avoid_last_hours=avoid_last_hours, @@ -78,7 +78,7 @@ class LatLonNes(Nes): @staticmethod def new(comm=None, path=None, info=False, dataset=None, parallel_method="Y", - avoid_first_hours=0, avoid_last_hours=0, first_level=0, last_level=None, create_nes=False, + avoid_first_hours=0, avoid_last_hours=0, first_level=0, last_level=None, create_nes=False, balanced=False, times=None, **kwargs): """ Initialize the Nes class. @@ -107,14 +107,14 @@ class LatLonNes(Nes): create_nes : bool Indicates if you want to create the object from scratch (True) or through an existing file. balanced : bool - Indicates if you want a balanced parallelization or not. + Indicates if you want a balanced parallelization or not. Balanced dataset cannot be written in chunking mode. times : list, None List of times to substitute the current ones while creation. """ new = LatLonNes(comm=comm, path=path, info=info, dataset=dataset, - parallel_method=parallel_method, avoid_first_hours=avoid_first_hours, + parallel_method=parallel_method, avoid_first_hours=avoid_first_hours, avoid_last_hours=avoid_last_hours, first_level=first_level, last_level=last_level, create_nes=create_nes, balanced=balanced, times=times, **kwargs) @@ -352,7 +352,7 @@ class LatLonNes(Nes): """ var.grid_mapping = "crs" - var.coordinates = "lat lon" + # var.coordinates = "lat lon" return None diff --git a/nes/nc_projections/lcc_nes.py b/nes/nc_projections/lcc_nes.py index f9eda6e108d204c897b97eabb36e9d03993770af..2aea9121731efffe7d1f8273130f8e6b3f852497 100644 --- a/nes/nc_projections/lcc_nes.py +++ b/nes/nc_projections/lcc_nes.py @@ -63,7 +63,7 @@ class LCCNes(Nes): create_nes : bool Indicates if you want to create the object from scratch (True) or through an existing file. balanced : bool - Indicates if you want a balanced parallelization or not. + Indicates if you want a balanced parallelization or not. Balanced dataset cannot be written in chunking mode. times : list, None List of times to substitute the current ones while creation. @@ -89,7 +89,7 @@ class LCCNes(Nes): # Dimensions screening self.y = self._get_coordinate_values(self.get_full_y(), "Y") self.x = self._get_coordinate_values(self.get_full_x(), "X") - + # Set axis limits for parallel writing self.write_axis_limits = self._get_write_axis_limits() @@ -101,7 +101,7 @@ class LCCNes(Nes): @staticmethod def new(comm=None, path=None, info=False, dataset=None, parallel_method="Y", - avoid_first_hours=0, avoid_last_hours=0, first_level=0, last_level=None, create_nes=False, + avoid_first_hours=0, avoid_last_hours=0, first_level=0, last_level=None, create_nes=False, balanced=False, times=None, **kwargs): """ Initialize the Nes class. @@ -130,7 +130,7 @@ class LCCNes(Nes): create_nes : bool Indicates if you want to create the object from scratch (True) or through an existing file. balanced : bool - Indicates if you want a balanced parallelization or not. + Indicates if you want a balanced parallelization or not. Balanced dataset cannot be written in chunking mode. times : list, None List of times to substitute the current ones while creation. @@ -261,7 +261,7 @@ class LCCNes(Nes): ) return projection - + def _get_projection_data(self, create_nes, **kwargs): """ Retrieves projection data based on grid details. @@ -467,12 +467,12 @@ class LCCNes(Nes): # Get edges for regular coordinates grid_edge_lon_data, grid_edge_lat_data = self.projection(x_grid_edge, y_grid_edge, inverse=True) - + # Create grid outline by stacking the edges in both coordinates model_grid_outline = vstack((grid_edge_lon_data, grid_edge_lat_data)).T grid_edge_lat = {"data": model_grid_outline[:, 1]} grid_edge_lon = {"data": model_grid_outline[:, 0]} - + return grid_edge_lat, grid_edge_lon # noinspection DuplicatedCode @@ -507,7 +507,7 @@ class LCCNes(Nes): :]} return None - + @staticmethod def _set_var_crs(var): """ @@ -520,7 +520,7 @@ class LCCNes(Nes): """ var.grid_mapping = "Lambert_Conformal" - var.coordinates = "lat lon" + # var.coordinates = "lat lon" return None @@ -567,13 +567,13 @@ class LCCNes(Nes): def create_shapefile(self): """ Create spatial GeoDataFrame (shapefile). - + Returns ------- shapefile : GeoPandasDataFrame Shapefile dataframe. """ - + if self.shapefile is None: # Get latitude and longitude cell boundaries @@ -594,7 +594,7 @@ class LCCNes(Nes): (aux_b_lon[i, 2], aux_b_lat[i, 2]), (aux_b_lon[i, 3], aux_b_lat[i, 3]), (aux_b_lon[i, 0], aux_b_lat[i, 0])])) - + # Create dataframe containing all polygons fids = self.get_fids() gdf = GeoDataFrame(index=Index(name="FID", data=fids.ravel()), geometry=geometry, crs="EPSG:4326") @@ -602,7 +602,7 @@ class LCCNes(Nes): else: gdf = self.shapefile - + return gdf # noinspection DuplicatedCode @@ -615,14 +615,14 @@ class LCCNes(Nes): centroids_gdf: GeoPandasDataFrame Centroids dataframe. """ - + # Get centroids from coordinates centroids = [] for lat_ind in range(0, self.lon["data"].shape[0]): for lon_ind in range(0, self.lon["data"].shape[1]): - centroids.append(Point(self.lon["data"][lat_ind, lon_ind], + centroids.append(Point(self.lon["data"][lat_ind, lon_ind], self.lat["data"][lat_ind, lon_ind])) - + # Create dataframe containing all points fids = self.get_fids() centroids_gdf = GeoDataFrame(index=Index(name="FID", data=fids.ravel()), geometry=centroids, crs="EPSG:4326") diff --git a/nes/nc_projections/mercator_nes.py b/nes/nc_projections/mercator_nes.py index 520f9bb4bfa9eea3da36fad13971d96e36bd7125..ef63cb741b4f56e6dccdaa3ae6f67c763baed4f9 100644 --- a/nes/nc_projections/mercator_nes.py +++ b/nes/nc_projections/mercator_nes.py @@ -57,7 +57,7 @@ class MercatorNes(Nes): avoid_last_hours : int Number of hours to remove from last time steps. balanced : bool - Indicates if you want a balanced parallelization or not. + Indicates if you want a balanced parallelization or not. Balanced dataset cannot be written in chunking mode. first_level : int Index of the first level to use. @@ -86,7 +86,7 @@ class MercatorNes(Nes): # Complete dimensions self._full_y = self._get_coordinate_dimension("y") self._full_x = self._get_coordinate_dimension("x") - + # Dimensions screening self.y = self._get_coordinate_values(self.get_full_y(), "Y") self.x = self._get_coordinate_values(self.get_full_x(), "X") @@ -131,7 +131,7 @@ class MercatorNes(Nes): create_nes : bool Indicates if you want to create the object from scratch (True) or through an existing file. balanced : bool - Indicates if you want a balanced parallelization or not. + Indicates if you want a balanced parallelization or not. Balanced dataset cannot be written in chunking mode. times : list, None List of times to substitute the current ones while creation. @@ -252,7 +252,7 @@ class MercatorNes(Nes): b=self.earth_radius[0], lat_ts=float64(self.projection_data["standard_parallel"]), lon_0=float64(self.projection_data["longitude_of_projection_origin"]),) - + return projection # noinspection DuplicatedCode @@ -449,12 +449,12 @@ class MercatorNes(Nes): # Get edges for regular coordinates grid_edge_lon_data, grid_edge_lat_data = self.projection(x_grid_edge, y_grid_edge, inverse=True) - + # Create grid outline by stacking the edges in both coordinates model_grid_outline = vstack((grid_edge_lon_data, grid_edge_lat_data)).T grid_edge_lat = {"data": model_grid_outline[:, 1]} grid_edge_lon = {"data": model_grid_outline[:, 0]} - + return grid_edge_lat, grid_edge_lon # noinspection DuplicatedCode @@ -480,15 +480,15 @@ class MercatorNes(Nes): # Obtain regular coordinates bounds self.set_full_latitudes_boundaries({"data": deepcopy(lat_bnds)}) self.lat_bnds = {"data": lat_bnds[self.write_axis_limits["y_min"]:self.write_axis_limits["y_max"], - self.write_axis_limits["x_min"]:self.write_axis_limits["x_max"], + self.write_axis_limits["x_min"]:self.write_axis_limits["x_max"], :]} self.set_full_longitudes_boundaries({"data": deepcopy(lon_bnds)}) self.lon_bnds = {"data": lon_bnds[self.write_axis_limits["y_min"]:self.write_axis_limits["y_max"], - self.write_axis_limits["x_min"]:self.write_axis_limits["x_max"], + self.write_axis_limits["x_min"]:self.write_axis_limits["x_max"], :]} return None - + @staticmethod def _set_var_crs(var): """ @@ -499,9 +499,9 @@ class MercatorNes(Nes): var : Variable netCDF4-python variable object. """ - + var.grid_mapping = "mercator" - var.coordinates = "lat lon" + # var.coordinates = "lat lon" return None @@ -520,7 +520,7 @@ class MercatorNes(Nes): mapping.grid_mapping_name = self.projection_data["grid_mapping_name"] mapping.standard_parallel = self.projection_data["standard_parallel"] mapping.longitude_of_projection_origin = self.projection_data["longitude_of_projection_origin"] - + return None def to_grib2(self, path, grib_keys, grib_template_path, lat_flip=False, info=False): @@ -540,7 +540,7 @@ class MercatorNes(Nes): info : bool Indicates if you want to print extra information during the process. """ - + raise NotImplementedError("Grib2 format cannot be written in a Mercator projection.") # noinspection DuplicatedCode @@ -555,7 +555,7 @@ class MercatorNes(Nes): """ if self.shapefile is None: - + # Get latitude and longitude cell boundaries if self.lat_bnds is None or self.lon_bnds is None: self.create_spatial_bounds() @@ -574,7 +574,7 @@ class MercatorNes(Nes): (aux_b_lon[i, 2], aux_b_lat[i, 2]), (aux_b_lon[i, 3], aux_b_lat[i, 3]), (aux_b_lon[i, 0], aux_b_lat[i, 0])])) - + # Create dataframe containing all polygons fids = self.get_fids() gdf = GeoDataFrame(index=Index(name="FID", data=fids.ravel()), geometry=geometry, crs="EPSG:4326") @@ -582,7 +582,7 @@ class MercatorNes(Nes): else: gdf = self.shapefile - + return gdf # noinspection DuplicatedCode @@ -595,14 +595,14 @@ class MercatorNes(Nes): centroids_gdf: GeoPandasDataFrame Centroids dataframe. """ - + # Get centroids from coordinates centroids = [] for lat_ind in range(0, self.lon["data"].shape[0]): for lon_ind in range(0, self.lon["data"].shape[1]): - centroids.append(Point(self.lon["data"][lat_ind, lon_ind], + centroids.append(Point(self.lon["data"][lat_ind, lon_ind], self.lat["data"][lat_ind, lon_ind])) - + # Create dataframe containing all points fids = self.get_fids() centroids_gdf = GeoDataFrame(index=Index(name="FID", data=fids.ravel()), geometry=centroids, crs="EPSG:4326") diff --git a/nes/nc_projections/points_nes.py b/nes/nc_projections/points_nes.py index 29022b50874c571580e25cc2239a1ecdaa623352..c63e9d5e99ba3e405d4760a26737b48d7b5bb4ea 100644 --- a/nes/nc_projections/points_nes.py +++ b/nes/nc_projections/points_nes.py @@ -62,7 +62,7 @@ class PointsNes(Nes): create_nes : bool Indicates if you want to create the object from scratch (True) or through an existing file. balanced : bool - Indicates if you want a balanced parallelization or not. + Indicates if you want a balanced parallelization or not. Balanced dataset cannot be written in chunking mode. times : list, None List of times to substitute the current ones while creation. @@ -123,7 +123,7 @@ class PointsNes(Nes): create_nes : bool Indicates if you want to create the object from scratch (True) or through an existing file. balanced : bool - Indicates if you want a balanced parallelization or not. + Indicates if you want a balanced parallelization or not. Balanced dataset cannot be written in chunking mode. times : list, None List of times to substitute the current ones while creation. @@ -466,12 +466,12 @@ class PointsNes(Nes): var[self.write_axis_limits["t_min"]:self.write_axis_limits["t_max"], self.write_axis_limits["x_min"]:self.write_axis_limits["x_max"]] = att_value except IndexError: - out_shape = var[self.write_axis_limits["t_min"]:self.write_axis_limits["t_max"], + out_shape = var[self.write_axis_limits["t_min"]:self.write_axis_limits["t_max"], self.write_axis_limits["x_min"]:self.write_axis_limits["x_max"]].shape raise IndexError("Different shapes. out_shape={0}, data_shp={1}".format( out_shape, att_value.shape)) except ValueError: - out_shape = var[self.write_axis_limits["t_min"]:self.write_axis_limits["t_max"], + out_shape = var[self.write_axis_limits["t_min"]:self.write_axis_limits["t_max"], self.write_axis_limits["x_min"]:self.write_axis_limits["x_max"]].shape raise ValueError("Axis limits cannot be accessed. out_shape={0}, data_shp={1}".format( out_shape, att_value.shape)) @@ -596,7 +596,7 @@ class PointsNes(Nes): def to_providentia(self, model_centre_lon, model_centre_lat, grid_edge_lon, grid_edge_lat): """ Transform a PointsNes into a PointsNesProvidentia object - + Returns ---------- points_nes_providentia : nes.Nes @@ -750,6 +750,6 @@ class PointsNes(Nes): var : Variable netCDF4-python variable object. """ - var.coordinates = "lat lon" + # var.coordinates = "lat lon" return None diff --git a/nes/nc_projections/rotated_nes.py b/nes/nc_projections/rotated_nes.py index c5c3794e82503721d16a0c32a57864bcc23faa67..e1647eab7ab31df2b39b8e388692fee07e6c6546 100644 --- a/nes/nc_projections/rotated_nes.py +++ b/nes/nc_projections/rotated_nes.py @@ -65,7 +65,7 @@ class RotatedNes(Nes): create_nes : bool Indicates if you want to create the object from scratch (True) or through an existing file. balanced : bool - Indicates if you want a balanced parallelization or not. + Indicates if you want a balanced parallelization or not. Balanced dataset cannot be written in chunking mode. times : list, None List of times to substitute the current ones while creation. @@ -260,7 +260,7 @@ class RotatedNes(Nes): o_lat_p=float64(self.projection_data["grid_north_pole_latitude"]), o_lon_p=float64(self.projection_data["grid_north_pole_longitude"]), ) - + return projection # noinspection DuplicatedCode @@ -532,13 +532,13 @@ class RotatedNes(Nes): # Get edges for regular coordinates grid_edge_lon_data, grid_edge_lat_data = self.rotated2latlon(rlon_grid_edge, rlat_grid_edge) - + # Create grid outline by stacking the edges in both coordinates model_grid_outline = vstack((grid_edge_lon_data, grid_edge_lat_data)).T grid_edge_lat = {"data": model_grid_outline[:, 1]} grid_edge_lon = {"data": model_grid_outline[:, 0]} - + return grid_edge_lat, grid_edge_lon # noinspection DuplicatedCode @@ -586,7 +586,7 @@ class RotatedNes(Nes): """ var.grid_mapping = "rotated_pole" - var.coordinates = "lat lon" + # var.coordinates = "lat lon" return None @@ -645,11 +645,11 @@ class RotatedNes(Nes): self.create_spatial_bounds() # Reshape arrays to create geometry - aux_b_lats = self.lat_bnds["data"].reshape((self.lat_bnds["data"].shape[0] * self.lat_bnds["data"].shape[1], + aux_b_lats = self.lat_bnds["data"].reshape((self.lat_bnds["data"].shape[0] * self.lat_bnds["data"].shape[1], self.lat_bnds["data"].shape[2])) - aux_b_lons = self.lon_bnds["data"].reshape((self.lon_bnds["data"].shape[0] * self.lon_bnds["data"].shape[1], + aux_b_lons = self.lon_bnds["data"].reshape((self.lon_bnds["data"].shape[0] * self.lon_bnds["data"].shape[1], self.lon_bnds["data"].shape[2])) - + # Get polygons from bounds geometry = [] for i in range(aux_b_lons.shape[0]): @@ -658,7 +658,7 @@ class RotatedNes(Nes): (aux_b_lons[i, 2], aux_b_lats[i, 2]), (aux_b_lons[i, 3], aux_b_lats[i, 3]), (aux_b_lons[i, 0], aux_b_lats[i, 0])])) - + # Create dataframe cointaining all polygons fids = self.get_fids() gdf = GeoDataFrame(index=Index(name="FID", data=fids.ravel()), geometry=geometry, crs="EPSG:4326") @@ -679,16 +679,16 @@ class RotatedNes(Nes): centroids_gdf: GeoPandasDataFrame Centroids dataframe. """ - + # Get centroids from coordinates centroids = [] for lat_ind in range(0, self.lon["data"].shape[0]): for lon_ind in range(0, self.lon["data"].shape[1]): - centroids.append(Point(self.lon["data"][lat_ind, lon_ind], + centroids.append(Point(self.lon["data"][lat_ind, lon_ind], self.lat["data"][lat_ind, lon_ind])) - + # Create dataframe cointaining all points fids = self.get_fids() centroids_gdf = GeoDataFrame(index=Index(name="FID", data=fids.ravel()), geometry=centroids, crs="EPSG:4326") - + return centroids_gdf