main_space_dims#

geobricks.main_space_dims(data, *, include_coords=False, include_vars=None)[source]#

Infer the spatial dimension names in a dataset.

For consistency, in the case of frames (tabular and vector data are loaded into pandas.DataFrames and geopandas.GeoDataFrames), this function does not scrap frame multi-indexes or multi-levels olumns, only frame with one single column level. If you want to retrieve the main dimensions from the index, you can preprocess your data (data is here a (geo)pandas.(Geo)DataFrame) as follow:

df.reset_index(inplace = True)

If you want to retrieve the main dimensions from multi-level columns, you can proprocess your data as follow:

# This will group the different levels into tuples
df.columns = df.columns.to_flat_index() 

Alternatively, you can drop column levels to keep only one:

# This will drop column levels df = df.droplevel(<int>, axis = 1) # <int> is the level number (0, 1, …)

Parameters#

datapath (str or pathlib.Path), or variable (xarray.Dataset, xarray.DataArray, geopandas.GeoDataFrame or pandas.DataFrame)

Data whose spatial dimension(s) will be retrieved.

include_coordsbool, default False

Only used if data is a netCDF or a xarray variable. If False, only dimensions are considered as potential time coordinates. If True, even coordinates not associated to any dimension will be considered as well as potential time coordinates (along dims).

include_varsbool, default False

If True, data variables will be considered as well as potential time coordinates (along dims).

Note: In netCDF or xarray variables, data variables correspond to data_vars. In vector files or (geo)pandas variables, data variables correspond to columns.

Returns#

List of tuples containing (name of the x-axis dimension, name of the y-axis dimension). The list is ordered from the most relevant tuple to the least.