astropy / astropy/astroquery

ESASky get_images Leaves Chandra Images open?

Open
#3,003 5 comments 0 reactions 0 assignees View on GitHub
esasky
Dominant language
Python
Stars
791
Forks
451
Avg merge
1d 3h
Merged PRs (30d)
4

Description

Hello,

I am using a Jupyter notebook in Windows 10 to query several coordinate pairs. If there are two coordinates in the same field, say:

ra dec
19.67 -0.868
19.66 -0.874

it appears that the Chandra image downloaded for the first coordinate pair isn't closed properly, so an error is returned when an attempt is made to download the same image for the 2nd coordinate pair.

Here is my code (meant to run on a longer list of coordinates, not simply the two I gave as an example):

~~~~~~~
for i in range(len(ra)):
coord_obj = coord.SkyCoord(ra=ra[i], dec=dec[i], unit=(u.deg, u.deg), frame='icrs')
images = ESASky.get_images(position=coord_obj, missions='Chandra')
if bool(images) is False:
print(f"Object {i} not found in database.")
else:
print(r"entry number {}".format(i))
wcs = WCS(images["CHANDRA"][0][0].header)
fig, ax = plt.subplots(1,1, figsize=(12,12), subplot_kw={'projection': wcs})
im, norm = imshow_norm(images["CHANDRA"][0][0].data, ax, origin='lower',interval=PercentileInterval(99.7), stretch=LinearStretch())
ax.scatter(ra[i], dec[i], s=200, edgecolor='red', facecolor='none', transform=ax.get_transform('icrs'),label=str(starname[i]))
ax.legend()
fig.colorbar(im)
plt.savefig(f"ADAPimages/{starname[i]}_CHANDRA.png", dpi=300, bbox_inches='tight', pad_inches=0.25)
~~~~~~~

The code worked fine with XMM images (and the full coordinate list), but now I'm getting the following error when I try it with Chandra images:

~~~~~~~
INFO: Starting download of CHANDRA data. (1 files) [astroquery.esasky.core]
INFO: Downloading Observation ID: 4963 from https://cdaftp.cfa.harvard.edu/cgi-bin/chaser_ftp_retrieve_file.cgi?filename=science/ao05/cat8/4963/primary/acisf04963N004_full_img2.fits [astroquery.esasky.core]
INFO: [Done] [astroquery.esasky.core]
INFO: Downloading of CHANDRA data complete. [astroquery.esasky.core]
INFO: Maps available at C:\Users\scott\Maps [astroquery.esasky.core]
entry number 15
WARNING: FITSFixedWarning: 'datfix' made the change 'Set DATEREF to '1998-01-01' from MJDREF.
Set MJD-END to 53415.180162 from DATE-END'. [astropy.wcs.wcs]
INFO: Starting download of CHANDRA data. (1 files) [astroquery.esasky.core]
INFO: Downloading Observation ID: 4963 from https://cdaftp.cfa.harvard.edu/cgi-bin/chaser_ftp_retrieve_file.cgi?filename=science/ao05/cat8/4963/primary/acisf04963N004_full_img2.fits [astroquery.esasky.core]
---------------------------------------------------------------------------
OSError Traceback (most recent call last)
Cell In[3], line 4
2 coord_obj = coord.SkyCoord(ra=ra[i], dec=dec[i], unit=(u.deg, u.deg), frame='icrs')
3 #images = ESASky.get_images(position=coord_obj, missions=['XMM', 'Chandra', 'eROSITA']) #trying default radius=0
----> 4 images = ESASky.get_images(position=coord_obj, missions='Chandra', cache=False)
5 if bool(images) is False:
6 print(f"Object {i} not found in database.")

File ~\anaconda3\envs\basenew\Lib\site-packages\astroquery\esasky\core.py:1140, in ESASkyClass.get_images(self, position, observation_ids, radius, missions, download_dir, cache)
1137 json = self._get_observation_json()
1138 for query_mission in map_query_result.keys():
1139 maps[query_mission] = (
-> 1140 self._get_maps_for_mission(
1141 map_query_result[query_mission],
1142 query_mission,
1143 download_dir,
1144 cache, json))
1146 if all([maps[mission].count(None) == len(maps[mission])
1147 for mission in maps]):
1148 log.info("No maps got downloaded, check errors above.")

File ~\anaconda3\envs\basenew\Lib\site-packages\astroquery\esasky\core.py:1509, in ESASkyClass._get_maps_for_mission(self, maps_table, mission, download_dir, cache, json, is_spectra)
1506 fits_data = response.content
-> 1507 with open(directory_path + file_name, 'wb') as fits_file:
1508 fits_file.write(fits_data)
1509 fits_file.flush()

OSError: [Errno 22] Invalid argument: 'Maps/CHANDRA/acisf04963N004_full_img2.fits'
~~~~~~~

If anyone knows what I am doing wrong (or if this is simply a known bug when using Jupyter in Windows), I'd would appreciate any help you could offer.

Thank you.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.