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

switch back certain configdb methods to allowing DISABLED instruments #32

Merged
merged 3 commits into from
Jun 17, 2019
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
31 changes: 17 additions & 14 deletions observation_portal/common/configdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,17 +221,16 @@ def is_valid_instrument(self, instrument_name):
return True
return False

def get_instruments(self, only_schedulable=False):
def get_instruments(self, exclude_states=None):
if not exclude_states:
exclude_states = []
site_data = self.get_site_data()
instruments = []
for site in site_data:
for enclosure in site['enclosure_set']:
for telescope in enclosure['telescope_set']:
for instrument in telescope['instrument_set']:
if (
(only_schedulable and self.is_schedulable(instrument))
or (not only_schedulable and self.is_active(instrument))
):
if instrument['state'].upper() not in exclude_states:
telescope_key = TelescopeKey(
site=site['code'],
enclosure=enclosure['code'],
Expand All @@ -250,8 +249,10 @@ def get_instrument_types_per_telescope(self, only_schedulable: bool = False) ->
Returns:
Available instrument types
"""
if only_schedulable:
exclude_states = ['DISABLED', 'ENABLED', 'COMMISSIONING']
telescope_instrument_types = {}
for instrument in self.get_instruments(only_schedulable=only_schedulable):
for instrument in self.get_instruments(exclude_states=exclude_states):
if instrument['telescope_key'] not in telescope_instrument_types:
telescope_instrument_types[instrument['telescope_key']] = []
instrument_type = instrument['science_camera']['camera_type']['code'].upper()
Expand All @@ -273,7 +274,7 @@ def get_instrument_names(
Available instrument names
"""
instrument_names = set()
for instrument in self.get_instruments():
for instrument in self.get_instruments(exclude_states=['DISABLED', ]):
if (
instrument['telescope_key'].site.lower() == site_code.lower()
and instrument['telescope_key'].enclosure.lower() == enclosure_code.lower()
Expand All @@ -283,7 +284,7 @@ def get_instrument_names(
instrument_names.add(instrument['science_camera']['code'].lower())
return instrument_names

def get_instrument_types_per_telescope_class(self, only_schedulable: bool = False) -> dict:
def get_instrument_types_per_telescope_class(self, exclude_states=None) -> dict:
"""Get a set of instrument types.

Instrument types are returned by telescope class (0m4, 1m0, etc...)
Expand All @@ -294,7 +295,7 @@ def get_instrument_types_per_telescope_class(self, only_schedulable: bool = Fals
Instrument types separated by class
"""
telescope_instrument_types = {}
for instrument in self.get_instruments(only_schedulable=only_schedulable):
for instrument in self.get_instruments(exclude_states=exclude_states):
tel_code = instrument['telescope_key'].telescope[:3]
if tel_code not in telescope_instrument_types:
telescope_instrument_types[tel_code] = set()
Expand All @@ -310,8 +311,10 @@ def get_telescopes_per_instrument_type(self, instrument_type: str, only_schedula
Returns:
Telescope keys
"""
if only_schedulable:
exclude_states = ['DISABLED', 'ENABLED', 'COMMISSIONING']
instrument_telescopes = set()
for instrument in self.get_instruments(only_schedulable=only_schedulable):
for instrument in self.get_instruments(exclude_states=exclude_states):
if instrument['science_camera']['camera_type']['code'].upper() == instrument_type:
instrument_telescopes.add(instrument['telescope_key'])
return instrument_telescopes
Expand All @@ -332,7 +335,7 @@ def get_optical_elements(self, instrument_type: str) -> dict:
Available optical elements
"""
optical_elements = {}
for instrument in self.get_instruments():
for instrument in self.get_instruments(exclude_states=['DISABLED', ]):
if instrument_type.upper() == instrument['science_camera']['camera_type']['code'].upper():
for optical_element_group in instrument['science_camera']['optical_element_groups']:
optical_elements[optical_element_group['type']] = []
Expand Down Expand Up @@ -467,7 +470,7 @@ def get_active_instrument_types(self, location: dict) -> set:
Available instrument_types (i.e. 1M0-SCICAM-SBIG, etc.)
"""
instrument_types = set()
for instrument in self.get_instruments(only_schedulable=True):
for instrument in self.get_instruments(exclude_states=['DISABLED', 'ENABLED', 'COMMISSIONING']):
split_string = instrument['__str__'].lower().split('.')
if (location.get('site', '').lower() in split_string[0]
and location.get('enclosure', '').lower() in split_string[1]
Expand All @@ -477,14 +480,14 @@ def get_active_instrument_types(self, location: dict) -> set:
return instrument_types

def get_guider_for_instrument_name(self, instrument_name):
jnation3406 marked this conversation as resolved.
Show resolved Hide resolved
instruments = self.get_instruments(only_schedulable=False)
instruments = self.get_instruments(exclude_states=['DISABLED'])
for instrument in instruments:
if instrument['code'].lower() == instrument_name.lower():
return instrument['autoguider_camera']['code'].lower()
raise ConfigDBException(_(f'Instrument not found: {instrument_name}'))

def is_valid_guider_for_instrument_name(self, instrument_name, guide_camera_name):
instruments = self.get_instruments(only_schedulable=False)
instruments = self.get_instruments(exclude_states=['DISABLED'])
for instrument in instruments:
if instrument['code'].upper() == instrument_name.upper():
if instrument['autoguider_camera']['code'].lower() == guide_camera_name.lower():
Expand Down
2 changes: 0 additions & 2 deletions observation_portal/common/test_data/configdb.json
Original file line number Diff line number Diff line change
Expand Up @@ -804,7 +804,6 @@
"horizon": 15.0,
"ha_limit_pos": 4.6,
"ha_limit_neg": -4.6,
"ha_limit_neg": -4.6,
"slew_rate": 0.0,
"minimum_slew_overhead": 2.0,
"maximum_slew_overhead": 2.0,
Expand Down Expand Up @@ -969,7 +968,6 @@
"horizon": 15.0,
"ha_limit_pos": 4.6,
"ha_limit_neg": -4.6,
"ha_limit_neg": -4.6,
"slew_rate": 0.0,
"minimum_slew_overhead": 2.0,
"maximum_slew_overhead": 2.0,
Expand Down
2 changes: 1 addition & 1 deletion observation_portal/sciapplications/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def proposal_code(self):

@property
def time_requested_by_class(self):
telescope_instrument_types = configdb.get_instrument_types_per_telescope_class()
telescope_instrument_types = configdb.get_instrument_types_per_telescope_class(exclude_states=['DISABLED'])
time_requests = {}
for tel_code, instrument_types in telescope_instrument_types.items():
time_requests[tel_code] = sum(
Expand Down