The NES object

Creating a NES object

nes.create_nes.create_nes(comm=None, info=False, projection=None, parallel_method='Y', balanced=False, times=None, avoid_first_hours=0, avoid_last_hours=0, first_level=0, last_level=None, **kwargs)[source]

Create a Nes class from scratch.

Parameters

commMPI.Comm, optional

MPI Communicator. If None, uses MPI.COMM_WORLD.

infobool, optional

Indicates if reading/writing info should be provided. Default is False.

projectionstr, optional

The projection type. Accepted values are None, “regular”, “global”, “rotated”, “rotated-nested”, “lcc”, “mercator”.

parallel_methodstr, optional

The parallelization method to use. Default is “Y”. Accepted values are [“X”, “Y”, “T”].

balancedbool, optional

Indicates if balanced parallelization is desired. Balanced datasets cannot be written in chunking mode. Default is False.

timeslist of datetime, optional

List of datetime objects representing the time dimension. If None, a default time array is created.

avoid_first_hoursint, optional

Number of hours to remove from the start of the time steps. Default is 0.

avoid_last_hoursint, optional

Number of hours to remove from the end of the time steps. Default is 0.

first_levelint, optional

Index of the first level to use. Default is 0.

last_levelint or None, optional

Index of the last level to use. If None, the last level is used. Default is None.

**kwargsadditional arguments

Additional parameters required for specific projections.

Returns

nesNes

An instance of the Nes class based on the specified parameters and projection.

Raises

ValueError

If any required projection-specific parameters are missing or if invalid parameters are provided.

NotImplementedError

If an unsupported parallel method or projection type is specified.

Notes

The function dynamically creates an instance of a specific Nes subclass based on the provided projection. The required parameters for each projection type are:

  • None: [“lat”, “lon”]

  • “regular”: [“lat_orig”, “lon_orig”, “inc_lat”, “inc_lon”, “n_lat”, “n_lon”]

  • “global”: [“inc_lat”, “inc_lon”]

  • “rotated”: [“centre_lat”, “centre_lon”, “west_boundary”, “south_boundary”, “inc_rlat”, “inc_rlon”]

  • “rotated-nested”: [“parent_grid_path”, “parent_ratio”, “i_parent_start”, “j_parent_start”, “n_rlat”, “n_rlon”]

  • “lcc”: [“lat_1”, “lat_2”, “lon_0”, “lat_0”, “nx”, “ny”, “inc_x”, “inc_y”, “x_0”, “y_0”]

  • “mercator”: [“lat_ts”, “lon_0”, “nx”, “ny”, “inc_x”, “inc_y”, “x_0”, “y_0”]

Example

>>> nes = create_nes(projection="regular", lat_orig=0, lon_orig=0, inc_lat=1, inc_lon=1, n_lat=180, n_lon=360)
nes.create_nes.from_shapefile(path, method=None, parallel_method='Y', **kwargs)[source]

Create NES from shapefile data.

  1. Create NES grid.

  2. Create shapefile for grid.

  3. Spatial join to add shapefile variables to NES variables.

Parameters

pathstr

Path to shapefile.

methodstr

Overlay method. Accepted values: [“nearest”, “intersection”, None].

parallel_methodstr

Indicates the parallelization method that you want. Default: “Y”. accepted values: [“X”, “Y”, “T”].

Loading a NES object

nes.load_nes.concatenate_netcdfs(nessy_list, comm=None, info=False, parallel_method='Y', avoid_first_hours=0, avoid_last_hours=0, first_level=0, last_level=None, balanced=False)[source]

Concatenate variables form different sources.

Parameters

nessy_listlist

A List of Nes objects or list of paths to concatenate.

commMPI.Comm

MPI Communicator.

info: bool

Indicates if you want to get reading/writing info.

parallel_methodstr

Indicates the parallelization method that you want. Default: “Y”. accepted values: [“X”, “Y”, “T”].

balancedbool

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

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.

Returns

Nes

A Nes object with all the variables.

nes.load_nes.open_netcdf(path, comm=None, info=False, parallel_method='Y', avoid_first_hours=0, avoid_last_hours=0, first_level=0, last_level=None, balanced=False)[source]

Open a netCDF file.

Parameters

pathstr

Path to the NetCDF file to read.

commMPI.COMM

MPI communicator to use in that netCDF. Default: MPI.COMM_WORLD.

infobool

Indicates if you want to print (stdout) the reading/writing steps.

avoid_first_hoursint

Number of hours to remove from first time steps.

avoid_last_hoursint

Number of hours to remove from last time steps.

parallel_methodstr

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

balancedbool

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

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.

Returns

Nes

A Nes object. Variables read in lazy mode (only metadata).