environmentaltools.common.netcdf
- environmentaltools.common.netcdf(file_name: str, variables: str = None, latlon: list = None, depth: float = None, time_series: bool = True, glob: bool = False)[source]
Read NetCDF4 files with spatial/temporal subsetting options.
Reads NetCDF files using xarray with support for multi-file datasets, spatial point extraction, and time series conversion.
- Parameters:
file_name (str) – Path to NetCDF file or directory pattern for glob.
variables (str or list, optional) – Variable name(s) to extract. Defaults to None (all).
latlon (list, optional) – [latitude, longitude] for point extraction. Defaults to None.
depth (float, optional) – Depth level for extraction. Defaults to None.
time_series (bool) – If True, converts to time series DataFrame. Defaults to True.
glob (bool) – If True, opens multiple files using pattern matching. Defaults to False.
- Returns:
- Extracted data. If latlon specified, returns
tuple of (DataFrame, (nearest_lat, nearest_lon)).
- Return type:
pd.DataFrame or xarray.Dataset
- Raises:
ValueError – If glob files are inconsistent.