finam_regrid.Regrid#
- class finam_regrid.Regrid(in_grid=None, out_grid=None, **regrid_args)[source]#
Bases:
ARegridding
FINAM adapter for regridding using ESMPy.
Supports all of ESMPy’s
regridding methods
. For parameters passed as**regrid_args
, see the ESMPy class RegridWarning
Does currently not support masked input data. Raises a
NotImplementedError
in that case.Examples
Simple usage with defaults and grid specifications from connected components:
import finam_regrid as fmr adapter = fmr.Regrid()
Using a specific regridding method:
adapter = fmr.Regrid( regrid_method=fmr.RegridMethod.CONSERVE_2ND, )
Using a specific regridding method and extrapolation:
adapter = fmr.Regrid( regrid_method=fmr.RegridMethod.CONSERVE_2ND, extrap_method=fmr.ExtrapMethod.NEAREST_IDAVG, )
- Parameters:
in_grid (finam.Grid, optional) – Input grid specification. Will be retrieved from upstream component if not specified.
out_grid (finam.Grid, optional) – Output grid specification. Will be retrieved from downstream component if not specified.
**regrid_args (Any) – Keyword argument passed to the ESMPy class Regrid.
Important keyword arguments are:
regrid_method (RegridMethod) – Regridding method. See
RegridMethod
. Defaults toRegridMethod.BILINEAR
.extrap_method (ExtrapMethod) – Extrapolation method. See
ExtrapMethod
. Defaults toNone
.unmapped_action (UnmappedAction) – Action on unmapped cells. See
UnmappedAction
. Defaults toUnmappedAction.IGNORE
.
- Attributes:
has_source
Flag if this input instance has a source.
has_targets
Flag if this output instance has any targets.
info
Info: The input’s data info.
is_static
Whether the input is static
logger
Logger for this component.
logger_name
Logger name derived from source logger name and class name.
memory_limit
The memory limit for this slot
memory_location
The memory-mapping location for this slot
metadata
The adapter’s meta data.
name
Input name.
needs_pull
bool: if the adapter needs pull.
needs_push
bool: if the adapter needs push.
time
The output’s time of the latest available data
uses_base_logger_name
Whether this class has a
base_logger_name
attribute.
Methods
add_target
(target)Add a target input or adapter for this output.
chain
(other)Chain outputs and adapters.
exchange_info
([info])Exchange the data info with the input's source.
finalize
()Called at the end of each run.
get_data
(time, target)Get the transformed data of this adapter.
get_info
(info)Exchange and get the output's data info.
Get the input's source output or adapter
Get target inputs and adapters for this output.
has_info
()Returns if the output has a data info.
notify_targets
(time)Notify all targets by calling their
source_updated(time)
method.ping
()Pings upstream to inform outputs about the number of connected inputs.
pinged
(source)Called when receiving a ping from a downstream input.
pull_data
(time[, target])Retrieve the data from the input's source.
push_data
(data, time)Push data into the output.
push_info
(info)Push data info into the output.
set_source
(source)Set the adapter input's source output or adapter
source_updated
(time)Informs the input that a new output is available.
with_name
(name)Renames the adapter and returns self.
- add_target(target)#
Add a target input or adapter for this output.
- Parameters:
target (
IInput
) – The target to add.
- chain(other)#
Chain outputs and adapters.
- Parameters:
other (
IInput
orIAdapter
) – The adapter or input to add as target to this output.- Returns:
The last element of the chain.
- Return type:
IOutput
- exchange_info(info=None)#
Exchange the data info with the input’s source.
- Parameters:
info (
Info
) – request parameters- Returns:
delivered parameters
- Return type:
Info
- finalize()#
Called at the end of each run. Calls
_finalize()
.
- get_data(time, target)#
Get the transformed data of this adapter.
Internally calls
_get_data()
.- Parameters:
time (
datetime
) – Simulation time to get the data for.target (
IInput
) – Requesting end point of this pull.
- Returns:
Transformed data-set for the requested time.
- Return type:
pint.Quantity
- get_info(info)#
Exchange and get the output’s data info.
- Parameters:
info (
Info
) – Requested data info- Returns:
Delivered data info
- Return type:
Info
- Raises:
FinamNoDataError – Raises the error if no info is available
- get_source()#
Get the input’s source output or adapter
- Returns:
The input’s source.
- Return type:
IOutput
- get_targets()#
Get target inputs and adapters for this output.
- Returns:
List of targets.
- Return type:
- has_info()#
Returns if the output has a data info.
The info is not required to be validly exchanged.
- notify_targets(time)#
Notify all targets by calling their
source_updated(time)
method.- Parameters:
time (
datetime
) – Simulation time of the simulation.
- ping()#
Pings upstream to inform outputs about the number of connected inputs.
Must be called after linking and before the connect phase.
- pinged(source)#
Called when receiving a ping from a downstream input.
- pull_data(time, target=None)#
Retrieve the data from the input’s source.
- Parameters:
time (
datetime
) – Simulation time to get the data for.target (
IInput
or None) – Requesting end point of this pull. Should beNone
for normal input pulls in components. Simple adapters should forward the source inAdapter._get_data()
. Push-based adapters should useself
inAdapter._source_updated()
.
- Returns:
Data set for the given simulation time.
- Return type:
pint.Quantity
- push_data(data, time)#
Push data into the output.
Should notify targets, and can handle the provided date.
- Parameters:
data (array_like) – Data set to push.
time (
datetime
) – Simulation time of the data set.
- push_info(info)#
Push data info into the output.
- Parameters:
info (
Info
) – Delivered data info
- set_source(source)#
Set the adapter input’s source output or adapter
- Parameters:
source – source output or adapter
- source_updated(time)#
Informs the input that a new output is available.
- Parameters:
time (
datetime
) – Simulation time of the notification.
- with_name(name)#
Renames the adapter and returns self.
- property has_source#
Flag if this input instance has a source.
- property has_targets#
Flag if this output instance has any targets.
- property info#
The input’s data info.
- Type:
Info
- property is_static#
Whether the input is static
- property logger#
Logger for this component.
- property logger_name#
Logger name derived from source logger name and class name.
- property memory_limit#
The memory limit for this slot
- property memory_location#
The memory-mapping location for this slot
- property metadata#
The adapter’s meta data. Will only be called after the connect phase of the composition.
Returns an empty
dict
unless overwritten in adapter implementation.
- property name#
Input name.
- property time#
The output’s time of the latest available data
- property uses_base_logger_name#
Whether this class has a
base_logger_name
attribute. True.