Projections

Default projection

class nes.nc_projections.default_nes.Nes(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, create_nes=False, balanced=False, times=None, **kwargs)[source]

Bases: object

Attributes

comm : MPI.Communicator. rank : int

MPI rank.

masterbool

True when rank == 0.

sizeint

Size of the communicator.

infobool

Indicates if you want to print reading/writing info.

is_xarraybool

(Not working) Indicates if you want to use xarray as default.

__ini_pathstr

Path to the original file to read when open_netcdf is called.

hours_startint

Number of hours to avoid from the first original values.

hours_endint

Number of hours to avoid from the last original values.

datasetxr.Dataset

(not working) xArray Dataset.

netcdfDataset

netcdf4-python Dataset.

variablesdict

Variables information. The variables are stored in a dictionary with the var_name as key and another dictionary with the information. The information dictionary contains the ‘data’ key with None (if the variable is not loaded) or the array values and the other keys are the variable attributes or description.

_timeList

Complete list of original time step values.

_levdict

Vertical level dictionary with the complete ‘data’ key for all the values and the rest of the attributes.

_latdict

Latitudes dictionary with the complete ‘data’ key for all the values and the rest of the attributes.

_lon _ dict

Longitudes dictionary with the complete ‘data’ key for all the values and the rest of the attributes.

parallel_methodstr

Parallel method to read/write. Can be chosen any of the following axis to parallelize: ‘T’, ‘Y’ or ‘X’.

read_axis_limitsdict

Dictionary with the 4D limits of the rank data to read. t_min, t_max, z_min, z_max, y_min, y_max, x_min and x_max.

write_axis_limitsdict

Dictionary with the 4D limits of the rank data to write. t_min, t_max, z_min, z_max, y_min, y_max, x_min and x_max.

timeList[datetime]

List of time steps of the rank data.

levdict

Vertical levels dictionary with the portion of ‘data’ corresponding to the rank values.

latdict

Latitudes dictionary with the portion of ‘data’ corresponding to the rank values.

londict

Longitudes dictionary with the portion of ‘data’ corresponding to the rank values.

global_attrsdict

Global attributes with the attribute name as key and data as values.

_var_dimNone or tuple

Name of the Y and X dimensions for the variables.

_lat_dimNone or tuple

Name of the dimensions of the Latitude values.

_lon_dimNone or tuple

Name of the dimensions of the Longitude values.

projectionpyproj.Proj

Grid projection.

projection_datadict

Dictionary with the projection information.

add_4d_vertical_info(info_to_add)[source]

To add the vertical information from other source.

Parameters

info_to_addnes.Nes, str

Nes object with the vertical information as variable or str with the path to the NetCDF file that contains the vertical data.

add_variables_to_shapefile(var_list, idx_lev=0, idx_time=0)[source]

Add variables data to shapefile.

var_listList or str

Variables to be loaded and saved in the shapefile.

idx_levint

Index of vertical level for which the data will be saved in the shapefile.

idx_timeint

Index of time for which the data will be saved in the shapefile.

append_time_step_data(i_time, out_format='DEFAULT')[source]

Fill the netCDF data for the indicated index time.

Parameters

i_timeint

index of the time step to write

out_formatstr

Indicates the output format type to change the units (if needed)

static calculate_geometry_area(geometry_list, earth_radius_minor_axis=6356752.3142, earth_radius_major_axis=6378137.0)[source]

Get coordinate bounds and call function to calculate the area of each cell of a set of geometries.

Parameters

geometry_listList

List with polygon geometries.

earth_radius_minor_axisfloat

Radius of the minor axis of the Earth.

earth_radius_major_axisfloat

Radius of the major axis of the Earth.

calculate_grid_area(overwrite=True)[source]

Get coordinate bounds and call function to calculate the area of each cell of a grid.

Parameters

selfnes.Nes

Source projection Nes Object.

overwritebool

Indicates if we want to overwrite the grid area

clear_communicator()[source]

Erase the communicator and the parallelization indexes.

close()[source]

Close the NetCDF with netcdf4-python.

concatenate(aux_nessy)[source]

Concatenate different variables into the same nes object.

Parameters

aux_nessyNes, str

Nes object or str with the path to the NetCDF file that contains the variables to add.

Returns

list

List of var names added.

copy(copy_vars=False)[source]

Copy the Nes object. The copy will avoid to copy the communicator, dataset and variables by default.

Parameters

copy_vars: bool

Indicates if you want to copy the variables (in lazy mode).

Returns

nessyNes

Copy of the Nes object.

create_shapefile()[source]

Create spatial geodataframe (shapefile).

Returns

shapefileGeoPandasDataFrame

Shapefile dataframe.

static create_single_spatial_bounds(coordinates, inc, spatial_nv=2, inverse=False)[source]

Calculate the vertices coordinates.

Parameters

coordinatesnp.array

Coordinates in degrees (latitude or longitude).

incfloat

Increment between centre values.

spatial_nvint

Non-mandatory parameter that informs the number of vertices that the boundaries must have. Default: 2.

inversebool

For some grid latitudes.

Returns

boundsnp.array

Array with as many elements as vertices for each value of coords.

create_spatial_bounds()[source]

Calculate longitude and latitude bounds and set them.

daily_statistic(op, type_op='calendar')[source]

Calculate daily statistic.

Parameters

opstr

Statistic to perform. Accepted values: “max”, “mean” and “min”.

type_opstr

Type of statistic to perform. Accepted values: “calendar”, “alltsteps”, and “withoutt0”. - “calendar”: Calculate the statistic using the time metadata.

It will avoid single time step by day calculations

  • “alltsteps”: Calculate a single time statistic with all the time steps.

  • “withoutt0”: Calculate a single time statistic with all the time steps avoiding the first one.

filter_coordinates_selection()[source]

Use the selection limits to filter time, lev, lat, lon, lon_bnds and lat_bnds.

find_time_id(time)[source]

Find index of time in time array.

Parameters

timedatetime.datetime

Time element.

Returns

int

Index of time element.

free_vars(var_list)[source]

Erase the selected variables from the variables’ information.

Parameters

var_listList or str

List (or single string) of the variables to be loaded.

get_centroids_from_coordinates()[source]

Get centroids from geographical coordinates.

Returns

centroids_gdf: GeoPandasDataFrame

Centroids dataframe.

get_climatology()[source]
static get_coordinate_id(array, value, axis=0)[source]

Get the index of the corresponding coordinate value.

Parameters

arraynp.array

Array with the coordinate data

valuefloat

Coordinate value to search.

axisint

Axis where find the value Default: 0.

Returns

int

Index of the coordinate array.

static get_earth_radius(ellps)[source]

Get minor and major axis of Earth.

Parameters

ellpsstr

Spatial reference system.

get_fids()[source]

Obtain the FIDs in a 2D format

Returns

np.array

2D array with the FID data

get_full_levels()[source]
get_full_times()[source]
get_idx_intervals()[source]

Calculate the index intervals

Returns

dict

Dictionary with the index intervals

get_read_axis_limits()[source]

Calculate the 4D reading axis limits depending on if them have to balanced or not.

Returns

dict

Dictionary with the 4D limits of the rank data to read. t_min, t_max, z_min, z_max, y_min, y_max, x_min and x_max.

get_read_axis_limits_balanced()[source]

Calculate the 4D reading balanced axis limits.

Returns

dict

Dictionary with the 4D limits of the rank data to read. t_min, t_max, z_min, z_max, y_min, y_max, x_min and x_max.

get_read_axis_limits_unbalanced()[source]

Calculate the 4D reading axis limits.

Returns

dict

Dictionary with the 4D limits of the rank data to read. t_min, t_max, z_min, z_max, y_min, y_max, x_min and x_max.

get_spatial_bounds_mesh_format()[source]

Get the spatial bounds in the pcolormesh format:

see: https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.pcolormesh.html

Returns

lon_bnds_meshnumpy.ndarray

Longitude boundaries in the mesh format

lat_bnds_meshnumpy.ndarray

Latitude boundaries in the mesh format

get_time_id(hours, first=True)[source]

Get the index of the corresponding time value.

Parameters

hoursint

Number of hours to avoid.

firstbool

Indicates if you want to avoid from the first hours (True) or from the last (False). Default: True.

Returns

int

Index of the time array.

get_time_interval()[source]

Calculate the interrval of hours between time steps.

Returns

int

Number of hours between time steps.

get_write_axis_limits()[source]

Calculate the 4D writing axis limits depending on if them have to balanced or not.

Returns

dict

Dictionary with the 4D limits of the rank data to write. t_min, t_max, z_min, z_max, y_min, y_max, x_min and x_max.

get_write_axis_limits_balanced()[source]

Calculate the 4D reading balanced axis limits.

Returns

dict

Dictionary with the 4D limits of the rank data to read. t_min, t_max, z_min, z_max, y_min, y_max, x_min and x_max.

get_write_axis_limits_unbalanced()[source]

Calculate the 4D writing axis limits.

Returns

dict

Dictionary with the 4D limits of the rank data to write. t_min, t_max, z_min, z_max, y_min, y_max, x_min and x_max.

interpolate_horizontal(dst_grid, weight_matrix_path=None, kind='NearestNeighbour', n_neighbours=4, info=False, to_providentia=False, only_create_wm=False, wm=None, flux=False)[source]

Horizontal methods from the current grid to another one.

Parameters

dst_gridnes.Nes

Final projection Nes object.

weight_matrix_pathstr, None

Path to the weight matrix to read/create.

kindstr

Kind of horizontal methods. choices = [‘NearestNeighbour’, ‘Conservative’].

n_neighbours: int

Used if kind == NearestNeighbour. Number of nearest neighbours to interpolate. Default: 4.

info: bool

Indicates if you want to print extra info during the methods process.

to_providentiabool

Indicates if we want the interpolated grid in Providentia format.

only_create_wmbool

Indicates if you want to only create the Weight Matrix.

wmNes

Weight matrix Nes File

fluxbool

Indicates if you want to calculate the weight matrix for flux variables

interpolate_vertical(new_levels, new_src_vertical=None, kind='linear', extrapolate=None, info=None, overwrite=False)[source]

Vertical interpolation function.

Parameters

selfNes

Source Nes object.

new_levelsList

New vertical levels.

new_src_vertical kind : str

Vertical methods type.

extrapolateNone, tuple, str

Extrapolate method (for non linear operations).

info: None, bool

Indicates if you want to print extra information.

overwrite: bool

Indicates if you want to compute the vertical interpolation in the same object or not

keep_vars(var_list)[source]

Keep the selected variables and erases the rest.

Parameters

var_listList or str

List (or single string) of the variables to be loaded.

last_time_step()[source]

Modify variables to keep only the last time step.

load(var_list=None)[source]

Load of the selected variables.

That function will fill the variable ‘data’ key with the corresponding values.

Parameters

var_listList, str, None

List (or single string) of the variables to be loaded.

static lon_lat_to_cartesian_ecef(lon, lat)[source]

# Convert observational/model geographic longitude/latitude coordinates to cartesian ECEF (Earth Centred, # Earth Fixed) coordinates, assuming WGS84 datum and ellipsoid, and that all heights = 0. # ECEF coordiantes represent positions (in meters) as X, Y, Z coordinates, approximating the earth surface # as an ellipsoid of revolution. # This conversion is for the subsequent calculation of euclidean distances of the model gridcell centres # from each observational station. # Defining the distance between two points on the earth’s surface as simply the euclidean distance # between the two lat/lon pairs could lead to inaccurate results depending on the distance # between two points (i.e. 1 deg. of longitude varies with latitude).

Parameters

lonnp.array

Longitude values.

latnp.array

Latitude values.

static new(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, create_nes=False, balanced=False, times=None, **kwargs)[source]

Initialize the Nes class.

Parameters

comm: MPI.COMM

MPI Communicator.

path: str

Path to the NetCDF to initialize the object.

info: bool

Indicates if you want to get reading/writing info.

dataset: Dataset

NetCDF4-python Dataset to initialize the class.

xarray: bool

(Not working) Indicates if you want to use xarray as default.

parallel_methodstr

Indicates the parallelization method that you want. Default over Y axis accepted values: [‘X’, ‘Y’, ‘T’].

avoid_first_hoursint

Number of hours to remove from first time steps.

avoid_last_hoursint

Number of hours to remove from last time steps.

first_levelint

Index of the first level to use.

last_levelint or None

Index of the last level to use. None if it is the last.

create_nesbool

Indicates if you want to create the object from scratch (True) or through an existing file.

balancedbool

Indicates if you want a balanced parallelization or not. Balanced dataset cannot be written in chunking mode.

timesList[datetime] or None

List of times to substitute the current ones while creation.

open()[source]

Open the NetCDF.

reverse_level_direction()[source]
rolling_mean(var_list=None, hours=8)[source]

Calculate rolling mean for given hours

Parameters

var_list: List, str, None

List (or single string) of the variables to be loaded.

hoursint, optional

Window hours to calculate rolling mean, by default 8

Returns

Nes

Nes object

sel(hours_start=None, time_min=None, hours_end=None, time_max=None, lev_min=None, lev_max=None, lat_min=None, lat_max=None, lon_min=None, lon_max=None)[source]

Select a slice of time, lev, lat or lon given a minimum and maximum limits.

sel_time(time, copy=False)[source]

To select only one time step.

Parameters

timedatetime.datetime

Time stamp to select.

copybool

Indicates if you want a copy with the selected time step (True) or to modify te existing one (False).

Returns

Nes

Nes object with the data (and metadata) of the selected time step.

set_climatology(is_climatology)[source]
set_communicator(comm)[source]

Set a new communicator and the correspondent parallelization indexes.

Parameters

comm: MPI.COMM

Communicator to be set.

set_level_direction(new_direction)[source]
set_levels(levels)[source]

Modify the original level values with new ones.

Parameters

levelsdict

Dictionary with the new level information to be set.

set_strlen(strlen=75)[source]

Set the strlen

75 is the standard value used in GHOST data

Parameters

strlenint or None

Max length of the string

set_time(time_list)[source]

Modify the original level values with new ones.

Parameters

time_listList[datetime]

List of time steps

set_time_bnds(time_bnds)[source]

Modify the original time bounds values with new ones.

Parameters

time_bndsList

List with the new time bounds information to be set.

set_time_resolution(new_resolution)[source]
spatial_join(ext_shp, method=None, var_list=None, info=False)[source]

Compute overlay intersection of two GeoPandasDataFrames.

Parameters

ext_shpGeoPandasDataFrame or str

File or path from where the data will be obtained on the intersection.

methodstr

Overlay method. Accepted values: [‘nearest’, ‘intersection’, ‘centroid’].

var_listList or None

Variables that will be included in the resulting shapefile.

infobool

Indicates if you want to print the process info or no

str2char(data)[source]
sum_axis(axis='Z')[source]
to_dtype(data_type='float32')[source]

Cast variables data into selected data type.

Parameters

data_typestr or Type

Data type, by default ‘float32’

to_grib2(path, grib_keys, grib_template_path, lat_flip=True, info=False)[source]

Write output file with grib2 format.

Parameters

pathstr

Path to the output file.

grib_keysdict

Dictionary with the grib2 keys.

grib_template_pathstr

Path to the grib2 file to use as template.

lat_flipbool

Indicates if the latitude values (and data) has to be flipped

infobool

Indicates if you want to print extra information during the process.

to_netcdf(path, compression_level=0, serial=False, info=False, chunking=False, type='NES', keep_open=False)[source]

Write the netCDF output file.

Parameters

pathstr

Path to the output netCDF file.

compression_levelint

Level of compression (0 to 9) Default: 0 (no compression).

serialbool

Indicates if you want to write in serial or not. Default: False.

infobool

Indicates if you want to print the information of each writing step by stdout Default: False.

chunkingbool

Indicates if you want a chunked netCDF output. Only available with non-serial writes. Default: False.

typestr

Type to NetCDf to write. ‘CAMS_RA’ or ‘NES’

keep_openbool

Indicates if you want to keep open the NetCDH to fill the data by time-step

to_shapefile(path, time=None, lev=None, var_list=None)[source]

Create shapefile from NES data.

  1. Create grid shapefile.

  2. Add variables to shapefile (as independent function).

  3. Write shapefile.

Parameters

pathstr

Path to the output file.

timedatetime.datetime

Time stamp to select.

levint

Vertical level to select.

var_listList, str, None

List (or single string) of the variables to be loaded and saved in the shapefile.

write_shapefile(path)[source]

Save spatial geodataframe (shapefile).

Parameters

pathstr

Path to the output file.

Regulat lat lon projection

class nes.nc_projections.latlon_nes.LatLonNes(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, create_nes=False, balanced=False, times=None, **kwargs)[source]

Bases: Nes

Attributes

_var_dimtuple

Tuple with the name of the Y and X dimensions for the variables. (‘lat’, ‘lon’) for a regular latitude-longitude projection.

_lat_dimtuple

Tuple with the name of the dimensions of the Latitude values. (‘lat’,) for a regular latitude-longitude projection.

_lon_dimtuple

Tuple with the name of the dimensions of the Longitude values. (‘lon’,) for a regular latitude-longitude projection.

create_providentia_exp_centre_coordinates()[source]

Calculate centre latitudes and longitudes from original coordinates and store as 2D arrays.

Returns

model_centre_latdict

Dictionary with data of centre coordinates for latitude in 2D (latitude, longitude).

model_centre_londict

Dictionary with data of centre coordinates for longitude in 2D (latitude, longitude).

create_providentia_exp_grid_edge_coordinates()[source]

Calculate grid edge latitudes and longitudes and get model grid outline.

Returns

grid_edge_latdict

Dictionary with data of grid edge latitudes.

grid_edge_londict

Dictionary with data of grid edge longitudes.

static new(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, create_nes=False, balanced=False, times=None, **kwargs)[source]

Initialize the Nes class.

Parameters

comm: MPI.COMM

MPI Communicator.

path: str

Path to the NetCDF to initialize the object.

info: bool

Indicates if you want to get reading/writing info.

dataset: Dataset

NetCDF4-python Dataset to initialize the class.

xarray: bool:

(Not working) Indicates if you want to use xarray as default.

parallel_methodstr

Indicates the parallelization method that you want. Default: ‘Y’. Accepted values: [‘X’, ‘Y’, ‘T’].

avoid_first_hoursint

Number of hours to remove from first time steps.

avoid_last_hoursint

Number of hours to remove from last time steps.

first_levelint

Index of the first level to use.

last_levelint, None

Index of the last level to use. None if it is the last.

create_nesbool

Indicates if you want to create the object from scratch (True) or through an existing file.

balancedbool

Indicates if you want a balanced parallelization or not. Balanced dataset cannot be written in chunking mode.

timeslist, None

List of times to substitute the current ones while creation.

to_grib2(path, grib_keys, grib_template_path, lat_flip=False, info=False)[source]

Write output file with grib2 format.

Parameters

lat_flipbool

Indicates if the latitudes have to be flipped

pathstr

Path to the output file.

grib_keysdict

Dictionary with the grib2 keys.

grib_template_pathstr

Path to the grib2 file to use as template.

infobool

Indicates if you want to print extra information during the process.

LCC projection

class nes.nc_projections.lcc_nes.LCCNes(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, create_nes=False, balanced=False, times=None, **kwargs)[source]

Bases: Nes

Attributes

_ydict

Y coordinates dictionary with the complete ‘data’ key for all the values and the rest of the attributes.

_xdict

X coordinates dictionary with the complete ‘data’ key for all the values and the rest of the attributes.

ydict

Y coordinates dictionary with the portion of ‘data’ corresponding to the rank values.

xdict

X coordinates dictionary with the portion of ‘data’ corresponding to the rank values.

_var_dimtuple

Tuple with the name of the Y and X dimensions for the variables. (‘y’, ‘x’,) for a LCC projection.

_lat_dimtuple

Tuple with the name of the dimensions of the Latitude values. (‘y’, ‘x’,) for a LCC projection.

_lon_dimtuple

Tuple with the name of the dimensions of the Longitude values. (‘y’, ‘x’) for a LCC projection.

create_providentia_exp_centre_coordinates()[source]

Calculate centre latitudes and longitudes from original coordinates and store as 2D arrays.

Returns

model_centre_latdict

Dictionary with data of centre coordinates for latitude in 2D (latitude, longitude).

model_centre_londict

Dictionary with data of centre coordinates for longitude in 2D (latitude, longitude).

create_providentia_exp_grid_edge_coordinates()[source]

Calculate grid edge latitudes and longitudes and get model grid outline.

Returns

grid_edge_latdict

Dictionary with data of grid edge latitudes.

grid_edge_londict

Dictionary with data of grid edge longitudes.

create_shapefile()[source]

Create spatial geodataframe (shapefile).

Returns

shapefileGeoPandasDataFrame

Shapefile dataframe.

create_spatial_bounds()[source]

Calculate longitude and latitude bounds and set them.

filter_coordinates_selection()[source]

Use the selection limits to filter y, x, time, lev, lat, lon, lon_bnds and lat_bnds.

get_centroids_from_coordinates()[source]

Get centroids from geographical coordinates.

Returns

centroids_gdf: GeoPandasDataFrame

Centroids dataframe.

static new(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, create_nes=False, balanced=False, times=None, **kwargs)[source]

Initialize the Nes class.

Parameters

comm: MPI.COMM

MPI Communicator.

path: str

Path to the NetCDF to initialize the object.

info: bool

Indicates if you want to get reading/writing info.

dataset: Dataset

NetCDF4-python Dataset to initialize the class.

xarray: bool:

(Not working) Indicates if you want to use xarray as default.

parallel_methodstr

Indicates the parallelization method that you want. Default: ‘Y’. Accepted values: [‘X’, ‘Y’, ‘T’].

avoid_first_hoursint

Number of hours to remove from first time steps.

avoid_last_hoursint

Number of hours to remove from last time steps.

first_levelint

Index of the first level to use.

last_levelint, None

Index of the last level to use. None if it is the last.

create_nesbool

Indicates if you want to create the object from scratch (True) or through an existing file.

balancedbool

Indicates if you want a balanced parallelization or not. Balanced dataset cannot be written in chunking mode.

timeslist, None

List of times to substitute the current ones while creation.

to_grib2(path, grib_keys, grib_template_path, lat_flip=False, info=False)[source]

Write output file with grib2 format.

Parameters

pathstr

Path to the output file.

grib_keysdict

Dictionary with the grib2 keys.

grib_template_pathstr

Path to the grib2 file to use as template.

infobool

Indicates if you want to print extra information during the process.

Mercator projection

class nes.nc_projections.mercator_nes.MercatorNes(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, create_nes=False, balanced=False, times=None, **kwargs)[source]

Bases: Nes

Attributes

_ydict

Y coordinates dictionary with the complete ‘data’ key for all the values and the rest of the attributes.

_xdict

X coordinates dictionary with the complete ‘data’ key for all the values and the rest of the attributes.

ydict

Y coordinates dictionary with the portion of ‘data’ corresponding to the rank values.

xdict

X coordinates dictionary with the portion of ‘data’ corresponding to the rank values.

_var_dimtuple

Tuple with the name of the Y and X dimensions for the variables. (‘y’, ‘x’) for a Mercator projection.

_lat_dimtuple

Tuple with the name of the dimensions of the Latitude values. (‘y’, ‘x’) for a Mercator projection.

_lon_dimtuple

Tuple with the name of the dimensions of the Longitude values. (‘y’, ‘x’) for a Mercator projection.

create_providentia_exp_centre_coordinates()[source]

Calculate centre latitudes and longitudes from original coordinates and store as 2D arrays.

Returns

model_centre_latdict

Dictionary with data of centre coordinates for latitude in 2D (latitude, longitude).

model_centre_londict

Dictionary with data of centre coordinates for longitude in 2D (latitude, longitude).

create_providentia_exp_grid_edge_coordinates()[source]

Calculate grid edge latitudes and longitudes and get model grid outline.

Returns

grid_edge_latdict

Dictionary with data of grid edge latitudes.

grid_edge_londict

Dictionary with data of grid edge longitudes.

create_shapefile()[source]

Create spatial geodataframe (shapefile).

Returns

shapefileGeoPandasDataFrame

Shapefile dataframe.

create_spatial_bounds()[source]

Calculate longitude and latitude bounds and set them.

filter_coordinates_selection()[source]

Use the selection limits to filter y, x, time, lev, lat, lon, lon_bnds and lat_bnds.

get_centroids_from_coordinates()[source]

Get centroids from geographical coordinates.

Returns

centroids_gdf: GeoPandasDataFrame

Centroids dataframe.

static new(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, create_nes=False, balanced=False, times=None, **kwargs)[source]

Initialize the Nes class.

Parameters

comm: MPI.COMM

MPI Communicator.

path: str

Path to the NetCDF to initialize the object.

info: bool

Indicates if you want to get reading/writing info.

dataset: Dataset

NetCDF4-python Dataset to initialize the class.

xarray: bool:

(Not working) Indicates if you want to use xarray as default.

parallel_methodstr

Indicates the parallelization method that you want. Default: ‘Y’. Accepted values: [‘X’, ‘Y’, ‘T’].

avoid_first_hoursint

Number of hours to remove from first time steps.

avoid_last_hoursint

Number of hours to remove from last time steps.

first_levelint

Index of the first level to use.

last_levelint, None

Index of the last level to use. None if it is the last.

create_nesbool

Indicates if you want to create the object from scratch (True) or through an existing file.

balancedbool

Indicates if you want a balanced parallelization or not. Balanced dataset cannot be written in chunking mode.

timeslist, None

List of times to substitute the current ones while creation.

to_grib2(path, grib_keys, grib_template_path, lat_flip=False, info=False)[source]

Write output file with grib2 format.

Parameters

pathstr

Path to the output file.

grib_keysdict

Dictionary with the grib2 keys.

grib_template_pathstr

Path to the grib2 file to use as template.

infobool

Indicates if you want to print extra information during the process.

Points projection

class nes.nc_projections.points_nes.PointsNes(comm=None, path=None, info=False, dataset=None, xarray=False, parallel_method='X', avoid_first_hours=0, avoid_last_hours=0, first_level=0, last_level=None, create_nes=False, balanced=False, times=None, **kwargs)[source]

Bases: Nes

Attributes

_var_dimtuple

Tuple with the name of the Y and X dimensions for the variables. (‘lat’, ‘lon’) for a points grid.

_lat_dimtuple

Tuple with the name of the dimensions of the Latitude values. (‘lat’,) for a points grid.

_lon_dimtuple

Tuple with the name of the dimensions of the Longitude values. (‘lon’,) for a points grid.

_stationtuple

Tuple with the name of the dimensions of the station values. (‘station’,) for a points grid.

add_variables_to_shapefile(var_list, idx_lev=0, idx_time=0)[source]

Add variables data to shapefile.

var_listlist, str

List (or single string) of the variables to be loaded and saved in the shapefile.

idx_levint

Index of vertical level for which the data will be saved in the shapefile.

idx_timeint

Index of time for which the data will be saved in the shapefile.

create_shapefile()[source]

Create spatial geodataframe (shapefile).

Returns

shapefileGeoPandasDataFrame

Shapefile dataframe.

create_spatial_bounds()[source]

Calculate longitude and latitude bounds and set them.

get_centroids_from_coordinates()[source]

Get centroids from geographical coordinates.

Returns

centroids_gdf: GeoPandasDataFrame

Centroids dataframe.

static new(comm=None, path=None, info=False, dataset=None, xarray=False, parallel_method='X', avoid_first_hours=0, avoid_last_hours=0, first_level=0, last_level=None, create_nes=False, balanced=False, times=None, **kwargs)[source]

Initialize the Nes class.

Parameters

comm: MPI.COMM

MPI Communicator.

path: str

Path to the NetCDF to initialize the object.

info: bool

Indicates if you want to get reading/writing info.

dataset: Dataset

NetCDF4-python Dataset to initialize the class.

xarray: bool:

(Not working) Indicates if you want to use xarray as default.

parallel_methodstr

Indicates the parallelization method that you want. Default: ‘X’. accepted values: [‘X’, ‘T’].

avoid_first_hoursint

Number of hours to remove from first time steps.

avoid_last_hoursint

Number of hours to remove from last time steps.

first_levelint

Index of the first level to use.

last_levelint, None

Index of the last level to use. None if it is the last.

create_nesbool

Indicates if you want to create the object from scratch (True) or through an existing file.

balancedbool

Indicates if you want a balanced parallelization or not. Balanced dataset cannot be written in chunking mode.

timeslist, None

List of times to substitute the current ones while creation.

to_grib2(path, grib_keys, grib_template_path, lat_flip=False, info=False)[source]

Write output file with grib2 format.

Parameters

pathstr

Path to the output file.

grib_keysdict

Dictionary with the grib2 keys.

grib_template_pathstr

Path to the grib2 file to use as template.

infobool

Indicates if you want to print extra information during the process.

to_providentia(model_centre_lon, model_centre_lat, grid_edge_lon, grid_edge_lat)[source]

Transform a PointsNes into a PointsNesProvidentia object

Returns

points_nes_providentianes.Nes

Points Nes Providentia Object

GHOST projection

class nes.nc_projections.points_nes_ghost.PointsNesGHOST(comm=None, path=None, info=False, dataset=None, xarray=False, parallel_method='X', avoid_first_hours=0, avoid_last_hours=0, first_level=0, last_level=None, create_nes=False, balanced=False, times=None, **kwargs)[source]

Bases: PointsNes

Attributes

_qadict

Quality flags (GHOST checks) dictionary with the complete ‘data’ key for all the values and the rest of the attributes.

_flagdict

Data flags (given by data provider) dictionary with the complete ‘data’ key for all the values and the rest of the attributes.

_qadict

Quality flags (GHOST checks) dictionary with the portion of ‘data’ corresponding to the rank values.

_flagdict

Data flags (given by data provider) dictionary with the portion of ‘data’ corresponding to the rank values.

add_variables_to_shapefile(var_list, idx_lev=0, idx_time=0)[source]

Add variables data to shapefile.

var_listlist, str

List (or single string) of the variables to be loaded and saved in the shapefile.

idx_levint

Index of vertical level for which the data will be saved in the shapefile.

idx_timeint

Index of time for which the data will be saved in the shapefile.

erase_flags()[source]
get_standard_metadata(GHOST_version)[source]

Get all possible GHOST variables for each version.

Parameters

GHOST_versionstr

Version of GHOST file.

Returns

metadata_variables[GHOST_version]list

List of metadata variables for a certain GHOST version

static new(comm=None, path=None, info=False, dataset=None, xarray=False, parallel_method='X', avoid_first_hours=0, avoid_last_hours=0, first_level=0, last_level=None, create_nes=False, balanced=False, times=None, **kwargs)[source]

Initialize the PointsNesGHOST class.

Parameters

comm: MPI.COMM

MPI Communicator.

path: str

Path to the NetCDF to initialize the object.

info: bool

Indicates if you want to get reading/writing info.

dataset: Dataset

NetCDF4-python Dataset to initialize the class.

xarray: bool:

(Not working) Indicates if you want to use xarray as default.

parallel_methodstr

Indicates the parallelization method that you want. Default: ‘X’. Accepted values: [‘X’].

avoid_first_hoursint

Number of hours to remove from first time steps.

avoid_last_hoursint

Number of hours to remove from last time steps.

first_levelint

Index of the first level to use.

last_levelint, None

Index of the last level to use. None if it is the last.

create_nesbool

Indicates if you want to create the object from scratch (True) or through an existing file.

balancedbool

Indicates if you want a balanced parallelization or not. Balanced dataset cannot be written in chunking mode.

timeslist, None

List of times to substitute the current ones while creation.

to_netcdf(path, compression_level=0, serial=False, info=False, chunking=False)[source]

Write the netCDF output file.

Parameters

pathstr

Path to the output netCDF file.

compression_levelint

Level of compression (0 to 9) Default: 0 (no compression).

serialbool

Indicates if you want to write in serial or not. Default: False.

infobool

Indicates if you want to print the information of each writing step by stdout Default: False.

chunkingbool

Indicates if you want a chunked netCDF output. Only available with non serial writes. Default: False.

to_points()[source]

Transform a PointsNesGHOST into a PointsNes object

Returns

points_nesnes.Nes

Points Nes Object (without GHOST metadata variables)

Providentia projection

class nes.nc_projections.points_nes_providentia.PointsNesProvidentia(comm=None, path=None, info=False, dataset=None, xarray=False, parallel_method='X', avoid_first_hours=0, avoid_last_hours=0, first_level=0, last_level=None, create_nes=False, balanced=False, times=None, model_centre_lon=None, model_centre_lat=None, grid_edge_lon=None, grid_edge_lat=None, **kwargs)[source]

Bases: PointsNes

Attributes

_model_centre_londict

Model centre longitudes dictionary with the complete ‘data’ key for all the values and the rest of the attributes.

_model_centre_latdict

Model centre latitudes dictionary with the complete ‘data’ key for all the values and the rest of the attributes.

_grid_edge_londict

Grid edge longitudes dictionary with the complete ‘data’ key for all the values and the rest of the attributes.

_grid_edge_latdict

Grid edge latitudes dictionary with the complete ‘data’ key for all the values and the rest of the attributes.

model_centre_londict

Model centre longitudes dictionary with the portion of ‘data’ corresponding to the rank values.

model_centre_latdict

Model centre latitudes dictionary with the portion of ‘data’ corresponding to the rank values.

grid_edge_londict

Grid edge longitudes dictionary with the portion of ‘data’ corresponding to the rank values.

grid_edge_latdict

Grid edge latitudes dictionary with the portion of ‘data’ corresponding to the rank values.

add_variables_to_shapefile(var_list, idx_lev=0, idx_time=0)[source]

Add variables data to shapefile.

var_listlist, str

List (or single string) of the variables to be loaded and saved in the shapefile.

idx_levint

Index of vertical level for which the data will be saved in the shapefile.

idx_timeint

Index of time for which the data will be saved in the shapefile.

static new(comm=None, path=None, info=False, dataset=None, xarray=False, parallel_method='X', avoid_first_hours=0, avoid_last_hours=0, first_level=0, last_level=None, create_nes=False, balanced=False, times=None, model_centre_lon=None, model_centre_lat=None, grid_edge_lon=None, grid_edge_lat=None, **kwargs)[source]

Initialize the PointsNesProvidentia class.

Parameters

comm: MPI.COMM

MPI Communicator.

path: str

Path to the NetCDF to initialize the object.

info: bool

Indicates if you want to get reading/writing info.

dataset: Dataset

NetCDF4-python Dataset to initialize the class.

xarray: bool:

(Not working) Indicates if you want to use xarray as default.

parallel_methodstr

Indicates the parallelization method that you want. Default: ‘X’. Accepted values: [‘X’].

avoid_first_hoursint

Number of hours to remove from first time steps.

avoid_last_hoursint

Number of hours to remove from last time steps.

first_levelint

Index of the first level to use

last_levelint, None

Index of the last level to use. None if it is the last.

balancedbool

Indicates if you want a balanced parallelization or not. Balanced dataset cannot be written in chunking mode.

timeslist, None

List of times to substitute the current ones while creation.

create_nesbool

Indicates if you want to create the object from scratch (True) or through an existing file.

model_centre_londict

Model centre longitudes dictionary with the portion of ‘data’ corresponding to the rank values.

model_centre_latdict

Model centre latitudes dictionary with the portion of ‘data’ corresponding to the rank values.

grid_edge_londict

Grid edge longitudes dictionary with the portion of ‘data’ corresponding to the rank values.

grid_edge_latdict

Grid edge latitudes dictionary with the portion of ‘data’ corresponding to the rank values.

to_netcdf(path, compression_level=0, serial=False, info=False, chunking=False)[source]

Write the netCDF output file.

Parameters

pathstr

Path to the output netCDF file.

compression_levelint

Level of compression (0 to 9) Default: 0 (no compression).

serialbool

Indicates if you want to write in serial or not. Default: False.

infobool

Indicates if you want to print the information of each writing step by stdout Default: False.

chunkingbool

Indicates if you want a chunked netCDF output. Only available with non serial writes. Default: False.

Rotated projection

class nes.nc_projections.rotated_nes.RotatedNes(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, create_nes=False, balanced=False, times=None, **kwargs)[source]

Bases: Nes

Attributes

_rlatdict

Rotated latitudes dictionary with the complete ‘data’ key for all the values and the rest of the attributes.

_rlondict

Rotated longitudes dictionary with the complete ‘data’ key for all the values and the rest of the attributes.

rlatdict

Rotated latitudes dictionary with the portion of ‘data’ corresponding to the rank values.

rlondict

Rotated longitudes dictionary with the portion of ‘data’ corresponding to the rank values.

_var_dimtuple

Tuple with the name of the Y and X dimensions for the variables. (‘rlat’, ‘rlon’) for a rotated projection.

_lat_dimtuple

Tuple with the name of the dimensions of the Latitude values. (‘rlat’, ‘rlon’) for a rotated projection.

_lon_dimtuple

Tuple with the name of the dimensions of the Longitude values. (‘rlat’, ‘rlon’) for a rotated projection.

create_providentia_exp_centre_coordinates()[source]

Calculate centre latitudes and longitudes from original coordinates and store as 2D arrays.

Returns

model_centre_latdict

Dictionary with data of centre coordinates for latitude in 2D (latitude, longitude).

model_centre_londict

Dictionary with data of centre coordinates for longitude in 2D (latitude, longitude).

create_providentia_exp_grid_edge_coordinates()[source]

Calculate grid edge latitudes and longitudes and get model grid outline.

Returns

grid_edge_latdict

Dictionary with data of grid edge latitudes.

grid_edge_londict

Dictionary with data of grid edge longitudes.

create_shapefile()[source]

Create spatial geodataframe (shapefile).

Returns

shapefileGeoPandasDataFrame

Shapefile dataframe.

create_spatial_bounds()[source]

Calculate longitude and latitude bounds and set them.

filter_coordinates_selection()[source]

Use the selection limits to filter rlat, rlon, time, lev, lat, lon, lon_bnds and lat_bnds.

get_centroids_from_coordinates()[source]

Get centroids from geographical coordinates.

Returns

centroids_gdf: GeoPandasDataFrame

Centroids dataframe.

static new(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, create_nes=False, balanced=False, times=None, **kwargs)[source]

Initialize the Nes class.

Parameters

comm: MPI.COMM

MPI Communicator.

path: str

Path to the NetCDF to initialize the object.

info: bool

Indicates if you want to get reading/writing info.

dataset: Dataset

NetCDF4-python Dataset to initialize the class.

xarray: bool:

(Not working) Indicates if you want to use xarray as default.

parallel_methodstr

Indicates the parallelization method that you want. Default: ‘Y’. Accepted values: [‘X’, ‘Y’, ‘T’].

avoid_first_hoursint

Number of hours to remove from first time steps.

avoid_last_hoursint

Number of hours to remove from last time steps.

create_nesbool

Indicates if you want to create the object from scratch (True) or through an existing file.

balancedbool

Indicates if you want a balanced parallelization or not. Balanced dataset cannot be written in chunking mode.

timeslist, None

List of times to substitute the current ones while creation.

rotated2latlon(lon_deg, lat_deg, lon_min=-180)[source]

Calculate the unrotated coordinates using the rotated ones.

Parameters

lon_degnumpy.array

Rotated longitude coordinate.

lat_degnumpy.array

Rotated latitude coordinate.

lon_minfloat

Minimum value for the longitudes: -180 (-180 to 180) or 0 (0 to 360).

Returns

almdnumpy.array

Unrotated longitudes.

aphdnumpy.array

Unrotated latitudes.

to_grib2(path, grib_keys, grib_template_path, lat_flip=False, info=False)[source]

Write output file with grib2 format.

Parameters

pathstr

Path to the output file.

grib_keysdict

Dictionary with the grib2 keys.

grib_template_pathstr

Path to the grib2 file to use as template.

infobool

Indicates if you want to print extra information during the process.

Rotated nested projection

class nes.nc_projections.rotated_nested_nes.RotatedNestedNes(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, create_nes=False, balanced=False, times=None, **kwargs)[source]

Bases: RotatedNes