pyfvcom2.namelist module
- class pyfvcom2.namelist.NamelistManager(casename: str = 'casename', fabm: bool = False)
Bases:
objectManager for FVCOM run namelists.
Holds a complete FVCOM namelist configuration with sensible defaults and exposes methods to update individual entries before writing to an ASCII
.nmlfile.The defaults correspond to a barotropic, tide-only cold-start run with no surface forcing, rivers, or data assimilation. The only mandatory entries that have no defaults are
NML_CASE / START_DATEandNML_CASE / END_DATE; everything else is pre-populated.- Parameters:
casename – Model case name used to construct default file-path strings. Defaults to
'casename'.fabm – If
True, add FABM output controls to the relevant sections and append anNML_FABMsection. Defaults toFalse.
Examples
>>> nml = NamelistManager(casename='tamar_v09') >>> nml.update('NML_CASE', 'START_DATE', '2020-05-01 00:00:00') >>> nml.update('NML_CASE', 'END_DATE', '2020-06-01 00:00:00') >>> nml.update('NML_INTEGRATION', 'EXTSTEP_SECONDS', 2.0) >>> nml.update('NML_PHYSICS', 'TEMPERATURE_ACTIVE', True) >>> nml.update_ramp(24) # 24-hour ramp >>> nml.write('tamar_v09_run.nml')
- update(section: str, entry: str, value=None, fmt: str | None = None) None
Update the value and/or format specifier of a namelist entry.
- Parameters:
section – Section name (e.g.
'NML_CASE'). A leading'&'is accepted and stripped.entry – Entry name within the section.
value – New value.
boolis converted to'T'/'F'automatically. PassNoneto leave unchanged.fmt – New Python format specification string (e.g.
'f','.3f','d'). PassNoneto leave unchanged.
- Raises:
KeyError – If
sectionorentrydoes not exist.PyFVCOM2ValueError – If neither
valuenorfmtis supplied.
- update_nesting_interval(target_interval: int = 900) None
Find and set a
NCNEST_OUT_INTERVALcompatible with the model.Searches candidate intervals from 60 s up to ten times
target_interval(in 60 s steps) and selects the valid candidate closest totarget_interval.- Parameters:
target_interval – Target interval in seconds. Defaults to 900 s.
- Raises:
PyFVCOM2ValueError – If no suitable interval is found — try a different
target_interval,NCNEST_BLOCKSIZE, orEXTSTEP_SECONDS.
- update_nudging(recovery_time: float) None
Set OBC nudging timescales from a physical recovery time.
Computes the dimensionless FVCOM nudging timescale (
EXTSTEP_SECONDS / recovery_time_seconds) and applies it to temperature, salinity, and — when FABM is enabled — FABM OBC nudging.- Parameters:
recovery_time – Recovery time in hours.
- update_ramp(duration: float) None
Set
IRAMPto the number of external time steps fordurationhours.- Parameters:
duration – Ramp duration in hours.
- valid_nesting_timescale(interval: float | None = None) bool
Check whether a nesting output interval is compatible with the model.
The simulation duration must be evenly divisible by
NCNEST_OUT_INTERVAL × NCNEST_BLOCKSIZE, and the quotient must be evenly divisible byEXTSTEP_SECONDS.- Parameters:
interval – Candidate interval in seconds. If
None, reads the currentNCNEST_OUT_INTERVALvalue from the config.- Returns:
Trueif the interval is compatible,Falseotherwise.
- value(section: str, entry: str)
Return the current value of a namelist entry.
- Parameters:
section – Section name (e.g.
'NML_CASE'). A leading'&'is accepted and stripped.entry – Entry name within the section.
- Returns:
The current value (
str,int,float, orNone).- Raises:
KeyError – If
sectionorentrydoes not exist.
- write(path: str) None
Write the namelist configuration to an ASCII
.nmlfile.Before writing,
None-valued*_FIRST_OUTentries and the dye release start/stop are back-filled fromNML_CASE / START_DATEandNML_CASE / END_DATE.- Parameters:
path – Output file path.
- Raises:
PyFVCOM2ValueError – If
START_DATEorEND_DATEhave not been set, ifNCNEST_ONis'T'but the nesting interval is invalid, or if any other mandatory entry is stillNoneat write time.