gs_Dataset
- class gspy.src.classes.data.xarray_gs.Dataset.Dataset(xarray_obj)
Accessor to xarray.Dataset to better handle coordinates/dimensions and variables that honour the CF convention.
Checks necessary metadata to satisfy the CF convention, and allows use with GIS software.
- Returns:
out
- Return type:
xarray.Dataset
- add_bounds_to_coordinate(name, **kwargs)
Adds bounds to a coordinate.
Important
Make sure you call this method into a return variable
ds = ds.add_coordinate_from_dict
Otherwise, the bounds will not be added correctly.
- Parameters:
name (str) – Name of the variable to add bounds to.
- Returns:
Dataset with added bounds.
- Return type:
- add_coordinate_from_dict(name, discrete=False, is_dimension=False, **kwargs)
Attach a coordinate/dimension to a Dataset from a dictionary.
The DataSet is returned with the coordinate attached. Bounds are also added to the Dataset if this coordinate is not discrete.
Important
Make sure you call this method into a return variable
ds = ds.add_coordinate_from_dict
Otherwise, the coordinate will not be added correctly.
- Parameters:
name (str) – Name of the coordinate
discrete (bool, optional) – Is this coordinate discrete? by default False
is_dimension (bool, optional) – Is this a coordinate-dimension? by default False
- Returns:
Dataset with added coordinate.
- Return type:
See also
Coordinate.Coordinate.from_dict
for pertinent Coordinate keywords and metadata
- add_coordinate_from_values(name, values, discrete=False, is_dimension=False, **kwargs)
Attach a coordinate/dimension to a Dataset using an array of values defining center values.
The DataSet is returned with the coordinate attached. Bounds are also added to the Dataset if this coordinate is not discrete.
Important
Make sure you call this method into a return variable
ds = ds.add_coordinate_from_dict
Otherwise, the coordinate will not be added correctly.
- Parameters:
name (str) – Name of the coordinate
discrete (bool, optional) – Is this coordinate discrete? by default False
is_dimension (bool, optional) – Is this a coordinate-dimension? by default False
- Returns:
Dataset with added coordinate.
- Return type:
See also
Coordinate.Coordinate.from_values
for pertinent Coordinate keywords and metadata
- add_variable_from_values(name, values, **kwargs)
Add a variable to the Dataset
Automatically maintains coords on the variable given its dims.
Important
Make sure you call this method into a return variable
ds = ds.add_coordinate_from_dict
Otherwise, the variable will not be added correctly.
- Parameters:
name (str) – Name of the variable
values (array_like) – Values of the variable
- Returns:
Dataset with variable added.
- Return type:
- Raises:
ValueError – If the shape of the values does not match the specified dimensions.
- property is_projected
Does the dataset have a projected spatial reference
- Returns:
out
- Return type:
bool
- property json_metadata
- classmethod open_dataset(*args, **kwargs)
Open (lazy loading) a netcdf.
Wraps around the xarray open_dataset but forces xarray to honour gate times and the CF convention.
- Returns:
Native xrray Dataset
- Return type:
xarray.Dataset
- classmethod open_netcdf(filename, group, **kwargs)
Read Data from a netcdf file using xrray’s lazy open_dataset
- Parameters:
filename (str) – Path to the netcdf file
group (str) – Netcdf group name containing Dataset
- Return type:
- plot(hue, **kwargs)
Scatter plot of variable against x, y co-ordinates
- Parameters:
variable (str) – Xarray Dataset variable name
- Returns:
ax (matplotlib.Axes) – Figure handle
sc (xarray.plot.scatter) – Plotting handle
- read_metadata(filename)
Read json metadata file
- Parameters:
filename (str) – Json file
- Returns:
dic – Dictionary of JSON metadata
- Return type:
dict
- scatter(**kwargs)
Scatter plot of variable against x, y co-ordinates
- Parameters:
variable (str) – Xarray Dataset variable name
- Returns:
ax (matplotlib.Axes) – Figure handle
sc (xarray.plot.scatter) – Plotting handle
- set_spatial_ref(kwargs)
Set the spatial ref of the Dataset.
Specifically adds an xarray coordinate called ‘spatial_ref’ which is required for GIS software and the CF convention.
Important
Make sure you call this method into a return variable
ds = ds.add_coordinate_from_dict
Otherwise, the spatial_ref will not be added correctly.
- Parameters:
kwargs (dict, gspy.Spatial_ref, or xarray.DataArray) –
If dict: creates a Spatial_ref from a dict of metadata.
If an existing spatial ref, assign by reference
- Returns:
Dataset with spatial_ref added.
- Return type:
See also
Survey.Spatial_ref
for more details of creating a Spatial_ref
- property spatial_ref
- update_attrs(**kwargs)
Adds metadata from Json with keys flattened. This is the only way to add nested metadata as dicts into xarray attrs.
- write_ncml(filename, group, index)
Write an NCML file
- Parameters:
filename (str) – NCML filename
group (str) – Group name in Netcdf file to generate NCML output for.
index (str) – todo
- write_netcdf(filename, group, **kwargs)
Write to netcdf file
- Parameters:
filename (str) – Path to the file
group (str) – Netcdf group name to write to
- write_zarr(filename, group, **kwargs)
Write to netcdf file
- Parameters:
filename (str) – Path to the file
group (str) – Netcdf group name to write to