8. Python API

class planetmagfields.Planet(name='earth', model=None, year=None, r=1.0, nphi=256, datDir='/home/runner/work/planetMagFields/planetMagFields/planetmagfields/data/', unit='muT', info=True)[source]

Planet class

The Planet class contains all information about a planet. It contains arrays of Gauss coefficients, glm and hlm, the maximum spherical harmonic degree lmax to which data is available, and also computes and stores the (optionally filtered) radial magnetic field at a surface and the Lowes spectrum.

extrapolate(rout)[source]

Potential extrapolation of the magnetic field

Parameters:

rout (array_like) – Array of radial levels

Returns:

Assigns three arrays self.br_ex,self.btheta_ex,self.bphi_ex to the planet class for radial, colatitudinal and azimuthal components of the extrapolated field, respectively.

Return type:

None

orbit_path(r, theta, phi)[source]
Extrapolates the magnetic field along an orbit trajectory.

Assigns objects self.br_orb, self.btheta_orb, self.bphi_orb which are extrpolated values of radial, co-latitudinal and azimuthal components of the magnetic field, respectively.

Parameters:
  • r (array_like) – Array of radial distances

  • theta (array_like) – Array of co-latitudes in radians

  • phi (array_like) – Array of longitudes in radians

plot(r=None, levels=30, cmap='RdBu_r', proj='Mollweide', vmin=None, vmax=None)[source]

Plots the radial magnetic field of a planet at a radial surface.

Parameters:
  • r (float, optional) – Radial surface for plot, by default 1

  • levels (int, optional) – Number of contour levels, by default 30

  • cmap (str, optional) – Colormap for contours, by default ‘RdBu_r’

  • proj (str, optional) – Map projection, by default ‘Mollweide’

  • vmin (float, optional) – Minimum of colorscale, by default None

  • vmax (float, optional) – Maximum of colorscale, by default None

Return type:

None

plot_filt(r=1.0, larr=None, marr=None, lCutMin=0, lCutMax=None, mmin=0, mmax=None, levels=30, cmap='RdBu_r', proj='Mollweide', vmin=None, vmax=None, iplot=True)[source]

Plots a filtered radial magnetic field at a radial level. Filters can be set using specific values of degree and order of spherical harmonics given through the arrays larr and marr or by providing a range using lCutMin, lCutMax and mmin, mmax.

Parameters:
  • r (float, optional) – Radial level for plot, scaled to planetary radius, by default 1

  • larr (array_like, optional) – Array of spherical harmonic degrees, if None, uses lmax, by default None

  • marr (array_like, optional) – Array of spherical harmonic orders, if None, uses lmax, by default None

  • lCutMin (int, optional) – Minimum spherical harmonic degree to retain, by default 0

  • lCutMax (int, optional) – Maximum spherical harmonic degree to retain, if None, uses lmax, by default None

  • mmin (int, optional) – Minimum spherical harmonic order to retain, by default 0

  • mmax (int, optional) – Maximum spherical harmonic degree to retain, if None, uses lmax, by default None

  • levels (int, optional) – Number of contour levels, by default 30

  • cmap (str, optional) – Colormap for contours, by default ‘RdBu_r’

  • proj (str, optional) – Map projection, by default ‘Mollweide’

  • vmin (float, optional) – Minimum of colorscale, by default None

  • vmax (float, optional) – Maximum of colorscale, by default None

  • iplot (logical, optional) – Flag for producing a plot, by default True

Return type:

None

spec(r=1.0, iplot=True)[source]

General plot of Lowes spectrum of a planet at a radial level, scaled to planetary radius. Also computes dipolarity (energy of axial dipole) to total and total dipolarity (dipTot, energy of total dipole to total magnetic energy)

Parameters:
  • r (float, optional) – Radial level scaled to planetary radius, by default 1.0

  • iplot (bool, optional) – If True, generates a plot, by default True

Return type:

None

writeVtsFile(potExtra=False, ratio_out=2, nrout=32)[source]

Writes an unstructured vtk (.vts) file for 3D visualization. Uses the SHTns library for potential extrapolation and the pyevtk library for writing the vtk file.

Parameters:
  • potExtra (bool, optional) – Whether to use potential extrapolation, by default False

  • ratio_out (int, optional) – Radial level to which the magnetic field needs to be upward continued, scaled to planetary radius, by default 2

  • nrout (int, optional) – Number of radial grid levels, by default 32

Return type:

None

planetmagfields.get_models(planetname, datDir='/home/runner/work/planetMagFields/planetMagFields/planetmagfields/data/')[source]

Prints available models for a planet.

Parameters:
  • datDir (str) – Directory where the data file is present. Files are assumed to be named as <planetname>_<modelname>.dat, e.g.: earth_igrf13.dat, jupiter_jrm09.dat etc.

  • planetname (str) – Name of the planet

Returns:

models – Array of available model names

Return type:

str array