Skip to content

Commit

Permalink
Removes dependency on downloading orbital elemetns files to predict o…
Browse files Browse the repository at this point in the history
…ccultations with JPL BPS and conveys BSP download exceptions to the prediction log and database.
  • Loading branch information
rcboufleur committed Feb 16, 2024
1 parent 906eafc commit c7500af
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 13 deletions.
43 changes: 31 additions & 12 deletions predict_occultation/src/asteroid/asteroid.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,10 +316,11 @@ def download_jpl_bsp(self, end_period, force=False, start_period=None):

log.info(f"Asteroid BSP Downloaded in {tdelta}")

return data
return (data, "")
except Exception as e:
log.warning("Failed to Download BSP. Error: [%s]" % e)
return None
download_exception_warning = "Failed to Download BSP. Error: [%s]" % e
log.warning(download_exception_warning)
return (None, download_exception_warning)

def check_bsp_jpl(self, end_period, days_to_expire=None, start_period=None):
log = self.get_log()
Expand Down Expand Up @@ -390,16 +391,19 @@ def check_bsp_jpl(self, end_period, days_to_expire=None, start_period=None):
self.spkid = None
self.get_spkid()

# Separa o dado da mensagem/exception retornada do metodo bsp_jpl
bsp_jpl, exp_msg = bsp_jpl
if bsp_jpl:
# Atualiza os dados do bsp
self.bsp_jpl = bsp_jpl

return True
else:
msg = "BSP JPL file was not created."
self.bsp_jpl = dict({"message": msg})
self.bsp_jpl = dict({"message": msg + " " + exp_msg})

log.warning("Asteroid [%s] %s" % (self.name, msg))
log.warning("Asteroid [%s] %s" % (self.name, exp_msg))
return False

except Exception as e:
Expand All @@ -420,7 +424,7 @@ def check_bsp_jpl(self, end_period, days_to_expire=None, start_period=None):

self.write_asteroid_json()

def check_orbital_elements(self, days_to_expire=None):
def check_orbital_elements(self, days_to_expire=None, ignore=False):
log = self.get_log()

tp0 = dt.now(tz=timezone.utc)
Expand Down Expand Up @@ -462,14 +466,29 @@ def check_orbital_elements(self, days_to_expire=None):
"Pre-existing Orbital Elements is still valid and will be reused."
)

if not orb_ele:
# Fazer um novo Download
# Tenta primeiro vindo do AstDys
orb_ele = aei.download_astdys_orbital_elements(force=True)

if ignore:
msg = "The download of orbital elements was skipped."
orb_ele = {
"source": None,
"filename": "",
"size": 0,
"dw_start": None,
"dw_finish": None,
"dw_time": 0,
"downloaded_in_this_run": False,
"tp_start": None,
"tp_finish": None,
}
log.warning("%s" % (msg))
else:
if not orb_ele:
# Tenta no MPC
orb_ele = aei.download_mpc_orbital_elements(force=True)
# Fazer um novo Download
# Tenta primeiro vindo do AstDys
orb_ele = aei.download_astdys_orbital_elements(force=True)

if not orb_ele:
# Tenta no MPC
orb_ele = aei.download_mpc_orbital_elements(force=True)

if orb_ele:
# Atualiza os dados
Expand Down
4 changes: 3 additions & 1 deletion predict_occultation/src/run_pred_occ.py
Original file line number Diff line number Diff line change
Expand Up @@ -802,8 +802,10 @@ def submit_tasks(jobid: int):
continue

# ORBITAL ELEMENTS ----------------------------------------------
# Use ignore=False ou omita para que aos elementos orbitais sejam baixados.
# have_orb_ele = a.check_orbital_elements(days_to_expire=ORBITAL_ELEMENTS_DAYS_TO_EXPIRE)
have_orb_ele = a.check_orbital_elements(
days_to_expire=ORBITAL_ELEMENTS_DAYS_TO_EXPIRE
days_to_expire=ORBITAL_ELEMENTS_DAYS_TO_EXPIRE, ignore=True
)

if have_orb_ele is False:
Expand Down

0 comments on commit c7500af

Please sign in to comment.