0.1.33
Loading...
Searching...
No Matches
pyhelios.EnergyBalance.EnergyBalanceModel Class Reference

High-level interface for energy balance modeling and thermal calculations. More...

Detailed Description

High-level interface for energy balance modeling and thermal calculations.

This class provides a user-friendly wrapper around the native Helios energy balance plugin with automatic plugin availability checking and graceful error handling.

The energy balance model computes surface temperatures based on local energy balance equations, including radiation absorption, convection, and transpiration. It supports both steady-state and dynamic (time-stepping) calculations.

System requirements:

  • NVIDIA GPU with CUDA support
  • CUDA Toolkit installed
  • Energy balance plugin compiled into PyHelios
Example
>>> with Context() as context: ... # Add some geometry ... patch_uuid = context.addPatch(center=[0, 0, 1], size=[1, 1]) ... ... with EnergyBalanceModel(context) as energy_balance: ... # Add radiation band for flux calculations ... energy_balance.addRadiationBand("SW") ... ... # Run steady-state energy balance ... energy_balance.run() ... ... # Or run dynamic simulation with timestep ... energy_balance.run(dt=60.0) # 60 second timestep

Definition at line 60 of file EnergyBalance.py.

Public Member Functions

 __init__ (self, Context context)
 Initialize EnergyBalanceModel with graceful plugin handling.
 
 __enter__ (self)
 Context manager entry.
 
 __exit__ (self, exc_type, exc_value, traceback)
 Context manager exit with proper cleanup.
 
 __del__ (self)
 Destructor to ensure C++ resources freed even without 'with' statement.
 
 getNativePtr (self)
 Get the native pointer for advanced operations.
 
None enableMessages (self)
 Enable console output messages from the energy balance model.
 
None disableMessages (self)
 Disable console output messages from the energy balance model.
 
None run (self, Optional[List[int]] uuids=None, Optional[float] dt=None)
 Run the energy balance model.
 
None addRadiationBand (self, Union[str, List[str]] band)
 Add a radiation band or bands for absorbed flux calculations.
 
None enableAirEnergyBalance (self, Optional[float] canopy_height_m=None, Optional[float] reference_height_m=None)
 Enable air energy balance model for canopy-scale thermal calculations.
 
None enableCanopyAirspaceModel (self, List[int] canopy_UUIDs, float canopy_height_m, float reference_height_m, float leaf_area_index, int num_layers=1, Optional[List[int]] ground_UUIDs=None)
 Enable the canopy airspace model.
 
None disableCanopyAirspaceModel (self)
 Disable the canopy airspace model.
 
None setCanopyAirspaceConvergence (self, float tolerance_K=0.01, int max_iterations=50)
 Set convergence criteria for the canopy airspace iteration.
 
None evaluateAirEnergyBalance (self, float dt_sec, float time_advance_sec, Optional[List[int]] UUIDs=None)
 Advance the air energy balance over time.
 
None optionalOutputPrimitiveData (self, str label)
 Add optional output primitive data to the Context.
 
None printDefaultValueReport (self, Optional[List[int]] UUIDs=None)
 Print a report detailing usage of default input values.
 
bool is_available (self)
 Check if EnergyBalanceModel is available in current build.
 
None enableGPUAcceleration (self)
 Enable GPU acceleration for energy balance calculations.
 
None disableGPUAcceleration (self)
 Disable GPU acceleration and force CPU mode.
 
bool isGPUAccelerationEnabled (self)
 Check if GPU acceleration is currently enabled.
 

Static Public Member Functions

bool isGPUAccelerationAvailable ()
 Check if GPU acceleration functions are available in this build.
 

Public Attributes

 context = context
 
 energy_model = None
 

Protected Member Functions

 _check_context_alive (self)
 Raise if the owning Context has been destroyed (see Context.check_context_alive).
 

Constructor & Destructor Documentation

◆ __init__()

pyhelios.EnergyBalance.EnergyBalanceModel.__init__ ( self,
Context context )

Initialize EnergyBalanceModel with graceful plugin handling.

Parameters
contextHelios Context instance
Exceptions
TypeErrorIf context is not a Context instance
EnergyBalanceModelErrorIf energy balance plugin is not available

Definition at line 72 of file EnergyBalance.py.

◆ __del__()

pyhelios.EnergyBalance.EnergyBalanceModel.__del__ ( self)

Destructor to ensure C++ resources freed even without 'with' statement.

Definition at line 146 of file EnergyBalance.py.

Member Function Documentation

◆ __enter__()

pyhelios.EnergyBalance.EnergyBalanceModel.__enter__ ( self)

Context manager entry.

Definition at line 131 of file EnergyBalance.py.

◆ __exit__()

pyhelios.EnergyBalance.EnergyBalanceModel.__exit__ ( self,
exc_type,
exc_value,
traceback )

Context manager exit with proper cleanup.

Definition at line 135 of file EnergyBalance.py.

◆ _check_context_alive()

pyhelios.EnergyBalance.EnergyBalanceModel._check_context_alive ( self)
protected

Raise if the owning Context has been destroyed (see Context.check_context_alive).

Definition at line 127 of file EnergyBalance.py.

◆ addRadiationBand()

None pyhelios.EnergyBalance.EnergyBalanceModel.addRadiationBand ( self,
Union[str, List[str]] band )

Add a radiation band or bands for absorbed flux calculations.

   The energy balance model uses radiation bands from the RadiationModel
   plugin to calculate absorbed radiation flux for each primitive.
Parameters
bandName of radiation band (e.g., "SW", "PAR", "NIR", "LW") or list of band names
Exceptions
ValueErrorIf band name is invalid
EnergyBalanceModelErrorIf operation fails
Example
>>> energy_balance.addRadiationBand("SW") # Single band >>> energy_balance.addRadiationBand(["SW", "LW", "PAR"]) # Multiple bands

Definition at line 254 of file EnergyBalance.py.

◆ disableCanopyAirspaceModel()

None pyhelios.EnergyBalance.EnergyBalanceModel.disableCanopyAirspaceModel ( self)

Disable the canopy airspace model.

   Subsequent calls to :meth:`run` perform a single surface energy balance pass using
   whatever ``air_temperature`` and ``air_humidity`` primitive data are currently set.
Exceptions
EnergyBalanceModelErrorIf the operation fails.

Definition at line 405 of file EnergyBalance.py.

◆ disableGPUAcceleration()

None pyhelios.EnergyBalance.EnergyBalanceModel.disableGPUAcceleration ( self)

Disable GPU acceleration and force CPU mode.

   Forces the use of OpenMP CPU implementation even if GPU is available.
   Useful for testing, benchmarking, or when CPU performance is preferred.
Exceptions
EnergyBalanceModelErrorIf operation fails
Example
>>> energy_balance.disableGPUAcceleration()
Note
Only available when PyHelios is compiled with CUDA support. Has no effect if GPU support is not compiled in.

Definition at line 599 of file EnergyBalance.py.

◆ disableMessages()

None pyhelios.EnergyBalance.EnergyBalanceModel.disableMessages ( self)

Disable console output messages from the energy balance model.

Exceptions
EnergyBalanceModelErrorIf operation fails

Definition at line 178 of file EnergyBalance.py.

◆ enableAirEnergyBalance()

None pyhelios.EnergyBalance.EnergyBalanceModel.enableAirEnergyBalance ( self,
Optional[float] canopy_height_m = None,
Optional[float] reference_height_m = None )

Enable air energy balance model for canopy-scale thermal calculations.

   The air energy balance computes average air temperature and water vapor
   mole fraction based on the energy balance of the air layer in the canopy.
Parameters
canopy_height_mOptional canopy height in meters. If not provided, computed automatically from primitive bounding box.
reference_height_mOptional reference height in meters where ambient conditions are measured. If not provided, assumes reference height is at canopy top.
Exceptions
ValueErrorIf parameters are invalid
EnergyBalanceModelErrorIf operation fails
Example
>>> # Automatic canopy height detection >>> energy_balance.enable_air_energy_balance()
>>> # Manual canopy and reference heights >>> energy_balance.enable_air_energy_balance(canopy_height_m=5.0, reference_height_m=10.0)

Definition at line 302 of file EnergyBalance.py.

◆ enableCanopyAirspaceModel()

None pyhelios.EnergyBalance.EnergyBalanceModel.enableCanopyAirspaceModel ( self,
List[int] canopy_UUIDs,
float canopy_height_m,
float reference_height_m,
float leaf_area_index,
int num_layers = 1,
Optional[List[int]] ground_UUIDs = None )

Enable the canopy airspace model.

   Resolves the within-canopy air temperature and humidity surrounding leaves from a
   vertically layered resistance network, instead of holding them at a prescribed
   value, so the canopy feeds back on the air driving its own transpiration. The
   airspace is divided into vertical layers of equal leaf area index, each exchanging
   sensible heat and water vapor with its leaves, its neighboring layers and -- for
   the outermost layers -- the soil surface and the above-canopy reference air.

   Unlike :meth:`enableAirEnergyBalance`, which evolves a prognostic boundary layer
   and thereby assumes a horizontally infinite canopy, this model suits canopies of
   limited extent subject to advection, such as an orchard block. The two determine
   the same air state and **may not both be enabled**.

   Because it solves for a steady state, it cannot be combined with the form of
   :meth:`run` that takes a timestep.

   The above-canopy boundary condition is read from global data
   ``air_temperature_reference``, ``air_humidity_reference`` and
   ``wind_speed_reference`` when present, otherwise from this model's defaults. Set
   them with :meth:`Context.setGlobalData` before calling :meth:`run`.

   After :meth:`run`, primitive data ``air_temperature``, ``air_humidity`` and
   ``wind_speed`` are set on the canopy primitives, and global data
   ``canopy_air_temperature``, ``canopy_air_humidity``, their per-layer counterparts,
   ``aerodynamic_resistance`` and ``canopy_airspace_iterations`` are reported.
Parameters
canopy_UUIDsCanopy (leaf) primitives exchanging heat and moisture with the airspace.
canopy_height_mHeight of the canopy in meters.
reference_height_mHeight at which above-canopy conditions are measured, in meters. Must be greater than canopy_height_m.
leaf_area_indexOne-sided leaf area index on a ground-area basis.
num_layersNumber of vertical layers of equal leaf area index. 1 gives a single within-canopy node.
ground_UUIDsGround primitives forming the soil node beneath the canopy. When omitted there is no exchange with the soil surface.
Exceptions
ValueErrorIf parameters are invalid.
EnergyBalanceModelErrorIf the operation fails.
Example
>>> energy_balance.enableCanopyAirspaceModel( ... canopy_UUIDs=leaf_uuids, canopy_height_m=3.0, reference_height_m=5.0, ... leaf_area_index=2.5, num_layers=5, ground_UUIDs=ground_uuids) >>> energy_balance.run()

Definition at line 371 of file EnergyBalance.py.

◆ enableGPUAcceleration()

None pyhelios.EnergyBalance.EnergyBalanceModel.enableGPUAcceleration ( self)

Enable GPU acceleration for energy balance calculations.

   Attempts to enable GPU acceleration using CUDA. If GPU is not available at runtime,
   this will raise an error. The energy balance model will use three-tier execution:
   GPU (CUDA), OpenMP (parallel CPU), or serial CPU fallback.
Exceptions
NotImplementedErrorIf library not compiled with CUDA support
EnergyBalanceModelErrorIf GPU acceleration cannot be enabled
Example
>>> with EnergyBalanceModel(context) as energy_balance: ... try: ... energy_balance.enableGPUAcceleration() ... print("GPU acceleration enabled") ... except NotImplementedError: ... print("GPU not available - using CPU mode")
Note
Only available when PyHelios is compiled with CUDA support. OpenMP CPU mode is recommended for most workloads without GPU.

Definition at line 574 of file EnergyBalance.py.

◆ enableMessages()

None pyhelios.EnergyBalance.EnergyBalanceModel.enableMessages ( self)

Enable console output messages from the energy balance model.

Exceptions
EnergyBalanceModelErrorIf operation fails

Definition at line 165 of file EnergyBalance.py.

◆ evaluateAirEnergyBalance()

None pyhelios.EnergyBalance.EnergyBalanceModel.evaluateAirEnergyBalance ( self,
float dt_sec,
float time_advance_sec,
Optional[List[int]] UUIDs = None )

Advance the air energy balance over time.

   This method advances the air energy balance model by integrating over
   multiple timesteps to reach the target time advancement.
Parameters
dt_secTimestep in seconds for integration
time_advance_secTotal time to advance in seconds (must be >= dt_sec)
UUIDsOptional list of primitive UUIDs. If None, processes all primitives.
Exceptions
ValueErrorIf parameters are invalid
EnergyBalanceModelErrorIf operation fails
Example
>>> # Advance air energy balance by 1 hour using 60-second timesteps >>> energy_balance.evaluate_air_energy_balance(dt_sec=60.0, time_advance_sec=3600.0)
>>> # Advance for specific primitives >>> energy_balance.evaluate_air_energy_balance( ... dt_sec=30.0, time_advance_sec=1800.0, uuids=[patch1_uuid, patch2_uuid])

Definition at line 463 of file EnergyBalance.py.

◆ getNativePtr()

pyhelios.EnergyBalance.EnergyBalanceModel.getNativePtr ( self)

Get the native pointer for advanced operations.

Definition at line 156 of file EnergyBalance.py.

◆ is_available()

bool pyhelios.EnergyBalance.EnergyBalanceModel.is_available ( self)

Check if EnergyBalanceModel is available in current build.

Returns
True if plugin is available, False otherwise

Definition at line 547 of file EnergyBalance.py.

◆ isGPUAccelerationAvailable()

bool pyhelios.EnergyBalance.EnergyBalanceModel.isGPUAccelerationAvailable ( )
static

Check if GPU acceleration functions are available in this build.

Returns
True if GPU acceleration support is compiled in, False otherwise
Example
>>> if EnergyBalanceModel.isGPUAccelerationAvailable(): ... print("GPU acceleration supported") ... else: ... print("GPU acceleration not compiled in - CPU mode only")

Definition at line 642 of file EnergyBalance.py.

◆ isGPUAccelerationEnabled()

bool pyhelios.EnergyBalance.EnergyBalanceModel.isGPUAccelerationEnabled ( self)

Check if GPU acceleration is currently enabled.

Returns
True if GPU acceleration is enabled and available, False otherwise
Example
>>> if energy_balance.isGPUAccelerationEnabled(): ... print("Using GPU acceleration") ... else: ... print("Using CPU mode")
Note
Returns False if library not compiled with CUDA support.

Definition at line 621 of file EnergyBalance.py.

◆ optionalOutputPrimitiveData()

None pyhelios.EnergyBalance.EnergyBalanceModel.optionalOutputPrimitiveData ( self,
str label )

Add optional output primitive data to the Context.

   This method adds additional data fields to primitives that will be
   calculated and stored during energy balance execution.
Parameters
labelName of the data field to add (e.g., "vapor_pressure_deficit", "boundary_layer_conductance", "net_radiation")
Exceptions
ValueErrorIf label is invalid
EnergyBalanceModelErrorIf operation fails
Example
>>> energy_balance.add_optional_output_data("vapor_pressure_deficit") >>> energy_balance.add_optional_output_data("net_radiation")

Definition at line 499 of file EnergyBalance.py.

◆ printDefaultValueReport()

None pyhelios.EnergyBalance.EnergyBalanceModel.printDefaultValueReport ( self,
Optional[List[int]] UUIDs = None )

Print a report detailing usage of default input values.

   This diagnostic method prints information about which primitives are
   using default values for energy balance parameters, helping identify
   where additional parameter specification might be needed.
Parameters
UUIDsOptional list of primitive UUIDs to report on. If None, reports on all primitives.
Exceptions
EnergyBalanceModelErrorIf operation fails
Example
>>> # Report on all primitives >>> energy_balance.print_default_value_report()
>>> # Report on specific primitives >>> energy_balance.print_default_value_report(uuids=[patch1_uuid, patch2_uuid])

Definition at line 531 of file EnergyBalance.py.

◆ run()

None pyhelios.EnergyBalance.EnergyBalanceModel.run ( self,
Optional[List[int]] uuids = None,
Optional[float] dt = None )

Run the energy balance model.

   This method supports multiple execution modes:
   - Steady state for all primitives: run()
   - Dynamic with timestep for all primitives: run(dt=60.0)
   - Steady state for specific primitives: run(uuids=[1, 2, 3])
   - Dynamic with timestep for specific primitives: run(uuids=[1, 2, 3], dt=60.0)
Parameters
uuidsOptional list of primitive UUIDs to process. If None, processes all primitives.
dtOptional timestep in seconds for dynamic simulation. If None, runs steady-state.
Exceptions
ValueErrorIf parameters are invalid
EnergyBalanceModelErrorIf energy balance calculation fails
Example
>>> # Steady state for all primitives >>> energy_balance.run()
>>> # Dynamic simulation with 60-second timestep >>> energy_balance.run(dt=60.0)
>>> # Steady state for specific patches >>> energy_balance.run(uuids=[patch1_uuid, patch2_uuid])
>>> # Dynamic simulation for specific patches >>> energy_balance.run(uuids=[patch1_uuid, patch2_uuid], dt=30.0)

Definition at line 216 of file EnergyBalance.py.

◆ setCanopyAirspaceConvergence()

None pyhelios.EnergyBalance.EnergyBalanceModel.setCanopyAirspaceConvergence ( self,
float tolerance_K = 0.01,
int max_iterations = 50 )

Set convergence criteria for the canopy airspace iteration.

Parameters
tolerance_KTemperature convergence tolerance in Kelvin. Iteration stops when the maximum change in any layer's air temperature falls below this value.
max_iterationsMaximum number of coupled surface-energy-balance and airspace
iterations.
Exceptions
ValueErrorIf parameters are invalid.
EnergyBalanceModelErrorIf the operation fails.

Definition at line 425 of file EnergyBalance.py.

Member Data Documentation

◆ context

pyhelios.EnergyBalance.EnergyBalanceModel.context = context

Definition at line 77 of file EnergyBalance.py.

◆ energy_model

pyhelios.EnergyBalance.EnergyBalanceModel.energy_model = None

Definition at line 78 of file EnergyBalance.py.


The documentation for this class was generated from the following file: