Skip to content

Commit

Permalink
Fixes to schedtel table writer and transition block included in table…
Browse files Browse the repository at this point in the history
… now
  • Loading branch information
WWGolay committed Dec 20, 2023
1 parent a2c4794 commit 5643bd5
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 115 deletions.
4 changes: 3 additions & 1 deletion pyscope/telrun/sch.py
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,8 @@ def read(
final_fname = f"{fname}_{j}"
else:
final_fname = f"{fname}"
temp_id = astrotime.Time.now()
temp_id.format = "mjd"
blocks.append(
astroplan.ObservingBlock(
target=obj,
Expand All @@ -867,7 +869,7 @@ def read(
"pm_dec": pm_dec,
"comment": comment,
"sch": filename.split("/")[-1].split(".")[0],
"ID": astrotime.Time.now(),
"ID": temp_id,
"status": "U",
"message": "Unscheduled",
"sched_time": None,
Expand Down
138 changes: 49 additions & 89 deletions pyscope/telrun/schedtab.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,76 +31,84 @@ def blocks_to_table(observing_blocks):

unscheduled_blocks_mask = np.array(
[
type(block) is astroplan.ObservingBlock and block.start_time is None
hasattr(block, "target") and block.start_time is None
for block in observing_blocks
]
)

open_slots_mask = np.array(
[type(block) is astroplan.Slot for block in observing_blocks]
[not hasattr(block, "target") for block in observing_blocks]
)

t["ID"] = np.ma.array(
[
block.configuration["ID"]
if hasattr(block, "target")
else astrotime.Time(0, format="mjd")
for block in observing_blocks
],
mask=open_slots_mask,
)

# Populate simple columns
t["name"] = [
block.name
if type(block) is astroplan.ObservingBlock
if hasattr(block, "target")
else "TransitionBlock"
if type(block) is astroplan.TransitionBlock
if type(block) is not astroplan.Slot
else "EmptyBlock"
for block in observing_blocks
]

t["start_time"] = astrotime.Time(
np.ma.array(
[
block.start.jd
block.start.mjd
if type(block) is astroplan.Slot
else 0
if block.start_time is None
else block.start_time.jd
else block.start_time.mjd
for block in observing_blocks
],
mask=unscheduled_blocks_mask,
),
format="jd",
format="mjd",
)

t["end_time"] = astrotime.Time(
np.ma.array(
[
block.end.jd
block.end.mjd
if type(block) is astroplan.Slot
else 0
if block.end_time is None
else block.end_time.jd
else block.end_time.mjd
for block in observing_blocks
],
mask=unscheduled_blocks_mask,
),
format="jd",
format="mjd",
)

t["target"] = coord.SkyCoord(
[
block.target.to_string("hmsdms")
if type(block) is astroplan.ObservingBlock
if hasattr(block, "target")
else "0h0m0.0s -90d0m0.0s"
for block in observing_blocks
]
)

t["priority"] = np.ma.array(
[
block.priority if type(block) is astroplan.ObservingBlock else 0
block.priority if hasattr(block, "target") else 0
for block in observing_blocks
],
mask=open_slots_mask,
)

temp_list = [
block.configuration["observer"]
if type(block) is astroplan.ObservingBlock
else [""]
block.configuration["observer"] if hasattr(block, "target") else [""]
for block in observing_blocks
]
t["observer"] = np.ma.array(
Expand All @@ -109,88 +117,70 @@ def blocks_to_table(observing_blocks):

t["code"] = np.ma.array(
[
block.configuration["code"]
if type(block) is astroplan.ObservingBlock
else ""
block.configuration["code"] if hasattr(block, "target") else ""
for block in observing_blocks
],
mask=open_slots_mask,
)

t["title"] = np.ma.array(
[
block.configuration["title"]
if type(block) is astroplan.ObservingBlock
else ""
block.configuration["title"] if hasattr(block, "target") else ""
for block in observing_blocks
],
mask=open_slots_mask,
)

t["filename"] = np.ma.array(
[
block.configuration["filename"]
if type(block) is astroplan.ObservingBlock
else ""
block.configuration["filename"] if hasattr(block, "target") else ""
for block in observing_blocks
],
mask=open_slots_mask,
)

t["type"] = np.ma.array(
[
block.configuration["type"]
if type(block) is astroplan.ObservingBlock
else ""
block.configuration["type"] if hasattr(block, "target") else ""
for block in observing_blocks
],
mask=open_slots_mask,
)

t["backend"] = np.ma.array(
[
block.configuration["backend"]
if type(block) is astroplan.ObservingBlock
else ""
block.configuration["backend"] if hasattr(block, "target") else ""
for block in observing_blocks
],
mask=open_slots_mask,
)

t["filter"] = np.ma.array(
[
block.configuration["filter"]
if type(block) is astroplan.ObservingBlock
else ""
block.configuration["filter"] if hasattr(block, "target") else ""
for block in observing_blocks
],
mask=open_slots_mask,
)

t["exposure"] = np.ma.array(
[
block.configuration["exposure"]
if type(block) is astroplan.ObservingBlock
else 0
block.configuration["exposure"] if hasattr(block, "target") else 0
for block in observing_blocks
],
mask=open_slots_mask,
)

t["nexp"] = np.ma.array(
[
block.configuration["nexp"]
if type(block) is astroplan.ObservingBlock
else 0
block.configuration["nexp"] if hasattr(block, "target") else 0
for block in observing_blocks
],
mask=open_slots_mask,
)

temp_list = [
block.configuration["repositioning"]
if type(block) is astroplan.ObservingBlock
else (0, 0)
block.configuration["repositioning"] if hasattr(block, "target") else (0, 0)
for block in observing_blocks
]
t["repositioning"] = np.ma.array(
Expand All @@ -199,48 +189,38 @@ def blocks_to_table(observing_blocks):

t["shutter_state"] = np.ma.array(
[
block.configuration["shutter_state"]
if type(block) is astroplan.ObservingBlock
else False
block.configuration["shutter_state"] if hasattr(block, "target") else False
for block in observing_blocks
],
mask=open_slots_mask,
)

t["readout"] = np.ma.array(
[
block.configuration["readout"]
if type(block) is astroplan.ObservingBlock
else 0
block.configuration["readout"] if hasattr(block, "target") else 0
for block in observing_blocks
],
mask=open_slots_mask,
)

temp_list = [
block.configuration["binning"]
if type(block) is astroplan.ObservingBlock
else (1, 1)
block.configuration["binning"] if hasattr(block, "target") else (1, 1)
for block in observing_blocks
]
t["binning"] = np.ma.array(
temp_list, mask=_mask_expander(temp_list, open_slots_mask)
)

temp_list = [
block.configuration["frame_position"]
if type(block) is astroplan.ObservingBlock
else (0, 0)
block.configuration["frame_position"] if hasattr(block, "target") else (0, 0)
for block in observing_blocks
]
t["frame_position"] = np.ma.array(
temp_list, mask=_mask_expander(temp_list, open_slots_mask)
)

temp_list = [
block.configuration["frame_size"]
if type(block) is astroplan.ObservingBlock
else (0, 0)
block.configuration["frame_size"] if hasattr(block, "target") else (0, 0)
for block in observing_blocks
]
t["frame_size"] = np.ma.array(
Expand All @@ -250,7 +230,7 @@ def blocks_to_table(observing_blocks):
t["pm_ra_cosdec"] = np.ma.array(
[
block.configuration["pm_ra_cosdec"].to(u.arcsec / u.hour).value
if type(block) is astroplan.ObservingBlock
if hasattr(block, "target")
else 0
for block in observing_blocks
],
Expand All @@ -260,7 +240,7 @@ def blocks_to_table(observing_blocks):
t["pm_dec"] = np.ma.array(
[
block.configuration["pm_dec"].to(u.arcsec / u.hour).value
if type(block) is astroplan.ObservingBlock
if hasattr(block, "target")
else 0
for block in observing_blocks
],
Expand All @@ -269,49 +249,31 @@ def blocks_to_table(observing_blocks):

t["comment"] = np.ma.array(
[
block.configuration["comment"]
if type(block) is astroplan.ObservingBlock
else ""
block.configuration["comment"] if hasattr(block, "target") else ""
for block in observing_blocks
],
mask=open_slots_mask,
)

t["sch"] = np.ma.array(
[
block.configuration["sch"]
if type(block) is astroplan.ObservingBlock
else ""
for block in observing_blocks
],
mask=open_slots_mask,
)

t["ID"] = np.ma.array(
[
block.configuration["ID"]
if type(block) is astroplan.ObservingBlock
else astrotime.Time(0, format="jd")
block.configuration["sch"] if hasattr(block, "target") else ""
for block in observing_blocks
],
mask=open_slots_mask,
)

t["status"] = np.ma.array(
[
block.configuration["status"]
if type(block) is astroplan.ObservingBlock
else ""
block.configuration["status"] if hasattr(block, "target") else ""
for block in observing_blocks
],
mask=open_slots_mask,
)

t["message"] = np.ma.array(
[
block.configuration["message"]
if type(block) is astroplan.ObservingBlock
else ""
block.configuration["message"] if hasattr(block, "target") else ""
for block in observing_blocks
],
mask=open_slots_mask,
Expand All @@ -320,7 +282,7 @@ def blocks_to_table(observing_blocks):
t["sched_time"] = np.ma.array(
[
block.configuration["sched_time"]
if type(block) is astroplan.ObservingBlock
if hasattr(block, "target")
else astrotime.Time(0, format="jd")
for block in observing_blocks
],
Expand All @@ -333,9 +295,7 @@ def blocks_to_table(observing_blocks):
len(observing_blocks),
np.max(
[
len(block.constraints)
if type(block) is astroplan.ObservingBlock
else 0
len(block.constraints) if hasattr(block, "target") else 0
for block in observing_blocks
]
),
Expand All @@ -346,15 +306,13 @@ def blocks_to_table(observing_blocks):
constraint_list = np.full(
np.max(
[
len(block.constraints)
if type(block) is astroplan.ObservingBlock
else 0
len(block.constraints) if hasattr(block, "target") else 0
for block in observing_blocks
]
),
dict(),
)
if type(block) is astroplan.ObservingBlock:
if hasattr(block, "target"):
for constraint_num, constraint in enumerate(block.constraints):
if type(constraint) is astroplan.TimeConstraint:
constraint_dict = {
Expand Down Expand Up @@ -419,6 +377,8 @@ def blocks_to_table(observing_blocks):
constraints, mask=_mask_expander(constraints, open_slots_mask)
)

t.add_index("ID", unique=True)

return t


Expand Down
Loading

0 comments on commit 5643bd5

Please sign in to comment.