credit.physics_core

Contents

credit.physics_core#

Content:
  • physics_pressure_level

  • physics_hybrid_sigma_level

Reference:

Classes#

ModelLevelPressures

compute pressure levels given SP with (only compatible with torch)

physics_pressure_level

Pressure level physics

physics_hybrid_sigma_level

Hybrid sigma-pressure level physics

Functions#

compute_density(pressure, temperature, specific_humidity)

compute density given pressure (Pa), temperature (K), and specific humidity (kg/kg)

compute_virtual_temperature(temperature, specific_humidity)

ref: metpy

Module Contents#

credit.physics_core.compute_density(pressure, temperature, specific_humidity)#

compute density given pressure (Pa), temperature (K), and specific humidity (kg/kg)

credit.physics_core.compute_virtual_temperature(temperature, specific_humidity)#

ref: metpy

class credit.physics_core.ModelLevelPressures(a_vals, b_vals, plev_dim=1)#

Bases: torch.nn.Module

compute pressure levels given SP with (only compatible with torch) SP, a_vals with same units. a_vals, b_vals, with size levels at dimension plev_dim and all other dims with size 1, e.g. plev_dim = 1; a_vals.shape = (1, levels, 1, 1, 1) matching sp with size 1 at dimension plev_dim e.g. (b, 1, t, lat, lon)

plev_dim = 1#
is_fully_initialized = False#
compute_p(sp)#
compute_hlevs(plevs)#
compute_mlev_thickness(sp)#
class credit.physics_core.physics_pressure_level(lon: torch.Tensor, lat: torch.Tensor, upper_air_pressure: torch.Tensor, midpoint: bool = False)#

Pressure level physics

All inputs must be in the same torch device.

Full order of dimensions: (batch, time, level, latitude, longitude)

lon#
lat#
upper_air_pressure#
pressure_thickness#
area#
pressure_integral_midpoint(q_mid: torch.Tensor) torch.Tensor#

Compute the pressure level integral of a given quantity; assuming its mid point values are pre-computed

Parameters:

q_mid – the quantity with dims of (batch_size, time, level-1, latitude, longitude)

Returns:

Pressure level integrals of q

pressure_integral_midpoint_sliced(q_mid: torch.Tensor, ind_start: int, ind_end: int) torch.Tensor#

As in pressure_integral_midpoint, but supports pressure level indexing, so it can calculate integrals of a subset of levels

pressure_integral_trapz(q: torch.Tensor) torch.Tensor#

Compute the pressure level integral of a given quantity using the trapezoidal rule.

Parameters:

q – the quantity with dims of (batch_size, time, level, latitude, longitude)

Returns:

Pressure level integrals of q

pressure_integral_trapz_sliced(q: torch.Tensor, ind_start: int, ind_end: int) torch.Tensor#

As in pressure_integral_trapz, but supports pressure level indexing, so it can calculate integrals of a subset of levels

weighted_sum(q: torch.Tensor, axis: Dict[tuple, None] = None, keepdims: bool = False) torch.Tensor#

Compute the weighted sum of a given quantity for PyTorch tensors.

Parameters:
  • q – the quantity to be summed (PyTorch tensor)

  • axis – dims to compute the sum (can be int or tuple of ints)

  • keepdims – whether to keep the reduced dimensions or not

Returns:

Weighted sum (PyTorch tensor)

total_dry_air_mass(q: torch.Tensor) torch.Tensor#

Compute the total mass of dry air over the entire globe [kg]

total_column_water(q: torch.Tensor) torch.Tensor#

Compute total column water (TCW) per air column [kg/m2]

class credit.physics_core.physics_hybrid_sigma_level(lon: torch.Tensor, lat: torch.Tensor, coef_a: torch.Tensor, coef_b: torch.Tensor, midpoint: bool = False)#

Hybrid sigma-pressure level physics

lon#

Longitude in degrees.

Type:

torch.Tensor

lat#

Latitude in degrees.

Type:

torch.Tensor

surface_pressure#

Surface pressure in Pa.

Type:

torch.Tensor

coef_a#

Hybrid sigma-pressure coefficient ‘a’ [Pa].

Type:

torch.Tensor

coef_b#

Hybrid sigma-pressure coefficient ‘b’ [unitless].

Type:

torch.Tensor

area#

Area of grid cells [m^2].

Type:

torch.Tensor

integral#

Vertical integration method (midpoint or trapezoidal).

Type:

function

lon#
lat#
coef_a#
coef_b#
area#
pressure_integral_midpoint(q_mid: torch.Tensor, surface_pressure: torch.Tensor) torch.Tensor#

Compute the pressure level integral of a given quantity; assuming its mid-point values are pre-computed.

Parameters:
  • q_mid – The quantity with dims of (batch, level-1, time, latitude, longitude)

  • surface_pressure – Surface pressure in Pa (batch, time, latitude, longitude).

Returns:

Pressure level integrals of q

pressure_integral_midpoint_sliced(q_mid: torch.Tensor, surface_pressure: torch.Tensor, ind_start: int, ind_end: int) torch.Tensor#

As in pressure_integral_midpoint, but supports pressure level indexing, so it can calculate integrals of a subset of levels.

pressure_integral_trapz(q: torch.Tensor, surface_pressure: torch.Tensor) torch.Tensor#

Compute the pressure level integral of a given quantity using the trapezoidal rule.

Parameters:

q – The quantity with dims of (batch, level, time, latitude, longitude)

Returns:

Pressure level integrals of q

pressure_integral_trapz_sliced(q: torch.Tensor, surface_pressure: torch.Tensor, ind_start: int, ind_end: int) torch.Tensor#

As in pressure_integral_trapz, but supports pressure level indexing, so it can calculate integrals of a subset of levels.

weighted_sum(q: torch.Tensor, axis: Dict[tuple, None] = None, keepdims: bool = False) torch.Tensor#

Compute the weighted sum of a given quantity for PyTorch tensors.

Parameters:
  • data – the quantity to be summed (PyTorch tensor)

  • axis – dims to compute the sum (can be int or tuple of ints)

  • keepdims – whether to keep the reduced dimensions or not

Returns:

Weighted sum (PyTorch tensor)

total_dry_air_mass(q: torch.Tensor, surface_pressure: torch.Tensor) torch.Tensor#

Compute the total mass of dry air over the entire globe [kg]

total_column_water(q: torch.Tensor, surface_pressure: torch.Tensor) torch.Tensor#

Compute total column water (TCW) per air column [kg/m2]