Models#
- class tom_dataproducts.models.AstrometryReducedDatum(
- id,
- target,
- data_product,
- timestamp,
- value,
- telescope,
- instrument,
- source_name,
- source_location,
- ra,
- dec,
- ra_error,
- dec_error,
- ra_error_units,
- dec_error_units,
- exception DoesNotExist#
- exception MultipleObjectsReturned#
- class tom_dataproducts.models.DataProduct(*args, **kwargs)[source]#
Class representing a data product object in a TOM.
A DataProduct corresponds to any file containing data, from a FITS, to a PNG, to a CSV. It can optionally be associated with a specific observation, and is required to be associated with a target.
- Parameters:
product_id (str) – The identifier of the data product used by its original source.
target (Target) – The
Targetwith which this object is associated.observation_record (ObservationRecord) – The
ObservationRecordwith which this object is optionally associated.data (django.core.files.File) – The file this object refers to.
extra_data (str) – Arbitrary text field for storing additional information about this object.
group – Set of
DataProductGroupobjects this object is associated with.created (datetime) – The time at which this object was created.
modified (datetime) – The time at which this object was last modified.
data_product_type (str) – The type of data referred to by this object. Default options are photometry, fits_file, spectroscopy, or image_file. Can be configured in settings.py.
featured (boolean) – Whether or not the data product is intended to be featured, used by default on the target detail page as a “display” option. Only one
DataProductcan be featured perTarget.thumbnail (FileField) – The thumbnail file associated with this object. Only generated for FITS image files.
- exception DoesNotExist#
- exception MultipleObjectsReturned#
- create_thumbnail(width=None, height=None)[source]#
Creates a thumbnail image of this data product (if it is a valid FITS image file) with specified width and height, or the original width and height if none is specified.
- Keyword Arguments:
width (int): Desired width of the thumbnail
height (int): Desired height of the thumbnail
- Returns:
Thumbnail file if created, None otherwise
- Return type:
file
- get_file_extension()[source]#
Returns the extension of the file associated with this data product
- Returns:
File extension
- Return type:
str
- get_preview(size=(200, 200), redraw=False)[source]#
Returns path to the thumbnail of this data product, and creates a thumbnail if none exists
- Keyword Arguments:
size (tuple): Desired size of the thumbnail, as a 2-tuple of ints for width/height
redraw (boolean): True if the thumbnail will be recreated despite existing, False otherwise
- returns:
Path to the thumbnail image
- rtype:
str
- class tom_dataproducts.models.DataProductGroup(*args, **kwargs)[source]#
Class representing a group of
DataProductobjects in a TOM.- Parameters:
name (str) – The name of the group of
DataProductobjectscreated (datetime) – The time at which this object was created.
modified (datetime) – The time at which this object was last changed.
- exception DoesNotExist#
- exception MultipleObjectsReturned#
- class tom_dataproducts.models.PhotometryReducedDatum(
- id,
- target,
- data_product,
- timestamp,
- value,
- telescope,
- instrument,
- source_name,
- source_location,
- brightness,
- brightness_error,
- limit,
- unit,
- bandpass,
- exposure_time,
- exception DoesNotExist#
- exception MultipleObjectsReturned#
- class tom_dataproducts.models.ReducedDatum(*args, **kwargs)[source]#
Class representing a generic datum in a TOM that isn’t represented by any of the existing data types.
- Parameters:
data_type (str) – The type of data this datum represents. Default choices are the default values found in DATA_PRODUCT_TYPES in settings.py.
- exception DoesNotExist#
- exception MultipleObjectsReturned#
- validate_unique(*args, **kwargs)[source]#
Validates that the ReducedDatum is unique. Because the value field is a JSONField, it is not possible to rely on standard validation. Also, We do not want to repeat identical data from two different sources.
Do nothing if the uniqueness test passes. Otherwise, raise a ValidationError. see https://docs.djangoproject.com/en/5.0/ref/models/instances/#validating-objects
- class tom_dataproducts.models.ReducedDatumCommon(*args, **kwargs)[source]#
Abstract base class for all reduced datum models.
A
ReducedDatumgenerally refers to a single piece of data–e.g., a spectrum, or a photometry point. It is associated with a target, and optionally with the data product it came from. An example of aReducedDatumwithout an associated data product would be photometry ingested from a data service.There are concrete implementations of Photometry, Spectroscopy and Astrometry ReducedDatum models.- Parameters:
target – The
Targetwith which this object is associated.data_product – The
DataProductwith which this object is optionally associated.timestamp (datetime) – The timestamp of this datum.
value (dict) –
Freeform data. This is a dict, intended to store extra data with a variety of scopes. As an example, one might want to store the originating survey:
{ 'survey': 'lsst', }
source_name (str) – The original source of this datum. The current major use of this field is to track the data service a datum came from, but can be used for other sources.
source_location (str) – A reference to the location that this datum was originally sourced from. The current major use of this field is the URL path to the alert that this datum came from.
- class tom_dataproducts.models.ReducedDatumQuerySet(
- model=None,
- query=None,
- using=None,
- hints=None,
This is a custom queryset that allows us to extend the get_or_create to coincide with our custom validate_unique for ReducedDatum objects so that getting a ReducedDatum with get_or_create will return identical datums from different sources.
- class tom_dataproducts.models.SpectroscopyReducedDatum(
- id,
- target,
- data_product,
- timestamp,
- value,
- telescope,
- instrument,
- source_name,
- source_location,
- setup,
- exposure_time,
- wavelength,
- flux,
- error,
- flux_unit,
- exception DoesNotExist#
- exception MultipleObjectsReturned#
- tom_dataproducts.models.data_product_path(instance, filename)[source]#
Returns the TOM-style path for a
DataProductfile. Default behavior can be overridden by user in settings.DATA_PRODUCT_PATH DATA_PRODUCT_PATH must be a dot separated method name pointing to a method that takes two arguments: instance: The specific instance of theDataProductclass. filename: The filename to add to the path. The method must return a string representing the path to the file.The default structure is <target identifier>/<facility>/<filename>.
DataProductobjects not associated with a facility will save with ‘None’ as the facility.- Parameters:
instance (DataProduct) – The specific instance of the
DataProductclass.filename (str) – The filename to add to the path.
- Returns:
The TOM-style path of the file
- Return type:
str
- tom_dataproducts.models.find_fits_img_size(filename)[source]#
Returns the size of a FITS image, given a valid FITS image file
- Parameters:
filename (str) – The fully-qualified path of the FITS image file
- Returns:
Tuple of horizontal/vertical dimensions
- Return type:
tuple
- tom_dataproducts.models.is_fits_image_file(file)[source]#
Checks if a file is a valid FITS image by checking if any header contains ‘SCI’ in the ‘EXTNAME’.
- Parameters:
file – The file to be checked.
- Returns:
True if the file is a FITS image, False otherwise
- Return type:
boolean
- tom_dataproducts.models.try_parse_reduced_datum(
- data: dict,
Accepts unstructured data and attempts to create the correct ReducedDatum sublcass. If the heuristics fail, returns a generic ReducedDatum.