swot_simulator.plugins.data_handler.NetcdfLoader#

class swot_simulator.plugins.data_handler.NetcdfLoader(path: str, date_fmt: str, lon_name: str = 'lon', lat_name: str = 'lat', ssh_name: str = 'ssh', time_name: str = 'time', pattern: str = '.nc')[source]#

Bases: DatasetLoader

Plugin that implements a netcdf reader. The netcdf reader works on files whose names have the date in it. A pattern (ex. P(?<date>.*).nc), associated with a date formatter (ex. %Y%m%d) is used to get build the time series.

Netcdf files can be expensive to concatenate if there are a lot of files. This loader avoid loading too much files by building a dictionary matching file paths to their time. During the interpolation, where only a given time period is needed, only the files that cover the time period are loaded in the dataset.

__init__(path: str, date_fmt: str, lon_name: str = 'lon', lat_name: str = 'lat', ssh_name: str = 'ssh', time_name: str = 'time', pattern: str = '.nc')[source]#

Initialization of the netcdf loader.

Parameters
  • path (str) – Folder containing the netcdf files

  • date_fmt (str) – date formatter

  • lon_name (str) – longitude name in the netcdf files. Defaults to ‘lon’

  • lat_name (str) – latitude name in the netcdf files. Defaults to ‘lat’

  • ssh_name (str) – sea surface height name in the netcdf files. Defaults to ‘ssh’

  • time_name (str) – time name in the netcdf files. Defaults to ‘time’

  • pattern (str) – Pattern for the NetCDF file names. It should contain the P(?<date>) group to retrieve the time

Example

If we have netcdf files whose names are model_20120305_12h.nc, we must define the following to retrieve the time:

loader = NetcdfLoader(
    '.',
    pattern='model_P(?<date>\w+).nc',
    date_fmt='%Y%m%d_%Hh'
)

Methods

NetcdfLoader.load_dataset(first_date, last_date)

Loads the dataset between the given dates.

NetcdfLoader.select_netcdf_files(first_date, ...)

Selects the netcdf files that cover the time period.

NetcdfLoader._walk_netcdf(path)

Browse the NetCDF grids in the directory to create the time series constituted by these files (a file contains a time step).