Skip to content

Commit 76102c9

Browse files
authored
Merge pull request #3559 from esdc-esac-esa-int/ESA_euclid-update-get_cutout-method
EUCLIDSWRQ-285 Update get_cutout API and related tests
2 parents 5514c3e + e9489a7 commit 76102c9

4 files changed

Lines changed: 28 additions & 33 deletions

File tree

CHANGES.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ esa.euclid
2929
- The method ``get_spectrum`` accepts the new parameter ``linking_parameter`` to retrieve the spectra by source_id and
3030
sourcepatch_id. [#3543]
3131
- The ``source_id`` kwarg in the ``get_spectrum`` method has been renamed to ``ids``. [#3543]
32+
- Method ``get_cutout`` has deprecated the 'instrument' and 'id' parameters, providing them has no effect any more.
33+
The method now only supports retrieval of MER (background‑subtracted) image cutouts. [#3559]
3234
- The ``get_product_list`` method now also returns file_name_list column when the product type belongs to
3335
BASIC_DOWNLOAD_DATA_PRODUCTS. [#3562]
3436

astroquery/esa/euclid/core.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1399,20 +1399,20 @@ def get_product(self, *, file_name=None, product_id=None, schema='sedm', output_
13991399

14001400
return files
14011401

1402-
def get_cutout(self, *, file_path=None, instrument=None, id=None, coordinate, radius, output_file=None,
1403-
verbose=False):
1402+
@deprecated_renamed_argument(('instrument', 'id'), (None, None), since='0.4.12')
1403+
def get_cutout(self, *, file_path=None, coordinate, radius, output_file=None,
1404+
verbose=False, instrument=None, id=None):
14041405
"""
1405-
Downloads a cutout given its file path, instrument and obs_id, and the cutout region
1406+
Downloads a cutout from a MER mosaic (background-subtracted image) for a given
1407+
fits file path, centered on a coordinate and with a specified radius.
1408+
1409+
This method supports **only MER mosaic cutouts**.
14061410
14071411
Parameters
14081412
----------
14091413
file_path : str, mandatory, default None
1410-
file path for the product on the server
1411-
instrument : str, mandatory, default None
1412-
instrument for the product, can be 'VIS' or 'NISP'
1413-
id : str, mandatory, default None
1414-
the observation id or tile index for MER products
1415-
coordinate : astropy.coordinate, mandatory
1414+
file path for the product on the server (MER mosaic)
1415+
coordinate : astropy.coordinate or Simbad/VizieR/NED name (str), mandatory
14161416
coordinates center point
14171417
radius : astropy.units, mandatory
14181418
the radius of the cutout to generate
@@ -1426,7 +1426,7 @@ def get_cutout(self, *, file_path=None, instrument=None, id=None, coordinate, ra
14261426
The fits file is downloaded, and the local path where the cutout is saved is returned
14271427
"""
14281428

1429-
if file_path is None or instrument is None or id is None or coordinate is None or radius is None:
1429+
if file_path is None or coordinate is None or radius is None:
14301430
raise ValueError(self.__ERROR_MSG_REQUESTED_GENERIC)
14311431

14321432
# Parse POS
@@ -1438,8 +1438,7 @@ def get_cutout(self, *, file_path=None, instrument=None, id=None, coordinate, ra
14381438
ra = ra_hours * 15.0 # Converts to degrees
14391439
pos = """CIRCLE,{ra},{dec},{radius}""".format(**{'ra': ra, 'dec': dec, 'radius': radius_deg})
14401440

1441-
params_dict = {'TAPCLIENT': 'ASTROQUERY', 'FILEPATH': file_path, 'COLLECTION': instrument, 'OBSID': id,
1442-
'POS': pos}
1441+
params_dict = {'TAPCLIENT': 'ASTROQUERY', 'FILEPATH': file_path, 'POS': pos}
14431442

14441443
replace = os.path.basename(file_path).replace('.fits', '_cutout.fits')
14451444
output_file_full_path, output_dir = self.__set_dirs(output_file=output_file, observation_id=replace)
@@ -1450,12 +1449,12 @@ def get_cutout(self, *, file_path=None, instrument=None, id=None, coordinate, ra
14501449
self.__euclidcutout.load_data(params_dict=params_dict, output_file=output_file_full_path, verbose=verbose)
14511450
except HTTPError as err:
14521451
log.error(
1453-
f"Cannot retrieve the product for file_path {file_path}, obsId {id}, and collection {instrument}. "
1452+
f"Cannot retrieve the product for file_path {file_path}. "
14541453
f"HTTP error: {err}")
14551454
return None
14561455
except Exception as exx:
14571456
log.error(
1458-
f"Cannot retrieve the product for file_path {file_path}, obsId {id}, and collection {instrument}: "
1457+
f"Cannot retrieve the product for file_path {file_path}: "
14591458
f"{str(exx)}")
14601459
return None
14611460

astroquery/esa/euclid/tests/test_euclidtap.py

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,7 +1120,7 @@ def test_get_cutout(capsys):
11201120

11211121
result = tap.get_cutout(
11221122
file_path='/data/repository/NIR/19704/EUC_NIR_W-STACK_NIR-J-19704_20190718T001858.5Z_00.00.fits',
1123-
instrument='NISP', id='19704', coordinate=c, radius=r, output_file=None, verbose=True)
1123+
coordinate=c, radius=r, output_file=None, verbose=True)
11241124

11251125
assert result is not None
11261126

@@ -1148,29 +1148,23 @@ def test_get_cutout_exception():
11481148

11491149
c = coordinates.SkyCoord("187.89d 29.54d", frame='icrs')
11501150
r = 1 * u.arcmin
1151-
file_path = '/data/repository/NIR/19704/EUC_NIR_W-STACK_NIR-J-19704_20190718T001858.5Z_00.00.fits',
1151+
file_path = '/data/repository/NIR/19704/EUC_NIR_W-STACK_NIR-J-19704_20190718T001858.5Z_00.00.fits'
11521152

11531153
tap = EuclidClass(tap_plus_conn_handler=conn_handler, datalink_handler=tap_plus, cutout_handler=cutout_handler,
11541154
show_server_messages=False)
11551155

11561156
with pytest.raises(ValueError, match="Radius cannot be greater than 30 arcminutes"):
1157-
tap.get_cutout(file_path=file_path, instrument='NISP', id='19704', coordinate=c, radius=100 * u.arcmin,
1157+
tap.get_cutout(file_path=file_path, coordinate=c, radius=100 * u.arcmin,
11581158
output_file=None)
11591159

11601160
with pytest.raises(ValueError, match="Missing required argument"):
1161-
tap.get_cutout(file_path=None, instrument='NISP', id='19704', coordinate=c, radius=r, output_file=None)
1161+
tap.get_cutout(file_path=None, coordinate=c, radius=r, output_file=None)
11621162

11631163
with pytest.raises(ValueError, match="Missing required argument"):
1164-
tap.get_cutout(file_path=file_path, instrument=None, id='19704', coordinate=c, radius=r, output_file=None)
1164+
tap.get_cutout(file_path=file_path, coordinate=None, radius=r, output_file=None)
11651165

11661166
with pytest.raises(ValueError, match="Missing required argument"):
1167-
tap.get_cutout(file_path=file_path, instrument='NISP', id=None, coordinate=c, radius=r, output_file=None)
1168-
1169-
with pytest.raises(ValueError, match="Missing required argument"):
1170-
tap.get_cutout(file_path=file_path, instrument='NISP', id='19704', coordinate=None, radius=r, output_file=None)
1171-
1172-
with pytest.raises(ValueError, match="Missing required argument"):
1173-
tap.get_cutout(file_path=file_path, instrument='NISP', id='19704', coordinate=c, radius=None, output_file=None)
1167+
tap.get_cutout(file_path=file_path, coordinate=c, radius=None, output_file=None)
11741168

11751169

11761170
@patch.object(TapPlus, 'load_data')
@@ -1193,19 +1187,19 @@ def test_get_cutout_exceptions_2(mock_load_data, caplog):
11931187

11941188
mock_load_data.side_effect = HTTPError("launch_job_async HTTPError")
11951189

1196-
tap.get_cutout(file_path='hola.fits', instrument='NISP', id='19704', coordinate=SKYCOORD, radius=1 * u.arcmin,
1190+
tap.get_cutout(file_path='hola.fits', coordinate=SKYCOORD, radius=1 * u.arcmin,
11971191
output_file=None)
11981192

1199-
mssg = ("Cannot retrieve the product for file_path hola.fits, obsId 19704, and collection NISP. HTTP error: "
1193+
mssg = ("Cannot retrieve the product for file_path hola.fits. HTTP error: "
12001194
"launch_job_async HTTPError")
12011195
assert caplog.records[0].msg == mssg
12021196

12031197
mock_load_data.side_effect = Exception("launch_job_async Exception")
12041198

1205-
tap.get_cutout(file_path='hola.fits', instrument='NISP', id='19704', coordinate=SKYCOORD, radius=1 * u.arcmin,
1199+
tap.get_cutout(file_path='hola.fits', coordinate=SKYCOORD, radius=1 * u.arcmin,
12061200
output_file=None)
12071201

1208-
mssg = ("Cannot retrieve the product for file_path hola.fits, obsId 19704, and collection NISP: launch_job_async "
1202+
mssg = ("Cannot retrieve the product for file_path hola.fits: launch_job_async "
12091203
"Exception")
12101204
assert caplog.records[1].msg == mssg
12111205

docs/esa/euclid/euclid.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -360,12 +360,12 @@ and their sky coverage (in its "fov" field) is queried using ADQL_. Please note:
360360
1.7. MER Cutouts
361361
^^^^^^^^^^^^^^^^
362362

363-
It is also possible to download just small portions of the MER (background subtracted) images. The get_cutout_ allows to download image cutouts and store them locally - for reference, downloading a 1'x1'cutout takes less than one second and the downloaded fits file weights ~5.5 MB. In the example below, the results of Step 1 above are combined with the "file_path" and "file_name" values obtained from the mosaic_product TAP_ table to create the main input of the get_cutout_ method.
363+
It is also possible to download just small portions of the MER (background subtracted) images. The get_cutout_ allows to download image cutouts and store them locally - for reference, downloading a 1'x1'cutout takes less than one second and the downloaded fits file weights ~5.5 MB. In the example below, the results of Step 1 are used to build the file_path of the MER background-subtracted mosaic, which is the only required product input for the get_cutout method. This method now only retrieves cutouts from MER mosaics.
364364

365365
**Notes:**
366366
This method...
367367

368-
* makes use of the `Astroquery cutout service <https://astroquery.readthedocs.io/en/latest/image_cutouts/image_cutouts.html>`_ to download a cutout fits image from the Archive, and it only works for MER images. For more advanced use cases please see the Cutouts.ipynb notebook available in the Euclid Datalabs_.
368+
* makes use of the `Astroquery cutout service <https://astroquery.readthedocs.io/en/latest/image_cutouts/image_cutouts.html>`_ to extract a cutout from a MER (background-subtracted) mosaic. It only supports MER mosaics. For more advanced use cases please see the Cutouts.ipynb notebook available in the Euclid Datalabs_.
369369

370370
* accepts both Astropy SkyCoord_ coordinates and Simbad/VizieR/NED valid names (as string).
371371

@@ -375,7 +375,7 @@ Download the cutout...
375375
.. Skip testing as the example requires a lot of time to download a huge file
376376
377377
>>> file_path = f"{res['file_path'][0]}/{res['file_name'][0]}"
378-
>>> cutout_out = Euclid.get_cutout(file_path=file_path, coordinate='NGC 6505', radius= 0.1 * u.arcmin, output_file='ngc6505_cutout_mer.fits', instrument = 'None',id='None')
378+
>>> cutout_out = Euclid.get_cutout(file_path=file_path, coordinate='NGC 6505', radius= 0.1 * u.arcmin, output_file='ngc6505_cutout_mer.fits')
379379
>>> cutout_out = cutout_out[0]
380380
381381
... and inspect its content:

0 commit comments

Comments
 (0)