Bases: BaseSubComponent
Points in grid indices coordinates.
.. code-block:: text
Grid indices are 0-based and must be in the range 0 ≤ i ≤ mx and
0 ≤ j ≤ my where mx and my are the number of cells in each
direction as defined by the CGRID command.
Note
A value of -1 may be used as a sentinel for the last grid index: -1
in the i list is replaced by mx, and -1 in the j list is
replaced by my. The substitution is performed automatically by
:meth:SwanConfig.resolve_segment_ij_sentinels when the IJ object is used
as the points of a BOUNDSPEC SEGMENT location.
Warning
SWAN terminates its SEGMENT IJ reading loop when it encounters a negative
i value, so -1 cannot be passed literally to SWAN — it must be
resolved to the actual grid index before the INPUT file is written.
Examples
.. ipython:: python
:okwarning:
from rompy_swan.subcomponents.base import IJ
points = IJ(i=[0, 0, 5], j=[0, 19, 19])
print(points.render())
Source code in src/rompy_swan/subcomponents/base.py
| class IJ(BaseSubComponent):
"""Points in grid indices coordinates.
.. code-block:: text
< [i] [j] >
Grid indices are 0-based and must be in the range ``0 ≤ i ≤ mx`` and
``0 ≤ j ≤ my`` where ``mx`` and ``my`` are the number of cells in each
direction as defined by the CGRID command.
Note
----
A value of ``-1`` may be used as a sentinel for the last grid index: ``-1``
in the ``i`` list is replaced by ``mx``, and ``-1`` in the ``j`` list is
replaced by ``my``. The substitution is performed automatically by
:meth:`SwanConfig.resolve_segment_ij_sentinels` when the IJ object is used
as the points of a BOUNDSPEC SEGMENT location.
Warning
-------
SWAN terminates its SEGMENT IJ reading loop when it encounters a negative
``i`` value, so ``-1`` **cannot** be passed literally to SWAN — it must be
resolved to the actual grid index before the INPUT file is written.
Examples
--------
.. ipython:: python
:okwarning:
from rompy_swan.subcomponents.base import IJ
points = IJ(i=[0, 0, 5], j=[0, 19, 19])
print(points.render())
"""
model_type: Literal["ij", "IJ"] = Field(
default="ij",
description="Model type discriminator",
)
i: list[int] = Field(description="i-index values")
j: list[int] = Field(description="j-index values")
@model_validator(mode="after")
def validate_size(self) -> "IJ":
if len(self.i) != len(self.j):
raise ValueError("i and j must be the same size")
return self
@property
def size(self):
return len(self.i)
def cmd(self) -> str:
repr = ""
for i, j in zip(self.i, self.j):
repr += f"\ni={i} j={j}"
return repr + "\n"
|
Attributes
model_type
class-attribute
instance-attribute
model_type: Literal['ij', 'IJ'] = Field(default='ij', description='Model type discriminator')
i
class-attribute
instance-attribute
i: list[int] = Field(description='i-index values')
j
class-attribute
instance-attribute
j: list[int] = Field(description='j-index values')
Methods:
validate_size
Source code in src/rompy_swan/subcomponents/base.py
| @model_validator(mode="after")
def validate_size(self) -> "IJ":
if len(self.i) != len(self.j):
raise ValueError("i and j must be the same size")
return self
|
cmd
Source code in src/rompy_swan/subcomponents/base.py
| def cmd(self) -> str:
repr = ""
for i, j in zip(self.i, self.j):
repr += f"\ni={i} j={j}"
return repr + "\n"
|