wintertoo 1.1.0__py3-none-any.whl → 1.3.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of wintertoo might be problematic. Click here for more details.

@@ -30,6 +30,11 @@ WINTER_SCIENCE_FILTERS = ["Y", "J", "Hs"]
30
30
  SUMMER_BASE_WIDTH = 0.26112
31
31
  WINTER_BASE_WIDTH = 1.0
32
32
 
33
+ MAX_TARGNAME_LEN = 30
34
+
35
+ WinterImageTypes = Literal["exposure", "raw", "science", "stack", "diff"]
36
+ DEFAULT_IMAGE_TYPE = "stack"
37
+
33
38
  PROGRAM_DB_HOST = "jagati.caltech.edu"
34
39
 
35
40
  too_schedule_config_path = data_dir.joinpath("observing_request_schema.json")
@@ -17,7 +17,8 @@
17
17
  "ditherNumber": {"type": "integer", "default": 1},
18
18
  "ditherStepSize": {"type": "number", "comment": "arcsec", "default": 30.0},
19
19
  "fieldID": {"type": "integer", "default": 999999999},
20
- "targName": {"type": ["string", "null"], "comment": "Target name e.g. GW170817"}
20
+ "targName": {"type": ["string", "null"], "comment": "Target name e.g. GW170817", "default": null},
21
+ "bestDetector": {"type": "boolean", "comment": "Center Ra/Dec of target on best detector", "default": true}
21
22
  },
22
23
  "required": [
23
24
  "obsHistID",
@@ -2,6 +2,13 @@
2
2
  Models for the wintertoo
3
3
  """
4
4
 
5
+ from wintertoo.models.image import (
6
+ ConeImageQuery,
7
+ ImagePath,
8
+ ProgramImageQuery,
9
+ RectangleImageQuery,
10
+ TargetImageQuery,
11
+ )
5
12
  from wintertoo.models.program import Program, ProgramCredentials
6
13
  from wintertoo.models.too import (
7
14
  AllTooClasses,
wintertoo/models/image.py CHANGED
@@ -2,53 +2,80 @@
2
2
  Base models for image queries
3
3
  """
4
4
 
5
- from typing import Literal
5
+ from typing import Optional
6
6
 
7
7
  from astropy import units as u
8
8
  from astropy.time import Time
9
9
  from pydantic import BaseModel, Field, model_validator
10
10
 
11
+ from wintertoo.data import DEFAULT_IMAGE_TYPE, MAX_TARGNAME_LEN, WinterImageTypes
11
12
  from wintertoo.errors import WinterValidationError
12
- from wintertoo.models import ProgramCredentials
13
13
  from wintertoo.utils import get_date
14
14
 
15
15
 
16
- class BaseImageQuery(BaseModel):
16
+ class ImagePath(BaseModel):
17
+ """
18
+ Base model for image paths
19
+ """
20
+
21
+ path: str = Field(title="Path to image", min_length=1, example="path/to/image.fits")
22
+
23
+
24
+ class ProgramImageQuery(BaseModel):
17
25
  """
18
26
  Base model for image queries
19
27
  """
20
28
 
21
- program_list: list[ProgramCredentials] = Field(
22
- title="List of programs to search for", min_length=1
29
+ program_name: str = Field(
30
+ title="Program to search for", min_length=1, examples=["2020A000", "2021B001"]
23
31
  )
24
32
  start_date: int = Field(
25
33
  title="Start date for images",
26
34
  le=get_date(Time.now()),
27
35
  default=get_date(Time.now() - 30.0 * u.day),
36
+ examples=[get_date(Time.now() - 30.0 * u.day), "20230601"],
28
37
  )
29
38
  end_date: int = Field(
30
39
  title="End date for images",
31
40
  le=get_date(Time.now()),
32
41
  default=get_date(Time.now()),
42
+ examples=[get_date(Time.now() - 30.0 * u.day), get_date(Time.now())],
33
43
  )
34
- kind: Literal["raw", "science", "diff"] = Field(
35
- default="science", title="raw/science/diff"
44
+ kind: WinterImageTypes = Field(
45
+ default=DEFAULT_IMAGE_TYPE, example="raw/science/diff"
36
46
  )
37
47
 
38
48
 
39
- class RectangleImageQuery(BaseImageQuery):
49
+ class TargetImageQuery(ProgramImageQuery):
50
+ """
51
+ Model for image queries based on target name
52
+ """
53
+
54
+ target_name: Optional[str] = Field(
55
+ title="Name of target",
56
+ min_length=1,
57
+ max_length=MAX_TARGNAME_LEN,
58
+ examples=["SN2023ixf", "ZTF19aapreis"],
59
+ )
60
+
61
+
62
+ class RectangleImageQuery(ProgramImageQuery):
40
63
  """
41
64
  Model for image queries with a rectangular region
42
65
  """
43
66
 
44
- ra_min: float = Field(title="Minimum RA (degrees)", ge=0.0, le=360.0, default=0.0)
45
- ra_max: float = Field(title="Minimum RA (degrees)", ge=0.0, le=360.0, default=360.0)
67
+ ra_min: float = Field(
68
+ title="Minimum RA (degrees)", ge=0.0, le=360.0, examples=[90.0, 180.0]
69
+ )
70
+ ra_max: float = Field(
71
+ title="Minimum RA (degrees)", ge=0.0, le=360.0, examples=[90.0, 180.0]
72
+ )
46
73
 
47
74
  dec_min: float = Field(
48
- title="Minimum dec (degrees)", ge=-90.0, le=90.0, default=-90.0
75
+ title="Minimum dec (degrees)", ge=-90.0, le=90.0, examples=[-30.0, 10.0]
49
76
  )
50
77
  dec_max: float = Field(
51
- title="Minimum dec (degrees)", ge=-90.0, le=90.0, default=90.0
78
+ title="Minimum dec (degrees)", ge=-90.0, le=90.0, examples=[-30.0, 10.0]
52
79
  )
53
80
 
54
81
  @model_validator(mode="after")
@@ -72,13 +99,17 @@ class RectangleImageQuery(BaseImageQuery):
72
99
  return self
73
100
 
74
101
 
75
- class ConeImageQuery(BaseImageQuery):
102
+ class ConeImageQuery(ProgramImageQuery):
76
103
  """
77
104
  Model for image queries with a circular region
78
105
  """
79
106
 
80
- ra: float = Field(title="Center RA (degrees)", ge=0.0, le=360.0, default=0.0)
81
- dec: float = Field(title="Center dec (degrees)", ge=-90.0, le=90.0, default=-90.0)
107
+ ra: float = Field(
108
+ title="Center RA (degrees)", ge=0.0, le=360.0, examples=[90.0, 180.0]
109
+ )
110
+ dec: float = Field(
111
+ title="Center dec (degrees)", ge=-90.0, le=90.0, examples=[-30.0, 10.0]
112
+ )
82
113
  radius_deg: float = Field(
83
114
  title="Search radius in degrees", ge=0.0, le=90.0, default=1.0
84
115
  )
wintertoo/models/too.py CHANGED
@@ -8,6 +8,7 @@ from astropy.time import Time
8
8
  from pydantic import BaseModel, ConfigDict, Field, model_validator
9
9
 
10
10
  from wintertoo.data import (
11
+ MAX_TARGNAME_LEN,
11
12
  SUMMER_FILTERS,
12
13
  WINTER_SCIENCE_FILTERS,
13
14
  SummerFilters,
@@ -31,6 +32,13 @@ class ToORequest(BaseModel):
31
32
  title="Priority for target",
32
33
  ge=0.0,
33
34
  )
35
+ target_name: Optional[str] = Field(
36
+ title="Name of the target",
37
+ min_length=1,
38
+ max_length=MAX_TARGNAME_LEN,
39
+ examples=["SN2021abc", "ZTF19aapreis"],
40
+ default=get_default_value("targName"),
41
+ )
34
42
  t_exp: float = Field(
35
43
  default=get_default_value("visitExpTime"),
36
44
  title="Combined Exposure Time across dithers (s)",
@@ -56,6 +64,10 @@ class ToORequest(BaseModel):
56
64
  le=5,
57
65
  title="Allowed airmass range",
58
66
  )
67
+ use_best_detector: bool = Field(
68
+ default=get_default_value("bestDetector"),
69
+ title="Place ra/dec at the center of the best detector",
70
+ )
59
71
 
60
72
  @model_validator(mode="after")
61
73
  def validate_end_time(self):
@@ -116,9 +128,22 @@ class ObsWithRaDec(BaseModel):
116
128
  )
117
129
  use_field_grid: bool = Field(
118
130
  title="boolean whether to select nearest field in grid for central ra/dec",
119
- default=True,
131
+ default=False,
120
132
  )
121
133
 
134
+ @model_validator(mode="after")
135
+ def validate_field_best_detector(self):
136
+ """
137
+ Field validator to ensure that the end time is greater than the start time
138
+
139
+ :return: validated field value
140
+ """
141
+ if self.use_best_detector & self.use_field_grid:
142
+ raise WinterValidationError(
143
+ "Cannot use both use_best_detector and use_field_grid"
144
+ )
145
+ return self
146
+
122
147
 
123
148
  class ObsWithField(BaseModel):
124
149
  """
wintertoo/schedule.py CHANGED
@@ -45,6 +45,7 @@ def make_schedule(
45
45
  for filter_name in too.filters:
46
46
  for _ in range(too.n_exp):
47
47
  new = {
48
+ "targName": too.target_name,
48
49
  "raDeg": too.ra_deg,
49
50
  "decDeg": too.dec_deg,
50
51
  "fieldID": too.field_id,
@@ -60,6 +61,7 @@ def make_schedule(
60
61
  "maxAirmass": too.max_airmass,
61
62
  "ditherNumber": too.n_dither,
62
63
  "ditherStepSize": too.dither_distance,
64
+ "bestDetector": too.use_best_detector,
63
65
  }
64
66
  all_entries.append(new)
65
67
 
wintertoo/submit.py CHANGED
@@ -4,6 +4,7 @@ Module handling submission of ToO schedules
4
4
 
5
5
  import logging
6
6
  from datetime import datetime
7
+ from pathlib import Path
7
8
  from typing import Optional
8
9
 
9
10
  import pandas as pd
@@ -13,8 +14,27 @@ from wintertoo.validate import validate_schedule_df, validate_schedule_request
13
14
 
14
15
  logger = logging.getLogger(__name__)
15
16
 
17
+ FILE_DATE_FORMAT = "%Y_%m_%d_%H_%M_%S"
16
18
 
17
- def export_schedule_to_sqlitedb(schedule: pd.DataFrame, base_save_path: str):
19
+
20
+ def get_db_file_name(program_name: str, date: Optional[datetime] = None) -> str:
21
+ """
22
+ Function to get the name of a database file
23
+
24
+ :param program_name: Name of program
25
+ :param date: Date to use
26
+ :return: String of database file name
27
+ """
28
+
29
+ if date is None:
30
+ date = datetime.now()
31
+
32
+ strf_time = date.strftime(FILE_DATE_FORMAT)
33
+
34
+ return f"request_{program_name}_{strf_time}.db"
35
+
36
+
37
+ def export_schedule_to_sqlitedb(schedule: pd.DataFrame, base_save_path: str) -> Path:
18
38
  """
19
39
  Function to export a schedule to an sqlite db file
20
40
 
@@ -25,17 +45,26 @@ def export_schedule_to_sqlitedb(schedule: pd.DataFrame, base_save_path: str):
25
45
  # Validate format of schedule using json schema
26
46
  validate_schedule_df(schedule)
27
47
 
28
- date = datetime.now().strftime("%m_%d_%Y_%H_%s")
48
+ program_name = str(schedule["progName"].iloc[0])
49
+
50
+ schedule_file_name = get_db_file_name(program_name=program_name)
29
51
 
30
- save_path = f"{base_save_path}timed_requests_{date}.db"
52
+ save_path = Path(base_save_path).joinpath(schedule_file_name)
31
53
 
32
54
  logger.info(f"Saving to {save_path}")
33
55
 
34
56
  sqlite_table = "Summary"
35
57
 
58
+ if not save_path.parent.exists():
59
+ err = f"Parent directory {save_path.parent} does not exist"
60
+ logger.error(err)
61
+ raise ValueError(err)
62
+
36
63
  engine = create_engine(f"sqlite:///{save_path}?check_same_thread=False", echo=True)
37
64
  schedule.to_sql(sqlite_table, engine, if_exists="replace", index=False)
38
65
 
66
+ return save_path
67
+
39
68
 
40
69
  def submit_schedule( # pylint: disable=too-many-arguments
41
70
  schedule: pd.DataFrame,
@@ -47,7 +76,7 @@ def submit_schedule( # pylint: disable=too-many-arguments
47
76
  program_db_password: str,
48
77
  save_path: Optional[str] = None,
49
78
  submit_trigger: bool = True,
50
- ):
79
+ ) -> Optional[Path]:
51
80
  """
52
81
  Function to validate, and then optionally submit, a schedule
53
82
 
@@ -77,4 +106,6 @@ def submit_schedule( # pylint: disable=too-many-arguments
77
106
  logger.error(err)
78
107
  raise ValueError(err)
79
108
 
80
- export_schedule_to_sqlitedb(schedule, save_path)
109
+ return export_schedule_to_sqlitedb(schedule, save_path)
110
+
111
+ return None
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: wintertoo
3
- Version: 1.1.0
3
+ Version: 1.3.0
4
4
  Author-email: Robert Stein <rdstein@caltech.edu>, Danielle Frostig <frostig@mit.edu>, Viraj Karambelkar <viraj@astro.caltech.edu>
5
5
  License: MIT
6
6
  Project-URL: homepage, https://github.com/winter-telescope/wintertoo
@@ -0,0 +1,21 @@
1
+ wintertoo/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ wintertoo/database.py,sha256=Ng8qsnDN3p4q-hXRgsHvElzr3k_8H14vq3-C2XChkr8,3020
3
+ wintertoo/errors.py,sha256=iAFcy0z3A3bCnkJmAt_P-77fPaPHFGS1JbrK6O2dCEM,223
4
+ wintertoo/fields.py,sha256=TDSOwJeR4UvfzKQCaIqoPLv0hSU_73TZwQcZ2FbnO8Q,6029
5
+ wintertoo/schedule.py,sha256=Ll_8udFyn14uq3cVri9tVbsz6svluhkX2XXs8JFtLUU,5584
6
+ wintertoo/submit.py,sha256=kd6_aziOf5QcemsyyhSRSnbXlLj8OWsY1_Gj0ZXsUuo,3201
7
+ wintertoo/utils.py,sha256=BWgBZoSX5xfqURb2Nkvf3i6A_IcVYU2SoXFvp6ez7Xc,3306
8
+ wintertoo/validate.py,sha256=YpSABluVXxl33j_ht7TwfC-0SlN4IC0BnbbQiTwUk4c,10476
9
+ wintertoo/data/__init__.py,sha256=7998yomm2Kb0_687D82tjIhqwO-LOh7pru1sNUC1wI0,1594
10
+ wintertoo/data/observing_request_schema.json,sha256=R99sh_XEWVcUEP7eSGtFBw-SMa8M1CQRKfBESdyL9WU,1732
11
+ wintertoo/data/summer_fields.txt,sha256=5Sc7MBUacelzaq1KHSLmfAyZ3WB5YifMNwKRjBRBcRk,52684603
12
+ wintertoo/data/winter_fields.txt,sha256=TxySQTmJXCCgaf-oC1gzOYQb2Vr26KEKdJxqrZHHet0,3529364
13
+ wintertoo/models/__init__.py,sha256=c2GEbIHvOT34IhpiMyqA7Tn83hEmnwx6Q7BuxURp97k,379
14
+ wintertoo/models/image.py,sha256=up4ZnZ4oBkzmIb_8dLCikCWkVgShmv4DhHlhR7u5IS4,3220
15
+ wintertoo/models/program.py,sha256=mtewVnt7NxSK0hxX8aUO8qehEtOi_Cieli4voCCRh4I,1804
16
+ wintertoo/models/too.py,sha256=H9HctFxXL4UPqgjs7Xr8oW0iVLJ8BbLv9oza8HLzBW4,5513
17
+ wintertoo-1.3.0.dist-info/LICENSE,sha256=1-4yY2S7St-8Koy4JGheNG9QPkwff7831u2JITQ2oQs,1063
18
+ wintertoo-1.3.0.dist-info/METADATA,sha256=zKnTl6cA5h5DW740wEisYuT68K5a4Y9z2LKfdfHqHV0,2498
19
+ wintertoo-1.3.0.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
20
+ wintertoo-1.3.0.dist-info/top_level.txt,sha256=6SMjMBzaNrD77erdCiVcRTrPZ-x98SDX43akRjWj4T8,10
21
+ wintertoo-1.3.0.dist-info/RECORD,,
@@ -1,21 +0,0 @@
1
- wintertoo/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- wintertoo/database.py,sha256=Ng8qsnDN3p4q-hXRgsHvElzr3k_8H14vq3-C2XChkr8,3020
3
- wintertoo/errors.py,sha256=iAFcy0z3A3bCnkJmAt_P-77fPaPHFGS1JbrK6O2dCEM,223
4
- wintertoo/fields.py,sha256=TDSOwJeR4UvfzKQCaIqoPLv0hSU_73TZwQcZ2FbnO8Q,6029
5
- wintertoo/schedule.py,sha256=eZ7dGwZASXV_94QfZMPrDk0cjAkq17aqLPi7FPa67vs,5476
6
- wintertoo/submit.py,sha256=TSIx1AFrlNRLC7CCczSHOAwjOBM746sPmeAUUXPVXQ4,2411
7
- wintertoo/utils.py,sha256=BWgBZoSX5xfqURb2Nkvf3i6A_IcVYU2SoXFvp6ez7Xc,3306
8
- wintertoo/validate.py,sha256=YpSABluVXxl33j_ht7TwfC-0SlN4IC0BnbbQiTwUk4c,10476
9
- wintertoo/data/__init__.py,sha256=4wUZ12Y32rGlpoSWo9mky-0MRmgS3alzGf4as6Flfkw,1467
10
- wintertoo/data/observing_request_schema.json,sha256=D_RnemuUcSSVGe7PVyovcBq-R3B-ckmKNdz9-Zp3bVo,1602
11
- wintertoo/data/summer_fields.txt,sha256=5Sc7MBUacelzaq1KHSLmfAyZ3WB5YifMNwKRjBRBcRk,52684603
12
- wintertoo/data/winter_fields.txt,sha256=TxySQTmJXCCgaf-oC1gzOYQb2Vr26KEKdJxqrZHHet0,3529364
13
- wintertoo/models/__init__.py,sha256=TDWLfOnmRA894TIs3YoRLVtl7FBc8Mb2VlSGzjTSUao,235
14
- wintertoo/models/image.py,sha256=GmQWydKCZekUCMRiElPuAZo2NpvMoU0jD0N8hAYfn14,2453
15
- wintertoo/models/program.py,sha256=mtewVnt7NxSK0hxX8aUO8qehEtOi_Cieli4voCCRh4I,1804
16
- wintertoo/models/too.py,sha256=IosjV8ida1GoT7VddT05ujISFppIF8RHUvwZGBR0FkM,4665
17
- wintertoo-1.1.0.dist-info/LICENSE,sha256=1-4yY2S7St-8Koy4JGheNG9QPkwff7831u2JITQ2oQs,1063
18
- wintertoo-1.1.0.dist-info/METADATA,sha256=hoNO6J71dh9L_VhWGdr34hMXylNEP9F0cFNlUhZaT-Y,2498
19
- wintertoo-1.1.0.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
20
- wintertoo-1.1.0.dist-info/top_level.txt,sha256=6SMjMBzaNrD77erdCiVcRTrPZ-x98SDX43akRjWj4T8,10
21
- wintertoo-1.1.0.dist-info/RECORD,,