main_time_dims#

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

Infer the time dimension and the other main time variables from 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 columns, only frames 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 preprocess your data as follow:

# This will group the different levels into tuples
df['flat_index'] = df.index.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 time variable(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 data type is raster/netCDF, True if data type is vector

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#

varlist of str

List of potential time coordinate names, the first one being the most relevant.