swarmpal.toolboxes.dsecs.aux_tools#

Attributes#

Functions#

sph2sph(latP, lonP, latOld, lonOld, VtOld, VpOld)

Change coordinates and (horizontal part of) vectors from one spherical

sub_FindLongestNonZero(x)

Find the longest sequence of consecutive non-zero elements in an array.

sub_inversion(secsMat, regMat, epsSVD, alpha, magVec)

Solve matrix equation sysMat*resultVec = dataVec, using truncated

sub_LonInterp(lat, lon, intLat, method[, ekstra])

Robust interpolation of longitude by interpolating the sine and cosine

sub_Swarm_grids_1D(lat1, lat2, Dlat1D, ExtLat1D)

Creates 1D grid around the two Swarm satellite paths.

sub_Swarm_grids(lat1, lon1, lat2, lon2, Dlat2D, ...)

Creates 2D grids around the two Swarm satellite paths.

get_eq(ds[, lat_filter_max, ovals])

Splits data into a list of pieces suitable for DSECS analysis based on latitude.

_normalizev(v)

Creates an unit vector.

sub_points_along_fieldline(thetaSECS, Rsecs, L, minD)

Calculate points to be used in the Biot-Savart integral along field line

Module Contents#

swarmpal.toolboxes.dsecs.aux_tools.logger#
swarmpal.toolboxes.dsecs.aux_tools.sph2sph(latP, lonP, latOld, lonOld, VtOld, VpOld)[source]#
Change coordinates and (horizontal part of) vectors from one spherical

coordinate system to another.

Parameters:
  • latP (float) – Latitude and longitude of the new pole in the old coordinates, [deg]

  • lonP (float) – Latitude and longitude of the new pole in the old coordinates, [deg]

  • latOld (array) – Latitudes and longitudes of the data points to be transformed in the old coordinate system, [deg]

  • lonOld (array) – Latitudes and longitudes of the data points to be transformed in the old coordinate system, [deg]

  • VtOld (array) – Theta- and phi-components of a vector field at locations (latOld,lonOld). If you want to transform only coordinates make these empty arrays (np.array([])).

  • VpOld (array) – Theta- and phi-components of a vector field at locations (latOld,lonOld). If you want to transform only coordinates make these empty arrays (np.array([])).

Returns:

  • latNew, lonNew (array) – Coordinates of the points (latOld,lonOld) in the new system, [deg], same size as input parameters. Note that the old pole has longitude 0 and longitude is between 0 and 360.

  • VtNew, VpNew (array) – Theta- and phi-components of the vector field in the new system. If no input vector field was given, these are empty vectors [].

swarmpal.toolboxes.dsecs.aux_tools.sub_FindLongestNonZero(x)[source]#
Find the longest sequence of consecutive non-zero elements in an array.

Return the sequence and indices as y=x[ind].

Parameters:

x (array) – Input array

Returns:

  • y (array) – Longest sequence of consecutive non-zero elements

  • ind (array) – Indices of the sequence

swarmpal.toolboxes.dsecs.aux_tools.sub_inversion(secsMat, regMat, epsSVD, alpha, magVec)[source]#
Solve matrix equation sysMat*resultVec = dataVec, using truncated

singular value decomposition.

Parameters:
  • secsMat (ndarray) – Matrix giving the magnetic field from SECS amplitudes

  • regMat (ndarray) – Regularization matrix for the SECS amplitudes

  • epsSVD (float) – Pre-defined truncation parameter so that all singular values smaller than epsSVD*(largest singular value) will be ignored

  • alpha (float) – Parameter scaling the amount of regularization

  • magVec (array) – Magnetic measurements to be fitted

Returns:

result_Vec – Vector of SECS amplitudes

Return type:

array

swarmpal.toolboxes.dsecs.aux_tools.sub_LonInterp(lat, lon, intLat, method, ekstra=np.nan)[source]#

Robust interpolation of longitude by interpolating the sine and cosine of the angle. This way a 360 degree jump does not matter.

Parameters:
  • lat (ndarray) – Original coordinates, [degree].

  • lon (ndarray) – Original coordinates, [degree].

  • intLat (ndarray) – Latitudes where original longitudes are interpolated to, [degree].

  • method (str) – Interpolation method. Same as for scipy.interpolate.interp1d.

Returns:

intLon – Interpolated longitudes at latitudes intLat, [degree]. -180 <= intlon <= 180.

Return type:

ndarray

swarmpal.toolboxes.dsecs.aux_tools.sub_Swarm_grids_1D(lat1, lat2, Dlat1D, ExtLat1D)[source]#

Creates 1D grid around the two Swarm satellite paths.

Parameters:
  • lat1 (ndarray) – Geographic latitudes of the satellites’ paths, [degree].

  • lat2 (ndarray) – Geographic latitudes of the satellites’ paths, [degree].

  • Dlat1D (int or float) – 1D grid spacing in latitudinal direction, [degree].

  • ExtLat1D (int) – Number of points to extend the 1D grid outside the data area in latitudinal direction.

Returns:

  • lat1D (ndarray) – Geographic latitudes of the 1D grid, [degree].

  • mat1Dsecond (ndarray) – Second gradient matrix.

swarmpal.toolboxes.dsecs.aux_tools.sub_Swarm_grids(lat1, lon1, lat2, lon2, Dlat2D, LonRatio, ExtLat2D, ExtLon2D)[source]#

Creates 2D grids around the two Swarm satellite paths.

Parameters:
  • lat1 (ndarray) – Geographic latitudes of the satellites’ paths, [degree].

  • lat2 (ndarray) – Geographic latitudes of the satellites’ paths, [degree].

  • lon1 (ndarray) – Geographic longitudes of the satellites’ paths, [degree].

  • lon2 (ndarray) – Geographic longitudes of the satellites’ paths, [degree].

  • Dlat2D (float) – 2D grid spacing in latitudinal direction, [degree].

  • LonRatio (float) – Ratio between the satellite separation and longitudinal spacing of the 2D grid.

  • ExtLat2D (int) – Number of points to extend the 2D grid outside the data area in latitudinal and longitudinal directions.

  • ExtLon2D (int) – Number of points to extend the 2D grid outside the data area in latitudinal and longitudinal directions.

Returns:

  • lat2D, lon2D (ndarray) – Geographic latitudes and longitudes of the 2D grid, [degree].

  • angle2D (ndarray) – Half-angle of such a spherical cap that has the same area as the 2D grid cell, [radian].

  • mat2DsecondLat (ndarray) – Second gradient matrix in latitude.

swarmpal.toolboxes.dsecs.aux_tools.get_eq(ds, lat_filter_max=60, ovals=None)[source]#

Splits data into a list of pieces suitable for DSECS analysis based on latitude.

Parameters:
  • ds (xarray) – Input dataset.

  • lat_filter_max (int, optional) – Maximum geographic latitude (absolute value). All data above this limit is ignored. Default: 60

  • ovals (list) – list of pre-calculated numpy slices with which to split the data.

Returns:

out – List of data segments split for DSECS analysis if they have been precalculated.

Return type:

list of xarray, or None, None by default

swarmpal.toolboxes.dsecs.aux_tools._normalizev(v)[source]#

Creates an unit vector. :param v: Input array. :type v: ndarray

Returns:

Normalized unit vector.

Return type:

ndarray

swarmpal.toolboxes.dsecs.aux_tools.sub_points_along_fieldline(thetaSECS, Rsecs, L, minD)[source]#
Calculate points to be used in the Biot-Savart integral along field line

in function SECS_2D_CurlFree_AntiSym_magnetic_lineintegral

Parameters:
  • thetaSECS (float) – Co-latitude of the CF SECS, [radian]

  • Rsecs (float) – Radius of the sphere where CF SECS is located, [km]

  • L (float) – L-value of the field line starting from the CF SECS pole, [km NOTE: this is in kilometers, so really L*Rsecs;

  • minD (float) – minimum horizontal distance between the CF SECS pole and footpoints of the points where magnetic field is needed, [km], SCALAR

Returns:

co-latitudes of the integration points (= end points of the current elements), [radian]

Return type:

array