foscat.Plot#

Attributes#

Classes#

Functions#

lgnomproject(cell_ids, data, nside[, rot, xsize, ...])

Gnomonic projection from sparse HEALPix samples (cell_ids, data) to an image.

plot_scat(s1, s2, s3, s4)

power_spectrum_1d(data[, dx])

Compute the isotropic 1D power spectrum of a 2D field.

estimate_psd_slope(img[, dx, fmin_frac, fmax_frac])

Estimate beta in P(f) ~ f^-beta from the isotropic 1D PSD (log-log linear fit).

adjust_psd_slope(img[, dx, delta_beta, f_ref, band, ...])

Change the isotropic PSD slope by delta_beta (P -> P * f^{-delta_beta}).

latlon_to_xyz_frac(lat, lon, z)

Return fractional tile coordinates (xf, yf) at zoom z (Web Mercator).

xyz_frac_to_tile_pixel(xf, yf[, tile_size])

sample_esri_world_imagery(lat, lon[, zoom, tile_size])

lat, lon: arrays of shape (N,)

get_half_interp_weights_ang_general(nside_full, theta, phi)

Bilinear weights from the 'half-level' lattice (EVEN pixels of full grid) to arbitrary directions.

conjugate_gradient_normal_equation(data, x0, www, all_idx)

Solve the normal equation (Pᵗ P) x = Pᵗ y using the Conjugate Gradient method.

spectrum_polar_to_cartesian(w[, scales, orientations, ...])

If scale_kind == "frequency":

plot_wave(wave[, title, unit, cmap])

lonlat_edges_from_ref(shape, ref_lon, ref_lat, dlon, dlat)

Build lon/lat edges (H+1, W+1) for a regular, axis-aligned grid.

plot_image_lonlat(img, lon_edges, lat_edges[, cmap, ...])

Plot a 2D image on a lon/lat grid using pcolormesh (no reprojection).

plot_image_latlon(fig, ax, img, lat, lon[, mode, ...])

Plot an image given per-pixel lat/lon coordinates.

Module Contents#

foscat.Plot.lgnomproject(cell_ids, data, nside: int, rot=None, xsize: int = 400, ysize: int = 400, reso: float = None, fov_deg=None, nest: bool = True, reduce: str = 'mean', mask_outside: bool = True, unseen_value=None, return_image_only: bool = False, title: str = None, cmap: str = 'viridis', vmin=None, vmax=None, notext: bool = False, hold: bool = True, interp: bool = False, sub=(1, 1, 1), cbar: bool = False, unit: str = 'Value', rgb_clip=(0.0, 1.0))[source]#

Gnomonic projection from sparse HEALPix samples (cell_ids, data) to an image. Supports scalar data (N,) and RGB data (N,3). For RGB, colorbar/cmap/vmin/vmax are ignored.

foscat.Plot.plot_scat(s1, s2, s3, s4)[source]#
foscat.Plot.power_spectrum_1d(data, dx=1.0)[source]#

Compute the isotropic 1D power spectrum of a 2D field.

Parameters:
  • data (ndarray (ny, nx)) – Input 2D field.

  • dx (float) – Pixel size in the same spatial unit as desired frequency inverse. If dx is in meters, returned frequencies are in m^-1 (cycles per meter).

Returns:

  • f_centers (ndarray) – Radial spatial frequencies (cycles per unit length), e.g., m^-1 if dx is in meters.

  • Pk (ndarray) – Azimuthally averaged power spectrum over radial frequency bins (arbitrary units unless you add a normalization).

foscat.Plot.estimate_psd_slope(img, dx=1.0, fmin_frac=0.02, fmax_frac=0.4)[source]#

Estimate beta in P(f) ~ f^-beta from the isotropic 1D PSD (log-log linear fit). Uses the provided band [fmin_frac, fmax_frac] * f_max to avoid DC/Nyquist artifacts.

foscat.Plot.adjust_psd_slope(img, dx=1.0, delta_beta=0.0, f_ref=None, band=None, apodize=True, preserve_mean=True, match_variance=True, eps=None)[source]#

Change the isotropic PSD slope by delta_beta (P -> P * f^{-delta_beta}). - delta_beta > 0 : steeper spectrum (more large-scale, smoother image) - delta_beta < 0 : flatter/whiter spectrum (more small-scale, rougher image)

Parameters:
  • img (2D array) – Input image.

  • dx (float) – Pixel size (e.g., meters). Frequencies are cycles per unit of dx.

  • delta_beta (float) – Desired slope change: P’ ~ P * f^{-delta_beta}.

  • f_ref (float or None) – Reference frequency for normalization. If None, use median nonzero f.

  • band (tuple (f_lo, f_hi) or None) – If set, apply the slope change only within [f_lo, f_hi] (cycles per unit); smooth edges.

  • apodize (bool) – Apply 2D Hann window before FFT to reduce edge ringing.

  • preserve_mean (bool) – Keep DC (mean) unchanged.

  • match_variance (bool) – Rescale output to match input variance.

  • eps (float or None) – Small positive to protect f=0. If None, set to 1/(max(n)*dx).

Returns:

out (2D array (real)) – Image with adjusted spectrum slope.

foscat.Plot.latlon_to_xyz_frac(lat, lon, z)[source]#

Return fractional tile coordinates (xf, yf) at zoom z (Web Mercator).

foscat.Plot.xyz_frac_to_tile_pixel(xf, yf, tile_size=256)[source]#
foscat.Plot.ESRI_WORLD_IMAGERY = 'https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}'#
class foscat.Plot.TileCache[source]#
cache#
session#
get_tile(z, x, y, timeout=10)[source]#
foscat.Plot.sample_esri_world_imagery(lat, lon, zoom=17, tile_size=256)[source]#

lat, lon: arrays of shape (N,) zoom: Web Mercator zoom level returns: RGB uint8 array of shape (N, 3)

foscat.Plot.get_half_interp_weights_ang_general(nside_full, theta, phi, edge_mode='nearest')[source]#

Bilinear weights from the ‘half-level’ lattice (EVEN pixels of full grid) to arbitrary directions. Returns I (4 even NESTED ids) and W (4 weights summing to 1).

foscat.Plot.conjugate_gradient_normal_equation(data, x0, www, all_idx, LPT=None, LP=None, max_iter=100, tol=1e-08, verbose=True)[source]#

Solve the normal equation (Pᵗ P) x = Pᵗ y using the Conjugate Gradient method.

Parameters:
  • data (array_like) – Observed UTM data y ∈ ℝᵐ

  • x0 (array_like) – Initial guess for solution x ∈ ℝⁿ (HEALPix domain)

  • www (interpolation weights)

  • all_idx (interpolation indices)

  • LPT (implementation of adjoint operator Pᵗ)

  • LP (implementation of forward operator P)

  • max_iter (maximum number of CG iterations)

  • tol (stopping tolerance on residual norm)

  • verbose (print convergence info every 50 iterations)

Returns:

x (estimated HEALPix solution u ℝⁿ)

foscat.Plot.spectrum_polar_to_cartesian(w, scales=None, orientations=None, n_pixels=512, r_max=None, method='bilinear', fill_value=0.0, *, scale_kind='frequency', size_to_freq_factor=1.0)[source]#
If scale_kind == “frequency”:

scales are already radii in frequency units, strictly increasing (low->high freq).

If scale_kind == “size”:

scales are spatial sizes (e.g., km, px), strictly increasing (small->large size), and they are converted to frequency radii by: freq = size_to_freq_factor / size. Choose size_to_freq_factor to get the units you want (e.g., 1.0 for cycles/size).

foscat.Plot.plot_wave(wave, title='spectrum', unit='Amplitude', cmap='viridis')[source]#
foscat.Plot.lonlat_edges_from_ref(shape, ref_lon, ref_lat, dlon, dlat, anchor='center')[source]#

Build lon/lat edges (H+1, W+1) for a regular, axis-aligned grid.

Parameters:
  • shape (tuple(int, int)) – (H, W) of the image.

  • ref_lon, ref_lat (float) – Reference coordinate in degrees. Interpreted according to anchor.

  • dlon, dlat (float) – Pixel size in degrees along x (lon) and y (lat). Use positives.

  • anchor ({"center","topleft","topright","bottomleft","bottomright"}) – Where (ref_lon, ref_lat) sits relative to the image.

Returns:

lon_edges, lat_edges (2D arrays of shape (H+1, W+1)) – Corner coordinates suitable for pcolormesh.

foscat.Plot.plot_image_lonlat(img, lon_edges, lat_edges, cmap='viridis', vmin=None, vmax=None)[source]#

Plot a 2D image on a lon/lat grid using pcolormesh (no reprojection).

foscat.Plot.plot_image_latlon(fig, ax, img, lat, lon, mode='structured', cmap='viridis', vmin=None, vmax=None, shading='flat', aspect='equal')[source]#

Plot an image given per-pixel lat/lon coordinates.

Parameters:
  • img ((H, W) ndarray) – Image values per pixel.

  • lat, lon ((H, W) ndarray) – Latitude and longitude at pixel centers (same shape as img).

  • mode ({"structured", "scattered"}) –

    • “structured”: (i, j) grid is regular (rectangular index space), possibly warped.

      We’ll compute per-cell corners and use pcolormesh.

    • “scattered” : pixels are not on a regular (i, j) grid. We’ll triangulate points and use tripcolor.

  • cmap, vmin, vmax (matplotlib colormap settings.)

  • shading ({"flat","gouraud"} for pcolormesh/tripcolor. "flat" = one color per cell/triangle.)

  • aspect (matplotlib aspect for axes, e.g. "equal" or "auto")

Returns:

  • fig, ax (matplotlib Figure and Axes)

  • artist (QuadMesh (structured) or PolyCollection (scattered))