Skip to content

Commit

Permalink
SCHED-451: Cleanup and fixing test cases (#304)
Browse files Browse the repository at this point in the history
* SCHED-451: WIP.

* SCHED-451: Cleanup done.

* SCHED-451: Fixing broken test case due to change to lucupy.
  • Loading branch information
sraaphorst authored Aug 29, 2023
1 parent 50814cc commit ef608b4
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 23 deletions.
2 changes: 0 additions & 2 deletions scheduler/core/calculations/groupinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ class GroupInfo:
6. Scoring based on how the wind affects the group.
7. A list of indices of the time slots across the nights as to when the group can be scheduled.
8. The score assigned to the group.
A group can be split if and only if it contains more than one observation.
"""
minimum_conditions: Conditions
is_splittable: bool
Expand Down
1 change: 0 additions & 1 deletion scheduler/core/components/optimizer/greedymax.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

from dataclasses import dataclass
from datetime import datetime, timedelta
from enum import Enum
from typing import final, Dict, FrozenSet, List, Optional, Tuple

import matplotlib.pyplot as plt
Expand Down
6 changes: 4 additions & 2 deletions scheduler/core/programprovider/ocs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -663,8 +663,10 @@ def autocorr_lag(x):
# TODO: For now, we focus on instruments, and GMOS FPUs and dispersers exclusively.
instrument_resources = frozenset([self._sources.origin.resource.lookup_resource(instrument)])
if 'GMOS' in instrument:
# Convert FPUs and dispersers to barcodes.
fpu_resources = frozenset([self._sources.origin.resource.fpu_to_barcode(site, fpu, instrument) for fpu in fpus])
# Convert FPUs and dispersers to barcodes. Note that None might be contained in some of these
# sets, but we filter below to remove them.
fpu_resources = frozenset([self._sources.origin.resource.fpu_to_barcode(site, fpu, instrument)
for fpu in fpus])
disperser_resources = frozenset([self._sources.origin.resource.lookup_resource(disperser.split('_')[0])
for disperser in dispersers])
resources = frozenset([r for r in fpu_resources | disperser_resources | instrument_resources])
Expand Down
24 changes: 14 additions & 10 deletions scheduler/services/resource/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
from openpyxl import load_workbook

from definitions import ROOT_DIR
from scheduler.core.meta import Singleton
from .filters import *
from .night_resource_configuration import NightConfiguration
from .google_drive_downloader import GoogleDriveDownloader
Expand Down Expand Up @@ -65,6 +64,11 @@ class ResourceService(ExternalService):
'PinholeC': 'PinholeC'
}})

# Constants for converting MDF to barcodes.
_instd = {'GMOS': '1', 'GMOS-N': '1', 'GMOS-S': '1', 'Flamingos2': '3'}
_semd = {'A': '0', 'B': '1'}
_progd = {'Q': '0', 'C': '1', 'L': '2', 'F': '3', 'S': '8', 'D': '9'}

def __init__(self, sites: FrozenSet[Site] = ALL_SITES):
self._all_resources: Dict[str, Resource] = {}
self._sites = sites
Expand Down Expand Up @@ -102,16 +106,16 @@ def __init__(self, sites: FrozenSet[Site] = ALL_SITES):
# The final output from this class: the configuration per night.
self._night_configurations: Dict[Site, Dict[date, NightConfiguration]] = {site: {} for site in self._sites}

@staticmethod
def _mdf_to_barcode(mdfname: str, inst: str) -> Resource:
def _mdf_to_barcode(self, mdfname: str, inst: str) -> Optional[Resource]:
"""Legacy MOS mask barcode convention"""
barcode = None
instd = {'GMOS': '1', 'GMOS-N': '1', 'GMOS-S': '1', 'Flamingos2': '3'}
semd = {'A': '0', 'B': '1'}
progd = {'Q': '0', 'C': '1', 'L': '2', 'F': '3', 'S': '8', 'D': '9'}
if inst in instd.keys():
barcode = instd[inst] + semd[mdfname[6]] + progd[mdfname[7]] + mdfname[-6:-3] + mdfname[-2:]
return Resource(id=barcode)
if inst in ResourceService._instd.keys():
# Collect the components of the string from the MDF name.
inst_id = ResourceService._instd[inst]
sem_id = ResourceService._semd[mdfname[6]]
progtype_id = ResourceService._progd[mdfname[7]]
barcode = f'{inst_id}{sem_id}{progtype_id}{mdfname[-6:-3]}{mdfname[-2:]}'
return self.lookup_resource(barcode)

def _itcd_fpu_to_barcode_parser(self, r: List[str], site: Site) -> Set[str]:
return {self._itcd_fpu_to_barcode[site][r[0].strip()].id} | {i.strip() for i in r[1:]}
Expand Down Expand Up @@ -242,7 +246,7 @@ def _load_csv(self, site: Site,
the new date.
"""

def _process_file(f):
def _process_file(f) -> None:
reader = csv.reader(f, delimiter=',')
prev_row_date: Optional[date] = None

Expand Down
20 changes: 12 additions & 8 deletions tests/unit/scheduler/core/programprovider/ocs/test_ocs_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
from lucupy.helpers import dmsstr2deg
from lucupy.minimodel import (AndGroup, AndOption, Atom, Band, CloudCover, Conditions, Constraints, ElevationType,
GroupID, ImageQuality, Magnitude, MagnitudeBands, ObservationClass, ObservationID,
ObservationStatus, Priority, Program, ProgramID, ProgramMode, ProgramTypes, QAState,
Resource, ROOT_GROUP_ID, Semester, SemesterHalf, SetupTimeType, SiderealTarget, Site,
SkyBackground, TargetName, TargetType, TimeAccountingCode, TimeAllocation, TimingWindow,
TooType, WaterVapor, Wavelength)
ObservationMode, ObservationStatus, Priority, Program, ProgramID, ProgramMode,
ProgramTypes, QAState, Resource, ROOT_GROUP_ID, Semester, SemesterHalf, SetupTimeType,
SiderealTarget, Site, SkyBackground, TargetName, TargetType, TimeAccountingCode,
TimeAllocation, TimingWindow, TooType, WaterVapor, Wavelength)
from lucupy.observatory.gemini.geminiobservation import GeminiObservation
from lucupy.timeutils import sex2dec

Expand Down Expand Up @@ -118,7 +118,8 @@ def create_minimodel_program() -> Program:
qa_state=QAState.NONE,
guide_state=True,
resources=frozenset({gmosn, mirror}),
wavelengths=frozenset({Wavelength(0.475)})
wavelengths=frozenset({Wavelength(0.475)}),
obs_mode=ObservationMode.IMAGING
)
]

Expand Down Expand Up @@ -232,7 +233,8 @@ def create_minimodel_program() -> Program:
qa_state=QAState.NONE,
guide_state=True,
resources=frozenset({gnirs}),
wavelengths=frozenset({Wavelength(2.2)})
wavelengths=frozenset({Wavelength(2.2)}),
obs_mode=ObservationMode.IMAGING
)
]

Expand Down Expand Up @@ -351,7 +353,8 @@ def create_minimodel_program() -> Program:
qa_state=QAState.NONE,
guide_state=True,
resources=frozenset({gnirs}),
wavelengths=frozenset({Wavelength(2.2)})
wavelengths=frozenset({Wavelength(2.2)}),
obs_mode=ObservationMode.IMAGING
)
]

Expand Down Expand Up @@ -526,7 +529,8 @@ def create_minimodel_program() -> Program:
qa_state=QAState.NONE,
guide_state=True,
resources=frozenset({gmosn, mirror}),
wavelengths=frozenset({Wavelength(0.475)})
wavelengths=frozenset({Wavelength(0.475)}),
obs_mode=ObservationMode.IMAGING
)
]

Expand Down

0 comments on commit ef608b4

Please sign in to comment.