Models¶
- class tom_targets.base_models.TargetMatchManager(*args, **kwargs)¶
Search for matches amongst Target objects. Return Queryset containing relevant TARGET matches.
- NOTE:
is_unique
andmatch_name
are used throughout the code to determine if a target or a name is unique. These functions can be overridden in a subclass to provide custom matching logic. Examples of this can be found in the documentation (https://tom-toolkit.readthedocs.io/en/stable/targets/target_matcher.html).
- is_unique(target, *args, **kwargs)¶
Check if the given target is unique. This function uses
TargetMatchManager.match_target()
to determine if any targets exist in the DB other than the given target would be considered by the user to be a duplicate of the given target.This function is used in the
Target.validate_unique()
function to check for uniqueness.- Parameters:
target – The target object to be checked against.
- Returns:
True if the target is unique, False otherwise.
- match_target(target, *args, **kwargs)¶
Check if any other targets match the given target. This function returns a queryset that is used by
TargetMatchManager.is_unique()
to determine if a target is unique.By default, this checks for a match in the name field using the match_name function. This can be overridden in a subclass to provide custom matching logic.
- Parameters:
target – The target object to be checked against.
- Returns:
queryset containing matching Target(s).
- match_name(name)¶
Returns a queryset of targets with matching names.
By default, this checks for a fuzzy match using the
match_fuzzy_name
function. This can be overridden in a subclass to provide custom matching logic.- Parameters:
name – The string against which target names will be matched.
- Returns:
queryset containing matching Target(s).
- match_cone_search(ra: float, dec: float, radius: float)¶
Returns a queryset containing any targets that are within the given radius of the given ra and dec.
- Parameters:
ra (float) – The right ascension of the target in degrees.
dec (float) – The declination of the target in degrees.
radius (float) – The radius in arcseconds within which to search for targets.
- Returns:
queryset containing matching Target(s).
- match_exact_name(name)¶
Returns a queryset of targets with a name that exactly match the name that is received
- Parameters:
name – The string against which target names will be matched.
- Returns:
queryset containing matching Target(s).
- match_fuzzy_name(name, input_queryset=None)¶
Returns a queryset of targets with a name OR ALIAS that, when processed by
simplify_name
, match a similarly processed version of the name that is received.- Parameters:
name – The string against which target names and aliases will be matched.
input_queryset – Optional queryset to filter the results. If not provided, all targets will be considered.
- Returns:
queryset containing matching Targets. Will return targets even when matched value is an alias.
- simplify_name(name)¶
Create a simplified name to be used for comparison in
match_fuzzy_name
. By default, this method removes capitalization, spaces, dashes, underscores, and parentheses from the name. This can be overridden in a subclass to provide custom name simplification.- Parameters:
name – The string to be simplified.
- Returns:
A simplified string version of the given name.
- class tom_targets.base_models.BaseTarget(*args, **kwargs)¶
Class representing a target in a TOM
- Parameters:
name (str) – The name of this target e.g. Barnard’s star.
type (datetime) – The type of this target.
created – The time at which this target was created in the TOM database.
modified – The time at which this target was changed in the TOM database.
ra (float) – Right Ascension, in degrees.
dec (float) – Declination, in degrees.
epoch (float) – Julian Years. Max 2100.
parallax (float) – Parallax, in milliarcseconds.
pm_ra (float) – Proper Motion: RA. Milliarsec/year.
pm_dec (float) – Proper Motion: Dec. Milliarsec/year.
galactic_lng (float) – Galactic Longitude in degrees.
galactic_lat (float) – Galactic Latitude in degrees.
distance (float) – Parsecs.
distance_err (float) – Parsecs.
scheme (str) – Orbital Element Scheme
epoch_of_elements (float) – Epoch of elements in JD.
mean_anomaly (float) – Angle in degrees.
arg_of_perihelion (float) – Argument of Perhihelion. J2000. Degrees.
eccentricity (float) – Eccentricity
lng_asc_node (float) – Longitude of Ascending Node. J2000. Degrees.
inclination (float) – Inclination to the ecliptic. J2000. Degrees.
mean_daily_motion (float) – Degrees per day.
semimajor_axis (float) – Semimajor Axis in AU
epoch_of_perihelion (float) – Julian Date.
ephemeris_period (float) – Ephemeris period in days
ephemeris_period_err (float) – Days
ephemeris_epoch (float) – Days
ephemeris_epoch_err (float) – Days
- save(*args, **kwargs)¶
Saves Target model data to the database, including extra fields. After saving to the database, also runs the hook
target_post_save
. The hook run is the one specified insettings.py
.- Keyword Arguments:
extras (dict): dictionary of key/value pairs representing target attributes
- validate_unique(*args, **kwargs)¶
Ensures that Target.name and all aliases of the target are unique. Called automatically when checking form.is_valid(). Should call Target.full_clean() to validate before save.
- featured_image()¶
Gets the
DataProduct
associated with thisTarget
that is a FITS file and is uniquely marked as “featured”.- Returns:
DataProduct
with data_product_type offits_file
and featured asTrue
- Return type:
- property names¶
Gets a list with the name and aliases of this target
- Returns:
list of all names and TargetName values associated with this target
- Return type:
list
- property constellation¶
Gets the constellation of this target if it is sidereal
- Returns:
The constellation of this target according to astropy
- Return type:
str
- property future_observations¶
Gets all observations scheduled for this
Target
- Returns:
List of
ObservationRecord
objects without a terminal status- Return type:
list
- property extra_fields¶
Gets all
TargetExtra
fields associated with thisTarget
, provided the key is defined insettings.py
EXTRA_FIELDS
- Returns:
Dictionary of key/value pairs representing target attributes
- Return type:
dict
- property tags¶
Gets all
TargetExtra
fields associated with thisTarget
, provided the key is NOT defined insettings.py
EXTRA_FIELDS
- Returns:
Dictionary of key/value pairs representing target attributes
- Return type:
dict
- as_dict()¶
Returns dictionary representation of attributes, sets the order of attributes associated with the
type
of thisTarget
and then includes any additional attributes that are not empty and have not been ‘hidden’.- Returns:
Dictionary of key/value pairs representing target attributes
- Return type:
dict
- give_user_access(user)¶
Gives the given user permissions to view this target. :param user: :return:
- tom_targets.models.get_target_model_class()¶
Function to retrieve the target model class from settings.py. If not found, returns the default BaseTarget.
- class tom_targets.models.TargetName(*args, **kwargs)¶
Class representing an alternative name for a
Target
.- Parameters:
target – The
Target
object thisTargetName
is associated with.name (str) – The name that this
TargetName
object represents.created (datetime) – The time at which this target name was created in the TOM database.
modified (datetime) – The time at which this target name was modified in the TOM database.
- validate_unique(*args, **kwargs)¶
Ensures that Target.name and all aliases of the target are unique. Called automatically when checking form.is_valid(). Should call TargetName.full_clean() to validate before save.
- class tom_targets.models.TargetExtra(*args, **kwargs)¶
Class representing a list of targets in a TOM.
- Parameters:
target – The
Target
object thisTargetExtra
is associated with.key (str) – Denotation of the value represented by this
TargetExtra
object.value (str) – Value of the field stored in this object.
float_value (float) – Float representation of the
value
field for this object, if applicable.bool_value (bool) – Boolean representation of the
value
field for this object, if applicable.time_value (datetime) – Datetime representation of the
value
field for this object, if applicable.
- save(*args, **kwargs)¶
Saves TargetExtra model data to the database. In the process, converts the string value of the
TargetExtra
to the appropriate type, and stores it in the corresponding field as well.
- typed_value(type_val)¶
Returns the value of this
TargetExtra
in the corresponding type provided by the caller. If the type is invalid, returns the string representation.- Parameters:
type_val (str) – Requested type of the
TargetExtra
value
field- Returns:
Requested typed value field of this object
- Return type:
float, boolean, datetime, or str
- class tom_targets.models.TargetList(*args, **kwargs)¶
Class representing a list of targets in a TOM.
- Parameters:
name (str) – The name of the target list
targets – Set of
Target
objects associated with thisTargetList
created (datetime) – The time at which this target list was created.
modified (datetime) – The time at which this target list was modified in the TOM database.
Class representing a persistent share setup between a sharing destination and a Target
- Parameters:
target – The
Target
you want to shareuser – The
User
that created this PersistentShare, for accountability purposes.destination (str) – The sharing destination, as it appears in your TOM’s DATA_SHARING settings dict
created (datetime) – The time at which this PersistentShare was created