pygetm.output package

Subpackages

Submodules

Module contents

class pygetm.output.File(available_fields: Mapping[str, Array], logger: Logger, interval: timedelta | int = 1, interval_units: TimeUnit = TimeUnit.TIMESTEPS, start: datetime | None = None, stop: datetime | None = None, default_dtype: DTypeLike | None = None, save_initial: bool = True, sub: bool = False, add_coordinates: bool = True)[source]

Bases: FieldCollection

Parameters:
  • interval – time interval to save at

  • interval_units – units for time interval (not used if interval is given as datetime.timedelta)

  • start – simulation time at which to start saving. This defaults to the start of the simulation

  • stop – simulation time at which to stop saving. This defaults to the end of the simulation

  • default_dtype – default data type for real-valued variables

  • sub – whether to save separate files per subdomain

  • save_initial – whether to save at the very start of the simulation

close(seconds_passed: float, time: datetime | None)[source]
close_now(seconds_passed: float, time: datetime | None)[source]
static get_cf_time_attrs(time: datetime | None, seconds_passed: float, time_reference: datetime | None) tuple[dict[str, str], float][source]

Get CF-compliant time attributes and offset for output files.

This method generates metadata attributes for time variables following the Climate and Forecast (CF) conventions, along with a time offset to align the time coordinate with the reference time.

Parameters:
  • time – The current simulation time. If None, time is measured only as seconds since simulation start.

  • seconds_passed – Total number of seconds elapsed since the simulation started.

  • time_reference – Reference time for CF-compliant time units. This is typically the start time of the first simulation in a series. Only used when time is not None.

Returns:

  • attrs: Dictionary of CF-compliant attributes for the time variable, including “axis”, “units”, and optionally “calendar” or “standard_name”

  • time_offset: Offset in seconds between the time reference and the start of seconds_passed counting (0.0 if counting starts from time_reference)

Return type:

A tuple containing

save(seconds_passed: float, itimestep: int, time: datetime | None)[source]
save_now(seconds_passed: float, time: datetime | None)[source]
select_nonempty_fields() Mapping[str, Array][source]

Get all fields that contain data.

Returns:

Mapping of field names to arrays for all fields that contain data.

start(seconds_passed: float, itimestep: int, time: datetime | None, default_time_reference: datetime | None = None) bool[source]
start_now(seconds_passed: float, time: datetime | None, default_time_reference: datetime | None) bool[source]
class pygetm.output.OutputManager(fields: Mapping[str, Array], rank: int, logger: Logger | None = None)[source]

Bases: object

add_netcdf_file(path: PathLike[str] | str, **kwargs) netcdf.NetCDFFile[source]

Add a NetCDF file for output.

Parameters:
add_recorder(**kwargs) memory.MemoryFile[source]

Add an in-memory file to record output.

Parameters:

**kwargs – additional keyword arguments passed to pygetm.output.File

add_restart(path: PathLike[str] | str, **kwargs) netcdf.NetCDFFile[source]

Add a restart file to write to.

Parameters:

This is a wrapper around add_netcdf_file() that automatically adds all arrays with the _part_of_state flag. By default, the restart file will be configured to be written at the end of the simulation, but this can be customized by providing argument interval (see File).

add_zarr_group(store: zarr.StoreLike, **kwargs) zarr.ZarrGroup[source]

Add a Zarr group for output.

Parameters:
  • store – Zarr group to write to.

  • **kwargs – additional keyword arguments passed to pygetm.output.zarr.ZarrGroup

close(seconds_passed: float, time: datetime | None = None)[source]

Close all open files. Those marked to save at the end of the simulation will first have the final variable values written to them

Parameters:
  • seconds_passed – total number of seconds since the start of the simulation

  • time – the current time

dump(path: PathLike[str] | str, *fields: str | Array, seconds_passed: float = 0.0, time: datetime | None = None, **kwargs)[source]
prepare_save(*args, macro: bool = True)[source]

Begin a new time step. For time-averaged outputs, the current variable values will be added to the temporal mean.

Parameters:

macro – whether quantities defined at the macrotimestep are up to date. This is the case if the previous time step had “macro” processes active. It does not relate to the processes of the timestep that is newly starting!

save(seconds_passed: float, itimestep: int, time: datetime | None = None)[source]

End the current time step and save outputs.

Parameters:
  • seconds_passed – total number of seconds since the start of the simulation

  • itimestep – index of the time step that has just finished

  • time – the current time

start(itimestep: int = 0, time: datetime | None = None, default_time_reference: datetime | None = None)[source]

Tell the output manager that the simulation has started. Output files that are registered to save from this time will be opened; if they were also registered with save_initial (see File), they will have values written to them.

Parameters:
  • itimestep – index of the first time step

  • time – the current time

  • default_time_reference – default reference time to use in formats that require this (e.g., NetCDF). This is usually the start time of this simulation. However, if starting from a restart, it is the time reference from that restart, and thus the start time of the very first simulation.

class pygetm.output.TimeUnit(*values)[source]

Bases: Enum

DAYS = 5
HOURS = 4
MINUTES = 3
MONTHS = 6
SECONDS = 2
TIMESTEPS = 1
YEARS = 7