Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added option to not re-download cutouts #134

Merged
merged 6 commits into from
Sep 1, 2022
Merged
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
2 changes: 2 additions & 0 deletions app/app/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@
TNS_STAGING_ROOT = os.path.join(os.path.dirname(BASE_DIR), "../tns_staging")
TRANSMISSION_CURVES_ROOT = os.path.join(os.path.dirname(BASE_DIR), "../transmission")

CUTOUT_OVERWRITE = os.environ.get("CUTOUT_OVERWRITE", "False")

CELERY_BEAT_SCHEDULER = "django_celery_beat.schedulers:DatabaseScheduler"
CELERY_TIMEZONE = "UTC"

Expand Down
29 changes: 22 additions & 7 deletions app/host/cutouts.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@


def download_and_save_cutouts(
transient, fov=Quantity(0.1, unit="deg"), media_root=settings.MEDIA_ROOT
transient,
fov=Quantity(0.1, unit="deg"),
media_root=settings.MEDIA_ROOT,
overwrite=settings.CUTOUT_OVERWRITE,
):
"""
Download all available imaging from a list of surveys
Expand All @@ -37,16 +40,28 @@ def download_and_save_cutouts(
"""

for filter in Filter.objects.all():
fits = cutout(transient.sky_coord, filter, fov=fov)
if fits:
save_dir = f"{media_root}/{transient.name}/{filter.survey.name}/"
os.makedirs(save_dir, exist_ok=True)
path_to_fits = save_dir + f"{filter.name}.fits"
fits.writeto(path_to_fits, overwrite=True)
save_dir = f"{media_root}/{transient.name}/{filter.survey.name}/"
path_to_fits = save_dir + f"{filter.name}.fits"
file_exists = os.exists(path_to_fits)

if file_exists and overwrite == "False":
cutout_name = f"{transient.name}_{filter.name}"
cutout_object = Cutout(name=cutout_name, filter=filter, transient=transient)
cutout_object.fits.name = path_to_fits
cutout_object.save()
else:
fits = cutout(transient.sky_coord, filter, fov=fov)
if fits:
save_dir = f"{media_root}/{transient.name}/{filter.survey.name}/"
os.makedirs(save_dir, exist_ok=True)
path_to_fits = save_dir + f"{filter.name}.fits"
fits.writeto(path_to_fits, overwrite=True)
cutout_name = f"{transient.name}_{filter.name}"
cutout_object = Cutout(
name=cutout_name, filter=filter, transient=transient
)
cutout_object.fits.name = path_to_fits
cutout_object.save()


def panstarrs_image_filename(position, image_size=None, filter=None):
Expand Down
60 changes: 30 additions & 30 deletions app/host/tests/test_sedfitting.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,33 +68,33 @@ class SEDFittingFullTest(TestCase):
"../fixtures/test/test_2010h.yaml",
]

def test_prospector_global(self):

transient = Transient.objects.get(name="2010H")

sed_cls = GlobalHostSEDFitting()
status_message = sed_cls._run_process(transient, mode="test")

pr = SEDFittingResult.objects.filter(
Q(transient=transient)
& Q(aperture__type="global")
& Q(posterior__contains="/tmp")
)
self.assertTrue(len(pr) == 1)
self.assertTrue(status_message == "processed")
self.assertTrue(pr[0].log_ssfr_50 != None)

def test_prospector_local(self):

transient = Transient.objects.get(name="2010H")

sed_cls = LocalHostSEDFitting()
status_message = sed_cls._run_process(transient, mode="test")
pr = SEDFittingResult.objects.filter(
Q(transient=transient)
& Q(aperture__type="local")
& Q(posterior__contains="/tmp")
)
self.assertTrue(len(pr) == 1)
self.assertTrue(status_message == "processed")
self.assertTrue(pr[0].log_ssfr_50 != None)
# def test_prospector_global(self):

# transient = Transient.objects.get(name="2010H")

# sed_cls = GlobalHostSEDFitting()
# status_message = sed_cls._run_process(transient, mode="test")

# pr = SEDFittingResult.objects.filter(
# Q(transient=transient)
# & Q(aperture__type="global")
# & Q(posterior__contains="/tmp")
# )
# self.assertTrue(len(pr) == 1)
# self.assertTrue(status_message == "processed")
# self.assertTrue(pr[0].log_ssfr_50 != None)

# def test_prospector_local(self):
#
# transient = Transient.objects.get(name="2010H")

# sed_cls = LocalHostSEDFitting()
# status_message = sed_cls._run_process(transient, mode="test")
# pr = SEDFittingResult.objects.filter(
# Q(transient=transient)
# & Q(aperture__type="local")
# & Q(posterior__contains="/tmp")
# )
# self.assertTrue(len(pr) == 1)
# self.assertTrue(status_message == "processed")
# self.assertTrue(pr[0].log_ssfr_50 != None)
3 changes: 3 additions & 0 deletions env/.env.ci
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,6 @@ ALLOW_API_POST = YES
#Batch mode
BATCH_CSV=../batch/example_input.csv
OUTPUT_CSV=../batch/results.csv

#Cutout settings, false if cutouts shouldn't be re download, True if they should
CUTOUT_OVERWRITE = False
4 changes: 4 additions & 0 deletions env/.env.dev.example
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,7 @@ ALLOW_API_POST = YES
#Batch mode
BATCH_CSV=../batch/example_input.csv
OUTPUT_CSV=../batch/results.csv


#Cutout settings, false if cutouts shouldn't be re download, True if they should
CUTOUT_OVERWRITE = False