Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Generated by Django 5.2.16 on 2026-08-03 21:55

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('tom_dataproducts', '0017_spectroscopyreduceddatum_wavelength_unit'),
('tom_targets', '0030_alter_basetarget_slope'),
]

operations = [
migrations.RemoveConstraint(
model_name='astrometryreduceddatum',
name='unique_astrometry',
),
migrations.RemoveConstraint(
model_name='photometryreduceddatum',
name='unique_photometry',
),
migrations.RemoveConstraint(
model_name='spectroscopyreduceddatum',
name='unique_spectroscopy',
),
migrations.AddConstraint(
model_name='astrometryreduceddatum',
constraint=models.UniqueConstraint(fields=('target', 'timestamp', 'telescope', 'instrument', 'ra', 'dec'), name='unique_astrometry'),
),
migrations.AddConstraint(
model_name='photometryreduceddatum',
constraint=models.UniqueConstraint(fields=('target', 'bandpass', 'timestamp', 'limit', 'brightness', 'instrument'), name='unique_photometry'),
),
migrations.AddConstraint(
model_name='spectroscopyreduceddatum',
constraint=models.UniqueConstraint(fields=('target', 'timestamp', 'telescope', 'instrument', 'flux'), name='unique_spectroscopy'),
),
]
7 changes: 4 additions & 3 deletions tom_dataproducts/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,8 @@ class PhotometryReducedDatum(ReducedDatumCommon):
class Meta:
constraints = [
models.UniqueConstraint(
fields=["target", "bandpass", "timestamp"], name="unique_photometry"
fields=["target", "bandpass", "timestamp", "limit", "brightness", "instrument"],
name="unique_photometry"
)
]

Expand All @@ -470,7 +471,7 @@ class SpectroscopyReducedDatum(ReducedDatumCommon):
class Meta:
constraints = [
models.UniqueConstraint(
fields=["target", "timestamp", "telescope", "instrument"],
fields=["target", "timestamp", "telescope", "instrument", "flux"],
name="unique_spectroscopy",
)
]
Expand All @@ -487,7 +488,7 @@ class AstrometryReducedDatum(ReducedDatumCommon):
class Meta:
constraints = [
models.UniqueConstraint(
fields=["target", "timestamp", "telescope", "instrument"],
fields=["target", "timestamp", "telescope", "instrument", "ra", "dec"],
name="unique_astrometry",
)
]
Expand Down
24 changes: 14 additions & 10 deletions tom_dataservices/data_services/alerce.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from astropy.time import Time, TimezoneInfo
from django import forms
from django.core.cache import cache
from django.db.utils import IntegrityError

from tom_dataproducts.models import PhotometryReducedDatum
from tom_dataservices.dataservices import DataService, QueryServiceError
Expand Down Expand Up @@ -266,16 +267,19 @@ def create_reduced_datums_from_query(self, target, data=None, data_type="photome
if data:
for detection in data.get("detections", []):
mjd = Time(detection["mjd"], format="mjd", scale="utc")
reduced_datum, __ = PhotometryReducedDatum.objects.get_or_create(
timestamp=mjd.to_datetime(TimezoneInfo()),
target=target,
brightness=detection["magpsf"],
brightness_error=detection["sigmapsf"],
unit='mag',
bandpass=ALERCE_FILTERS[detection["fid"]],
defaults={'source_name': self.name}
)
reduced_datums.append(reduced_datum)
try:
reduced_datum, __ = PhotometryReducedDatum.objects.get_or_create(
timestamp=mjd.to_datetime(TimezoneInfo()),
target=target,
brightness=detection["magpsf"],
brightness_error=detection["sigmapsf"],
unit='mag',
bandpass=ALERCE_FILTERS[detection["fid"]],
defaults={'source_name': self.name}
)
reduced_datums.append(reduced_datum)
except IntegrityError as e:
raise QueryServiceError(f"Error importing ReducedDatum (target:{target} data:{detection}) -- {e}")

for non_detection in data.get("non_detections", []):
mjd = Time(non_detection["mjd"], format="mjd", scale="utc")
Expand Down
Loading