Skip to content
Snippets Groups Projects
Commit a1e1e8d2 authored by Roy de Goei's avatar Roy de Goei
Browse files

TMSS-687: Retrieve all stations function using the station common template

parent d5b7567d
Branches
Tags
1 merge request!399Resolve TMSS-687
......@@ -6,6 +6,8 @@ from astropy.coordinates import Angle, get_body
import astropy.time
from functools import lru_cache
from lofar.sas.tmss.tmss.tmssapp.models.calculations import StationTimeline
from lofar.sas.tmss.tmss.tmssapp.models.specification import CommonSchemaTemplate
from django.core.exceptions import ObjectDoesNotExist, MultipleObjectsReturned
import logging
......@@ -34,7 +36,7 @@ SUN_SET_RISE_PRECISION = 30
@lru_cache(maxsize=256, typed=False) # does not like lists, so use tuples to allow caching
def timestamps_and_stations_to_sun_rise_and_set(timestamps: tuple, stations: tuple, angle_to_horizon: Angle=SUN_SET_RISE_ANGLE_TO_HORIZON,
create_when_not_found=True) -> dict:
create_when_not_found=False) -> dict:
"""
Retrieve for given stations and given timestamps the sunrise/sunset/day/night data as dictionary
If station/timestamp is already calculated it will be retrieved from database otherwise it will be calculated
......@@ -42,6 +44,7 @@ def timestamps_and_stations_to_sun_rise_and_set(timestamps: tuple, stations: tup
Storing the pre-calculated data into a database makes retrieval faster.
TODO make a service to pre-calculate e.g. 1 year in advanced, currently only one week for all stations
during populate of testenvironment
TODO about the night.... when using a time in the timestamp
:param timestamps: tuple of datetimes, e.g. datetime(2020, 1, 1)
:param stations: tuple of station names, e.g. ("CS002")
:param angle_to_horizon: the angle between horizon and given coordinates for which rise and set times are returned
......@@ -284,9 +287,8 @@ def antennafields_for_antennaset_and_station(antennaset:str, station:str) -> lis
def get_all_stations():
"""
returns all possible stations.
TODO: should retrieved from the eneum values in common_schema_template-stations-1.json
or getting it the default values of station_groups of Core, Remote and International
"""
Retrieve station names from station template by getting the Dutch and International stations,
then you should have it all.
lst_stations = ["CS001", "CS002", "CS003", "CS004", "CS005", "CS006", "CS007", "CS011", "CS013", "CS017", "CS021",
"CS024", "CS026", "CS028", "CS030", "CS031", "CS032", "CS101", "CS103", "CS201", "CS301", "CS302",
"CS401", "CS501",
......@@ -294,4 +296,14 @@ def get_all_stations():
"RS503", "RS508", "RS509",
"DE601", "DE602", "DE603", "DE604", "DE605", "FR606", "SE607", "UK608", "DE609", "PL610", "PL611",
"PL612", "IE613", "LV614"]
"""
lst_stations = []
for station_group in ["Dutch", "International"]:
station_schema_template = CommonSchemaTemplate.objects.get(name="stations", version=1)
groups = station_schema_template.schema['definitions']['station_group']['anyOf']
try:
selected_group = next(g for g in groups if g['title'].lower() == station_group.lower())
except StopIteration:
raise ValueError('No station_group with name "%s" found in the JSON schema.' % station_group)
lst_stations.extend(selected_group['properties']['stations']['enum'][0])
return lst_stations
......@@ -489,7 +489,7 @@ def populate_calculations(nbr_days=3):
"""
Calculate a week of station timeline data of all stations
will take about a minute
TODO create a service which will do this continiously ?
TODO create a service which will do this continuously ?
"""
starttime = datetime.utcnow()
logger.info("Populate sunrise, sunset, day, night for ALL stations from today up to %d days" % nbr_days)
......@@ -498,6 +498,5 @@ def populate_calculations(nbr_days=3):
dt = datetime.combine(date.today(), datetime.min.time()) + timedelta(days=i)
lst_timestamps.append(dt)
# retrieving will create in db
timestamps_and_stations_to_sun_rise_and_set(tuple(lst_timestamps), tuple(get_all_stations()), create_when_not_found=True)
logger.info("Done in %.1fs", (datetime.utcnow()-starttime).total_seconds())
......@@ -30,7 +30,6 @@ import json
logger = logging.getLogger(__name__)
logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s', level=logging.INFO)
from lofar.sas.tmss.tmss.tmssapp.conversions import local_sidereal_time_for_utc_and_station, local_sidereal_time_for_utc_and_longitude
from lofar.common.test_utils import exit_with_skipped_code_if_skip_integration_tests
exit_with_skipped_code_if_skip_integration_tests()
......@@ -40,6 +39,10 @@ exit_with_skipped_code_if_skip_integration_tests()
# (ignore pycharm unused import statement, python unittests does use at RunTime the tmss_test_environment_unittest_setup module)
from lofar.sas.tmss.test.tmss_test_environment_unittest_setup import *
# The next import should be done after the 'tmss_test_environment_unittest_setup' magic !!!
from lofar.sas.tmss.tmss.tmssapp.conversions import local_sidereal_time_for_utc_and_station, local_sidereal_time_for_utc_and_longitude
class SiderealTime(unittest.TestCase):
def test_local_sidereal_time_for_utc_and_longitude_returns_correct_result(self):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment