Skip to content

Commit 5a4a7e6

Browse files
Jorge Fernandez Hernandezbsipocz
authored andcommitted
EUCLIDMNGT-1430 include dataSetReleases
1 parent b072dfe commit 5a4a7e6

2 files changed

Lines changed: 155 additions & 20 deletions

File tree

astroquery/esa/euclid/core.py

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1140,13 +1140,13 @@ def get_product_list(self, *, observation_id=None, tile_index=None, product_type
11401140
if tile_index is not None:
11411141
return self.__get_tile_catalogue_list(tile_index=tile_index, product_type=product_type, verbose=verbose)
11421142

1143-
dsr_condition = self.get_data_set_release_condition(dsr_part1, dsr_part2, dsr_part3)
1144-
extra_condition = '' if dsr_condition is None else f'AND {dsr_condition}'
1145-
11461143
query = None
11471144
if product_type in conf.OBSERVATION_STACK_PRODUCTS:
11481145
table = 'sedm.observation_stack'
11491146

1147+
dsr_condition = self.get_data_set_release_condition(dsr_part1, dsr_part2, dsr_part3, 'observation_stack')
1148+
extra_condition = '' if dsr_condition is None else f'AND {dsr_condition}'
1149+
11501150
query = (f"SELECT observation_stack.file_name, observation_stack.observation_stack_oid, "
11511151
f"observation_stack.observation_id, observation_stack.ra, observation_stack.dec, "
11521152
f"observation_stack.instrument_name, observation_stack.filter_name, "
@@ -1158,6 +1158,10 @@ def get_product_list(self, *, observation_id=None, tile_index=None, product_type
11581158

11591159
if product_type in conf.BASIC_DOWNLOAD_DATA_PRODUCTS:
11601160
table = 'sedm.basic_download_data'
1161+
1162+
dsr_condition = self.get_data_set_release_condition(dsr_part1, dsr_part2, dsr_part3, 'basic_download_data')
1163+
extra_condition = '' if dsr_condition is None else f'AND {dsr_condition}'
1164+
11611165
query = (
11621166
f"SELECT basic_download_data.basic_download_data_oid, basic_download_data.product_type, "
11631167
f"basic_download_data.product_id, CAST(basic_download_data.observation_id_list as text) AS "
@@ -1170,6 +1174,10 @@ def get_product_list(self, *, observation_id=None, tile_index=None, product_type
11701174

11711175
if product_type in conf.MER_SEGMENTATION_MAP_PRODUCTS:
11721176
table = 'sedm.mer_segmentation_map'
1177+
1178+
dsr_condition = self.get_data_set_release_condition(dsr_part1, dsr_part2, dsr_part3, 'mer_segmentation_map')
1179+
extra_condition = '' if dsr_condition is None else f'AND {dsr_condition}'
1180+
11731181
query = (
11741182
f"SELECT mer_segmentation_map.file_name, mer_segmentation_map.segmentation_map_oid, "
11751183
f"mer_segmentation_map.ra, mer_segmentation_map.dec, mer_segmentation_map.stc_s, "
@@ -1183,6 +1191,9 @@ def get_product_list(self, *, observation_id=None, tile_index=None, product_type
11831191
if product_type in conf.RAW_FRAME_PRODUCTS:
11841192
table = 'sedm.raw_frame'
11851193

1194+
dsr_condition = self.get_data_set_release_condition(dsr_part1, dsr_part2, dsr_part3, 'raw_frame')
1195+
extra_condition = '' if dsr_condition is None else f'AND {dsr_condition}'
1196+
11861197
if product_type == "dpdNispRawFrame":
11871198
instrument_name = "NISP"
11881199
else:
@@ -1198,6 +1209,10 @@ def get_product_list(self, *, observation_id=None, tile_index=None, product_type
11981209

11991210
if product_type in conf.CALIBRATED_FRAME_PRODUCTS:
12001211
table = 'sedm.calibrated_frame'
1212+
1213+
dsr_condition = self.get_data_set_release_condition(dsr_part1, dsr_part2, dsr_part3, 'calibrated_frame')
1214+
extra_condition = '' if dsr_condition is None else f'AND {dsr_condition}'
1215+
12011216
query = (
12021217
f"SELECT calibrated_frame.file_name, calibrated_frame.calibrated_frame_oid, "
12031218
f"calibrated_frame.observation_id, calibrated_frame.instrument_name, calibrated_frame.filter_name, "
@@ -1208,6 +1223,10 @@ def get_product_list(self, *, observation_id=None, tile_index=None, product_type
12081223

12091224
if product_type in conf.FRAME_CATALOG_PRODUCTS:
12101225
table = 'sedm.frame_catalog'
1226+
1227+
dsr_condition = self.get_data_set_release_condition(dsr_part1, dsr_part2, dsr_part3, 'frame_catalog')
1228+
extra_condition = '' if dsr_condition is None else f'AND {dsr_condition}'
1229+
12111230
query = (
12121231
f"SELECT frame_catalog.file_name, frame_catalog.catalog_oid, frame_catalog.observation_id, "
12131232
f"frame_catalog.instrument_name, frame_catalog.filter_name, frame_catalog.ra, frame_catalog.dec, "
@@ -1218,6 +1237,10 @@ def get_product_list(self, *, observation_id=None, tile_index=None, product_type
12181237

12191238
if product_type in conf.COMBINED_SPECTRA_PRODUCTS:
12201239
table = 'sedm.combined_spectra'
1240+
1241+
dsr_condition = self.get_data_set_release_condition(dsr_part1, dsr_part2, dsr_part3, 'combined_spectra')
1242+
extra_condition = '' if dsr_condition is None else f'AND {dsr_condition}'
1243+
12211244
query = (
12221245
f"SELECT combined_spectra.combined_spectra_oid, combined_spectra.lambda_range, "
12231246
f"combined_spectra.tile_index, combined_spectra.stc_s, combined_spectra.product_type, "
@@ -1229,6 +1252,10 @@ def get_product_list(self, *, observation_id=None, tile_index=None, product_type
12291252

12301253
if product_type in conf.SIR_SCIENCE_FRAME_PRODUCTS:
12311254
table = 'sedm.sir_science_frame'
1255+
1256+
dsr_condition = self.get_data_set_release_condition(dsr_part1, dsr_part2, dsr_part3, 'sir_science_frame')
1257+
extra_condition = '' if dsr_condition is None else f'AND {dsr_condition}'
1258+
12321259
instrument_name = "NISP"
12331260

12341261
query = (
@@ -1245,23 +1272,26 @@ def get_product_list(self, *, observation_id=None, tile_index=None, product_type
12451272
format_with_results_compressed=('votable_gzip',))
12461273
return job.get_results()
12471274

1248-
def get_data_set_release_condition(self, dsr_1_value=None, dsr_2_value=None, dsr_3_value=None):
1275+
def get_data_set_release_condition(self, dsr_1_value=None, dsr_2_value=None, dsr_3_value=None, alias=None):
12491276

12501277
query = None
12511278
if dsr_1_value is not None:
1252-
query = f"{self.dsr_1} = '{dsr_1_value}'"
1279+
dsr_1_final = '.'.join(filter(None, [alias, self.dsr_1]))
1280+
query = f"{dsr_1_final} = '{dsr_1_value}'"
12531281

12541282
if dsr_2_value is not None:
1283+
dsr_2_final = '.'.join(filter(None, [alias, self.dsr_2]))
12551284
if query is not None:
1256-
query = f"{query} AND {self.dsr_2} = {dsr_2_value}"
1285+
query = f"{query} AND {dsr_2_final} = '{dsr_2_value}'"
12571286
else:
1258-
query = f"{self.dsr_2} = {dsr_2_value}"
1287+
query = f"{dsr_2_final} = '{dsr_2_value}'"
12591288

12601289
if dsr_3_value is not None:
1290+
dsr_3_final = '.'.join(filter(None, [alias, str(self.dsr_3)]))
12611291
if query is not None:
1262-
query = f"{query} AND {self.dsr_3} = {dsr_3_value}"
1292+
query = f"{query} AND {dsr_3_final} = {dsr_3_value}"
12631293
else:
1264-
query = f"{self.dsr_3} = {dsr_3_value}"
1294+
query = f"{dsr_3_final} = {dsr_3_value}"
12651295

12661296
return query
12671297

@@ -1360,7 +1390,6 @@ def get_cutout(self, *, file_path=None, instrument=None, id=None, coordinate, ra
13601390
the radius of the cutout to generate
13611391
output_file : str, optional
13621392
output file. If no value is provided, a temporary one is created
1363-
13641393
verbose : bool, optional, default 'False'
13651394
flag to display information about the process
13661395
@@ -1475,6 +1504,8 @@ def get_spectrum(self, *, source_id, schema='sedm', retrieval_type="ALL", output
14751504
if os.listdir(output_dir):
14761505
raise IOError(f'The directory is not empty: {output_dir}')
14771506

1507+
files = []
1508+
14781509
try:
14791510
self.__eucliddata.load_data(params_dict=params_dict, output_file=output_file_full_path, verbose=verbose)
14801511
except HTTPError as err:
@@ -1484,7 +1515,6 @@ def get_spectrum(self, *, source_id, schema='sedm', retrieval_type="ALL", output
14841515
log.error(f'Cannot retrieve spectrum for source_id {source_id}, schema {schema}: {str(exx)}')
14851516
return None
14861517

1487-
files = []
14881518
self.__extract_file(output_file_full_path=output_file_full_path, output_dir=output_dir, files=files)
14891519

14901520
if files:

astroquery/esa/euclid/tests/test_euclidtap.py

Lines changed: 114 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,28 @@ def test_get_product_list():
667667
results = tap.get_product_list(observation_id='13', product_type=product_type)
668668
assert results is not None, "Expected a valid table"
669669

670+
##############
671+
672+
for product_type in conf.SIR_SCIENCE_FRAME_PRODUCTS:
673+
results = tap.get_product_list(observation_id='13', product_type=product_type, dsr_part1='CALBLOCK',
674+
verbose=True)
675+
assert results is not None, "Expected a valid table"
676+
677+
for product_type in conf.SIR_SCIENCE_FRAME_PRODUCTS:
678+
results = tap.get_product_list(observation_id='13', product_type=product_type, dsr_part1='CALBLOCK',
679+
dsr_part2='PV-023', verbose=True)
680+
assert results is not None, "Expected a valid table"
681+
682+
for product_type in conf.SIR_SCIENCE_FRAME_PRODUCTS:
683+
results = tap.get_product_list(observation_id='13', product_type=product_type, dsr_part1='CALBLOCK',
684+
dsr_part2='PV-023', dsr_part3=1, verbose=True)
685+
assert results is not None, "Expected a valid table"
686+
687+
for product_type in conf.SIR_SCIENCE_FRAME_PRODUCTS:
688+
results = tap.get_product_list(observation_id='13', product_type=product_type, dsr_part2='PV-023', dsr_part3=1,
689+
verbose=True)
690+
assert results is not None, "Expected a valid table"
691+
670692

671693
def test_get_product_list_by_tile_index():
672694
conn_handler = DummyConnHandler()
@@ -758,6 +780,39 @@ def test_get_product_by_product_id(tmp_path_factory):
758780
assert result is not None
759781

760782

783+
def test_get_product_by_product_id_data_set_release(tmp_path_factory):
784+
conn_handler = DummyConnHandler()
785+
tap_plus = TapPlus(url="http://test:1111/tap", data_context='data', client_id='ASTROQUERY',
786+
connhandler=conn_handler)
787+
# Launch response: we use default response because the query contains decimals
788+
responseLaunchJob = DummyResponse(200)
789+
responseLaunchJob.set_data(method='POST', context=None, body='', headers=None)
790+
791+
conn_handler.set_default_response(responseLaunchJob)
792+
793+
tap = EuclidClass(tap_plus_conn_handler=conn_handler, datalink_handler=tap_plus, show_server_messages=False)
794+
795+
result = tap.get_product(product_id='123456789', output_file=None, dsr_part1='CALBLOCK',
796+
dsr_part2='PV-023', dsr_part3=1)
797+
798+
assert result is not None
799+
800+
now = datetime.now()
801+
dirs = glob.glob(os.path.join(os.getcwd(), "temp_" + now.strftime("%Y%m%d") + '_*'))
802+
803+
assert len(dirs) == 1
804+
assert dirs[0] is not None
805+
806+
remove_temp_dir()
807+
808+
fits_file = os.path.join(tmp_path_factory.mktemp("euclid_tmp"), 'my_fits_file.fits')
809+
810+
result = tap.get_product(product_id='123456789', output_file=fits_file, dsr_part1='CALBLOCK',
811+
dsr_part2='PV-023', dsr_part3=1)
812+
813+
assert result is not None
814+
815+
761816
def test_get_product():
762817
conn_handler = DummyConnHandler()
763818
tap_plus = TapPlus(url="http://test:1111/tap", data_context='data', client_id='ASTROQUERY',
@@ -871,6 +926,44 @@ def test_get_observation_products(tmp_path_factory):
871926
assert result is not None
872927

873928

929+
def test_get_observation_products_data_set_release(tmp_path_factory):
930+
conn_handler = DummyConnHandler()
931+
tap_plus = TapPlus(url="http://test:1111/tap", data_context='data', client_id='ASTROQUERY',
932+
connhandler=conn_handler)
933+
# Launch response: we use default response because the query contains decimals
934+
responseLaunchJob = DummyResponse(200)
935+
responseLaunchJob.set_data(method='POST', context=None, body='', headers=None)
936+
937+
conn_handler.set_default_response(responseLaunchJob)
938+
939+
tap = EuclidClass(tap_plus_conn_handler=conn_handler, datalink_handler=tap_plus, show_server_messages=False)
940+
941+
result = tap.get_observation_products(id='13', product_type='observation', filter='VIS', output_file=None,
942+
dsr_part1='CALBLOCK', dsr_part2='PV-023', dsr_part3=1)
943+
944+
assert result is not None
945+
946+
result = tap.get_observation_products(id='13', product_type='mosaic', filter='VIS', output_file=None,
947+
dsr_part1='CALBLOCK', dsr_part2='PV-023', dsr_part3=1)
948+
949+
assert result is not None
950+
951+
now = datetime.now()
952+
dirs = glob.glob(os.path.join(os.getcwd(), "temp_" + now.strftime("%Y%m%d") + '_*'))
953+
954+
assert len(dirs) == 1
955+
assert dirs[0] is not None
956+
957+
remove_temp_dir()
958+
959+
fits_file = os.path.join(tmp_path_factory.mktemp("euclid_tmp"), 'my_fits_file.fits')
960+
961+
result = tap.get_observation_products(id='13', product_type='mosaic', filter='VIS', output_file=fits_file,
962+
dsr_part1='CALBLOCK', dsr_part2='PV-023', dsr_part3=1)
963+
964+
assert result is not None
965+
966+
874967
def test_get_observation_products_exceptions():
875968
conn_handler = DummyConnHandler()
876969
tap_plus = TapPlus(url="http://test:1111/tap", data_context='data', client_id='ASTROQUERY',
@@ -1129,46 +1222,58 @@ def test_get_scientific_data_product_list():
11291222
euclid = EuclidClass(tap_plus_conn_handler=conn_handler, datalink_handler=tap_plus, show_server_messages=False)
11301223

11311224
results = euclid.get_scientific_product_list(observation_id=11111)
1132-
11331225
assert results is not None, "Expected a valid table"
11341226

11351227
results = euclid.get_scientific_product_list(tile_index=11111)
1136-
11371228
assert results is not None, "Expected a valid table"
11381229

11391230
results = euclid.get_scientific_product_list(category='Clusters of Galaxies', group='GrpCatalog',
11401231
product_type='DpdLE3clAmicoAux')
1141-
11421232
assert results is not None, "Expected a valid table"
11431233

11441234
results = euclid.get_scientific_product_list(category='Weak Lensing Products', group='2PCF',
11451235
product_type='DpdCovarTwoPCFWLClPosPos2D')
1146-
11471236
assert results is not None, "Expected a valid table"
11481237

11491238
results = euclid.get_scientific_product_list(category='Weak Lensing Products')
1150-
11511239
assert results is not None, "Expected a valid table"
11521240

11531241
results = euclid.get_scientific_product_list(group='GrpCatalog')
1154-
11551242
assert results is not None, "Expected a valid table"
11561243

11571244
results = euclid.get_scientific_product_list(category='Weak Lensing Products', group='2PCF')
1158-
11591245
assert results is not None, "Expected a valid table"
11601246

11611247
results = euclid.get_scientific_product_list(group='2PCF', product_type='DpdCovarTwoPCFWLClPosPos2D')
1162-
11631248
assert results is not None, "Expected a valid table"
11641249

11651250
results = euclid.get_scientific_product_list(category='Weak Lensing Products',
11661251
product_type='DpdCovarTwoPCFWLClPosPos2D')
1167-
11681252
assert results is not None, "Expected a valid table"
11691253

11701254
results = euclid.get_scientific_product_list(product_type='DpdCovarTwoPCFWLClPosPos2D')
1255+
assert results is not None, "Expected a valid table"
1256+
1257+
########
1258+
1259+
results = euclid.get_scientific_product_list(product_type='DpdCovarTwoPCFWLClPosPos2D', dsr_part1='CALBLOCK',
1260+
verbose=True)
1261+
assert results is not None, "Expected a valid table"
1262+
1263+
results = euclid.get_scientific_product_list(product_type='DpdCovarTwoPCFWLClPosPos2D', dsr_part1='CALBLOCK',
1264+
dsr_part2='PV-023', verbose=True)
1265+
assert results is not None, "Expected a valid table"
1266+
1267+
results = euclid.get_scientific_product_list(product_type='DpdCovarTwoPCFWLClPosPos2D', dsr_part1='CALBLOCK',
1268+
dsr_part2='PV-023', dsr_part3=1, verbose=True)
1269+
assert results is not None, "Expected a valid table"
1270+
1271+
results = euclid.get_scientific_product_list(product_type='DpdCovarTwoPCFWLClPosPos2D', dsr_part1='CALBLOCK',
1272+
dsr_part3=1, verbose=True)
1273+
assert results is not None, "Expected a valid table"
11711274

1275+
results = euclid.get_scientific_product_list(product_type='DpdCovarTwoPCFWLClPosPos2D',
1276+
dsr_part2='PV-023', dsr_part3=1, verbose=True)
11721277
assert results is not None, "Expected a valid table"
11731278

11741279

0 commit comments

Comments
 (0)