pycsa.wrappers.interface

Interface wrapper module to ease setting up the CSA building blocks

Functions

taper_nonquad(params, simplex_lat, ...[, ...])

Applies tapering to a non-quadrilateral grid cell

taper_quad(params, simplex_lat, simplex_lon, ...)

Applies tapering to a quadrilateral grid cell

Classes

first_appx(nhi, nhj, params, topo[, ctx])

Wrapper class corresponding to the First Approximation step

get_pmf(nhi, nhj, U, V[, debug, ctx])

A wrapper class for the constrained spectral approximation method

second_appx(nhi, nhj, params, topo, tri[, ...])

Wrapper class corresponding to the Second Approximation step

class pycsa.wrappers.interface.get_pmf(nhi, nhj, U, V, debug=False, ctx=None)

A wrapper class for the constrained spectral approximation method

This class is used in the idealised experiments

__init__(nhi, nhj, U, V, debug=False, ctx=None)
Parameters:
  • nhi (int) – number of harmonics in the first horizontal direction

  • nhj (int) – number of harmonics in the second horizontal direction

  • U (float) – wind speed in the first horizontal direction

  • V (float) – wind speed in the second horizontal direction

  • debug (bool, optional) – debug flag, by default False

  • ctx (ComputeContext, optional) – Compute context bundling the buffer pool (and other per-task resources). Default-constructed if absent — preserves the previous behavior of one fresh BufferPool per get_pmf instance. Pass an explicit ctx to share resources across multiple get_pmf instances (e.g. FA + SA in do_cell).

sappx(cell, lmbda=0.1, scale=1.0, **kwargs)

Method to perform the constraint spectral approximation method

Parameters:
  • cell (pycsa.data.cell.topo_cell) – instance of the cell object

  • lmbda (float, optional) – regulariser factor, by default 0.1

  • scale (float, optional) – scales the amplitudes for debugging purposes, by default 1.0

  • **kwargs (dict, optional) –

    Additional options forwarded to the regression and analysis steps:

    iter_solvebool

    use the iterative least-squares solver, by default True

    save_coeffsbool

    retain the regression coefficient matrix, by default False

    use_sparsebool

    use the sparse solver path, by default False

    save_ambool

    store the solved amplitudes on self.fobj.a_m, by default False

    refinebool

    perform a second regression pass on the residual topography and accumulate the amplitudes, by default False

    updt_analysisbool

    attach the resulting analysis object to cell.analysis

    summedbool

    sum the idealised pseudo-momentum fluxes over modes, by default False

Returns:

returns tuple containing:
(the CSA spectral amplitudes,
computed idealised pseudo-momentum fluxes,
the reconstructed physical data)

Return type:

tuple

dfft(cell, summed=False, updt_analysis=False)

Wrapper that performs discrete fast-Fourier transform on a quadrilateral grid cell

Parameters:
Returns:

returns tuple containing:
(FFT-computed spectrum,
computed idealised pseudo-momentum fluxes,
the reconstructed physical data,
list [kks, lls] of the rFFT frequency vectors along
the two horizontal directions)

Return type:

tuple

cg_spsp(cell, freqs, kklls, dat_2D, summed=False, updt_analysis=False, scale=1.0)

Method to perform a coarse-graining of spectral space

Deprecated since version 0.90.0: This coarse-graining path is no longer used by the production pipeline and is retained only for back-compatibility.

Parameters:
  • cell (pycsa.data.cell.topo_cell) – instance of the cell object

  • freqs (array-like) – spectral amplitudes to coarse-grain

  • kklls (sequence) – two-element sequence [m_i, m_j] of the coarse-grained wavenumber indices along the two horizontal directions

  • dat_2D (array-like) – the reconstructed physical (2D) data

  • summed (bool, optional) – sum the idealised pseudo-momentum fluxes over modes, by default False

  • updt_analysis (bool, optional) – attach the resulting analysis object to cell.analysis, by default False

  • scale (float, optional) – scales the amplitudes for debugging purposes, by default 1.0

Returns:

returns tuple containing:
(the scaled CSA spectral amplitudes,
computed idealised pseudo-momentum fluxes,
the reconstructed physical data)

Return type:

tuple

recompute_rhs(cell, fobj, lmbda=0.1, **kwargs)

Method to recompute the reconstructed physical data given a set of spectral amplitudes

Parameters:
Returns:

returns tuple containing:
(the CSA spectral amplitude grid recomputed from the
supplied amplitudes fobj.a_m,
computed idealised pseudo-momentum fluxes,
the reconstructed physical data)

Return type:

tuple

pycsa.wrappers.interface.taper_quad(params, simplex_lat, simplex_lon, cell, topo)

Applies tapering to a quadrilateral grid cell

Parameters:
pycsa.wrappers.interface.taper_nonquad(params, simplex_lat, simplex_lon, cell, topo, res_topo=None)

Applies tapering to a non-quadrilateral grid cell

Parameters:
class pycsa.wrappers.interface.first_appx(nhi, nhj, params, topo, ctx=None)

Wrapper class corresponding to the First Approximation step

Use this routine to apply tapering and to separate the first and second approximation steps

__init__(nhi, nhj, params, topo, ctx=None)
Parameters:
do(simplex_lat, simplex_lon, res_topo=None, use_center=True)

Do the First Approximation step

Parameters:
  • simplex_lat (list) – list of latitudinal coordinates of the vertices

  • simplex_lon (list) – list of longitudinal coordinates of the vertices

  • res_topo (array-like, optional) – residual orography, only required in iterative refinement, by default None

  • use_center (bool, optional) – use centered planar projection (True) or corner-based (False), by default True

Returns:

contains the data for plotting:

computed CSA spectrum,
computed idealised pseudo-momentum fluxes,
the reconstructed physical data)

corresponding to sols in wrappers.diagnostics.diag_plotter.show()

Return type:

tuple

class pycsa.wrappers.interface.second_appx(nhi, nhj, params, topo, tri, ctx=None, selector=None)

Wrapper class corresponding to the Second Approximation step

Use this routine to apply tapering and to separate the first and second approximation steps

__init__(nhi, nhj, params, topo, tri, ctx=None, selector=None)
Parameters:
  • nhi (int) – number of harmonics in the first horizontal direction

  • nhj (int) – number of harmonics in the second horizontal direction

  • params (pycsa.config.params.params) – instance of the user-defined parameters class

  • topo (pycsa.data.cell.topo or pycsa.data.cell.topo_cell) – instance of an object with topography attribute

  • tri (scipy.spatial.Delaunay) – instance of the scipy Delaunay triangulation class

  • ctx (ComputeContext, optional) – Compute context shared with the inner get_pmf call. Default-constructed if absent.

  • selector (pycsa.core.mode_selection.ModeSelector, optional) – Pluggable selector for the FA→SA mode-selection step. When None (default), the existing inline greedy argmax loop is used and numerics are bit-identical to historical behavior. If ctx.selector is set and this kwarg is None, the context’s selector is used. Opt-in only; no production caller passes this kwarg.

do(idx, ampls_fa, res_topo=None, use_center=True)

Do the Second Approximation step

Parameters:
  • idx (int) – index of the non-quadrilateral grid cell

  • ampls_fa (array-like) – spectral modes identified in the first approximation step

  • res_topo (array-like, optional) – residual orography, only required in iterative refinement, by default None

  • use_center (bool, optional) – use centered planar projection (True) or corner-based (False), by default True

Returns:

contains the data for plotting:

computed CSA spectrum,
computed idealised pseudo-momentum fluxes,
the reconstructed physical data)

corresponding to sols in wrappers.diagnostics.diag_plotter.show().

If params.recompute_rhs = True, the tuple contains two lists. The first list is the contains the data above, and the second list contains the data from the recomputation over the quadrilateral domain.

Return type:

tuple