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: Optional[Literal['box', 'datalim']] = '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 adjustable parameter when setting the aspect ratio. Passed to matplotlib.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: FuncFormatter

Matplotlib tick formatter to display angular values as degrees, minutes and seconds e.g. 12°34′56″. Designed to work with DMSLocator.

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: Locator

Matplotlib 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 = '') str[source]

Create nicely formated 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.

Returns:

String representting the degress, minutes, seconds of the angle.

class planetmapper.utils.ignore_warnings(*warining_strings: str, **kwargs)[source]

Bases: catch_warnings

Context 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_warnings

Context manager to hide FITS Card is too long, comment will be truncated warnings.

planetmapper.utils.normalise(values: numpy.ndarray | list[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.