def test_get_airmass_for_target_2_ogg(self): time = datetime(2016, 5, 20, 20, 12, 32, 247312) airmasses = calculate_airmass_at_times([time], self.target_2, self.ogg_latitude, self.ogg_longitude, self.ogg_height) assert_equal(1, len(airmasses)) assert_almost_equal(1.33, airmasses[0], 2)
def test_get_airmass_for_target_3_cpt(self): time = datetime(2016, 5, 20, 3, 12, 32, 247312) airmasses = calculate_airmass_at_times([time], self.target_3, self.cpt_latitude, self.cpt_longitude, self.cpt_height) assert_equal(1, len(airmasses)) assert_almost_equal(1.52, airmasses[0], 2)
def test_get_airmass_for_target_2_ogg_fail(self): time = datetime(2016, 5, 20, 10, 12, 32, 247312) airmasses = calculate_airmass_at_times([time], self.target_2, self.ogg_latitude, self.ogg_longitude, self.ogg_height) assert_equal(1, len(airmasses)) # assert airmass is so high its not visible assert_greater(airmasses[0], 10)
def get_airmasses_for_request_at_sites(request_dict): instrument_type = request_dict['molecules'][0]['instrument_name'] constraints = request_dict['constraints'] site_data = configdb.get_sites_with_instrument_type_and_location( instrument_type=instrument_type, site_code=request_dict['location'].get('site'), observatory_code=request_dict['location'].get('observatory'), telescope_code=request_dict['location'].get('telescope')) rs_target = get_rise_set_target(request_dict['target']) data = {'airmass_data': {}} if request_dict['target']['type'].upper() != 'SATELLITE': for site_id, site_details in site_data.items(): night_times = [] site_lat = Angle(degrees=site_details['latitude']) site_lon = Angle(degrees=site_details['longitude']) site_alt = site_details['altitude'] intervals = get_rise_set_intervals(request_dict, site_id) for interval in intervals: night_times.extend([ time for time in date_range_from_interval( interval[0], interval[1], dt=timedelta(minutes=10)) ]) if len(night_times) > 0: if site_id not in data: data['airmass_data'][site_id] = {} data['airmass_data'][site_id]['times'] = [ time.strftime('%Y-%m-%dT%H:%M') for time in night_times ] data['airmass_data'][site_id][ 'airmasses'] = calculate_airmass_at_times( night_times, rs_target, site_lat, site_lon, site_alt) data['airmass_limit'] = constraints['max_airmass'] return data
def get_airmasses_for_request_at_sites(request_dict, is_staff=False): # TODO: Change to work with multiple instrument types and multiple constraints and multiple targets data = {'airmass_data': {}} instrument_type = request_dict['configurations'][0]['instrument_type'] constraints = request_dict['configurations'][0]['constraints'] target = request_dict['configurations'][0]['target'] target_type = str(target.get('type', '')).upper() only_schedulable = not (is_staff and ConfigDB.is_location_fully_set(request_dict.get('location', {}))) if target_type in ['ICRS', 'ORBITAL_ELEMENTS'] and TARGET_TYPE_HELPER_MAP[target_type](target).is_valid(): site_data = configdb.get_sites_with_instrument_type_and_location( instrument_type=instrument_type, site_code=request_dict['location'].get('site'), enclosure_code=request_dict['location'].get('enclosure'), telescope_code=request_dict['location'].get('telescope'), only_schedulable=only_schedulable ) rs_target = get_rise_set_target(target) for site_id, site_details in site_data.items(): night_times = [] site_lat = Angle(degrees=site_details['latitude']) site_lon = Angle(degrees=site_details['longitude']) site_alt = site_details['altitude'] intervals = get_filtered_rise_set_intervals_by_site(request_dict, site_id, is_staff=is_staff).get(site_id, []) for interval in intervals: night_times.extend( [time for time in date_range_from_interval(interval[0], interval[1], dt=timedelta(minutes=10))]) if len(night_times) > 0: if site_id not in data: data['airmass_data'][site_id] = {} data['airmass_data'][site_id]['times'] = [time.strftime('%Y-%m-%dT%H:%M') for time in night_times] data['airmass_data'][site_id]['airmasses'] = calculate_airmass_at_times( night_times, rs_target, site_lat, site_lon, site_alt ) data['airmass_limit'] = constraints['max_airmass'] return data
def get_airmasses_for_request_at_sites(request_dict, is_staff=False): data = { 'airmass_data': {}, } instrument_type = request_dict['configurations'][0]['instrument_type'] constraints = request_dict['configurations'][0]['constraints'] target = request_dict['configurations'][0]['target'] target_type = str(target.get('type', '')).upper() only_schedulable = not (is_staff and ConfigDB.is_location_fully_set( request_dict.get('location', {}))) if target_type in [ 'ICRS', 'ORBITAL_ELEMENTS' ] and TARGET_TYPE_HELPER_MAP[target_type](target).is_valid(): site_data = configdb.get_sites_with_instrument_type_and_location( instrument_type=instrument_type, site_code=request_dict['location'].get('site'), enclosure_code=request_dict['location'].get('enclosure'), telescope_code=request_dict['location'].get('telescope'), only_schedulable=only_schedulable) rs_target = get_rise_set_target(target) for site_id, site_details in site_data.items(): night_times = [] site_lat = Angle(degrees=site_details['latitude']) site_lon = Angle(degrees=site_details['longitude']) site_alt = site_details['altitude'] intervals = get_filtered_rise_set_intervals_by_site( request_dict, site_id, is_staff=is_staff).get(site_id, []) for interval in intervals: night_times.extend([ time for time in date_range_from_interval( interval[0], interval[1], dt=timedelta(minutes=10)) ]) if len(night_times) > 0: if site_id not in data: data['airmass_data'][site_id] = { 'times': [ time.strftime('%Y-%m-%dT%H:%M') for time in night_times ], } # Need to average airmass values for set of unique targets in request unique_targets_constraints = set([ json.dumps((configuration['target'], configuration['constraints'])) for configuration in request_dict['configurations'] ]) unique_count = len(unique_targets_constraints) max_airmass = 0.0 for target_constraints in unique_targets_constraints: (target, constraints) = json.loads(target_constraints) rs_target = get_rise_set_target(target) airmasses = calculate_airmass_at_times( night_times, rs_target, site_lat, site_lon, site_alt) if 'airmasses' in data['airmass_data'][site_id]: for index, airmass_value in enumerate(airmasses): data['airmass_data'][site_id]['airmasses'][ index] += airmass_value else: data['airmass_data'][site_id]['airmasses'] = airmasses max_airmass += constraints['max_airmass'] # Now we need to divide out the number of unique constraints/targets data['airmass_limit'] = max_airmass / unique_count data['airmass_data'][site_id]['airmasses'] = [ val / unique_count for val in data['airmass_data'][site_id]['airmasses'] ] return data