spatial
Coordinates Reference System (CRS) and spatial transformation routines
Can read netCDF4, HDF5, (cloud optimized) geotiff or (geo)parquet files
General Methods
- grounding_zones.spatial.case_insensitive_filename(filename: str | Path)[source]
Searches a directory for a filename without case dependence
- Parameters:
- filename: str
input filename
- grounding_zones.spatial.from_file(filename: str, format: str, **kwargs)[source]
Wrapper function for reading data from an input format
- Parameters:
- filename: str
full path of input file
- format: str
format of input file
- **kwargs: dict
Keyword arguments for file reader
- grounding_zones.spatial.from_ascii(filename: str, **kwargs)[source]
Read data from an ascii file
- Parameters:
- filename: str
full path of input ascii file
- compression: str or NoneType, default None
file compression type
- columns: list, default [‘time’, ‘y’, ‘x’, ‘data’]
column names of ascii file
- delimiter: str, default ‘,’
Delimiter for csv or ascii files
- header: int, default 0
header lines to skip from start of file
- parse_dates: bool, default False
Try parsing the time column
- grounding_zones.spatial.from_netCDF4(filename: str, **kwargs)[source]
Read data from a netCDF4 file
- Parameters:
- filename: str
full path of input netCDF4 file
- compression: str or NoneType, default None
file compression type
- group: str or NoneType, default None
netCDF4 variable group
- timename: str, default ‘time’
name for time-dimension variable
- xname: str, default ‘lon’
name for x-dimension variable
- yname: str, default ‘lat’
name for y-dimension variable
- varname: str, default ‘data’
name for data variable
- field_mapping: dict, default {}
mapping between output variables and input netCDF4
- grounding_zones.spatial.from_HDF5(filename: str | Path, **kwargs)[source]
Read data from a HDF5 file
- Parameters:
- filename: str
full path of input HDF5 file
- compression: str or NoneType, default None
file compression type
- group: str or NoneType, default None
netCDF4 variable group
- timename: str, default ‘time’
name for time-dimension variable
- xname: str, default ‘lon’
name for x-dimension variable
- yname: str, default ‘lat’
name for y-dimension variable
- varname: str, default ‘data’
name for data variable
- field_mapping: dict, default {}
mapping between output variables and input HDF5
- grounding_zones.spatial.from_geotiff(filename: str, **kwargs)[source]
Read data from a geotiff file
- Parameters:
- filename: str
full path of input geotiff file
- compression: str or NoneType, default None
file compression type
- bounds: list or NoneType, default bounds
extent of the file to read:
[xmin, xmax, ymin, ymax]
- grounding_zones.spatial.from_parquet(filename: str, **kwargs)[source]
Read data from a parquet file
- Parameters:
- filename: str
full path of input parquet file
- index: str, default ‘time’
name of index column
- columns: list or None, default None
column names of parquet file
- primary_column: str, default ‘geometry’
default geometry column in geoparquet files
- geometry_encoding: str, default ‘WKB’
default encoding for geoparquet files
- grounding_zones.spatial.to_file(output: dict, attributes: dict, filename: str | Path, format: str, **kwargs)[source]
Wrapper function for writing data to an output format
- Parameters:
- output: dict
python dictionary of output data
- attributes: dict
python dictionary of output attributes
- filename: str or pathlib.Path,
full path of output file
- format: str
format of output file
- **kwargs: dict
Keyword arguments for file writer
- grounding_zones.spatial.to_ascii(output: dict, attributes: dict, filename: str | Path, **kwargs)[source]
Write data to an ascii file
- Parameters:
- output: dict
python dictionary of output data
- attributes: dict
python dictionary of output attributes
- filename: str or pathlib.Path
full path of output ascii file
- delimiter: str, default ‘,’
delimiter for output spatial file
- columns: list, default [‘time’, ‘y’, ‘x’, ‘data’]
column names of ascii file
- header: bool, default False
create a YAML header with data attributes
- grounding_zones.spatial.to_netCDF4(output: dict, attributes: dict, filename: str | Path, **kwargs)[source]
Wrapper function for writing data to a netCDF4 file
- Parameters:
- output: dict
python dictionary of output data
- attributes: dict
python dictionary of output attributes
- filename: str or pathlib.Path
full path of output netCDF4 file
- mode: str, default ‘w’
NetCDF file mode
- data_type: str, default ‘drift’
Input data type
'time series''drift''grid'
- grounding_zones.spatial._drift_netCDF4(fileID, output: dict, attributes: dict, **kwargs)[source]
Write drift data variables to a netCDF4 file object
- Parameters:
- fileID: obj
open netCDF4 file object
- output: dict
python dictionary of output data
- attributes: dict
python dictionary of output attributes
- grounding_zones.spatial._grid_netCDF4(fileID, output: dict, attributes: dict, **kwargs)[source]
Write gridded data variables to a netCDF4 file object
- Parameters:
- fileID: obj
open netCDF4 file object
- output: dict
python dictionary of output data
- attributes: dict
python dictionary of output attributes
- grounding_zones.spatial._time_series_netCDF4(fileID, output: dict, attributes: dict, **kwargs)[source]
Write time series data variables to a netCDF4 file object
- Parameters:
- fileID: obj
open netCDF4 file object
- output: dict
python dictionary of output data
- attributes: dict
python dictionary of output attributes
- grounding_zones.spatial.to_HDF5(output: dict, attributes: dict, filename: str | Path, **kwargs)[source]
Write data to a HDF5 file
- Parameters:
- output: dict
python dictionary of output data
- attributes: dict
python dictionary of output attributes
- filename: str or pathlib.Path
full path of output HDF5 file
- mode: str, default ‘w’
HDF5 file mode
- grounding_zones.spatial.to_geotiff(output: dict, attributes: dict, filename: str | Path, **kwargs)[source]
Write data to a (cloud optimized) geotiff file
- Parameters:
- output: dict
python dictionary of output data
- attributes: dict
python dictionary of output attributes
- filename: str or pathlib.Path
full path of output geotiff file
- varname: str, default ‘data’
output variable name
- driver: str, default ‘cog’
GDAL driver
'GTiff': GeoTIFF'cog': Cloud Optimized GeoTIFF
- dtype: obj, default osgeo.gdal.GDT_Float64
GDAL data type
- options: list, default [‘COMPRESS=LZW’]
GDAL driver creation options
- grounding_zones.spatial.to_parquet(output: dict, attributes: dict, filename: str | Path, **kwargs)[source]
Write data to a (geo)parquet file
- Parameters:
- output: dict
python dictionary of output data
- attributes: dict
python dictionary of output attributes
- filename: str or pathlib.Path,
full path of output parquet file
- crs: int, default None
coordinate reference system EPSG code
- index: bool, default None
write index to parquet file
- compression: str, default ‘snappy’
file compression type
- geoparquet: bool, default False
write geoparquet file
- geometry_encoding: str, default ‘WKB’
default encoding for geoparquet geometry
- primary_column: str, default ‘geometry’
default column name for geoparquet geometry
- grounding_zones.spatial.expand_dims(obj: dict, varname: str = 'data')[source]
Add a singleton dimension to a spatial dictionary if non-existent
- Parameters:
- obj: dict
python dictionary of data
- varname: str, default data
variable name to expand