pywatershed.utils.netcdf_utils.subset_netcdf_file#
- pywatershed.utils.netcdf_utils.subset_netcdf_file(file_name, new_file_name, start_time=None, end_time=None, coord_dim_name=None, coord_dim_values_keep=None)[source]#
Subset a netcdf file on to coordinate or dimension values.
- Parameters:
file_name (
Union[Path,str]) – The name/path of the input file.new_file_name (
Union[Path,str]) – The name/path of the output file.start_time (
datetime64) – Optional start time if a “time” coord is present.end_time (
datetime64) – Optional end time if a “time” coord is present.coord_dim_name (
str) – Optional coord or dimension name to subset on.coord_dim_values_keep (
ndarray) – Optional values on the coord or dimension to retain in teh subset.
- Return type:
This currently works for 1-D coordinates, more dimensions not tested. Note: This uses the function
pywatershed.utils.netcdf_utils.subset_xr()under the hood, which can be called if you want to subset xr.Datasets in memory. There seem to beseveral edge cases lurking around here with zero length dimensions and xarray’s broadcasting rules. This function is a convenience function because xarray’s functionality is not ideal for our use cases and is confusing with pitfalls. See pydata/xarray#8796 for additional discussion.