@@ -790,20 +790,20 @@ def cone_search_async(self, coordinate, radius=None,
790790 verbose = verbose ,
791791 dump_to_file = dump_to_file )
792792
793- def query_target_name (self , target_name , target_resolver = "ALL" ,
794- radius = None ,
795- width = None ,
796- height = None ,
797- observation_id = None ,
798- cal_level = "Top" ,
799- prod_type = None ,
800- instrument_name = None ,
801- filter_name = None ,
802- proposal_id = None ,
803- only_public = False ,
804- show_all_columns = False ,
805- async_job = False ,
806- verbose = False ):
793+ def query_target (self , target_name , target_resolver = "ALL" ,
794+ radius = None ,
795+ width = None ,
796+ height = None ,
797+ observation_id = None ,
798+ cal_level = "Top" ,
799+ prod_type = None ,
800+ instrument_name = None ,
801+ filter_name = None ,
802+ proposal_id = None ,
803+ only_public = False ,
804+ show_all_columns = False ,
805+ async_job = False ,
806+ verbose = False ):
807807 """Launches a job
808808 TAP & TAP+
809809
@@ -1023,15 +1023,15 @@ def get_product_list(self, observation_id=None,
10231023
10241024 if observation_id is None :
10251025 raise ValueError (self .REQUESTED_OBSERVATION_ID )
1026- plane_id , max_cal_level = self .__get_plane_id (observation_id )
1026+ plane_ids , max_cal_level = self ._get_plane_id (observation_id )
10271027 if (cal_level == 3 and cal_level > max_cal_level ):
10281028 raise ValueError ("Requesting upper levels is not allowed" )
1029- list = self .__get_associated_planes ( plane_id , cal_level ,
1030- max_cal_level , False )
1029+ list = self ._get_associated_planes ( plane_ids , cal_level ,
1030+ max_cal_level , False )
10311031
10321032 query = "select distinct a.uri, a.filename, a.contenttype, " \
10331033 "a.producttype, p.calibrationlevel, p.public FROM {0} p JOIN {1} " \
1034- "a ON (p.planeid=a.planeid) WHERE a.planeid IN {2} {3};" \
1034+ "a ON (p.planeid=a.planeid) WHERE a.planeid IN {2}{3};" \
10351035 .format (self .JWST_PLANE_TABLE , self .JWST_ARTIFACT_TABLE , list ,
10361036 self .__get_artifact_producttype_condition (product_type ))
10371037 job = self .__jwsttap .launch_job (query = query )
@@ -1041,37 +1041,45 @@ def __validate_cal_level(self, cal_level):
10411041 if (cal_level not in self .CAL_LEVELS ):
10421042 raise ValueError ("This calibration level is not valid" )
10431043
1044- def __get_associated_planes (self , plane_id , cal_level ,
1045- max_cal_level , is_url ):
1044+ def _get_associated_planes (self , plane_ids , cal_level ,
1045+ max_cal_level , is_url ):
10461046 if (cal_level == max_cal_level ):
10471047 if (not is_url ):
1048- list = "('{}')" .format (plane_id )
1048+ list = "('{}')" .format (plane_ids )
10491049 else :
1050- list = plane_id
1050+ list = "{}" .format ("," .join (plane_ids ))
1051+ return list
10511052 else :
1052- siblings = self .__get_sibling_planes (plane_id , cal_level )
1053- members = self .__get_member_planes (plane_id , cal_level )
1054- pids_table = vstack ([siblings , members ])
1053+ plane_list = []
1054+ for plane_id in plane_ids :
1055+ siblings = self .__get_sibling_planes (plane_id , cal_level )
1056+ members = self .__get_member_planes (plane_id , cal_level )
1057+ plane_id_table = vstack ([siblings , members ])
1058+ plane_list .extend (plane_id_table ['product_planeid' ].pformat (
1059+ show_name = False ))
10551060 if (not is_url ):
1056- list = "('{}')" .format ("', '" .join (
1057- pids_table ["product_planeid" ].pformat (show_name = False )))
1061+ list = "('{}')" .format ("', '" .join (plane_list ))
10581062 else :
1059- list = "{}" .format ("," .join (
1060- pids_table ["product_planeid" ].pformat (show_name = False )))
1063+ list = "{}" .format ("," .join (plane_list ))
10611064 return list
10621065
1063- def __get_plane_id (self , observation_id ):
1066+ def _get_plane_id (self , observation_id ):
10641067 try :
1065- query_plane = "select m.planeid, m.calibrationlevel from {} m " \
1066- "where m.observationid = '{}'" \
1068+ planeids = []
1069+ query_plane = "select distinct m.planeid, m.calibrationlevel " \
1070+ "from {} m where m.observationid = '{}'" \
10671071 .format (self .JWST_MAIN_TABLE , observation_id )
10681072 job = self .__jwsttap .launch_job (query = query_plane )
1069- job .get_results ().sort (["planeid " ])
1070- planeid = job .get_results ()[ "planeid" ][ 0 ]. decode ( 'utf-8' )
1073+ job .get_results ().sort (["calibrationlevel " ])
1074+ job .get_results (). reverse ( )
10711075 max_cal_level = job .get_results ()["calibrationlevel" ][0 ]
1072- return planeid , max_cal_level
1076+ for row in job .get_results ():
1077+ if (row ["calibrationlevel" ] == max_cal_level ):
1078+ planeids .append (row ["planeid" ].decode ('utf-8' ))
1079+ return planeids , max_cal_level
10731080 except Exception as e :
1074- raise ValueError (e )
1081+ raise ValueError ("This observation_id does not exist in "
1082+ "JWST database" )
10751083
10761084 def __get_sibling_planes (self , planeid , cal_level = 'ALL' ):
10771085 where_clause = ""
@@ -1169,6 +1177,7 @@ def get_product(self, artifact_id=None, file_name=None):
11691177 params_dict ['DATA_RETRIEVAL_ORIGIN' ] = 'ASTROQUERY'
11701178
11711179 if artifact_id is None and file_name is None :
1180+ log .info ("ARTIFACT NONE" )
11721181 raise ValueError ("Missing required argument: "
11731182 "'artifact_id' or 'file_name'" )
11741183 else :
@@ -1188,14 +1197,15 @@ def get_product(self, artifact_id=None, file_name=None):
11881197 self .__jwsttap .load_data (params_dict = params_dict ,
11891198 output_file = output_file_name )
11901199 except Exception as exx :
1200+ log .info ("error" )
11911201 raise ValueError ('Error retrieving product for ' +
11921202 err_msg + ': %s' % str (exx ))
11931203 print ("Product saved at: %s" % (output_file_name ))
11941204 return output_file_name
11951205
1196- def get_obs_products (self , observation_id = None , cal_level = None ,
1206+ def get_obs_products (self , observation_id = None , cal_level = "ALL" ,
11971207 product_type = None , output_file = None ):
1198- """Get a JWST product given its Artifact ID.
1208+ """Get a JWST product given its observation ID.
11991209
12001210 Parameters
12011211 ----------
@@ -1224,7 +1234,7 @@ def get_obs_products(self, observation_id=None, cal_level=None,
12241234
12251235 if observation_id is None :
12261236 raise ValueError (self .REQUESTED_OBSERVATION_ID )
1227- plane_id , max_cal_level = self .__get_plane_id (observation_id )
1237+ plane_ids , max_cal_level = self ._get_plane_id (observation_id )
12281238
12291239 if (cal_level == 3 and cal_level > max_cal_level ):
12301240 raise ValueError ("Requesting upper levels is not allowed" )
@@ -1233,13 +1243,13 @@ def get_obs_products(self, observation_id=None, cal_level=None,
12331243 params_dict ['RETRIEVAL_TYPE' ] = 'OBSERVATION'
12341244 params_dict ['DATA_RETRIEVAL_ORIGIN' ] = 'ASTROQUERY'
12351245
1236- if ( cal_level == 2 and max_cal_level != 2 ):
1237- plane_id = self . __get_associated_planes ( plane_id , 2 ,
1238- max_cal_level , True )
1239- params_dict ['planeid' ] = plane_id
1246+ plane_ids = self . _get_associated_planes ( plane_ids , cal_level ,
1247+ max_cal_level , True )
1248+ log . info ( plane_ids )
1249+ params_dict ['planeid' ] = plane_ids
12401250 self .__set_additional_parameters (params_dict , cal_level , max_cal_level ,
12411251 product_type )
1242-
1252+ log . info ( params_dict )
12431253 output_file_full_path , output_dir = self .__set_dirs (output_file ,
12441254 observation_id )
12451255 # Get file name only
@@ -1440,7 +1450,7 @@ def __get_artifact_producttype_condition(self, product_type=None):
14401450 raise ValueError ("product_type must be one of: " +
14411451 str (', ' .join (self .ARTIFACT_PRODUCT_TYPES )))
14421452 else :
1443- condition = " AND producttype LIKE '" + product_type + "' "
1453+ condition = " AND producttype LIKE '" + product_type + "'"
14441454 return condition
14451455
14461456 def __get_calibration_level_condition (self , cal_level = None ):
0 commit comments