Raster

Inheritance diagram of gspy.src.classes.data.Raster
class gspy.src.classes.data.Raster.Raster(xarray_obj)

Class defining a set of gridded data (2D or 3D).

The raster class allows for single 2D rasters, or ‘stacks’ of multiple 2D rasters into a 3D block.

Raster.read(metadata_file, spatial_ref, **kwargs)

Parameters:
  • metadata_file (str, optional) – Json file name, by default None

  • spatial_ref (dict or gspy.Spatial_ref or xarray.DataArray, optional) – Spatial ref object, by default None

Return type:

xarray.Dataset

See also

Raster.read

Class method for reading file into class

gspy.Spatial_ref

For co-ordinate reference instantiation requirements

property bounds

Spatial bounds of the raster

Return type:

list

property is_tif
classmethod read(metadata_file, spatial_ref=None, netcdf_file=None, **kwargs)

Instantiate a Raster class from metadata and data files.

When reading the metadata and data file, the following are established in order * User defined dimensions * User defined coordinates * X and Y are automatically pulled from the first raster

Read the metadata and data files and to Raster class

Parameters:
  • metadata_file (str, optional) – Json file name, by default None

  • spatial_ref (dict, gspy.Spatial_ref, or xarray.DataArray, optional) – Spatial ref object, by default None

read_raster_using_metadata(name, json_metadata, **kwargs)
read_tif(filename)

Reads GeoTIFF file

Uses rioxarray to read GeoTIFF file as an xarray Dataset

Parameters:

filename (str) – Name of GeoTIFF file

Returns:

ds – Dataset containing the GeoTIFF variable

Return type:

xarray.Dataset

read_var_netcdf(filename, key, var_meta)

Reads variable from NetCDF file and adds to Raster xarray

Parameters:
  • filename (str) – Name of NetCDF file to read

  • key (str) – Variable name

  • var_meta (dict) – Variable attributes

Raises:

NotImplementedError – Function is planned but not yet implemented

to_tif()

Export GeoTIFF files from xarray

2D variables are exported directly to GeoTIFF files, one for each variable, following the naming convention “{variable}.tif”

3D variables are sliced along the right most dimension and exported to incremented GeoTIFF files following the naming convention “{variable}_{i}.tif”.

write_metadata_template(filename='raster_md.yml')

Write JSON metadata template for a raster dataset

Outputs a template JSON metadata file needed for adding Raster data. All required dictionaries are printed (dataset_attrs, key_mapping, raster_files, variable_metadata). Additional dictionaries can be optionally added to document more information or ancillary metadata relevant to the specific Raster data.

Raises:

Exception – Tells user to specify metadata file when instantiating Raster data

write_netcdf(filename, group='raster')

Write to netcdf file

Parameters:
  • filename (str) – Path to the file

  • group (str) – Name of group within netcdf file

write_zarr(filename, group='raster')

Write to netcdf file

Parameters:
  • filename (str) – Path to the file

  • group (str) – Name of group within netcdf file