dapper.Exporter¶
- class dapper.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:
objectSource-agnostic meteorological exporter.
This class orchestrates a two-pass pipeline that ingests time-sharded CSVs for many sites/cells, preprocesses them via a pluggable adapter, and writes ELM-ready NetCDF outputs in two layouts:
"cellset"– one NetCDF per variable with dims('DTIME','lat','lon')(global packing; sparse lat/lon axes are OK)."sites"– one directory per site; each directory contains one NetCDF per variable with dims('n','DTIME')wheren=1(per-site packing).
Exporter is source-agnostic: all dataset-specific logic (file discovery, unit conversions, renaming to ELM short names, etc.) lives in an adapter that implements the BaseAdapter interface (e.g., an
ERA5Adapter). The exporter handles staging (CSV → per-site parquet), global DTIME axis creation, packing scans, chunking, and NetCDF I/O.- Parameters:
adapter (BaseAdapter) – Implements:
discover_files,normalize_locations,preprocess_shard,required_vars, andpack_params.csv_directory (str or pathlib.Path) – Directory containing time-sharded CSV files for all sites/cells.
out_dir (str or pathlib.Path) – Destination directory for NetCDF outputs and temporary parquet shards.
df_loc (pandas.DataFrame) – Locations table with at least columns
["gid","lat","lon"]; optional"zone". The adapter’snormalize_locations: - validates columns, - adds"lon_0-360", - fills/validates"zone", - sorts for stable site order.id_col (str, optional) – Kept for backward compatibility (unused when
"gid"is assumed).calendar ({"noleap","standard"}, default "noleap") – Calendar for numeric DTIME coordinate; Feb 29 filtered for “noleap”.
dtime_resolution_hrs (int, default 1) – Target time resolution in hours for the DTIME axis.
dtime_units ({"days","hours"}, default "days") – Units of the numeric DTIME coordinate (e.g.,
"days since YYYY-MM-DD HH:MM:SS").domain (Domain)
dformat (str)
append_attrs (dict | None)
clip_to_full_years (bool | None)
- dformat{“BYPASS”,”DATM_MODE”}, default “BYPASS”
Target ELM format selector passed through to the adapter.
- append_attrsdict, optional
Extra global NetCDF attributes to include in every file. The exporter also adds:
export_mode("cellset"or"sites") andpack_scope("global"or"per-site").- chunkstuple[int,…], optional
Explicit NetCDF chunk sizes.
- include_vars / exclude_varsIterable[str], optional
Allow-/block-lists of ELM short names applied after preprocess. Meta columns
{"gid","time","LATIXY","LONGXY","zone"}are always kept.- clip_to_full_yearsbool or None, optional
Controls whether the discovered export year range is clipped to full calendar years. Clipping raises if no complete year exists.
Nonepreserves the adapter default (True for ERA5).
Side Effects¶
Creates a temporary directory of per-site parquet shards under
out_dir.Writes NetCDF files to
out_dirin the chosen layout.Writes a
zone_mappings.txtfile either at the root (cellset) or inside each site directory (sites).
Notes
Packing: global packing for
cellset; per-site packing forsites.Required columns: CSV shards and
df_locboth use"gid"; CSVs include the adapter’s date/time column (renamed to"time"during preprocess).Combined (lat/lon) layout: does not enforce regular grids; axes are the unique sorted lat/lon from
df_loc(sparse OK).
- __init__(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]¶
Create a MET exporter for a given Domain.
- Parameters:
adapter – A met adapter implementing the BaseAdapter interface.
src_path – Input directory containing time-sharded CSV files.
out_dir – Optional override for the run_dir root. If not provided, defaults to
domain.run_dir. The exporter will write into<run_dir>/MET(cellset mode) or<run_dir>/<gid>/MET(sites mode).append_attrs (
dict|None) – Extra global NetCDF attributes to append to every output file.calendar (str)
dtime_resolution_hrs (float)
dtime_units (str)
dformat (str)
clip_to_full_years (bool | None)
Methods
__init__(adapter, src_path, *, domain[, ...])Create a MET exporter for a given Domain.
run(*[, pack_scope, filename, overwrite])Run the MET export for this exporter’s Domain.
- 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}.ncand a per-sitezone_mappings.txt(always zone=01, id=1).cellset: writes<run_dir>/MET/{prefix_}{var}.ncand a singlezone_mappings.txtcovering all locations (zones taken from df_loc, default 1).
- Parameters:
pack_scope – Optional packing strategy override. Defaults to
per-sitefor sites andglobalfor 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
- The output layout is derived from