@@ -119,6 +119,70 @@ def download_product(self, observation_id, *, calibration_level=None,
119
119
120
120
shutil .move (response , filename )
121
121
122
+ def get_member_observations (self , observation_id ):
123
+ """
124
+ Parameters
125
+ ----------
126
+ observation_id : str, mandatory
127
+ Observation identifier.
128
+
129
+ Returns
130
+ -------
131
+ A list of strings with the observation_id of the associated
132
+ observations that can be used in get_product_list and
133
+ get_obs_products functions
134
+ """
135
+ if observation_id is None :
136
+ raise ValueError (self .REQUESTED_OBSERVATION_ID )
137
+ observation_type = self .get_observation_type (observation_id )
138
+
139
+ if 'Composite' in observation_type :
140
+ oids = self ._select_members (observation_id )
141
+ elif 'Simple' in observation_type :
142
+ oids = self ._select_composite (observation_id )
143
+ else :
144
+ raise ValueError ("Invalid observation id" )
145
+ return oids
146
+
147
+ def get_hap_hst_link (self , observation_id ):
148
+ if observation_id is None :
149
+ raise ValueError (self .REQUESTED_OBSERVATION_ID )
150
+ observation_type = self .get_observation_type (observation_id )
151
+
152
+ if 'HAP' in observation_type :
153
+ oids = self ._select_members (observation_id )
154
+ elif 'HST' in observation_type :
155
+ query = f"select observation_id from ehst.observation where obs_type='HAP Simple' and members like '%{ observation_id } %'"
156
+ job = self .query_hst_tap (query = query )
157
+ oids = job ["observation_id" ].pformat (show_name = False )
158
+ else :
159
+ raise ValueError ("Invalid observation id" )
160
+ return oids
161
+
162
+ def get_observation_type (self , observation_id ):
163
+ if observation_id is None :
164
+ raise ValueError (self .REQUESTED_OBSERVATION_ID )
165
+
166
+ query = f"select obs_type from ehst.observation where observation_id='{ observation_id } '"
167
+ job = self .query_hst_tap (query = query )
168
+ if any (job ["obs_type" ]):
169
+ obs_type = ESAHubbleClass .get_decoded_string (job ["obs_type" ][0 ])
170
+ else :
171
+ raise ValueError ("Invalid Observation ID" )
172
+ return obs_type
173
+
174
+ def _select_members (self , observation_id ):
175
+ query = f"select members from ehst.observation where observation_id='{ observation_id } '"
176
+ job = self .query_hst_tap (query = query )
177
+ oids = ESAHubbleClass .get_decoded_string (job ["members" ][0 ]).replace ("caom:HST/" , "" ).split (" " )
178
+ return oids
179
+
180
+ def _select_composite (self , observation_id ):
181
+ query = f"select observation_id from ehst.observation where members like '%{ observation_id } %'"
182
+ job = self .query_hst_tap (query = query )
183
+ oids = job ["observation_id" ].pformat (show_name = False )
184
+ return oids
185
+
122
186
def __validate_product_type (self , product_type ):
123
187
if (product_type not in self .product_types ):
124
188
raise ValueError ("This product_type is not allowed" )
@@ -696,5 +760,13 @@ def _getCoordInput(self, value):
696
760
else :
697
761
return value
698
762
763
+ @staticmethod
764
+ def get_decoded_string (str ):
765
+ try :
766
+ return str .decode ('utf-8' )
767
+ # return str
768
+ except (UnicodeDecodeError , AttributeError ):
769
+ return str
770
+
699
771
700
772
ESAHubble = ESAHubbleClass ()
0 commit comments