Skip to content

Commit

Permalink
Add retry
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanconn committed Sep 17, 2024
1 parent c2c0687 commit 2092874
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions chandra_aca/dark_subtract.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

import numba
import numpy as np
import requests.exceptions
from astropy.table import Table, vstack
from cheta import fetch_sci
from cxotime import CxoTime, CxoTimeLike
from mica.archive import aca_l0
from mica.archive.aca_dark import get_dark_cal_props
from ska_helpers import retry

from chandra_aca import maude_decom
from chandra_aca.dark_model import dark_temp_scale_img
Expand Down Expand Up @@ -41,6 +43,7 @@ def get_dark_data(time: CxoTimeLike):
return dc_img, dc_tccd


@retry.retry(exceptions=requests.exceptions.RequestException, delay=5, tries=3)
def get_tccd_data(start: CxoTimeLike, stop: CxoTimeLike, source="maude"):
"""
Get the CCD temperature for a given time range.
Expand Down Expand Up @@ -75,6 +78,7 @@ def get_tccd_data(start: CxoTimeLike, stop: CxoTimeLike, source="maude"):
return t_ccd, t_ccd_times


@retry.retry(exceptions=requests.exceptions.RequestException, delay=5, tries=3)
def get_dcsub_aca_images(
start=None,
stop=None,
Expand Down Expand Up @@ -183,7 +187,6 @@ def get_dark_current_imgs(img_table, dc_img, dc_tccd, t_ccd, t_ccd_times):
"""
Get the scaled dark current values for a table of ACA images.
Parameters
----------
img_table : astry.table.Table
Expand Down Expand Up @@ -327,6 +330,7 @@ def get_mica_images(start: CxoTimeLike, stop: CxoTimeLike, cols=None):
return slot_data


@retry.retry(exceptions=requests.exceptions.RequestException, delay=5, tries=3)
@lru_cache(maxsize=2)
def get_maude_images(start: CxoTimeLike, stop: CxoTimeLike, fetch_limit_hours=100):
"""
Expand Down Expand Up @@ -356,6 +360,8 @@ def get_maude_images(start: CxoTimeLike, stop: CxoTimeLike, fetch_limit_hours=10
# Break maude fetches into max 3 hour chunks required by maude_decom fetch
for mstart in np.arange(tstart, tstop, 60 * 60 * 3):
mstop = np.min([tstop, mstart + 60 * 60 * 3])
# Add a retry here if necessary

imgs = maude_decom.get_aca_images(mstart, mstop)
slot_chunks.append(imgs)
slot_chunks = vstack(slot_chunks)
Expand All @@ -367,6 +373,7 @@ def get_maude_images(start: CxoTimeLike, stop: CxoTimeLike, fetch_limit_hours=10
return slot_data


@retry.retry(exceptions=requests.exceptions.RequestException, delay=5, tries=3)
def get_aca_images(
start=None,
stop=None,
Expand All @@ -376,11 +383,10 @@ def get_aca_images(
dc_img=None,
dc_tccd=None,
source="maude",
):
):
"""
Get aca images for a given time range.
Parameters
----------
start : str, optional
Expand Down

0 comments on commit 2092874

Please sign in to comment.