Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
LOFAR
Manage
Activity
Members
Labels
Plan
Issues
Wiki
Jira issues
Open Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
RadioObservatory
LOFAR
Commits
e240a579
Commit
e240a579
authored
1 year ago
by
Jorrit Schaap
Browse files
Options
Downloads
Patches
Plain Diff
TMSS-2865
: even more exception handling around astropy bug(s)
parent
0933aa8c
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
SAS/TMSS/backend/src/tmss/tmssapp/conversions.py
+14
-23
14 additions, 23 deletions
SAS/TMSS/backend/src/tmss/tmssapp/conversions.py
with
14 additions
and
23 deletions
SAS/TMSS/backend/src/tmss/tmssapp/conversions.py
+
14
−
23
View file @
e240a579
...
...
@@ -165,19 +165,11 @@ def timestamps_and_stations_to_sun_rise_and_set(timestamps: tuple, stations: tup
observer
=
create_astroplan_observer_for_station
(
station
)
for
timestamp
in
timestamps
:
# TODO: check if ALL stations/timestamps are in DB once.
# Do it now in a loop for each station/timestamp, because we might missing something
try
:
obj
=
StationTimeline
.
objects
.
get
(
station_name
=
station
,
timestamp
=
datetime
.
date
(
timestamp
))
station_timestamp_found
=
True
except
ObjectDoesNotExist
:
station_timestamp_found
=
False
if
station_timestamp_found
:
logger
.
debug
(
"
StationTimeline data found in DB for station=%s, timestamp=%s
"
%
(
station
,
timestamp
))
sunrise_dict
=
{
"
start
"
:
obj
.
sunrise_start
,
"
end
"
:
obj
.
sunrise_end
}
sunset_dict
=
{
"
start
"
:
obj
.
sunset_start
,
"
end
"
:
obj
.
sunset_end
}
e
lse
:
e
xcept
ObjectDoesNotExist
:
# Not found in database so calculate it
sunrise_dict
,
sunset_dict
=
calculate_and_get_sunrise_and_sunset_of_observer_day
(
observer
,
timestamp
,
angle_to_horizon
,
n_grid_points
=
n_grid_points
)
...
...
@@ -193,12 +185,11 @@ def timestamps_and_stations_to_sun_rise_and_set(timestamps: tuple, stations: tup
sunset_end
=
sunset_dict
[
'
end
'
])
logger
.
debug
(
"
StationTimeline %s calculated and created for station=%s, timestamp=%s
"
%
(
station_timeline
,
station
,
timestamp
))
except
IntegrityError
as
e
:
if
'
unique_station_time_line
'
in
str
(
e
):
logger
.
info
(
"
StationTimeline with station=%s and timestamp=%s already exists,
"
"
so not added to database
"
,
station
,
timestamp
)
else
:
raise
except
IntegrityError
:
# already exists in db
pass
except
Exception
as
e
:
logger
.
error
(
"
timestamps_and_stations_to_sun_rise_and_set: %s
"
,
str
(
e
))
# Create overall result
return_dict
.
setdefault
(
station
,
{})
...
...
@@ -299,8 +290,8 @@ def calculate_and_get_sunrise_and_sunset_of_observer_day(observer, timestamp: da
n_grid_points
=
n_grid_points
)
try
:
sunrise_dict
[
'
start
'
]
=
round_to_second_precision
(
sunrise_start
.
to_datetime
())
except
ValueError
:
# sun never rises
except
(
ValueError
,
AttributeError
)
:
# sun never rises
/ astropy bug
sun_body
=
astropy
.
coordinates
.
get_body
(
"
sun
"
,
Time
(
noon
),
observer
.
location
)
if
observer
.
target_is_up
(
target
=
sun_body
,
time
=
Time
(
noon
),
horizon
=-
angle_to_horizon
):
sunrise_dict
[
'
start
'
]
=
prev_midnight
...
...
@@ -311,8 +302,8 @@ def calculate_and_get_sunrise_and_sunset_of_observer_day(observer, timestamp: da
n_grid_points
=
n_grid_points
)
try
:
sunrise_dict
[
'
end
'
]
=
round_to_second_precision
(
sunrise_end
.
to_datetime
())
except
ValueError
:
# sun never rises
except
(
ValueError
,
AttributeError
)
:
# sun never rises
/ astropy bug
sun_body
=
astropy
.
coordinates
.
get_body
(
"
sun
"
,
Time
(
sunrise_dict
[
'
start
'
]),
observer
.
location
)
if
observer
.
target_is_up
(
target
=
sun_body
,
time
=
Time
(
sunrise_dict
[
'
start
'
]),
horizon
=
angle_to_horizon
):
sunrise_dict
[
'
end
'
]
=
prev_midnight
...
...
@@ -323,8 +314,8 @@ def calculate_and_get_sunrise_and_sunset_of_observer_day(observer, timestamp: da
n_grid_points
=
n_grid_points
)
try
:
sunset_dict
[
'
start
'
]
=
round_to_second_precision
(
sunset_start
.
to_datetime
())
except
ValueError
:
# sun never rises
except
(
ValueError
,
AttributeError
)
:
# sun never rises
/ astropy bug
sun_body
=
astropy
.
coordinates
.
get_body
(
"
sun
"
,
Time
(
noon
),
observer
.
location
)
if
observer
.
target_is_up
(
target
=
sun_body
,
time
=
Time
(
noon
),
horizon
=
angle_to_horizon
):
sunset_dict
[
'
start
'
]
=
next_midnight
...
...
@@ -335,8 +326,8 @@ def calculate_and_get_sunrise_and_sunset_of_observer_day(observer, timestamp: da
n_grid_points
=
n_grid_points
)
try
:
sunset_dict
[
'
end
'
]
=
round_to_second_precision
(
sunset_end
.
to_datetime
())
except
ValueError
:
# sun never rises
except
(
ValueError
,
AttributeError
)
:
# sun never rises
/ astropy bug
sun_body
=
astropy
.
coordinates
.
get_body
(
"
sun
"
,
Time
(
noon
),
observer
.
location
)
if
observer
.
target_is_up
(
target
=
sun_body
,
time
=
Time
(
noon
),
horizon
=-
angle_to_horizon
):
sunset_dict
[
'
end
'
]
=
next_midnight
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment