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

Tickets/preops 1256 #198

Merged
merged 4 commits into from
Jun 22, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 24 additions & 0 deletions rubin_sim/scheduler/basis_functions/basis_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,18 @@ def __call__(self, conditions, **kwargs):
self.value = self._calc_value(conditions, **kwargs)
return self.value

def label(self):
"""Creata a label for this basis function.

Returns
-------
label : `str`
A string suitable for labeling the basis function in a plot or table.
"""

label = self.__class__.__name__.replace("_basis_function", "")
return label


class Constant_basis_function(Base_basis_function):
"""Just add a constant"""
Expand Down Expand Up @@ -1192,6 +1204,18 @@ def _calc_value(self, conditions, indx=None):
result = -conditions.slewtime / self.maxtime
return result

def label(self):
"""Creata a label for this basis function.

Returns
-------
label : `str`
A string suitable for labeling the basis function in a plot or table.
"""

label = f"{self.__class__.__name__.replace('_basis_function', '')} {self.maxtime} {self.filtername}"
return label


class Aggressive_Slewtime_basis_function(Base_basis_function):
"""Reward slews that take little time
Expand Down
153 changes: 153 additions & 0 deletions rubin_sim/scheduler/features/conditions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from io import StringIO
import numpy as np
import pandas as pd
from rubin_sim.utils import (
_approx_RaDec2AltAz,
Site,
Expand Down Expand Up @@ -474,3 +476,154 @@ def season(self, modulo=None, max_season=None, season_length=365.25, floor=True)
self._season = None

return self._season

def __repr__(self):
return f"<{self.__class__.__name__} mjd_start='{self.mjd_start}' at {hex(id(self))}>"

def __str__(self):
# If dependencies of to_markdown are not installed, fall back on repr
try:
pd.DataFrame().to_markdown()
except ImportError:
return repr(self)

output = StringIO()
print(f"{self.__class__.__qualname__} at {hex(id(self))}", file=output)
print("============================", file=output)
print("nside: ", self.nside, file=output)
print("site: ", self.site.name, file=output)
print("exptime: ", self.exptime, file=output)
print("lmst: ", self.lmst, file=output)
print("season_offset: ", self.season_offset, file=output)
print("sun_RA_start: ", self.sun_RA_start, file=output)
print("clouds: ", self.clouds, file=output)
print("current_filter: ", self.current_filter, file=output)
print("mounted_filters: ", self.mounted_filters, file=output)
print("night: ", self.night, file=output)
print("wind_speed: ", self.wind_speed, file=output)
print("wind_direction: ", self.wind_direction, file=output)
print(
"len(scheduled_observations): ",
len(self.scheduled_observations),
file=output,
)
print("len(queue): ", len(self.queue), file=output)
print("moonPhase: ", self.moonPhase, file=output)
print("bulk_cloud: ", self.bulk_cloud, file=output)
print("targets_of_opportunity: ", self.targets_of_opportunity, file=output)
print("season_modulo: ", self.season_modulo, file=output)
print("season_max_season: ", self.season_max_season, file=output)
print("season_length: ", self.season_length, file=output)
print("season_floor: ", self.season_floor, file=output)
print("cumulative_azimuth_rad: ", self.cumulative_azimuth_rad, file=output)

positions = [
{
"name": "sun",
"alt": self.sunAlt,
"az": self.sunAz,
"RA": self.sunRA,
"decl": self.sunDec,
}
]
positions.append(
{
"name": "moon",
"alt": self.moonAlt,
"az": self.moonAz,
"RA": self.moonRA,
"decl": self.moonDec,
}
)
for planet_name in ("venus", "mars", "jupiter", "saturn"):
positions.append(
{
"name": planet_name,
"RA": np.asscalar(self.planet_positions[planet_name + "_RA"]),
"decl": np.asscalar(self.planet_positions[planet_name + "_dec"]),
}
)
positions.append(
{
"name": "telescope",
"alt": self.telAlt,
"az": self.telAz,
"RA": self.telRA,
"decl": self.telDec,
"rot": self.rotTelPos,
}
)
positions = pd.DataFrame(positions).set_index("name")
print(file=output)
print("Positions (radians)", file=output)
print("-------------------", file=output)
print(positions.to_markdown(), file=output)

positions_deg = np.degrees(positions)
print(file=output)
print("Positions (degrees)", file=output)
print("-------------------", file=output)
print(positions_deg.to_markdown(), file=output)

events = (
"mjd_start",
"mjd",
"sunset",
"sun_n12_setting",
"sun_n18_setting",
"sun_n18_rising",
"sun_n12_rising",
"sunrise",
"moonrise",
"moonset",
"sun_0_setting",
"sun_0_rising",
)
event_rows = []
for event in events:
mjd = getattr(self, event)
time = pd.to_datetime(mjd + 2400000.5, unit="D", origin="julian")
event_rows.append({"event": event, "MJD": mjd, "date": time})
event_df = pd.DataFrame(event_rows).set_index("event").sort_values(by="MJD")
print("", file=output)
print("Events", file=output)
print("------", file=output)
print(event_df.to_markdown(), file=output)

map_stats = []
for map_name in ("ra", "dec", "slewtime", "airmass"):
values = getattr(self, map_name)
map_stats.append(
{
"map": map_name,
"nside": hp.npix2nside(len(values)),
"min": np.nanmin(values),
"max": np.nanmax(values),
"median": np.nanmedian(values),
}
)

for base_map_name in ("skybrightness", "FWHMeff"):
for band in "ugrizy":
values = getattr(self, base_map_name)[band]
map_name = f"{base_map_name}_{band}"
map_stats.append(
{
"map": map_name,
"nside": hp.npix2nside(len(values)),
"min": np.nanmin(values),
"max": np.nanmax(values),
"median": np.nanmedian(values),
}
)
maps_df = pd.DataFrame(map_stats).set_index("map")
print("", file=output)
print("Maps", file=output)
print("----", file=output)
print(maps_df.to_markdown(), file=output)

result = output.getvalue()
return result

def _repr_markdown_(self):
return str(self)