eradiate.grid#

class eradiate.grid.SpatialGrid#

Abstract base class for regular 3D grids on which atmospheric radiative properties are evaluated.

A grid is defined by its cell edges along three axes X, Y and Z. All grids store the same data and expose it through axis-generic accessors (x_edges, x_centers, x_cell_size, x_extent, n_x_cells, etc.). Subclasses set the meaning and units of each axis and add aliases named after it:

  • CartesianGrid (plane-parallel geometry): local Cartesian frame (X: position [length], Y: position [length], Z: altitude [length]).

  • SphericalGrid (spherical-shell geometry): geocentric spherical frame (X: azimuth [angle], Y: colatitude [angle], Z: altitude [length]).

The Z axis is altitude for all grids, with aliases levels (edges), layers (centres), layer_height (cell size) and total_height (extent).

These frames locate objects in the scene; they are not geodetic coordinate systems or map projections.

Edges are regularly spaced along each axis, with independent spacing per axis.

Parameters:
  • x_edges (quantity or array-like) – Cell edges along the X axis, regularly spaced. Unitless values are interpreted in the axis’s default units (see the class description).

  • y_edges (quantity or array-like) – Cell edges along the Y axis, regularly spaced. Unitless values are interpreted in the axis’s default units (see the class description).

  • z_edges (quantity or array-like) – Cell edges along the Z axis, regularly spaced. Unitless values are interpreted in the axis’s default units (see the class description).

Fields:
  • x_edges (pint.Quantity) – Cell edges along the X axis, regularly spaced.

  • y_edges (pint.Quantity) – Cell edges along the Y axis, regularly spaced.

  • z_edges (pint.Quantity) – Cell edges along the Z axis, regularly spaced.

Notes

  • Instances are immutable.

  • Instances are hashed by ID, so they can be passed to LRU-cached functions.

  • Instances are passed to the eval() family of methods of atmosphere components.

classmethod convert(value)#

Convert a value to a SpatialGrid, if possible.

Parameters:

value – Value to convert. Conversion rules:

  • "cartesian": return CartesianGrid.default().

  • 1D quantity, array or list of numbers: interpret as altitude levels and return from_levels(value).

  • Sequence of three 1D quantities or arrays (or 2D array with three rows): interpret as (x_edges, y_edges, z_edges) and pass them to the constructor.

  • Dictionary: its "type" entry ("cartesian" or "spherical") selects the grid class; other entries are passed to its constructor.

  • Anything else is returned unchanged.

Array rules build an instance of the class this method is called on, or a CartesianGrid if it is called on SpatialGrid. Unitless arrays are interpreted in the default units of each axis.

Returns:

SpatialGrid or object – Converted grid, or value if no rule applies.

Raises:

ValueError – If value is a string other than "cartesian" or a dictionary with an unknown "type".

property x_centers#

Cell centres along the X axis.

property y_centers#

Cell centres along the Y axis.

property z_centers#

Cell centres along the Z axis.

property x_cell_size#

Uniform cell size along the X axis.

property y_cell_size#

Uniform cell size along the Y axis.

property z_cell_size#

Uniform cell size along the Z axis.

property x_extent#

Grid extent along the X axis.

property y_extent#

Grid extent along the Y axis.

property z_extent#

Grid extent along the Z axis.

property n_x_cells#

Number of cells along the X axis.

property n_y_cells#

Number of cells along the Y axis.

property n_z_cells#

Number of cells along the Z axis.

property n_x_edges#

Number of edges along the X axis.

property n_y_edges#

Number of edges along the Y axis.

property n_z_edges#

Number of edges along the Z axis.

property shape#

Number of cells along each axis, in (X, Y, Z) order.

property is_1d#

True if the grid has a single cell in X and Y.

property levels#

Altitude levels (alias of z_edges).

property layers#

Altitudes of layer centres (alias of z_centers).

property layer_height#

Uniform layer height (alias of z_cell_size).

property total_height#

Distance between the lowest and highest levels (alias of z_extent).

property n_levels#

Number of levels (alias of n_z_edges).

property n_layers#

Number of layers (alias of n_z_cells).

with_cell_counts(n_x_cells=None, n_y_cells=None, n_z_cells=None)#

Return a copy with the same bounds and new cell counts.

Parameters:

n_x_cells, n_y_cells, n_z_cells – Number of cells along each axis. If None, the axis is left unchanged.

Returns:

SpatialGrid – Grid of the same type as this one.

with_cell_sizes(x_cell_size=None, y_cell_size=None, z_cell_size=None, x_atol=None, y_atol=None, z_atol=None)#

Return a copy with the same bounds and new cell sizes.

The cell count along each axis is the number of whole cells of the requested size fitting in the extent; the cell size is then adjusted so that the cells fill the extent exactly.

Parameters:
  • x_cell_size, y_cell_size, z_cell_size – Target cell size along each axis. If None, the axis is left unchanged. Unitless values are interpreted in the axis’s default units.

  • x_atol, y_atol, z_atol – Absolute tolerance on the remainder left when dividing the extent by the cell size along each axis. If None, the remainder is ignored. Unitless values are interpreted in the axis’s default units.

Returns:

SpatialGrid – Grid of the same type as this one.

Raises:

ValueError – If a tolerance is set and the remainder along that axis exceeds it.

abstract property to_world#

Transform from the unit cube to the grid’s volume, in kernel units, used as the to_world parameter of the kernel volume plugin.

class eradiate.grid.CartesianGrid(x_edges=None, y_edges=None, z_edges=None, *, levels=None)#

Cartesian grid [cartesian].

Grid for plane-parallel geometries, in a local Cartesian frame (X: position [length], Y: position [length], Z: altitude [length]). Unitless edges are interpreted in ucc['length'] on all axes.

The constructor takes cell edges along each axis; Z edges can alternatively be passed as levels (exclusive with z_edges). The from_* class methods build grids centred horizontally at the origin from extents, cell sizes and cell counts; the with_* and *ed methods return modified copies.

Parameters:
  • x_edges (quantity or array-like) – Cell edges along the X axis, regularly spaced. Unitless values are interpreted in the axis’s default units (see the class description).

  • y_edges (quantity or array-like) – Cell edges along the Y axis, regularly spaced. Unitless values are interpreted in the axis’s default units (see the class description).

  • z_edges (quantity or array-like) – Cell edges along the Z axis, regularly spaced. Unitless values are interpreted in the axis’s default units (see the class description).

Fields:
  • x_edges (pint.Quantity) – Cell edges along the X axis, regularly spaced.

  • y_edges (pint.Quantity) – Cell edges along the Y axis, regularly spaced.

  • z_edges (pint.Quantity) – Cell edges along the Z axis, regularly spaced.

property to_world#

Transform from the unit cube to the grid’s volume, in kernel units, used as the to_world parameter of the kernel volume plugin.

classmethod default()#

Build the default grid for Eradiate atmospheres.

Levels span 0 to 120 km with 100 m layers; the grid has a single horizontal cell spanning 10⁶ km in X and Y.

Returns:

CartesianGrid

classmethod from_levels(levels)#

Build a single-column grid from altitude levels.

The single horizontal cell spans 10⁶ km in X and Y, centred at the origin.

Parameters:

levels – Altitude levels (Z edges). Unitless values are interpreted in ucc['length'].

Returns:

CartesianGrid

classmethod from_extent_and_resolution(x_extent, y_extent, n_x_cells, n_y_cells, z_edges=None, *, levels=None)#

Build a grid centred horizontally at the origin from extents and cell counts.

Parameters:
  • x_extent, y_extent – Grid extent along the X and Y axes. Unitless values are interpreted in ucc['length'].

  • n_x_cells, n_y_cells – Number of cells along the X and Y axes.

  • z_edges – Cell edges along the Z axis. Unitless values are interpreted in ucc['length'].

  • levels – Alias of z_edges (exclusive).

Returns:

CartesianGrid

classmethod from_extent_and_cell_size(x_extent, y_extent, x_cell_size, y_cell_size, z_edges=None, *, levels=None, x_atol=None, y_atol=None)#

Build a grid centred horizontally at the origin from extents and cell sizes.

The cell count along each axis is the number of whole cells of the requested size fitting in the extent; the cell size is then adjusted so that the cells fill the extent exactly.

Parameters:
  • x_extent, y_extent – Grid extent along the X and Y axes. Unitless values are interpreted in ucc['length'].

  • x_cell_size, y_cell_size – Cell size along the X and Y axes. Unitless values are interpreted in ucc['length'].

  • z_edges – Cell edges along the Z axis. Unitless values are interpreted in ucc['length'].

  • levels – Alias of z_edges (exclusive).

  • x_atol, y_atol – Absolute tolerance on the remainder left when dividing the extent by the cell size along the X and Y axes. If None, the remainder is ignored. Unitless values are interpreted in ucc['length'].

Returns:

CartesianGrid

Raises:

ValueError – If a tolerance is set and the remainder along that axis exceeds it.

classmethod from_cell_size_and_resolution(x_cell_size, y_cell_size, n_x_cells, n_y_cells, z_edges=None, *, levels=None)#

Build a grid centred horizontally at the origin from cell sizes and counts.

The extent along each axis is cell_size * n_cells.

Parameters:
  • x_cell_size, y_cell_size – Cell size along the X and Y axes. Unitless values are interpreted in ucc['length'].

  • n_x_cells, n_y_cells – Number of cells along the X and Y axes.

  • z_edges – Cell edges along the Z axis. Unitless values are interpreted in ucc['length'].

  • levels – Alias of z_edges (exclusive).

Returns:

CartesianGrid

extended_by_cells(n_x_cells, n_y_cells)#

Return a copy extended symmetrically by whole cells.

The cell size is preserved; the cell count grows by 2 * n_x_cells in X and 2 * n_y_cells in Y.

Parameters:

n_x_cells, n_y_cells – Number of cells added on each side along the X and Y axes.

Returns:

CartesianGrid

extended_by_margin(x_margin, y_margin, x_atol=None, y_atol=None)#

Return a copy extended symmetrically by a margin on each side.

The cell size is preserved. The margin is rounded down to a whole number of cells.

Parameters:
  • x_margin, y_margin – Margin added on each side along the X and Y axes. Unitless values are interpreted in ucc['length'].

  • x_atol, y_atol – Absolute tolerance on the remainder left when dividing the margin by the cell size along the X and Y axes. If None, the remainder is ignored. Unitless values are interpreted in ucc['length'].

Returns:

CartesianGrid

Raises:

ValueError – If a tolerance is set and the remainder along that axis exceeds it.

cropped(x_extent, y_extent)#

Return a copy cropped symmetrically to a smaller extent.

Cells are removed in equal numbers on both sides; the requested extent is rounded down to a whole number of cells.

Parameters:

x_extent, y_extent – Target extent along the X and Y axes. Unitless values are interpreted in ucc['length'].

Returns:

CartesianGrid

Raises:

ValueError – If a target extent exceeds the grid extent, or if the number of cells to remove along an axis is odd.

centered()#

Return a copy translated horizontally so that it is centred at the origin.

Returns:

CartesianGrid

single_column()#

Return a copy with a single horizontal cell spanning the grid extent.

Returns:

CartesianGrid

class eradiate.grid.SphericalGrid(x_edges=None, y_edges=None, z_edges=None, *, azimuths=None, colatitudes=None, levels=None)#

Spherical grid [spherical].

Grid for spherical-shell geometries, in a geocentric spherical frame (X: azimuth [angle], Y: colatitude [angle], Z: altitude [length]). Unitless edges are interpreted in ucc['angle'] along X and Y and in ucc['length'] along Z.

The constructor takes cell edges along each axis, or their aliases (exclusive with the generic arguments): azimuths (X), colatitudes (Y) and levels (Z). Cells along X are called sectors and cells along Y are called bands.

The azimuth range must be at most 360° wide; see kernel_azimuths() for the ranges accepted by the kernel. Colatitudes must lie in [0°, 180°].

Parameters:
  • x_edges (quantity or array-like) – Cell edges along the X axis, regularly spaced. Unitless values are interpreted in the axis’s default units (see the class description).

  • y_edges (quantity or array-like) – Cell edges along the Y axis, regularly spaced. Unitless values are interpreted in the axis’s default units (see the class description).

  • z_edges (quantity or array-like) – Cell edges along the Z axis, regularly spaced. Unitless values are interpreted in the axis’s default units (see the class description).

Fields:
  • x_edges (pint.Quantity) – Cell edges along the X axis, regularly spaced.

  • y_edges (pint.Quantity) – Cell edges along the Y axis, regularly spaced.

  • z_edges (pint.Quantity) – Cell edges along the Z axis, regularly spaced.

classmethod from_levels(levels)#

Build a single-column grid from altitude levels.

The single cell spans the whole sphere (azimuths 0° to 360°, colatitudes 0° to 180°).

Parameters:

levels – Altitude levels (Z edges). Unitless values are interpreted in ucc['length'].

Returns:

SphericalGrid

property azimuths#

Azimuths of sector edges (alias of x_edges).

property sectors#

Azimuths of sector centres (alias of x_centers).

property sector_width#

Uniform sector width (alias of x_cell_size).

property colatitudes#

Colatitudes of band edges (alias of y_edges).

property bands#

Colatitudes of band centres (alias of y_centers).

property band_width#

Uniform band width (alias of y_cell_size).

kernel_azimuths()#

Map the azimuth range to the kernel’s [-π, π] convention.

sphericalcoordsvolume maps the azimuth \(\varphi = \operatorname{atan2}(y, x) \in [-\pi, \pi]\) to the volume’s Z coordinate. The grid’s azimuth range is placed in that interval as follows:

  • if it fits after a shift by a multiple of 2π, the edges are shifted and the data order is unchanged;

  • if it covers the full circle and the ±π cut falls on a cell edge, the edges become [-π, π] and the data must be rolled along the azimuth axis so that the first kernel cell is the one starting at the cut;

  • a single cell covering the full circle maps to [-π, π].

Returns:

  • phi_min, phi_max (float) – Kernel-side azimuth bounds in radians.

  • n_roll (int) – Number of cells by which volume data must be rolled backwards along the azimuth axis (np.roll(data, -n_roll, axis=0)).

Raises:

ValueError – If the range is wider than 2π, or crosses the ±π cut without being a full circle with the cut on a cell edge.

property to_world#

Transform from the unit cube to the part of sphericalcoordsvolume’s normalized coordinate space covered by the grid.

The kernel’s volume coordinates are (radius, colatitude, azimuth), each normalized to [0, 1]. The grid always covers the full radius range; the colatitude and azimuth ranges are those of the grid edges (see kernel_azimuths()).