dapper.met.adapters package

Submodules

dapper.met.adapters.base module

Adapter interface between met sources and the Exporter.

class dapper.met.adapters.base.BaseAdapter[source]

Bases: ABC

Adapter contract for met sources. The Exporter depends only on this interface. Implementations may override defaults as needed.

abstractmethod discover_files(csv_directory, calendar, *, clip_to_full_years=None)[source]

Return (csv_files, start_year, end_year).

Parameters:
  • calendar (str)

  • clip_to_full_years (bool | None)

normalize_locations(df_loc, id_col=None)[source]

Standardize df_loc to include [‘gid’,’lat’,’lon’,’lon_0-360’,’zone’], sorted by (lat, lon).

Zones are treated as a per-location grouping label (e.g., to support E3SM/ELM decomposition hints across a cellset). If df_loc lacks a ‘zone’ column, we default every location to zone=1.

We intentionally do not auto-expand locations across multiple zones. If you want multiple zones, supply an explicit ‘zone’ column in df_loc with one row per location.

Return type:

DataFrame

Parameters:

df_loc (DataFrame)

pack_params(elm_var, data=None)[source]

Default: use elm_utils.elm_var_packing_params if available; otherwise a safe fallback. Adapters can override for source-specific packing strategies.

Parameters:

elm_var (str)

abstractmethod preprocess_shard(df_merged, start_year, end_year, calendar, dformat)[source]

Return a DataFrame with at least: [‘gid’,’time’,’LATIXY’,’LONGXY’,’zone’, <ELM vars>]

Return type:

DataFrame

Parameters:
  • df_merged (DataFrame)

  • start_year (int)

  • end_year (int)

  • calendar (str)

  • dformat (str)

required_vars(dformat)[source]

Optional: return a list of ELM var short names that this adapter will produce for the given dformat (‘BYPASS’ or ‘DATM_MODE’). Exporter doesn’t require it.

Parameters:

dformat (str)

temporal_metadata(options=None)[source]

Return NetCDF attributes describing source-specific time handling.

Return type:

dict

Parameters:

options (dict | None)

temporal_options(df, *, start_year, end_year, calendar)[source]

Return source-specific options for temporal.create_dtime.

Return type:

dict

Parameters:
  • df (DataFrame)

  • start_year (int)

  • end_year (int)

  • calendar (str)

dapper.met.adapters.era5 module

ERA5-Land adapter implementation.

class dapper.met.adapters.era5.ERA5Adapter[source]

Bases: BaseAdapter

ERA5-Land hourly → ELM adapter.

Handles ERA5-specific file discovery, unit conversions, humidity diagnostics, renaming to ELM short names, and nonnegativity so the Exporter stays source-agnostic.

preprocess_shard steps:

  1. keep rows from Jan 1 of start_year through Jan 1 00:00 of end_year + 1 (a one-hour lookahead for end-labeled fluxes); Feb 29 is kept here and dropped later during temporal alignment

  2. unit conversions: J/m² per hour → W/m² (÷3600), m/hr → mm/s (÷3.6), wind speed from u/v

  3. RH and specific humidity when temperature, dewpoint, and surface pressure are all present

  4. rename to ELM short names via dapper.config.metsources.era5.RAW_TO_ELM

  5. clip canonical nonnegative variables at 0

  6. return the format’s required variables plus LONGXY, LATIXY, time, gid, zone, sorted by time and location

Accumulated fields (FSDS, FLDS, PRECTmms) are labeled at interval end; temporal_options() tells the exporter to relabel them to interval start.

DRIVER_TAG = 'ERA5'
GEE_COLLECTION_START = Timestamp('1950-01-01 01:00:00')
INTERVAL_END_VARS = ('FSDS', 'FLDS', 'PRECTmms')
SOURCE_INTERVAL_HOURS = 1.0
SOURCE_NAME = 'ERA5-Land hourly reanalysis'
discover_files(csv_directory, calendar, *, clip_to_full_years=None)[source]

Discover ERA5 CSV shards in a directory and infer the inclusive year range.

id_column_for_csv(df_csv, id_col)[source]

Return the identifier column name expected in ERA5 CSV shards (“gid”).

Deprecated: the Exporter always uses gid and never calls this.

pack_params(elm_var, data=None)[source]

Return (add_offset, scale_factor) used to pack a variable for NetCDF output.

preprocess_shard(df_merged, start_year, end_year, calendar, dformat)[source]

Convert one merged CSV shard to canonical ELM columns (see class docstring).

required_vars(dformat)[source]

Return the canonical ELM variables required for the requested output format.

temporal_metadata(options=None)[source]

NetCDF provenance for ERA5-Land interval alignment.

temporal_options(df, *, start_year, end_year, calendar)[source]

Describe how GEE’s ERA5-Land hourly fields are time-labeled.

dapper.met.adapters.fluxnet module

FLUXNET (AmeriFlux ONEFlux) to ELM adapter.

class dapper.met.adapters.fluxnet.FluxnetAdapter[source]

Bases: BaseAdapter

AmeriFlux FLUXNET → ELM adapter.

Assumptions

  • User provides a single FLUXNET CSV (FULLSET or SUBSET) per run.

  • CSV contains TIMESTAMP_START/TIMESTAMP_END (or TIMESTAMP) columns.

  • Missing values are coded as -9999.

  • Exporter supplies df_merged with [‘gid’,’lat’,’lon’,’zone’, …] already merged in from df_loc.

DRIVER_TAG = 'FLUXNET'
SOURCE_NAME = 'FLUXNET (AmeriFlux ONEFlux) tower data'
discover_files(csv_directory, calendar, *, clip_to_full_years=None)[source]

Return (csv_files, start_year, end_year).

Parameters:

calendar (str)

preprocess_shard(df_merged, start_year, end_year, calendar, dformat)[source]

Return a DataFrame with at least: [‘gid’,’time’,’LATIXY’,’LONGXY’,’zone’, <ELM vars>]

Return type:

DataFrame

Parameters:
  • df_merged (DataFrame)

  • start_year (int)

  • end_year (int)

  • calendar (str)

  • dformat (str)

required_vars(dformat)[source]

Optional: return a list of ELM var short names that this adapter will produce for the given dformat (‘BYPASS’ or ‘DATM_MODE’). Exporter doesn’t require it.

Parameters:

dformat (str)

dapper.met.adapters.fluxnet.infer_fluxnet_dt_hours(df)[source]

Infer native FLUXNET timestep from timestamp columns in hours.

Handles:
  • half-hourly/hourly/weekly: TIMESTAMP_START, TIMESTAMP_END (YYYYMMDDHHMM)

  • daily/monthly/yearly: TIMESTAMP (YYYYMMDD or YYYYMM, etc.)

Returns:

Approximate timestep in hours.

Return type:

float

Raises:

ValueError – If no suitable timestamp columns are found or dt cannot be inferred.

Parameters:

df (DataFrame)

Module contents

MET adapters.

This package contains dataset-specific adapters (ERA5, Fluxnet, …).

The source-agnostic exporter lives in dapper.met.exporter, but we re-export it here for convenience/back-compat.

class dapper.met.adapters.BaseAdapter[source]

Bases: ABC

Adapter contract for met sources. The Exporter depends only on this interface. Implementations may override defaults as needed.

abstractmethod discover_files(csv_directory, calendar, *, clip_to_full_years=None)[source]

Return (csv_files, start_year, end_year).

Parameters:
  • calendar (str)

  • clip_to_full_years (bool | None)

normalize_locations(df_loc, id_col=None)[source]

Standardize df_loc to include [‘gid’,’lat’,’lon’,’lon_0-360’,’zone’], sorted by (lat, lon).

Zones are treated as a per-location grouping label (e.g., to support E3SM/ELM decomposition hints across a cellset). If df_loc lacks a ‘zone’ column, we default every location to zone=1.

We intentionally do not auto-expand locations across multiple zones. If you want multiple zones, supply an explicit ‘zone’ column in df_loc with one row per location.

Return type:

DataFrame

Parameters:

df_loc (DataFrame)

pack_params(elm_var, data=None)[source]

Default: use elm_utils.elm_var_packing_params if available; otherwise a safe fallback. Adapters can override for source-specific packing strategies.

Parameters:

elm_var (str)

abstractmethod preprocess_shard(df_merged, start_year, end_year, calendar, dformat)[source]

Return a DataFrame with at least: [‘gid’,’time’,’LATIXY’,’LONGXY’,’zone’, <ELM vars>]

Return type:

DataFrame

Parameters:
  • df_merged (DataFrame)

  • start_year (int)

  • end_year (int)

  • calendar (str)

  • dformat (str)

required_vars(dformat)[source]

Optional: return a list of ELM var short names that this adapter will produce for the given dformat (‘BYPASS’ or ‘DATM_MODE’). Exporter doesn’t require it.

Parameters:

dformat (str)

temporal_metadata(options=None)[source]

Return NetCDF attributes describing source-specific time handling.

Return type:

dict

Parameters:

options (dict | None)

temporal_options(df, *, start_year, end_year, calendar)[source]

Return source-specific options for temporal.create_dtime.

Return type:

dict

Parameters:
  • df (DataFrame)

  • start_year (int)

  • end_year (int)

  • calendar (str)

class dapper.met.adapters.ERA5Adapter[source]

Bases: BaseAdapter

ERA5-Land hourly → ELM adapter.

Handles ERA5-specific file discovery, unit conversions, humidity diagnostics, renaming to ELM short names, and nonnegativity so the Exporter stays source-agnostic.

preprocess_shard steps:

  1. keep rows from Jan 1 of start_year through Jan 1 00:00 of end_year + 1 (a one-hour lookahead for end-labeled fluxes); Feb 29 is kept here and dropped later during temporal alignment

  2. unit conversions: J/m² per hour → W/m² (÷3600), m/hr → mm/s (÷3.6), wind speed from u/v

  3. RH and specific humidity when temperature, dewpoint, and surface pressure are all present

  4. rename to ELM short names via dapper.config.metsources.era5.RAW_TO_ELM

  5. clip canonical nonnegative variables at 0

  6. return the format’s required variables plus LONGXY, LATIXY, time, gid, zone, sorted by time and location

Accumulated fields (FSDS, FLDS, PRECTmms) are labeled at interval end; temporal_options() tells the exporter to relabel them to interval start.

DRIVER_TAG = 'ERA5'
GEE_COLLECTION_START = Timestamp('1950-01-01 01:00:00')
INTERVAL_END_VARS = ('FSDS', 'FLDS', 'PRECTmms')
SOURCE_INTERVAL_HOURS = 1.0
SOURCE_NAME = 'ERA5-Land hourly reanalysis'
discover_files(csv_directory, calendar, *, clip_to_full_years=None)[source]

Discover ERA5 CSV shards in a directory and infer the inclusive year range.

id_column_for_csv(df_csv, id_col)[source]

Return the identifier column name expected in ERA5 CSV shards (“gid”).

Deprecated: the Exporter always uses gid and never calls this.

pack_params(elm_var, data=None)[source]

Return (add_offset, scale_factor) used to pack a variable for NetCDF output.

preprocess_shard(df_merged, start_year, end_year, calendar, dformat)[source]

Convert one merged CSV shard to canonical ELM columns (see class docstring).

required_vars(dformat)[source]

Return the canonical ELM variables required for the requested output format.

temporal_metadata(options=None)[source]

NetCDF provenance for ERA5-Land interval alignment.

temporal_options(df, *, start_year, end_year, calendar)[source]

Describe how GEE’s ERA5-Land hourly fields are time-labeled.

class dapper.met.adapters.Exporter(adapter, src_path, *, domain, out_dir=None, calendar='noleap', dtime_resolution_hrs=1, dtime_units='days', dformat='BYPASS', append_attrs=None, chunks=None, include_vars=None, exclude_vars=None, clip_to_full_years=None)[source]

Bases: object

Source-agnostic meteorological exporter.

Ingests time-sharded CSVs for all sites/cells, preprocesses each shard with a pluggable adapter, stages per-gid parquet files, and writes packed (int16) ELM MET NetCDFs. The layout follows domain.mode:

  • "cellset": <out_dir>/MET/<file>.nc per variable with dims ('DTIME', 'lat', 'lon'), one global packing, and a single DTIME axis shared by every point (sparse lat/lon axes are allowed).

  • "sites": <out_dir>/<gid>/MET/<file>.nc per variable with dims ('n', 'DTIME') (n=1), per-site packing, and a per-site DTIME axis.

Each MET directory also gets a zone_mappings.txt.

All dataset-specific logic (file discovery, unit conversions, renaming to ELM short names) lives in the adapter (see dapper.met.adapters.base.BaseAdapter).

Parameters:
  • adapter (BaseAdapter) – Source adapter (e.g. ERA5Adapter).

  • src_path (str or pathlib.Path) – Input location passed to adapter.discover_files.

  • domain (Domain) – Sites/cells to export; gid links CSV rows to cells.

  • out_dir (str or pathlib.Path, optional) – Output root. Defaults to domain.run_dir (requires domain.path_out).

  • calendar (str, default "noleap") – DTIME calendar; Feb 29 is dropped for no-leap aliases.

  • dtime_resolution_hrs (float, default 1) – Target DTIME step in hours (fractions allowed).

  • dtime_units ({"days", "hours"}, default "days") – Units of the numeric DTIME coordinate.

  • dformat ({"BYPASS", "DATM_MODE"}, default "BYPASS") – ELM forcing format passed to the adapter.

  • append_attrs (dict, optional) – Extra global attributes for every file. Exporter provenance (domain_mode, pack_scope, export_start_year, …) is added without overriding user keys, except domain_mode, pack_scope, clip_to_full_years and the export years, which always win.

  • chunks (tuple[int, ...], optional) – Explicit NetCDF chunk sizes; auto-chunked when omitted.

  • include_vars (Iterable[str], optional) – Allow/block lists of ELM short names applied after preprocessing. Meta columns gid, time, LATIXY, LONGXY and zone are kept.

  • exclude_vars (Iterable[str], optional) – Allow/block lists of ELM short names applied after preprocessing. Meta columns gid, time, LATIXY, LONGXY and zone are kept.

  • clip_to_full_years (bool or None, optional) – Clip the discovered year range to complete calendar years (raises if none). None keeps the adapter default (True for ERA5).

Notes

Temporary parquet shards are written under <out_dir>/.dapper_tmp and removed at the end of run().

run(*, pack_scope=None, filename=None, overwrite=False)[source]

Run the MET export for this exporter’s Domain.

The output layout is derived from Domain.mode:
  • sites: writes <run_dir>/<gid>/MET/{prefix_}{var}.nc and a per-site zone_mappings.txt (always zone=01, id=1).

  • cellset: writes <run_dir>/MET/{prefix_}{var}.nc and a single zone_mappings.txt covering all locations (zones taken from df_loc, default 1).

Parameters:
  • pack_scope (str | None) – Optional packing strategy override. Defaults to per-site for sites and global for cellset outputs.

  • filename (str | None) – Optional filename template for output NetCDF files. Supports two formats: - Template with {var} placeholder: ‘ERA5_{var}_1950-2025_z01’ generates ‘ERA5_TBOT_1950-2025_z01.nc’ - Simple prefix (legacy): ‘prefix’ generates ‘prefix_TBOT.nc’ If omitted, the default is ‘<driver>_<var>_<start>-<end>_z01.nc’. The ‘.nc’ extension is added automatically.

  • overwrite (bool) – If True, clears existing MET outputs before writing.

Return type:

None

class dapper.met.adapters.FluxnetAdapter[source]

Bases: BaseAdapter

AmeriFlux FLUXNET → ELM adapter.

Assumptions

  • User provides a single FLUXNET CSV (FULLSET or SUBSET) per run.

  • CSV contains TIMESTAMP_START/TIMESTAMP_END (or TIMESTAMP) columns.

  • Missing values are coded as -9999.

  • Exporter supplies df_merged with [‘gid’,’lat’,’lon’,’zone’, …] already merged in from df_loc.

DRIVER_TAG = 'FLUXNET'
SOURCE_NAME = 'FLUXNET (AmeriFlux ONEFlux) tower data'
discover_files(csv_directory, calendar, *, clip_to_full_years=None)[source]

Return (csv_files, start_year, end_year).

Parameters:

calendar (str)

native_dt_hours: float | None
preprocess_shard(df_merged, start_year, end_year, calendar, dformat)[source]

Return a DataFrame with at least: [‘gid’,’time’,’LATIXY’,’LONGXY’,’zone’, <ELM vars>]

Return type:

DataFrame

Parameters:
  • df_merged (DataFrame)

  • start_year (int)

  • end_year (int)

  • calendar (str)

  • dformat (str)

required_vars(dformat)[source]

Optional: return a list of ELM var short names that this adapter will produce for the given dformat (‘BYPASS’ or ‘DATM_MODE’). Exporter doesn’t require it.

Parameters:

dformat (str)

resolution: str | None