Utilities

tom_observations.utils.ephem_to_datetime(ephem_time)

Converts PyEphem time object to a datetime object

Parameters

ephem_time (PyEphem date) – time to be converted to datetime

Returns

datetime time equivalent to the ephem_time

Return type

datetime

tom_observations.utils.get_last_rise_set_pair(rise_sets, time)

Gets the rise/set pair for the last rise before the given time, using a binary search

Parameters
  • rise_sets (array) – array of tuples representing set of rise/sets to search

  • time (float) – time value used to find the most recent rise, in UNIX time

Returns

Most recent rise/set pair with respect to the given time

Return type

tuple

tom_observations.utils.get_next_rise_set_pair(rise_sets, time)

Gets the upcoming rise/set pair for the next rise after the given time, using a binary search

Parameters
  • rise_sets (array) – array of tuples representing set of rise/sets to search

  • time (float) – time value used to find the next rise, in UNIX time

Returns

Soonest upcoming rise/set with respect to the given time

Return type

tuple

tom_observations.utils.get_pyephem_instance_for_type(target)

Constructs a pyephem body corresponding to the proper object type in order to perform positional calculations for the target

Returns

FixedBody or EllipticalBody

Raises

Exception – When a target type other than sidereal or non-sidereal is supplied

tom_observations.utils.get_rise_set(observer, target, start_time, end_time)

Calculates all of the rises and sets for a target, from a position on Earth, within a given window.

If the target is up at the start time, the rise is included in the result despite not being within the window. Similarly, if the target is up at the end time, the next setting beyond the end window is included in the result.

Parameters
  • observer (PyEphem Observer) – Represents the position from which to calculate the rise/sets

  • target (Target) – The object for which to calculate the rise/sets

  • start_time (datetime) – start of the calculation window

  • end_time (datetime) – end of the calculation window

Returns

A list of 2-tuples, each a pair of values representing a rise and a set, both datetime objects

Return type

list

tom_observations.utils.get_visibility(target, start_time, end_time, interval, airmass_limit=10)

Calculates the airmass for a target for each given interval between the start and end times.

The resulting data omits any airmass above the provided limit (or default, if one is not provided), as well as any airmass calculated during the day.

Parameters
  • start_time (datetime) – start of the window for which to calculate the airmass

  • end_time (datetime) – end of the window for which to calculate the airmass

  • interval (int) – time interval, in minutes, at which to calculate airmass within the given window

  • airmass_limit (int) – maximum acceptable airmass for the resulting calculations

Returns

A dictionary containing the airmass data for each site. The dict keys consist of the site name prepended with the observing facility. The values are the airmass data, structured as an array containing two arrays. The first array contains the set of datetimes used in the airmass calculations. The second array contains the corresponding set of airmasses calculated.

Return type

dict