@@ -45,13 +45,6 @@ class JwstClass(object):
4545 """
4646 Proxy class to default TapPlus object (pointing to JWST Archive)
4747 """
48- JWST_MAIN_TABLE = conf .JWST_MAIN_TABLE
49- JWST_OBSERVATION_TABLE = conf .JWST_OBSERVATION_TABLE
50- JWST_OBS_MEMBER_TABLE = conf .JWST_OBS_MEMBER_TABLE
51- JWST_MAIN_TABLE_RA = conf .JWST_MAIN_TABLE_RA
52- JWST_MAIN_TABLE_DEC = conf .JWST_MAIN_TABLE_DEC
53- JWST_PLANE_TABLE = conf .JWST_PLANE_TABLE
54- JWST_ARTIFACT_TABLE = conf .JWST_ARTIFACT_TABLE
5548
5649 JWST_DEFAULT_COLUMNS = ['observationid' , 'calibrationlevel' , 'public' ,
5750 'dataproducttype' , 'instrument_name' ,
@@ -348,27 +341,27 @@ def __query_region(self, coordinate, radius=None, width=None, height=None,
348341 if show_all_columns :
349342 columns = '*'
350343
351- query = "SELECT DISTANCE(POINT('ICRS'," + \
352- str (self .JWST_MAIN_TABLE_RA ) + "," + \
353- str (self .JWST_MAIN_TABLE_DEC ) + " ), \
354- POINT('ICRS'," + str (ra ) + "," + str (dec ) + " )) "\
355- "AS dist, " + columns + " \
356- FROM " + str (self .JWST_MAIN_TABLE ) + " \
357- WHERE CONTAINS(\
358- POINT('ICRS'," + \
359- str (self .JWST_MAIN_TABLE_RA )+ "," + \
360- str (self .JWST_MAIN_TABLE_DEC )+ "), \
361- BOX('ICRS'," + str (ra ) + "," + str (dec )+ " , " + \
362- str (widthDeg .value )+ " , " + \
363- str (heightDeg .value )+ " ))=1 " + \
364- obsid_cond + \
365- cal_level_condition + \
366- public_condition + \
367- prod_cond + \
368- instr_cond + \
369- filter_name_cond + \
370- props_id_cond + \
371- "ORDER BY dist ASC"
344+ query = ( f "SELECT DISTANCE(POINT('ICRS',"
345+ f" { str (conf .JWST_MAIN_TABLE_RA )} ,"
346+ f" { str (conf .JWST_MAIN_TABLE_DEC )} ), "
347+ f" POINT('ICRS',{ str (ra )} , { str (dec )} )) "
348+ f "AS dist, { columns } "
349+ f"FROM { str (conf .JWST_MAIN_TABLE )} "
350+ f" WHERE CONTAINS("
351+ f" POINT('ICRS',"
352+ f" { str (conf .JWST_MAIN_TABLE_RA )} ,"
353+ f" { str (conf .JWST_MAIN_TABLE_DEC )} ),"
354+ f" BOX('ICRS',{ str (ra )} , { str (dec )} , "
355+ f" { str (widthDeg .value )} , "
356+ f" { str (heightDeg .value )} ))=1 "
357+ f" { obsid_cond } "
358+ f" { cal_level_condition } "
359+ f" { public_condition } "
360+ f" { prod_cond } "
361+ f" { instr_cond } "
362+ f" { filter_name_cond } "
363+ f" { props_id_cond } "
364+ f "ORDER BY dist ASC")
372365 print (query )
373366 if async_job :
374367 job = self .__jwsttap .launch_job_async (query , verbose = verbose )
@@ -598,23 +591,23 @@ def __cone_search(self, coordinate, radius,
598591 radius_quantity = self .__get_quantity_input (radius , "radius" )
599592 radius_deg = commons .radius_to_unit (radius_quantity , unit = 'deg' )
600593
601- query = "SELECT DISTANCE(POINT('ICRS'," + \
602- str (self .JWST_MAIN_TABLE_RA ) + "," + \
603- str (self .JWST_MAIN_TABLE_DEC ) + " ), \
604- POINT('ICRS'," + str (ra ) + "," + str (dec ) + " )) AS dist, " + columns + " \
605- FROM " + str (self .JWST_MAIN_TABLE ) + " WHERE CONTAINS(\
606- POINT('ICRS'," + str (self .JWST_MAIN_TABLE_RA ) + "," + \
607- str (self .JWST_MAIN_TABLE_DEC )+ "), \
608- CIRCLE('ICRS'," + str (ra )+ "," + str (dec ) + " , " + \
609- str (radius_deg )+ " ))=1" + \
610- obsid_condition + \
611- cal_level_condition + \
612- public_condition + \
613- prod_type_cond + \
614- inst_name_cond + \
615- filter_name_condition + \
616- proposal_id_condition + \
617- "ORDER BY dist ASC"
594+ query = ( f "SELECT DISTANCE(POINT('ICRS',"
595+ f" { str (conf .JWST_MAIN_TABLE_RA )} ,"
596+ f" { str (conf .JWST_MAIN_TABLE_DEC )} ), "
597+ f" POINT('ICRS',{ str (ra )} , { str (dec )} )) AS dist, { columns } "
598+ f"FROM { str (conf .JWST_MAIN_TABLE )} WHERE CONTAINS("
599+ f" POINT('ICRS',{ str (conf .JWST_MAIN_TABLE_RA )} ,"
600+ f" { str (conf .JWST_MAIN_TABLE_DEC )} ),"
601+ f" CIRCLE('ICRS',{ str (ra )} , { str (dec )} , "
602+ f" { str (radius_deg )} ))=1"
603+ f" { obsid_condition } "
604+ f" { cal_level_condition } "
605+ f" { public_condition } "
606+ f" { prod_type_cond } "
607+ f" { inst_name_cond } "
608+ f" { filter_name_condition } "
609+ f" { proposal_id_condition } "
610+ f "ORDER BY dist ASC")
618611 if async_job :
619612 return self .__jwsttap .launch_job_async (query = query ,
620613 output_file = output_file ,
@@ -891,8 +884,8 @@ def resolve_target_coordinates(self, target_name, target_resolver):
891884 if target_resolver == "ALL" or target_resolver == "SIMBAD" :
892885 try :
893886 result_table = Simbad .query_object (target_name )
894- return SkyCoord ('{} {}' . format ( result_table ["RA" ][0 ],
895- result_table ["DEC" ][0 ]),
887+ return SkyCoord (( f' { result_table ["RA" ][0 ]} '
888+ f' { result_table ["DEC" ][0 ]} ' ),
896889 unit = (units .hourangle ,
897890 units .deg ), frame = "icrs" )
898891 except Exception :
@@ -917,8 +910,8 @@ def resolve_target_coordinates(self, target_name, target_resolver):
917910 except Exception :
918911 log .info ("VIZIER could not resolve this target" )
919912 if result_table is None :
920- raise ValueError ("This target name cannot be determined with"
921- " this resolver: {}" . format ( target_resolver ) )
913+ raise ValueError (f "This target name cannot be determined with"
914+ f " this resolver: { target_resolver } " )
922915
923916 def remove_jobs (self , jobs_list , verbose = False ):
924917 """Removes the specified jobs
@@ -1047,12 +1040,12 @@ def get_product_list(self, observation_id=None,
10471040 list = self ._get_associated_planes (plane_ids , cal_level ,
10481041 max_cal_level , False )
10491042
1050- query = "select distinct a.uri, a.artifactid, a.filename, " \
1051- "a.contenttype, a.producttype, p.calibrationlevel, " \
1052- "p.public FROM {0 } p JOIN {1} a ON (p.planeid=a.planeid) " \
1053- "WHERE a .planeid IN {2}{3};" \
1054- . format ( self . JWST_PLANE_TABLE , self . JWST_ARTIFACT_TABLE , list ,
1055- self .__get_artifact_producttype_condition (product_type ))
1043+ query = ( f "select distinct a.uri, a.artifactid, a.filename, "
1044+ f "a.contenttype, a.producttype, p.calibrationlevel, "
1045+ f "p.public FROM { conf . JWST_PLANE_TABLE } p JOIN "
1046+ f" { conf . JWST_ARTIFACT_TABLE } a ON (p .planeid=a.planeid) "
1047+ f"WHERE a.planeid IN { list } "
1048+ f" { self .__get_artifact_producttype_condition (product_type )} ;" )
10561049 job = self .__jwsttap .launch_job (query = query )
10571050 return job .get_results ()
10581051
@@ -1085,9 +1078,9 @@ def _get_associated_planes(self, plane_ids, cal_level,
10851078 def _get_plane_id (self , observation_id ):
10861079 try :
10871080 planeids = []
1088- query_plane = "select distinct m.planeid, m.calibrationlevel " \
1089- "from {} m where m.observationid = '{}'" \
1090- . format ( self . JWST_MAIN_TABLE , observation_id )
1081+ query_plane = ( f "select distinct m.planeid, m.calibrationlevel "
1082+ f "from { conf . JWST_MAIN_TABLE } m where "
1083+ f"m.observationid = ' { observation_id } '" )
10911084 job = self .__jwsttap .launch_job (query = query_plane )
10921085 job .get_results ().sort (["calibrationlevel" ])
10931086 job .get_results ().reverse ()
@@ -1107,19 +1100,18 @@ def __get_sibling_planes(self, planeid, cal_level='ALL'):
11071100 where_clause = "WHERE sp.calibrationlevel<=p.calibrationlevel " \
11081101 "AND p.planeid ="
11091102 else :
1110- where_clause = "WHERE sp.calibrationlevel={} AND " \
1111- "p.planeid =" . format ( cal_level )
1103+ where_clause = ( f "WHERE sp.calibrationlevel={ cal_level } AND "
1104+ f "p.planeid =" )
11121105 try :
1113- query_siblings = "SELECT o.observationuri, p.planeid, " \
1114- "p.calibrationlevel, sp.planeid as " \
1115- "product_planeid, sp.calibrationlevel as " \
1116- "product_level FROM {0} o JOIN {1} p ON " \
1117- "p.obsid=o.obsid JOIN {1} sp ON " \
1118- "sp.obsid=o.obsid {2}'{3}'" \
1119- .format (self .JWST_OBSERVATION_TABLE ,
1120- self .JWST_PLANE_TABLE ,
1121- where_clause ,
1122- planeid )
1106+ query_siblings = (f"SELECT o.observationuri, p.planeid, "
1107+ f"p.calibrationlevel, sp.planeid as "
1108+ f"product_planeid, sp.calibrationlevel as "
1109+ f"product_level FROM "
1110+ f"{ conf .JWST_OBSERVATION_TABLE } o JOIN "
1111+ f"{ conf .JWST_PLANE_TABLE } p ON "
1112+ f"p.obsid=o.obsid JOIN "
1113+ f"{ conf .JWST_PLANE_TABLE } sp ON "
1114+ f"sp.obsid=o.obsid { where_clause } '{ planeid } '" )
11231115 job = self .__jwsttap .launch_job (query = query_siblings )
11241116 return job .get_results ()
11251117 except Exception as e :
@@ -1130,22 +1122,23 @@ def __get_member_planes(self, planeid, cal_level='ALL'):
11301122 if (cal_level == "ALL" ):
11311123 where_clause = "WHERE p.planeid ="
11321124 else :
1133- where_clause = "WHERE mp.calibrationlevel={} AND " \
1134- "p.planeid =" . format ( cal_level )
1125+ where_clause = ( f "WHERE mp.calibrationlevel={ cal_level } AND "
1126+ f "p.planeid =" )
11351127 try :
1136- query_members = "SELECT o.observationuri, p.planeid, " \
1137- "p.calibrationlevel, mp.planeid as " \
1138- "product_planeid, mp.calibrationlevel as " \
1139- "product_level FROM {0} o JOIN {1} p on " \
1140- "o.obsid=p.obsid JOIN {2} m on " \
1141- "o.obsid=m.parentid JOIN {0} " \
1142- "mo on m.memberid=mo.observationuri JOIN " \
1143- "{1} mp on mo.obsid=mp.obsid {3}'{4}'" \
1144- .format (self .JWST_OBSERVATION_TABLE ,
1145- self .JWST_PLANE_TABLE ,
1146- self .JWST_OBS_MEMBER_TABLE ,
1147- where_clause ,
1148- planeid )
1128+ query_members = (f"SELECT o.observationuri, p.planeid, "
1129+ f"p.calibrationlevel, mp.planeid as "
1130+ f"product_planeid, mp.calibrationlevel as "
1131+ f"product_level FROM "
1132+ f"{ conf .JWST_OBSERVATION_TABLE } o JOIN "
1133+ f"{ conf .JWST_PLANE_TABLE } p on "
1134+ f"o.obsid=p.obsid JOIN "
1135+ f"{ conf .JWST_OBS_MEMBER_TABLE } m on "
1136+ f"o.obsid=m.parentid JOIN "
1137+ f"{ conf .JWST_OBSERVATION_TABLE } "
1138+ f"mo on m.memberid=mo.observationuri JOIN "
1139+ f"{ conf .JWST_PLANE_TABLE } mp on "
1140+ f"mo.obsid=mp.obsid "
1141+ f"{ where_clause } '{ planeid } '" )
11491142 job = self .__jwsttap .launch_job (query = query_members )
11501143 return job .get_results ()
11511144 except Exception as e :
@@ -1170,14 +1163,16 @@ def get_related_observations(self, observation_id):
11701163 """
11711164 if observation_id is None :
11721165 raise ValueError (self .REQUESTED_OBSERVATION_ID )
1173- query_upper = "select * from {} m where m.members like " \
1174- "'%{}%'" .format (self .JWST_MAIN_TABLE , observation_id )
1166+ query_upper = (f"select * from { conf .JWST_MAIN_TABLE } m "
1167+ f"where m.members like "
1168+ f"'%{ observation_id } %'" )
11751169 job = self .__jwsttap .launch_job (query = query_upper )
11761170 if any (job .get_results ()["observationid" ]):
11771171 oids = job .get_results ()["observationid" ].pformat (show_name = False )
11781172 else :
1179- query_members = "select m.members from {} m where m.observationid" \
1180- "='{}'" .format (self .JWST_MAIN_TABLE , observation_id )
1173+ query_members = (f"select m.members from { conf .JWST_MAIN_TABLE } "
1174+ f"m where m.observationid"
1175+ f"='{ observation_id } '" )
11811176 job = self .__jwsttap .launch_job (query = query_members )
11821177 oids = JwstClass .get_decoded_string (
11831178 job .get_results ()["members" ][0 ]).\
@@ -1238,14 +1233,16 @@ def get_product(self, artifact_id=None, file_name=None):
12381233
12391234 def _query_get_product (self , artifact_id = None , file_name = None ):
12401235 if (file_name ):
1241- query_artifactid = "select * from {} a where a.filename = " \
1242- "'{}'" .format (self .JWST_ARTIFACT_TABLE , file_name )
1236+ query_artifactid = (f"select * from { conf .JWST_ARTIFACT_TABLE } "
1237+ f"a where a.filename = "
1238+ f"'{ file_name } '" )
12431239 job = self .__jwsttap .launch_job (query = query_artifactid )
12441240 return JwstClass .get_decoded_string (
12451241 job .get_results ()['artifactid' ][0 ])
12461242 else :
1247- query_filename = "select * from {} a where a.artifactid = " \
1248- "'{}'" .format (self .JWST_ARTIFACT_TABLE , artifact_id )
1243+ query_filename = (f"select * from { conf .JWST_ARTIFACT_TABLE } a "
1244+ f"where a.artifactid = "
1245+ f"'{ artifact_id } '" )
12491246 job = self .__jwsttap .launch_job (query = query_filename )
12501247 return JwstClass .get_decoded_string (
12511248 job .get_results ()['filename' ][0 ])
0 commit comments