Source code for pycif.plugins.datastreams.fluxes.point_sources.get_domain

import numpy as np
import itertools
import os
import pandas as pd
from .....utils.classes.domains import Domain
from .....utils.check.errclass import CifError


[docs] def get_domain(ref_dir, ref_file, input_interval, target_dir, tracer=None): """Build an unstructured, per-point domain from the point-source CSV file. Reads the CSV's ``lon``/``lat``/``alt`` columns and builds a `Domain` with one "cell" per point source (no shared grid; cell centers and corners coincide), with vertical extent equal to the number of sources (one level per source, positioned at its altitude). Args: ref_dir (str): Unused directly, kept for interface consistency; the reference file is instead taken from `tracer.input_files`. ref_file (str): Unused directly, kept for interface consistency. input_interval (list): Unused directly, kept for interface consistency. target_dir (str): Unused directly, kept for interface consistency. tracer: The flux tracer plugin, providing ``input_files`` (as populated by `fetch`). Returns: Domain: an unstructured domain with one cell per point source. Raises: CifError: If the reference CSV file is not found. """ # Looking for a reference file to read lon/lat in ref_file = list(tracer.input_files.values())[0][0] if not os.path.isfile(ref_file): raise CifError( "TNO domain could not be initialized as no file was found" ) # Read the emissions file ds = pd.read_csv(ref_file, sep=";", parse_dates=["datei", "datef"]) # Put it to a domain Plugin zlon, zlat = np.meshgrid(ds["lon"], ds["lat"]) domain = Domain(nlon=len(ds), nlat=len(ds), zlon=zlon, zlat=zlat, zlonc=zlon, zlatc=zlat, nlev=len(ds), heights=ds["alt"], height_unit="m") return domain