@@ -66,7 +66,7 @@ class JwstClass(object):
6666 'preview' ]
6767 INSTRUMENT_NAMES = ['NIRISS' , 'NIRSPEC' , 'NIRCAM' , 'MIRI' , 'FGS' ]
6868 TARGET_RESOLVERS = ['ALL' , 'SIMBAD' , 'NED' , 'VIZIER' ]
69- CAL_LEVELS = ['ALL' , 1 , 2 , 3 ]
69+ CAL_LEVELS = ['ALL' , 1 , 2 , 3 , - 1 ]
7070 REQUESTED_OBSERVATION_ID = "Missing required argument: 'observation_id'"
7171
7272 def __init__ (self , tap_plus_handler = None , data_handler = None ):
@@ -1002,17 +1002,17 @@ def get_product_list(self, observation_id=None,
10021002 ----------
10031003 observation_id : str, mandatory
10041004 Observation identifier.
1005- cal_level : str, optional
1006- Calibration level. Default value ia 'ALL', to download all the
1007- products associated to this observation_id and lower levels.
1008- Requesting more accurate levels than the one associated to the
1009- observation_id is not allowed (as level 3 observations are
1005+ cal_level : str or int , optional
1006+ Calibration level. Default value is 'ALL', to download all the
1007+ products associated to this observation_id and lower processing
1008+ levels. Requesting more accurate levels than the one associated
1009+ to the observation_id is not allowed (as level 3 observations are
10101010 composite products based on level 2 products). To request upper
10111011 levels, please use get_related_observations functions first.
1012- Possible values: 'ALL', '3', '2', '1'
1012+ Possible values: 'ALL', 3, 2, 1, -1
10131013 product_type : str, optional, default None
1014- List only products of the given type. If None, all products are \
1015- listed. Possible values: 'thumbnail', 'preview', 'info', \
1014+ List only products of the given type. If None, all products are
1015+ listed. Possible values: 'thumbnail', 'preview', 'info',
10161016 'auxiliary', 'science'.
10171017
10181018 Returns
@@ -1029,9 +1029,10 @@ def get_product_list(self, observation_id=None,
10291029 list = self ._get_associated_planes (plane_ids , cal_level ,
10301030 max_cal_level , False )
10311031
1032- query = "select distinct a.uri, a.filename, a.contenttype, " \
1033- "a.producttype, p.calibrationlevel, p.public FROM {0} p JOIN {1} " \
1034- "a ON (p.planeid=a.planeid) WHERE a.planeid IN {2}{3};" \
1032+ query = "select distinct a.uri, a.artifactid, a.filename, " \
1033+ "a.contenttype, a.producttype, p.calibrationlevel, " \
1034+ "p.public FROM {0} p JOIN {1} a ON (p.planeid=a.planeid) " \
1035+ "WHERE a.planeid IN {2}{3};" \
10351036 .format (self .JWST_PLANE_TABLE , self .JWST_ARTIFACT_TABLE , list ,
10361037 self .__get_artifact_producttype_condition (product_type ))
10371038 job = self .__jwsttap .launch_job (query = query )
@@ -1045,7 +1046,7 @@ def _get_associated_planes(self, plane_ids, cal_level,
10451046 max_cal_level , is_url ):
10461047 if (cal_level == max_cal_level ):
10471048 if (not is_url ):
1048- list = "('{}')" .format (plane_ids )
1049+ list = "('{}')" .format ("', '" . join ( plane_ids ) )
10491050 else :
10501051 list = "{}" .format ("," .join (plane_ids ))
10511052 return list
@@ -1132,8 +1133,10 @@ def __get_member_planes(self, planeid, cal_level='ALL'):
11321133 raise ValueError (e )
11331134
11341135 def get_related_observations (self , observation_id ):
1135- """Get the list of level 3 products that make use of a given JWST
1136- observation_id.
1136+ """In case of processing levels < 3, get the list of level 3
1137+ products that make use of a given JWST observation_id. In case of
1138+ processing level 3, retrieves the list of products used to create
1139+ this composite observation
11371140
11381141 Parameters
11391142 ----------
@@ -1154,7 +1157,11 @@ def get_related_observations(self, observation_id):
11541157 if any (job .get_results ()["observationid" ]):
11551158 oids = job .get_results ()["observationid" ].pformat (show_name = False )
11561159 else :
1157- oids = [observation_id ]
1160+ query_members = "select m.members from {} m where m.observationid" \
1161+ "='{}'" .format (self .JWST_MAIN_TABLE , observation_id )
1162+ job = self .__jwsttap .launch_job (query = query_members )
1163+ oids = job .get_results ()["members" ][0 ].decode ("utf-8" ).\
1164+ replace ("caom:JWST/" , "" ).split (" " )
11581165 return oids
11591166
11601167 def get_product (self , artifact_id = None , file_name = None ):
@@ -1176,22 +1183,29 @@ def get_product(self, artifact_id=None, file_name=None):
11761183 params_dict ['RETRIEVAL_TYPE' ] = 'PRODUCT'
11771184 params_dict ['DATA_RETRIEVAL_ORIGIN' ] = 'ASTROQUERY'
11781185
1179- if artifact_id is None and file_name is None :
1180- raise ValueError ("Missing required argument: "
1181- "'artifact_id' or 'file_name'" )
1182- else :
1183- if file_name is None :
1184- output_file_name = str (artifact_id )
1186+ self .__check_product_input (artifact_id , file_name )
1187+
1188+ if file_name is None :
1189+ try :
1190+ output_file_name = self ._query_get_product (artifact_id )
11851191 err_msg = str (artifact_id )
1186- else :
1187- output_file_name = str (file_name )
1188- err_msg = str (file_name )
1192+ except Exception as exx :
1193+ raise ValueError ('Cannot retrieve product for artifact_id ' +
1194+ artifact_id + ': %s' % str (exx ))
1195+ else :
1196+ output_file_name = str (file_name )
1197+ err_msg = str (file_name )
1198+
1199+ if artifact_id is not None :
1200+ params_dict ['ARTIFACTID' ] = str (artifact_id )
1201+ else :
1202+ try :
1203+ params_dict ['ARTIFACTID' ] = (self ._query_get_product (
1204+ file_name = file_name ))
1205+ except Exception as exx :
1206+ raise ValueError ('Cannot retrieve product for file_name ' +
1207+ file_name + ': %s' % str (exx ))
11891208
1190- if artifact_id is not None :
1191- params_dict ['ARTIFACTID' ] = str (artifact_id )
1192- else :
1193- params_dict ['ARTIFACT_URI' ] = 'mast:JWST/product/' + \
1194- str (file_name )
11951209 try :
11961210 self .__jwsttap .load_data (params_dict = params_dict ,
11971211 output_file = output_file_name )
@@ -1202,6 +1216,23 @@ def get_product(self, artifact_id=None, file_name=None):
12021216 print ("Product saved at: %s" % (output_file_name ))
12031217 return output_file_name
12041218
1219+ def _query_get_product (self , artifact_id = None , file_name = None ):
1220+ if (file_name ):
1221+ query_artifactid = "select * from {} a where a.filename = " \
1222+ "'{}'" .format (self .JWST_ARTIFACT_TABLE , file_name )
1223+ job = self .__jwsttap .launch_job (query = query_artifactid )
1224+ return job .get_results ()['artifactid' ][0 ].decode ("utf-8" )
1225+ else :
1226+ query_filename = "select * from {} a where a.artifactid = " \
1227+ "'{}'" .format (self .JWST_ARTIFACT_TABLE , artifact_id )
1228+ job = self .__jwsttap .launch_job (query = query_filename )
1229+ return job .get_results ()['filename' ][0 ].decode ("utf-8" )
1230+
1231+ def __check_product_input (self , artifact_id , file_name ):
1232+ if artifact_id is None and file_name is None :
1233+ raise ValueError ("Missing required argument: "
1234+ "'artifact_id' or 'file_name'" )
1235+
12051236 def get_obs_products (self , observation_id = None , cal_level = "ALL" ,
12061237 product_type = None , output_file = None ):
12071238 """Get a JWST product given its observation ID.
@@ -1210,14 +1241,14 @@ def get_obs_products(self, observation_id=None, cal_level="ALL",
12101241 ----------
12111242 observation_id : str, mandatory
12121243 Observation identifier.
1213- cal_level : str, optional
1244+ cal_level : str or int , optional
12141245 Calibration level. Default value ia 'ALL', to download all the
12151246 products associated to this observation_id and lower levels.
12161247 Requesting more accurate levels than the one associated to the
12171248 observation_id is not allowed (as level 3 observations are
12181249 composite products based on level 2 products). To request upper
12191250 levels, please use get_related_observations functions first.
1220- Possible values: 'ALL', '3', '2', '1'
1251+ Possible values: 'ALL', 3, 2, 1, -1
12211252 product_type : str, optional, default None
12221253 List only products of the given type. If None, all products are \
12231254 listed. Possible values: 'thumbnail', 'preview', 'auxiliary', \
0 commit comments