Class NetCdfWeatherDataset
A NetCDF-CF wind and wave file read into a WeatherGridSet: the grid, the parameters the weather table knows (and the ones it doesn't), their time steps, and where the data comes from. Time steps are read from the file only when they're decoded, so the dataset keeps the file open until it's disposed.
public sealed class NetCdfWeatherDataset : IDisposable
- Inheritance
-
NetCdfWeatherDataset
- Implements
- Inherited Members
Remarks
How the file is read (design note weather-sources.md §7.1):
-
Latitude, longitude and time are found by
standard_name, byaxis(Y,X,T), or by their units (degrees_north,degrees_east, "<unit> since …"). They must be one-dimensional and evenly spaced; 2-D latitude and longitude (a curvilinear grid) or agrid_mappingother thanlatitude_longitudefails with an UnsupportedWeatherGridException naming the grid type. -
Data variables are matched to the weather parameter table by their
standard_name(FindByCfStandardName(string)) and converted to its stored units. A variable may have extra dimensions of length 1 (a single height or depth); a 10 m height is read as the wind level. When two variables map to the same parameter, the one whose standard name the table prefers is kept and the other is listed as unknown. -
Values have
_FillValue,missing_value,valid_min,valid_maxandvalid_rangeapplied to the stored values (and the NetCDF default fill value when there's no_FillValue), become NaN where missing, and are then unpacked withscale_factorandadd_offset. -
The model is the global
source,institutionortitleattribute, in that order; the run time is aforecast_reference_timevariable or global attribute when there is one.
A file with no recognisable coordinates, or no variable the table knows, fails with a CfConventionsException that lists the variables found.
Properties
Conventions
The global Conventions attribute, for example "CF-1.6", or null.
public string? Conventions { get; }
Property Value
File
The open NetCDF file the steps are read from.
public NetCdfFile File { get; }
Property Value
Format
The file's format.
public NetCdfFormat Format { get; }
Property Value
GridSet
The grid set: origin, grid and parameters with lazily read time steps.
public WeatherGridSet GridSet { get; }
Property Value
IgnoredVariables
Data variables left out of the grid set, with why.
public IReadOnlyList<NetCdfIgnoredVariable> IgnoredVariables { get; }
Property Value
Institution
The global institution attribute, or null.
public string? Institution { get; }
Property Value
ReferenceTime
The model run's reference time (UTC), from a forecast_reference_time
variable or global attribute, or null when the file
doesn't give one (RunTime is then the first
valid time).
public DateTime? ReferenceTime { get; }
Property Value
Source
The global source attribute (the model, in CF), or null.
public string? Source { get; }
Property Value
Times
The valid times of the time coordinate, in file order.
public IReadOnlyList<DateTime> Times { get; }
Property Value
Title
The global title attribute, or null.
public string? Title { get; }
Property Value
Methods
Dispose()
Closes the file.
public void Dispose()
Open(Stream, string?, bool)
Opens and reads a NetCDF file from a seekable stream.
public static NetCdfWeatherDataset Open(Stream stream, string? name = null, bool leaveOpen = false)
Parameters
streamStreamThe file's bytes; readable and seekable.
namestringThe file's name, used as the model name when the file names none.
leaveOpenboolWhether disposing the dataset leaves
streamopen.
Returns
- NetCdfWeatherDataset
The dataset.
Exceptions
- NetCdfFormatException
The bytes aren't a NetCDF file this library can read.
- CfConventionsException
The file doesn't follow the CF conventions this reader needs.
- UnsupportedWeatherGridException
The grid isn't a regular latitude/longitude grid.
Open(string)
Opens and reads the NetCDF file at path.
public static NetCdfWeatherDataset Open(string path)
Parameters
pathstringThe file's path.
Returns
- NetCdfWeatherDataset
The dataset; dispose it to close the file.
Exceptions
- NetCdfFormatException
The file isn't a NetCDF file this library can read.
- CfConventionsException
The file doesn't follow the CF conventions this reader needs.
- UnsupportedWeatherGridException
The grid isn't a regular latitude/longitude grid.
Read(NetCdfFile, string?)
Reads an open NetCDF file as CF weather data. The dataset takes
ownership of file, and disposes it if reading fails.
public static NetCdfWeatherDataset Read(NetCdfFile file, string? name = null)
Parameters
fileNetCdfFileThe open file.
namestringThe file's name, used as the model name when the file names none.
Returns
- NetCdfWeatherDataset
The dataset.
Exceptions
- CfConventionsException
The file doesn't follow the CF conventions this reader needs.
- UnsupportedWeatherGridException
The grid isn't a regular latitude/longitude grid.