finam_vtk.PVDReader#
- class finam_vtk.PVDReader(path, reference_date, time_unit, calendar='standard', outputs=None, grid_arguments=None)[source]#
Bases:
TimeComponent
VTK reader component that steps along a date/time coordinate dimension of a dataset.
- Parameters:
path (str) – Path to the PVD file to read.
reference_date (datetime.datetime) – Reference datetime to determine times.
time_unit (string) – Unit of the timesteps (e.g. “seconds”, “hours”, “days”, …)
calendar (str, optional) – Describes the calendar used in the time calculations. All the values currently defined in the CF metadata convention are supported. Valid calendars ‘standard’, ‘gregorian’, ‘proleptic_gregorian’ ‘noleap’, ‘365_day’, ‘360_day’, ‘julian’, ‘all_leap’, ‘366_day’ by default “standard”
outputs (list of str or DataArray, optional) – Output arrays to provide. By default all arrays found in the vtk file(s).
grid_arguments (dict, optional) – Arguments forwarded to
grid_from_pyvista()
, by default None
- Attributes:
connector
The component’s
tools.ConnectHelper
.inputs
dict: The component’s inputs.
logger
Logger for this component.
logger_name
Logger name derived from base logger name and class name.
metadata
The component’s metadata.
name
Component name.
next_time
The component’s predicted simulation time of the next pulls.
outputs
dict: The component’s outputs.
status
The component’s current status.
time
The component’s current simulation time.
uses_base_logger_name
Whether this class has a
base_logger_name
attribute.
Methods
connect
(start_time)Connect exchange data and metadata with linked components.
create_connector
([pull_data, in_info_rules, ...])Initialize the component's
tools.ConnectHelper
.finalize
()Finalize and clean up the component.
Initialize the component.
try_connect
(start_time[, exchange_infos, ...])Exchange the info and data with linked components.
update
()Update the component by one time step.
validate
()Validate the correctness of the component's settings and coupling.
with_name
(name)Renames the component and returns self.
- connect(start_time)#
Connect exchange data and metadata with linked components.
The method can be called multiple times if there are failed pull attempts.
After each method call, the component should have
status
ComponentStatus.CONNECTED
if connecting was completed,ComponentStatus.CONNECTING
if some but not all required initial input(s) could be pulled, andComponentStatus.CONNECTING_IDLE
if nothing could be pulled.- Parameters:
start_time (
datetime
) – The composition’s starting time. Can be before the component’s actual time.
- create_connector(pull_data=None, in_info_rules=None, out_info_rules=None, cache=True)#
Initialize the component’s
tools.ConnectHelper
.See also
try_connect()
,connector
andConnectHelper
for details.- Parameters:
pull_data (arraylike) – Names of the inputs that are to be pulled.
in_info_rules (dict) – Info transfer rules for inputs. See the examples for details.
See also
tools.FromInput
,tools.FromOutput
andtools.FromValue
.out_info_rules (dict) – Info transfer rules for outputs. See the examples for details.
See also
tools.FromInput
,tools.FromOutput
andtools.FromValue
.cache (bool) – Whether data and
Info
objects passed viatry_connect()
are cached for later calls. DefaultTrue
.
Examples
The following examples show the usage of this method in
_initialize()
.Simple usage if no input data or any metadata from connected components is required:
self.inputs.add(name="In", time=self.time, grid=fm.NoGrid()) self.outputs.add(name="Out", time=self.time, grid=fm.NoGrid()) self.create_connector()
To pull specific inputs, use
pull_data
like this:self.inputs.add(name="In1", time=self.time, grid=fm.NoGrid()) self.inputs.add(name="In2", time=self.time, grid=fm.NoGrid()) self.create_connector(pull_data=["In1", "In2"])
With the
in_info_rules
andout_info_rules
, metadata can be transferred between coupling slots.Here, the metadata for an output is taken from an input:
self.inputs.add(name="In", time=self.time, grid=None, units=None) self.outputs.add(name="Out") self.create_connector( out_info_rules={ "Out": [ fm.tools.FromInput("In") ] } )
The
Info
object for outputOut
will be created and pushed automatically intry_connect()
as soon as the metadata forIn
becomes available.Here, the metadata of an output is composed from the metadata of two inputs and a user-defined value:
self.inputs.add(name="In1", time=self.time, grid=None, units=None) self.inputs.add(name="In2", time=self.time, grid=None, units=None) self.outputs.add(name="Out") self.create_connector( out_info_rules={ "Out": [ fm.tools.FromInput("In1", ["time", "grid"]), fm.tools.FromInput("In2", ["units"]), fm.tools.FromValue("source", "FINAM"), ] } )
The
Info
object for outputOut
would be automatically composed intry_connect()
as soon as the infos of both inputs become available.time
andgrid
would be taken fromIn1
,units
fromIn2
, andsource
would be set to"finam"
.Rules are evaluated in the given order. Later rules can overwrite attributes set by earlier rules.
- finalize()#
Finalize and clean up the component.
After the method call, the component should have
status
ComponentStatus.FINALIZED
.
- initialize()#
Initialize the component.
After the method call, the component’s inputs and outputs must be available, and the component should have
status
ComponentStatus.INITIALIZED
.
- try_connect(start_time, exchange_infos=None, push_infos=None, push_data=None)#
Exchange the info and data with linked components.
Values passed by the arguments are cached internally for later calls to the method if the connector was created with
cache=True
(the default). Thus, it is sufficient to provide only data and infos that became newly available. Giving the same data or infos repeatedly overwrites the cache.Sets the component’s
status
according to success of exchange.See also
create_connector()
,connector
andConnectHelper
for details.- Parameters:
start_time (
datetime
) – the composition’s starting time as passed toComponent.try_connect()
exchange_infos (dict of [str, Info]) – currently or newly available input data infos by input name
push_infos (dict of [str, Info]) – currently or newly available output data infos by output name
push_data (dict of [str, array-like]) – currently or newly available output data by output name
- update()#
Update the component by one time step. Push new values to outputs.
After the method call, the component should have
status
ComponentStatus.UPDATED
orComponentStatus.FINISHED
.
- validate()#
Validate the correctness of the component’s settings and coupling.
After the method call, the component should have
status
ComponentStatus.VALIDATED
.
- with_name(name)#
Renames the component and returns self.
- property connector#
The component’s
tools.ConnectHelper
.See also
create_connector()
andtry_connect()
.
- property logger#
Logger for this component.
- property logger_name#
Logger name derived from base logger name and class name.
- property metadata#
The component’s metadata. Will only be called after the connect phase from
Composition.metadata
.Components can overwrite this property to add their own specific metadata:
import finam as fm class MyComponent(fm.Component): @property def metadata(self): # Get the default metadata md = super().metadata # Add your own metadata md["my_field"] = "some value" # Return the dictionary return md
- Returns:
- A
dict
with the following default metadata: name
- the component’s nameclass
- the component’s classinputs
-dict
of metadata for all inputsoutputs
-dict
of metadata for all outputs
- A
- Return type:
- property name#
Component name.
- property next_time#
The component’s predicted simulation time of the next pulls.
Can be
None
if the component has no inputs.
- property status#
The component’s current status.
- property time#
The component’s current simulation time.
- property uses_base_logger_name#
Whether this class has a
base_logger_name
attribute. True.