pycsa.wrappers.interface¶
Interface wrapper module to ease setting up the CSA building blocks
Functions
|
Applies tapering to a non-quadrilateral grid cell |
|
Applies tapering to a quadrilateral grid cell |
Classes
|
Wrapper class corresponding to the First Approximation step |
|
A wrapper class for the constrained spectral approximation method |
|
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_pmfinstance. Pass an explicit ctx to share resources across multipleget_pmfinstances (e.g. FA + SA indo_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 objectlmbda (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:
- dfft(cell, summed=False, updt_analysis=False)¶
Wrapper that performs discrete fast-Fourier transform on a quadrilateral grid cell
- Parameters:
cell (
pycsa.data.cell.topo_cell) – instance of the cell objectsummed (bool, optional) – toggles whether to sum the spectral components, by default False
updt_analysis (bool, optional) – toggles update of the <analysis
pycsa.data.results.analysis>, by default False
- Returns:
- returns tuple containing:
- (FFT-computed spectrum,computed idealised pseudo-momentum fluxes,the reconstructed physical data,list
[kks, lls]of the rFFT frequency vectors alongthe two horizontal directions)
- Return type:
- 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 objectfreqs (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 directionsdat_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 Falsescale (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:
- recompute_rhs(cell, fobj, lmbda=0.1, **kwargs)¶
Method to recompute the reconstructed physical data given a set of spectral amplitudes
- Parameters:
cell (
pycsa.data.cell.topo_cell) – instance of the cell objectfobj (
pycsa.core.fourier.f_trans) – instance of the Fourier transformer classlmbda (float, optional) – regularisation factor, by default 0.1
- Returns:
- returns tuple containing:
- (the CSA spectral amplitude grid recomputed from thesupplied amplitudes
fobj.a_m,computed idealised pseudo-momentum fluxes,the reconstructed physical data)
- Return type:
- pycsa.wrappers.interface.taper_quad(params, simplex_lat, simplex_lon, cell, topo)¶
Applies tapering to a quadrilateral grid cell
- Parameters:
params (
pycsa.config.params.params) – instance of the user-defined parameters classsimplex_lat (list) – list of latitudinal coordinates of the vertices
simplex_lon (list) – list of longitudinal coordinates of the vertices
cell (
pycsa.data.cell.topo_cell) – instance of a cell objecttopo (
pycsa.data.cell.topoorpycsa.data.cell.topo_cell) – instance of an object with topography attribute
- pycsa.wrappers.interface.taper_nonquad(params, simplex_lat, simplex_lon, cell, topo, res_topo=None)¶
Applies tapering to a non-quadrilateral grid cell
- Parameters:
params (
pycsa.config.params.params) – instance of the user-defined parameters classsimplex_lat (list) – list of latitudinal coordinates of the vertices
simplex_lon (list) – list of longitudinal coordinates of the vertices
cell (
pycsa.data.cell.topo_cell) – instance of a cell objecttopo (
pycsa.data.cell.topoorpycsa.data.cell.topo_cell) – instance of an object with topography attributesres_topo (array-like, optional) – residual orography, only required in iterative refinement, by default None
- 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:
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 classtopo (
pycsa.data.cell.topoorpycsa.data.cell.topo_cell) – instance of an object with topography attributectx (ComputeContext, optional) – Compute context shared with the inner
get_pmfcall. Default-constructed if absent.
- 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:
(pycsa.data.cell.topo_cellinstance,computed CSA spectrum,computed idealised pseudo-momentum fluxes,the reconstructed physical data)corresponding to
solsinwrappers.diagnostics.diag_plotter.show()- Return type:
- 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 classtopo (
pycsa.data.cell.topoorpycsa.data.cell.topo_cell) – instance of an object with topography attributetri (
scipy.spatial.Delaunay) – instance of the scipy Delaunay triangulation classctx (ComputeContext, optional) – Compute context shared with the inner
get_pmfcall. Default-constructed if absent.selector (
pycsa.core.mode_selection.ModeSelector, optional) – Pluggable selector for the FA→SA mode-selection step. WhenNone(default), the existing inline greedyargmaxloop is used and numerics are bit-identical to historical behavior. Ifctx.selectoris set and this kwarg isNone, 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:
(pycsa.data.cell.topo_cellinstance,computed CSA spectrum,computed idealised pseudo-momentum fluxes,the reconstructed physical data)corresponding to
solsinwrappers.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: