planetmapper.utils
Various general helpful utilities.
- planetmapper.utils.format_radec_axes(ax: Axes, dec: float, dms_ticks: bool = True, add_axis_labels: bool = True, aspect_adjustable: Literal['box', 'datalim'] | None = 'datalim') None[source]
Format an axis to display RA/Dec coordinates nicely.
- Parameters:
ax – Matplotlib axis to format.
dec – Declination in degrees of centre of axis.
dms_ticks – Toggle between showing ticks as degrees, minutes and seconds (e.g. 12°34′56″) or decimal degrees (e.g. 12.582).
add_axis_labels – Add axis labels.
aspect_adjustable – Set
adjustableparameter when setting the aspect ratio. Passed tomatplotlib.axes.Axes.set_aspect(). Set to None to skip setting the aspect ratio (generally this is only recommended if you’re setting the aspect ratio yourself).
- class planetmapper.utils.DMSFormatter[source]
Bases:
FuncFormatterMatplotlib tick formatter to display angular values as degrees, minutes and seconds e.g.
12°34′56″. Designed to work withDMSLocator.ax = plt.cga() ax.yaxis.set_major_locator(planetmapper.utils.DMSLocator()) ax.yaxis.set_major_formatter(planetmapper.utils.DMSFormatter()) ax.xaxis.set_major_locator(planetmapper.utils.DMSLocator()) ax.xaxis.set_major_formatter(planetmapper.utils.DMSFormatter())
- class planetmapper.utils.DMSLocator[source]
Bases:
LocatorMatplotlib tick locator to display angular values as degrees, minutes and seconds. Designed to work with
DMSFormatter.ax = plt.cga() ax.yaxis.set_major_locator(planetmapper.utils.DMSLocator()) ax.yaxis.set_major_formatter(planetmapper.utils.DMSFormatter()) ax.xaxis.set_major_locator(planetmapper.utils.DMSLocator()) ax.xaxis.set_major_formatter(planetmapper.utils.DMSFormatter())
- planetmapper.utils.decimal_degrees_to_dms(decimal_degrees: float) tuple[int, int, float][source]
Get degrees, minutes, seconds from decimal degrees.
decimal_degrees_to_dms(-11.111)returns(-11.0, 6.0, 39.6).- Parameters:
decimal_degrees – Decimal degrees.
- Returns:
(degrees, minutes, seconds)tuple
- planetmapper.utils.decimal_degrees_to_dms_str(decimal_degrees: float, seconds_fmt: str = 'g') str[source]
Create nicely formatted DMS string from decimal degrees value (e.g.
'12°34′56″').Uses
decimal_degrees_to_dms()to perform the conversion.- Parameters:
decimal_degrees – Decimal degrees.
seconds_fmt – Optionally specify a format string for the seconds part of the returned value. For example,
seconds_fmt='.3f'will fix three decimal places for the fractional part of the seconds value. Note that the integral part of the seconds value will always be zero-padded to two digits, soseconds_fmt='.3f'will return seconds as e.g.01.234.
- Returns:
String representing the degrees, minutes, seconds of the angle.
- class planetmapper.utils.ignore_warnings(*warning_strings: str, **kwargs)[source]
Bases:
catch_warningsContext manager to ignore general warnings using warnings.filterwarnings.
- class planetmapper.utils.filter_fits_comment_warning(*, record=False, module=None, action=None, category=<class 'Warning'>, lineno=0, append=False)[source]
Bases:
catch_warningsContext manager to hide FITS
Card is too long, comment will be truncatedwarnings.
- planetmapper.utils.normalise(values: ndarray | Sequence[float], top: float = 1.0, bottom: float = 0.0, single_value: float | None = None) ndarray[source]
Normalise iterable.
- Parameters:
values – Iterable of values to normalise.
top – Top of normalised range.
bottom – Bottom of normalised range.
single_value – If all values are the same, return this value.
- Returns:
Normalised values.
- planetmapper.utils.check_path(path: str) None[source]
Checks if file path’s directory tree exists, and creates it if necessary.
Assumes path is to a file if
os.path.split(path)[1]contains ‘.’, otherwise assumes path is to a directory.
- exception planetmapper.utils.GetWavelengthsError[source]
Bases:
ValueErrorError raised when wavelength information cannot be extracted from a FITS header.
- planetmapper.utils.generate_wavelengths_from_header(header: Header | dict, *, check_ctype: bool = True, axis: int = 3) ndarray[source]
Generate wavelength array from keyword values in a FITS Header.
This uses the NAXIS3, CRVAL3, CDELT3 (or CD3_3) and CRPIX3 keywords to generate the wavelength array described by the Header. The axis to generate wavelengths for can be customised using the
axisparameter.By default, this function will raise an exception if the CTYPE of the axis is not ‘WAVE’. This can be disabled by setting
check_ctypeto False.See the JWST documentation for an an example of how the wavelength array can be generated from the FITS Header.
- Parameters:
header – FITS Header object (or dictionary).
check_ctype – Check that the CTYPE of the axis is ‘WAVE’.
axis – Axis to generate wavelengths for, using FITS (1-based) counting. This defaults to 3.
- Returns:
Wavelength array.
- Raises:
GetWavelengthsError – If the wavelength array cannot be generated from the FITS Header.