SWAN Output Components¶
This notebook shows examples of using the SWAN components to define model output commands
In [1]:
Copied!
%load_ext autoreload
%autoreload 2
import warnings
warnings.filterwarnings("ignore")
%load_ext autoreload
%autoreload 2
import warnings
warnings.filterwarnings("ignore")
In [2]:
Copied!
from rompy_swan.components.group import OUTPUT
from rompy_swan.subcomponents.time import TimeRangeOpen
from rompy_swan.components.output import (
SPECIAL_NAMES,
BaseLocation,
FRAME,
GROUP,
CURVE,
CURVES,
RAY,
ISOLINE,
POINTS,
POINTS_FILE,
NGRID,
NGRID_UNSTRUCTURED,
QUANTITY,
QUANTITIES,
OUTPUT_OPTIONS,
BLOCK,
BLOCKS,
TABLE,
SPECOUT,
NESTOUT,
TEST,
)
from rompy_swan.components.group import OUTPUT
from rompy_swan.subcomponents.time import TimeRangeOpen
from rompy_swan.components.output import (
SPECIAL_NAMES,
BaseLocation,
FRAME,
GROUP,
CURVE,
CURVES,
RAY,
ISOLINE,
POINTS,
POINTS_FILE,
NGRID,
NGRID_UNSTRUCTURED,
QUANTITY,
QUANTITIES,
OUTPUT_OPTIONS,
BLOCK,
BLOCKS,
TABLE,
SPECOUT,
NESTOUT,
TEST,
)
OUTPUT group component¶
The OUTPUT group component provides an interface for the different types of SWAN output commands
In [3]:
Copied!
OUTPUT?
OUTPUT?
Init signature: OUTPUT( *, model_type: Literal['output', 'OUTPUT'] = 'output', frame: Optional[Annotated[rompy_swan.components.output.FRAME, FieldInfo(annotation=NoneType, required=True, description='Frame locations component')]] = None, group: Optional[Annotated[rompy_swan.components.output.GROUP, FieldInfo(annotation=NoneType, required=True, description='Group locations component')]] = None, curve: Optional[Annotated[rompy_swan.components.output.CURVES, FieldInfo(annotation=NoneType, required=True, description='Curve locations component')]] = None, ray: Optional[Annotated[rompy_swan.components.output.RAY, FieldInfo(annotation=NoneType, required=True, description='Ray locations component')]] = None, isoline: Optional[Annotated[rompy_swan.components.output.ISOLINE, FieldInfo(annotation=NoneType, required=True, description='Isoline locations component')]] = None, points: Optional[Annotated[Union[rompy_swan.components.output.POINTS, rompy_swan.components.output.POINTS_FILE], FieldInfo(annotation=NoneType, required=True, description='Points locations component', discriminator='model_type')]] = None, ngrid: Optional[Annotated[Union[rompy_swan.components.output.NGRID, rompy_swan.components.output.NGRID_UNSTRUCTURED], FieldInfo(annotation=NoneType, required=True, description='Ngrid locations component', discriminator='model_type')]] = None, quantity: Optional[Annotated[rompy_swan.components.output.QUANTITIES, FieldInfo(annotation=NoneType, required=True, description='Quantity component')]] = None, output_options: Optional[Annotated[rompy_swan.components.output.OUTPUT_OPTIONS, FieldInfo(annotation=NoneType, required=True, description='Output options component')]] = None, block: Optional[Annotated[Union[rompy_swan.components.output.BLOCK, rompy_swan.components.output.BLOCKS], FieldInfo(annotation=NoneType, required=True, description='Block write component', discriminator='model_type')]] = None, table: Optional[Annotated[rompy_swan.components.output.TABLE, FieldInfo(annotation=NoneType, required=True, description='Table write component')]] = None, specout: Optional[Annotated[rompy_swan.components.output.SPECOUT, FieldInfo(annotation=NoneType, required=True, description='Spectra write component')]] = None, nestout: Optional[Annotated[rompy_swan.components.output.NESTOUT, FieldInfo(annotation=NoneType, required=True, description='Nest write component')]] = None, test: Optional[Annotated[rompy_swan.components.output.TEST, FieldInfo(annotation=NoneType, required=True, description='Intermediate write component')]] = None, ) -> None Docstring: Output group component. .. code-block:: text FRAME 'sname' ... GROUP 'sname' ... CURVE 'sname' ... RAY 'rname' ... ISOLINE 'sname' 'rname' ... POINTS 'sname ... NGRID 'sname' ... QUANTITY ... OUTPUT OPTIONS ... BLOCK 'sname' ... TABLE 'sname' ... SPECOUT 'sname' ... NESTOUT 'sname ... This group component is used to define multiple types of output locations and write components in a single model. Only fields that are explicitly prescribed are rendered by this group component. Note ---- The components prescribed are validated according to some constraints as defined in the SWAN manual: - The name `'sname'` of each Locations component must be unique. - The Locations `'sname'` assigned to each write component must be defined. - The BLOCK component must be associated with either a `FRAME` or `GROUP`. - The ISOLINE write component must be associated with a `RAY` component. - The NGRID and NESTOUT components must be defined together. Examples -------- .. ipython:: python :okwarning: from rompy_swan.components.output import POINTS, BLOCK, QUANTITIES, TABLE from rompy_swan.components.group import OUTPUT points = POINTS(sname="outpts", xp=[172.3, 172.4], yp=[-39, -39]) quantity = QUANTITIES( quantities=[ dict(output=["depth", "hsign", "tps", "dir", "tm01"], excv=-9), ] ) times = dict(tbeg="2012-01-01T00:00:00", delt="PT30M", tfmt=1, dfmt="min") block = BLOCK( model_type="block", sname="COMPGRID", fname="./swangrid.nc", output=["depth", "hsign", "tps", "dir"], times=times, ) table = TABLE( sname="outpts", format="noheader", fname="./swantable.nc", output=["hsign", "hswell", "dir", "tps", "tm01", "watlev", "qp"], times=times, ) out = OUTPUT( points=points, quantity=quantity, block=block, table=table, ) print(out.render()) Init docstring: Create a new model by parsing and validating input data from keyword arguments. Raises [`ValidationError`][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model. `self` is explicitly positional-only to allow `self` as a field name. File: /source/csiro/rompy-swan/src/rompy_swan/components/group.py Type: ModelMetaclass Subclasses:
BLOCK¶
In [4]:
Copied!
# Specifying a single block component
block = BLOCK(
sname="COMPGRID",
fname="outgrid.nc",
output=["depth", "wind", "hsign", "hswell", "dir", "tps"],
times=TimeRangeOpen(tfmt=1, dfmt="min"),
idla=3,
)
print(block.render())
# Note
# ----
# The times field is overriden in the SwanConfig class using the general TimeRange
# but it can be used here to specify the time format and the time delta formats
# Specifying a single block component
block = BLOCK(
sname="COMPGRID",
fname="outgrid.nc",
output=["depth", "wind", "hsign", "hswell", "dir", "tps"],
times=TimeRangeOpen(tfmt=1, dfmt="min"),
idla=3,
)
print(block.render())
# Note
# ----
# The times field is overriden in the SwanConfig class using the general TimeRange
# but it can be used here to specify the time format and the time delta formats
BLOCK sname='COMPGRID' fname='outgrid.nc' LAYOUT idla=3 &
DEPTH &
WIND &
HSIGN &
HSWELL &
DIR &
TPS &
OUTPUT tbegblk=19700101.000000 deltblk=60.0 MIN
In [5]:
Copied!
# Specifying multiple block components
block1 = BLOCK(sname="COMPGRID", fname="depth.txt", output=["depth"])
block2 = BLOCK(sname="COMPGRID", fname="hsign.txt", output=["hsign"])
block3 = BLOCK(sname="COMPGRID", fname="tps.txt", output=["tps"])
block4 = BLOCK(sname="COMPGRID", fname="dir.txt", output=["dir"])
blocks = BLOCKS(components=[block1, block2, block3, block4])
print(blocks.render())
# Specifying multiple block components
block1 = BLOCK(sname="COMPGRID", fname="depth.txt", output=["depth"])
block2 = BLOCK(sname="COMPGRID", fname="hsign.txt", output=["hsign"])
block3 = BLOCK(sname="COMPGRID", fname="tps.txt", output=["tps"])
block4 = BLOCK(sname="COMPGRID", fname="dir.txt", output=["dir"])
blocks = BLOCKS(components=[block1, block2, block3, block4])
print(blocks.render())
BLOCK sname='COMPGRID' fname='depth.txt' DEPTH BLOCK sname='COMPGRID' fname='hsign.txt' HSIGN BLOCK sname='COMPGRID' fname='tps.txt' TPS BLOCK sname='COMPGRID' fname='dir.txt' DIR
In [6]:
Copied!
output = OUTPUT(block=blocks)
print(output.render())
output = OUTPUT(block=blocks)
print(output.render())
BLOCK sname='COMPGRID' fname='depth.txt' DEPTH BLOCK sname='COMPGRID' fname='hsign.txt' HSIGN BLOCK sname='COMPGRID' fname='tps.txt' TPS BLOCK sname='COMPGRID' fname='dir.txt' DIR