hydromt.data_adapter.DataFrameAdapter#
- class hydromt.data_adapter.DataFrameAdapter(path: str, driver: str | None = None, filesystem: str = 'local', nodata: dict | float | int | None = None, rename: dict = {}, unit_mult: dict = {}, unit_add: dict = {}, meta: dict = {}, attrs: dict = {}, driver_kwargs: dict = {}, name: str = '', catalog_name: str = '', **kwargs)[source]#
DataAdapter implementation for Pandas Dataframes.
Initiate data adapter for 2D tabular data.
This object contains all properties required to read supported files into a
pandas.DataFrame()
. In addition it keeps meta data to be able to reproduce which data is used.- Parameters:
path (
str
,Path
) – Path to data source. If the dataset consists of multiple files, the path may contain {variable}, {year}, {month} placeholders as well as path search pattern using a ‘*’ wildcard.driver (
{'csv', 'xlsx', 'xls', 'fwf'}
, optional) – Driver to read files with, for ‘csv’read_csv()
, for {‘xlsx’, ‘xls’}read_excel()
, and for ‘fwf’read_fwf()
. By default the driver is inferred from the file extension and falls back to ‘csv’ if unknown.filesystem (
{'local', 'gcs', 's3'}
, optional) – Filesystem where the data is stored (local, cloud, http etc.). By default, local.nodata (
dict
,float
,int
, optional) – Missing value number. Only used if the data has no native missing value. Nodata values can be differentiated between variables using a dictionary.rename (
dict
, optional) – Mapping of native data source variable to output source variable name as required by hydroMT.unit_mult (
dict
, optional) – Scaling multiplication and addition to change to map from the native data unit to the output data unit as required by hydroMT.unit_add (
dict
, optional) – Scaling multiplication and addition to change to map from the native data unit to the output data unit as required by hydroMT.meta (
dict
, optional) – Metadata information of dataset, prefably containing the following keys: {‘source_version’, ‘source_url’, ‘source_license’, ‘paper_ref’, ‘paper_doi’, ‘category’}placeholders (
dict
, optional) – Placeholders to expand yaml entry to multiple entries (name and path) based on placeholder valuesattrs (
dict
, optional) – Additional attributes relating to data variables. For instance unit or long name of the variable.driver_kwargs – Additional key-word arguments passed to the driver.
dict – Additional key-word arguments passed to the driver.
optional – Additional key-word arguments passed to the driver.
name (
str
, optional) – Name of the dataset and catalog, optional for now.catalog_name (
str
, optional) – Name of the dataset and catalog, optional for now.
- __init__(path: str, driver: str | None = None, filesystem: str = 'local', nodata: dict | float | int | None = None, rename: dict = {}, unit_mult: dict = {}, unit_add: dict = {}, meta: dict = {}, attrs: dict = {}, driver_kwargs: dict = {}, name: str = '', catalog_name: str = '', **kwargs)[source]#
Initiate data adapter for 2D tabular data.
This object contains all properties required to read supported files into a
pandas.DataFrame()
. In addition it keeps meta data to be able to reproduce which data is used.- Parameters:
path (
str
,Path
) – Path to data source. If the dataset consists of multiple files, the path may contain {variable}, {year}, {month} placeholders as well as path search pattern using a ‘*’ wildcard.driver (
{'csv', 'xlsx', 'xls', 'fwf'}
, optional) – Driver to read files with, for ‘csv’read_csv()
, for {‘xlsx’, ‘xls’}read_excel()
, and for ‘fwf’read_fwf()
. By default the driver is inferred from the file extension and falls back to ‘csv’ if unknown.filesystem (
{'local', 'gcs', 's3'}
, optional) – Filesystem where the data is stored (local, cloud, http etc.). By default, local.nodata (
dict
,float
,int
, optional) – Missing value number. Only used if the data has no native missing value. Nodata values can be differentiated between variables using a dictionary.rename (
dict
, optional) – Mapping of native data source variable to output source variable name as required by hydroMT.unit_mult (
dict
, optional) – Scaling multiplication and addition to change to map from the native data unit to the output data unit as required by hydroMT.unit_add (
dict
, optional) – Scaling multiplication and addition to change to map from the native data unit to the output data unit as required by hydroMT.meta (
dict
, optional) – Metadata information of dataset, prefably containing the following keys: {‘source_version’, ‘source_url’, ‘source_license’, ‘paper_ref’, ‘paper_doi’, ‘category’}placeholders (
dict
, optional) – Placeholders to expand yaml entry to multiple entries (name and path) based on placeholder valuesattrs (
dict
, optional) – Additional attributes relating to data variables. For instance unit or long name of the variable.driver_kwargs – Additional key-word arguments passed to the driver.
dict – Additional key-word arguments passed to the driver.
optional – Additional key-word arguments passed to the driver.
name (
str
, optional) – Name of the dataset and catalog, optional for now.catalog_name (
str
, optional) – Name of the dataset and catalog, optional for now.
Methods
__init__
(path[, driver, filesystem, nodata, ...])Initiate data adapter for 2D tabular data.
get_data
([variables, time_tuple, logger])Return a DataFrame.
get_filesystem
(**kwargs)Return an initialised filesystem object.
resolve_paths
([time_tuple, variables, ...])Resolve {year}, {month} and {variable} keywords in self.path.
summary
()Return a dictionary summary of the data adapter.
to_dict
()Return a dictionary view of the data source.
to_file
(data_root, data_name[, driver, ...])Save a dataframe slice to a file.
Attributes
data_type
Return the datatype of the addapter.