Skip to content

Commit

Permalink
pyfabm: fix require_data, annotation tweaks (#96)
Browse files Browse the repository at this point in the history
  • Loading branch information
jornbr authored Oct 26, 2024
1 parent effe676 commit eee3520
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/pyfabm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,9 @@ def output_name(self) -> str:

@property
def options(self) -> Optional[Sequence]:
pass
"""Collection of values that this variable can take.
`None` if the variable is not limited to any particular value."""
return None

def __repr__(self) -> str:
postfix = f"={self.value}" if hasattr(self, "value") else ""
Expand All @@ -645,16 +647,16 @@ def __init__(self, model: "Model", variable_pointer: ctypes.c_void_p):

@property
def long_path(self) -> str:
"""Long model instance name, followed by a slash, followed by long variable name."""
strlong_name = ctypes.create_string_buffer(ATTRIBUTE_LENGTH)
self.model.fabm.variable_get_long_path(
self._pvariable, ATTRIBUTE_LENGTH, strlong_name
)
return strlong_name.value.decode("ascii")

@property
def missing_value(self) -> Optional[float]:
"""Value that indicates missing data, for instance, on land.
`None` if not set."""
def missing_value(self) -> float:
"""Value that indicates missing data, for instance, on land."""
return self.model.fabm.variable_get_missing_value(self._pvariable)

def getRealProperty(self, name, default=-1.0) -> float:
Expand Down Expand Up @@ -1570,7 +1572,7 @@ def find_standard_variable(self, name: str) -> Optional[StandardVariable]:
return StandardVariable(self, pointer)

def require_data(self, standard_variable: StandardVariable):
return self.fabm.require_data(self.pmodel, standard_variable.pointer)
return self.fabm.require_data(self.pmodel, standard_variable._pvariable)

def _get_parameter_tree(self) -> Mapping:
root = {}
Expand All @@ -1582,7 +1584,7 @@ def _get_parameter_tree(self) -> Mapping:
parent[pathcomps[-1]] = parameter
return root

def start(self, verbose: bool = True, stop: bool = False):
def start(self, verbose: bool = True, stop: bool = False) -> bool:
ready = True
if self.fabm.mask_type and self._mask is None:
log("Mask not yet assigned")
Expand Down Expand Up @@ -1631,13 +1633,16 @@ def updateTime(self, nsec: float):
def printInformation(self):
"""Show information about the model."""

def printArray(classname: str, array: Iterable[Variable]):
def printArray(classname: str, array: Sequence[Variable]):
if not array:
return
log(f" {len(array)} {classname}:")
for variable in array:
log(f" {variable.name} = {variable.value} {variable.units}")

def parameter2str(p: Parameter) -> str:
return f"{p.value} {p.units}"

log("FABM model contains the following:")
printArray("interior state variables", self.interior_state_variables)
printArray("bottom state variables", self.bottom_state_variables)
Expand All @@ -1648,7 +1653,7 @@ def printArray(classname: str, array: Iterable[Variable]):
)
printArray("external variables", self.dependencies)
log(f" {len(self.parameters)} parameters:")
printTree(self._get_parameter_tree(), lambda x: f"{x.value} {x.units}", " ")
printTree(self._get_parameter_tree(), parameter2str, " ")


class Simulator(object):
Expand Down

0 comments on commit eee3520

Please sign in to comment.