Skip to content

Commit 9658eab

Browse files
committed
Retry read errors spherex_psf.md
1 parent 6031a2e commit 9658eab

1 file changed

Lines changed: 17 additions & 6 deletions

File tree

tutorials/spherex/spherex_psf.md

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,10 @@ The following packages must be installed to run this notebook.
5555
```
5656

5757
```{code-cell} ipython3
58+
import http.client
5859
import re
5960
import time
61+
import urllib.error
6062
6163
import astropy.units as u
6264
import matplotlib.pyplot as plt
@@ -139,12 +141,21 @@ As we do below, you can use `hdul.info()` to print the list of FITS layers of th
139141
```
140142

141143
```{code-cell} ipython3
142-
with fits.open(spectral_image_url) as hdul:
143-
hdul.info()
144-
cutout_header = hdul['IMAGE'].header
145-
psf_header = hdul['PSF'].header
146-
cutout = hdul['IMAGE'].data
147-
psfcube = hdul['PSF'].data
144+
Max number of times to retry transient read errors.
145+
max_retries = 3
146+
for attempt in range(max_retries):
147+
try:
148+
with fits.open(spectral_image_url) as hdul:
149+
hdul.info()
150+
cutout_header = hdul['IMAGE'].header
151+
psf_header = hdul['PSF'].header
152+
cutout = hdul['IMAGE'].data
153+
psfcube = hdul['PSF'].data
154+
break
155+
except (urllib.error.HTTPError, http.client.IncompleteRead):
156+
if attempt == max_retries - 1:
157+
raise
158+
time.sleep(10 * (attempt + 1))
148159
```
149160

150161
The downloaded SPHEREx image cutout contains 5 FITS layers, which are described in the [SPHEREx Explanatory Supplement](https://irsa.ipac.caltech.edu/data/SPHEREx/docs/SPHEREx_Expsupp_QR.pdf).

0 commit comments

Comments
 (0)