pysecs.SECS.fit#

SECS.fit(obs_loc: ndarray, obs_B: ndarray, obs_std: ndarray | None = None, epsilon: float = 0.05, mode: str = 'relative', robust: str | None = None, robust_maxiter: int = 20, robust_tol: float = 1e-06, *, J_loc: ndarray | None = None, obs_J: ndarray | None = None, J_std: ndarray | None = None) → SECS#

Fits the SECS to the given observations.

Given a number of observation locations and measurements, this function fits the SEC system to them. It uses singular value decomposition (SVD) to fit the SEC amplitudes with the epsilon parameter used to regularize the solution.

Sheet current density observations can be fit jointly with the magnetic field by also passing J_loc, obs_J and J_std. This is useful because ground magnetometers only see the divergence-free (equivalent) currents, while current observations also constrain the curl-free currents and their field-aligned currents (see fit_J()).

Parameters:
  • obs_locs (ndarray (nobs, 3 [lat, lon, r])) – Contains latitude, longitude, and radius of the observation locations (place where the measurements are made)

  • obs_B (ndarray (ntimes, nobs, 3 [Bx, By, Bz])) – An array containing the measured/observed B-fields.

  • obs_std (ndarray (ntimes, nobs, 3 [stdX, stdY, stdZ]), optional) – Standard error (1-sigma) of vector components at each observation location. This can be used to weight different observations more/less heavily. An infinite value eliminates the observation from the fit. Default: ones(nobs, 3) equal weights

  • epsilon (float) – Value used to regularize/smooth the SECS amplitudes. Epsilon has different meanings depending on the mode used, described in that parameter section. Must be between 0 and 1. A higher number produces a more regularized (smoother) solution. Default: 0.05

  • mode (str) –

    The mode used to filter the singular values. Options are:

    • ’relative’: filter singular values that are less than epsilon times the largest singular value, keep [S >= epsilon * S.max()].

    • ’variance’: filter singular values that contribute to 1-epsilon of the total energy of the system (% total variance as a ratio).

    Default: ‘relative’

  • robust (str, optional) –

    Robust reweighting of the observations. A localized disturbance at a single station (spikes, baseline jumps, instrument noise) is inconsistent with any smooth current system this basis can produce, so it shows up as a large standardized residual and is automatically downweighted by iteratively reweighted least squares (IRLS). Weights are applied per vector component and per time step. Options are:

    • None: ordinary weighted least squares (default).

    • ’huber’: Huber weights, downweights outliers gradually.

    • ’bisquare’: Tukey biweight, fully rejects gross outliers.

  • robust_maxiter (int) – Maximum number of IRLS iterations. Each iteration refits every time step with its own weights, so robust fits of long time series cost roughly robust_maxiter times the ordinary fit. Default: 20

  • robust_tol (float) – Relative amplitude change used to declare IRLS convergence. Default: 1e-6

  • J_loc (ndarray (nJ, 3 [lat, lon, r]), optional) – Locations of current density observations to fit jointly with the magnetic field. Must be given together with obs_J.

  • obs_J (ndarray (ntimes, nJ, 2 [Jx, Jy] or 3 [Jx, Jy, Jz]), optional) – Horizontal sheet current densities (A/m) observed at J_loc, as described in fit_J().

  • J_std (ndarray, same shape as obs_J, optional) – Standard error (1-sigma) of obs_J. Magnetic fields and currents have different units, so a joint fit requires both obs_std and J_std to weight them against each other. Both must be in SI units (T and A/m), the units of the transfer functions.

Returns:

This system, with the fitted amplitudes stored in sec_amps.

Return type:

SECS