Skip to content

Commit

Permalink
Update with new ToO model (#66)
Browse files Browse the repository at this point in the history
* Update with new ToO model

* Use set not list
  • Loading branch information
robertdstein authored Feb 27, 2024
1 parent bd2ac9a commit 5359417
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 12 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "wintertoo"
version = "1.3.2"
version = "1.4.0"
description = ""
authors = [
{name = "Robert Stein", email = "[email protected]"},
Expand Down
2 changes: 2 additions & 0 deletions tests/test_schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ def test_generate_schedule(self):
too=SummerRaDecToO(
ra_deg=173.7056754,
dec_deg=11.253441,
total_exposure_time=100.0,
n_dither=1,
),
program=program,
)
Expand Down
2 changes: 1 addition & 1 deletion tests/testdata/test_schedule.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"targName":{"0":null,"1":null,"2":null,"3":null},"raDeg":{"0":173.7056754,"1":173.7056754,"2":173.7056754,"3":173.7056754},"decDeg":{"0":11.253441,"1":11.253441,"2":11.253441,"3":11.253441},"fieldID":{"0":999999999,"1":999999999,"2":999999999,"3":999999999},"filter":{"0":"u","1":"g","2":"r","3":"i"},"visitExpTime":{"0":30.0,"1":30.0,"2":30.0,"3":30.0},"priority":{"0":50.0,"1":50.0,"2":50.0,"3":50.0},"progPI":{"0":"Stein","1":"Stein","2":"Stein","3":"Stein"},"progName":{"0":"2021A000","1":"2021A000","2":"2021A000","3":"2021A000"},"progID":{"0":1,"1":1,"2":1,"3":1},"validStart":{"0":62721.1894969287,"1":62721.1894969287,"2":62721.1894969287,"3":62721.1894969287},"validStop":{"0":62722.1894969452,"1":62722.1894969452,"2":62722.1894969452,"3":62722.1894969452},"observed":{"0":false,"1":false,"2":false,"3":false},"maxAirmass":{"0":2.0,"1":2.0,"2":2.0,"3":2.0},"ditherNumber":{"0":1,"1":1,"2":1,"3":1},"ditherStepSize":{"0":30.0,"1":30.0,"2":30.0,"3":30.0},"bestDetector":{"0":true,"1":true,"2":true,"3":true},"obsHistID":{"0":0,"1":1,"2":2,"3":3}}
{"targName":{"0":null,"1":null,"2":null,"3":null},"raDeg":{"0":173.7056754,"1":173.7056754,"2":173.7056754,"3":173.7056754},"decDeg":{"0":11.253441,"1":11.253441,"2":11.253441,"3":11.253441},"fieldID":{"0":999999999,"1":999999999,"2":999999999,"3":999999999},"filter":{"0":"u","1":"g","2":"r","3":"i"},"visitExpTime":{"0":960.0,"1":960.0,"2":960.0,"3":960.0},"singleExpTime":{"0":120.0,"1":120.0,"2":120.0,"3":120.0},"priority":{"0":50.0,"1":50.0,"2":50.0,"3":50.0},"progPI":{"0":"Stein","1":"Stein","2":"Stein","3":"Stein"},"progName":{"0":"2021A000","1":"2021A000","2":"2021A000","3":"2021A000"},"progID":{"0":1,"1":1,"2":1,"3":1},"validStart":{"0":62721.1894969287,"1":62721.1894969287,"2":62721.1894969287,"3":62721.1894969287},"validStop":{"0":62722.1894969452,"1":62722.1894969452,"2":62722.1894969452,"3":62722.1894969452},"observed":{"0":false,"1":false,"2":false,"3":false},"maxAirmass":{"0":2.0,"1":2.0,"2":2.0,"3":2.0},"ditherNumber":{"0":8,"1":8,"2":8,"3":8},"ditherStepSize":{"0":30.0,"1":30.0,"2":30.0,"3":30.0},"bestDetector":{"0":true,"1":true,"2":true,"3":true},"obsHistID":{"0":0,"1":1,"2":2,"3":3}}
4 changes: 2 additions & 2 deletions wintertoo/data/observing_request_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"raDeg": {"type": "number", "comment": "Degrees (decimal)"},
"decDeg": {"type": "number", "comment": "Degrees (decimal)"},
"filter": {"type": "string", "comment": "'u'/'g'/'r'/'i'/'Y'/'J'/'H'/'dark'"},
"visitExpTime": {"type": "number", "comment": "Total observation time (seconds)", "default": 30.0},
"visitExpTime": {"type": "number", "comment": "Total observation time (seconds)", "default": 960.0},
"priority": {"type": "number", "comment": "Priority of observation"},
"progPI": {"type": "string", "comment": "PI of observation"},
"progID": {"type": "integer", "comment": "Between 0 and 4 (0-Calibration, 1-Survey, 2-MIT, 3-Caltech, 4-Engineering)"},
Expand All @@ -14,7 +14,7 @@
"validStop": {"type": "number", "comment": "Format: MJD"},
"observed": {"anyOf": [{"type": "boolean", "default": false}, {"type" : "integer", "minimum" : 0, "maximum" : 1}]},
"maxAirmass": {"type": "number", "comment": "Maximum airmass for observation", "default": 2.0},
"ditherNumber": {"type": "integer", "default": 1},
"ditherNumber": {"type": "integer", "default": 8},
"ditherStepSize": {"type": "number", "comment": "arcsec", "default": 30.0},
"fieldID": {"type": "integer", "default": 999999999},
"targName": {"type": ["string", "null"], "comment": "Target name e.g. GW170817", "default": null},
Expand Down
32 changes: 28 additions & 4 deletions wintertoo/models/too.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@
from typing import List, Optional, Union

from astropy.time import Time
from pydantic import BaseModel, ConfigDict, Field, model_validator
from pydantic import (
AliasChoices,
BaseModel,
ConfigDict,
Field,
computed_field,
model_validator,
)

from wintertoo.data import (
MAX_TARGNAME_LEN,
Expand Down Expand Up @@ -39,15 +46,21 @@ class ToORequest(BaseModel):
examples=["SN2021abc", "ZTF19aapreis"],
default=get_default_value("targName"),
)
t_exp: float = Field(
total_exposure_time: float = Field(
default=get_default_value("visitExpTime"),
title="Combined Exposure Time across dithers (s)",
ge=1.0,
validation_alias=AliasChoices("total_exposure_time", "t_exp"),
)
n_exp: int = Field(default=1, ge=1, title="Number of dither sets")
n_dither: int = Field(
default=get_default_value("ditherNumber"), ge=1, title="Number of dithers"
)
n_repetitions: int = Field(
default=1,
ge=1,
title="Number of repeated dither sets",
validation_alias=AliasChoices("n_repetitions", "n_exp"),
)
dither_distance: float = Field(
get_default_value("ditherStepSize"), ge=0.0, title="dither distance (arcsec)"
)
Expand All @@ -69,6 +82,17 @@ class ToORequest(BaseModel):
title="Place ra/dec at the center of the best detector",
)

@computed_field
@property
def single_exposure_time(self) -> float:
"""
Computed field to get the exposure time per dither.
Equivalent to total_exposure_time/n_dither
:return: Exposure time per dither
"""
return self.total_exposure_time / self.n_dither

@model_validator(mode="after")
def validate_end_time(self):
"""
Expand All @@ -93,7 +117,7 @@ def validate_t_exp(self):
:return: Validated total exposure time per dither set
"""
n_dithers = self.n_dither
t_exp = self.t_exp
t_exp = self.total_exposure_time
t_per_dither = t_exp / n_dithers

if t_per_dither > MAX_EXPOSURE_TIME:
Expand Down
16 changes: 12 additions & 4 deletions wintertoo/schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,15 @@ def make_schedule(

for too in toos:
for filter_name in too.filters:
for _ in range(too.n_exp):
for _ in range(too.n_repetitions):
new = {
"targName": too.target_name,
"raDeg": too.ra_deg,
"decDeg": too.dec_deg,
"fieldID": too.field_id,
"filter": filter_name,
"visitExpTime": too.t_exp,
"visitExpTime": too.total_exposure_time,
"singleExpTime": too.single_exposure_time,
"priority": too.target_priority,
"progPI": program.pi_name,
"progName": program.progname,
Expand Down Expand Up @@ -121,7 +122,10 @@ def schedule_ra_dec(
else:
field_id = get_default_value("fieldID")

full_request = FullTooRequest(field_id=field_id, **too.model_dump())
full_request = FullTooRequest(
field_id=field_id,
**too.model_dump(exclude=set(too.model_computed_fields.keys())),
)

schedule = make_schedule(
toos=[full_request],
Expand Down Expand Up @@ -152,7 +156,11 @@ def schedule_field(
ra_deg = float(field_details["RA"].iloc[0])
dec_deg = float(field_details["Dec"].iloc[0])

full_request = FullTooRequest(ra_deg=ra_deg, dec_deg=dec_deg, **too.model_dump())
full_request = FullTooRequest(
ra_deg=ra_deg,
dec_deg=dec_deg,
**too.model_dump(exclude=set(too.model_computed_fields.keys())),
)

schedule = make_schedule(
toos=[full_request],
Expand Down

0 comments on commit 5359417

Please sign in to comment.