tracmass.load#
- tracmass.load(filename=None, *, env=None, dtm=None, reverse=None, columns=None, filters=None, lonlat=False, gcm=None, clean=True, rampup=False)[source]#
Load a trajectory file written by
ParticleRecorder.The file is chosen by, in order of precedence:
filename, if given;
env and/or dtm: the file the settings-driven recorder writes for that environment (default: the active one) and run start date —
{output_folder}/{stem}_{forward|reverse}_{dtm}.parquet(also looked for inbase_output_diritself and its{env}/{output_name}sub-folders, where files written with a differentuse_sub_foldersetting end up). Without dtm, the newest file of that environment;nothing given: the newest
.parquetfile inbase_output_diror one of its sub-folders, i.e. the most recently written run.
- Parameters:
filename (
strorPathorNone, optional) – Path of the file to read.env (
strorNone, optional) –tracmass.tomlenvironment whosebase_output_dir/use_sub_folder/output_namelocate the file. Read withsettings.from_env; the active environment is not changed.dtm (
strorpd.TimestamporNone, optional) – Run start date (the date in the file name).reverse (
boolorNone, optional) – Run direction. DefaultNone: either, as long as only one matches.columns (
listofstrorNone, optional) – Columns to read. Default: all.filters (
dictorlistorNone, optional) – Rows to read, applied while reading (row groups that cannot match are skipped). A dict{"window": 0}meanscolumn == valuefor each item (a list/tuple/set value meanscolumn in value); otherwise pyarrow filters: a list of(column, op, value)tuples (ANDed), or a list of such lists (ORed). Filter columns need not be in columns. Combined (AND) with the clean row filter. Default: all rows.lonlat (
bool, optional) – Addlon/latcolumns (degrees), converted fromx/ywith the GCM adapter’sxy_to_lonlat(glorys,ecco2).x/yare read for this even if not in columns. DefaultFalse.gcm (
strorNone, optional) – Adapter for lonlat. Default:gcmin the file’s metadata, else[env.gcm] nameof env, of theenvin the file’s metadata, or of the active environment. The file’sgcm_product(e.g."glorys12v1") selects which of the adapter’s grids is used, whatever product is currently configured.clean (
bool, optional) – Return only the snapshot rows (event_type == "snapshot"; no deactivation events) and only the columnsid,x,y,dtm(pluslon,latwith lonlat). An explicit columns takes precedence over the column part. DefaultTrue;clean=Falsereturns every row and column.rampup (
bool, optional) – With clean, also keep theevent_type == "rampup"rows (the extra saves inside the first windows of a run withrampup_windows), and add theevent_typecolumn (unless columns is given) to tell them from the window snapshots. The time between consecutive saves isdf.attrs["tracmass.run"] ["save_dt_seconds"]. DefaultFalse.
- Returns:
pd.DataFrame– The trajectory rows.df.attrs["path"]is the file read anddf.attrs["tracmass.run"]its run metadata ({}if none; seetracmass.runsetup.run_metadata()for the keys).- Raises:
FileNotFoundError – If no matching file exists.
TypeError – If filename is given together with env / dtm.
ValueError – If dtm matches both a forward and a reverse run and reverse is not given, or lonlat is set and no GCM with
xy_to_lonlatcan be found.
- Return type:
Examples
>>> df = tracmass.load() # newest run, id/x/y/dtm >>> df = tracmass.load(clean=False) # every row and column >>> df = tracmass.load(env="omi_falkor") # newest omi_falkor run >>> df = tracmass.load(env="omi_falkor", dtm="2007-06-01") >>> df = tracmass.load("traj.parquet", columns=["id", "dtm", "x", "y"]) >>> df = tracmass.load(filters={"window": 0}) # first window only >>> df = tracmass.load(filters=[("window", "<", 10), ("reason", "==", 2)]) >>> df = tracmass.load(env="omi_falkor", lonlat=True) # + lon, lat columns >>> df = tracmass.load(lonlat=True) # id, x, y, dtm, lon, lat >>> df = tracmass.load(rampup=True) # + ramp-up saves, event_type column