5
5
import json
6
6
7
7
from cdci_data_analysis .analysis .products import LightCurveProduct , BaseQueryProduct , ImageProduct , SpectrumProduct
8
- from cdci_data_analysis .analysis .parameters import Parameter
8
+ from cdci_data_analysis .analysis .parameters import Parameter , subclasses_recursive
9
+ from cdci_data_analysis .analysis .exceptions import ProductProcessingError
9
10
from oda_api .data_products import NumpyDataProduct , ODAAstropyTable , BinaryProduct , PictureProduct
11
+
10
12
from .util import AstropyTableViewParser , with_hashable_dict
11
13
from oda_api .ontology_helper import Ontology
12
14
from io import StringIO
@@ -35,34 +37,18 @@ def write(self, file_name=None, overwrite=True, file_dir=None):
35
37
file_path = self .file_path .path
36
38
37
39
self .table_data .write (file_path , overwrite = overwrite , format = 'ascii.ecsv' )
38
-
39
- class NB2WProduct :
40
- def __init__ (self ,
41
- encoded_data ,
42
- data_product_type = BaseQueryProduct ,
43
- out_dir = './' ,
44
- name = 'nb2w' ,
45
- extra_metadata = {}):
46
40
47
- # this constructor is only valid for NumpyDataProduct-based products
48
-
49
- self .name = name
50
- self .extra_metadata = extra_metadata
51
- metadata = encoded_data .get ('meta_data' , {})
52
- self .out_dir = out_dir
53
- numpy_data_prod = NumpyDataProduct .decode (encoded_data )
54
-
55
- if not numpy_data_prod .name :
56
- numpy_data_prod .name = self .name
57
41
58
- self .dispatcher_data_prod = data_product_type (
59
- name = self .name ,
60
- data = numpy_data_prod ,
61
- meta_data = metadata ,
62
- file_dir = out_dir ,
63
- file_name = f"{ self .name } .fits" )
64
-
42
+ class NB2WProduct :
65
43
44
+ def __init__ (self , * args , ** kwargs ):
45
+ error_msg = "The output"
46
+ name = kwargs .get ('name' , None )
47
+ if name is not None :
48
+ error_msg += f" with name \" { name } \" "
49
+ error_msg += " has been wrongly annotated."
50
+ raise ProductProcessingError (error_msg )
51
+
66
52
def write (self ):
67
53
file_path = self .dispatcher_data_prod .file_path
68
54
self .dispatcher_data_prod .write ()
@@ -74,10 +60,10 @@ def get_html_draw(self):
74
60
@classmethod
75
61
def _init_as_list (cls , encoded_data , * args , ** kwargs ):
76
62
encoded_data = cls ._dejsonify (encoded_data )
77
-
63
+
78
64
if isinstance (encoded_data , list ):
79
65
return [cls (elem , * args , ** kwargs ) for elem in encoded_data ]
80
-
66
+
81
67
return [cls (encoded_data , * args , ** kwargs )]
82
68
83
69
@classmethod
@@ -96,7 +82,7 @@ def _prod_list_description_analyser(
96
82
onto = None
97
83
par_prod_class_dict = {}
98
84
99
- mapping = {getattr (x , 'type_key' ): x for x in cls . __subclasses__ ( ) if hasattr (x , 'type_key' )}
85
+ mapping = {getattr (x , 'type_key' ): x for x in subclasses_recursive ( cls ) if hasattr (x , 'type_key' )}
100
86
mapping .update (par_prod_class_dict )
101
87
102
88
prod_classes_dict = {}
@@ -135,7 +121,7 @@ def _prod_list_description_analyser(
135
121
extra_kw .update ({'extra_metadata' : extra_metadata })
136
122
137
123
prod_classes_dict [key ] = (mapping .get (cls_owl_type , cls ), name , extra_kw )
138
-
124
+
139
125
return prod_classes_dict
140
126
141
127
@@ -152,7 +138,8 @@ def prod_list_factory(cls, output_description_dict, output, out_dir = './', onto
152
138
name = val [1 ],
153
139
** val [2 ]))
154
140
except Exception as e :
155
- logger .error ('unable to construct %s product: %s from this: %s ' , key , e , output [key ])
141
+ logger .error ('unable to construct %s product: %s from %s' , key , e , val [0 ])
142
+ raise
156
143
157
144
return prod_list
158
145
@@ -165,8 +152,44 @@ def _dejsonify(encoded_data):
165
152
pass
166
153
return encoded_data
167
154
155
+
156
+ class _CommentProduct (NB2WProduct ):
157
+ type_key = 'http://odahub.io/ontology#WorkflowResultComment'
158
+
159
+ def __init__ (self , * args , ** kwargs ): ...
160
+
161
+ @classmethod
162
+ def _init_as_list (cls , encoded_data , * args , ** kwargs ):
163
+ return []
164
+
165
+ class NB2WNumpyDataProduct (NB2WProduct ):
166
+ type_key = 'http://odahub.io/ontology#NumpyDataProduct'
167
+
168
+ def __init__ (self ,
169
+ encoded_data ,
170
+ data_product_type = BaseQueryProduct ,
171
+ out_dir = './' ,
172
+ name = 'nb2w' ,
173
+ extra_metadata = {}):
174
+
175
+ self .name = name
176
+ self .extra_metadata = extra_metadata
177
+ metadata = encoded_data .get ('meta_data' , {})
178
+ self .out_dir = out_dir
179
+ numpy_data_prod = NumpyDataProduct .decode (encoded_data )
180
+ if not numpy_data_prod .name :
181
+ numpy_data_prod .name = self .name
182
+
183
+ self .dispatcher_data_prod = data_product_type (
184
+ name = self .name ,
185
+ data = numpy_data_prod ,
186
+ meta_data = metadata ,
187
+ file_dir = out_dir ,
188
+ file_name = f"{ self .name } .fits" )
189
+
190
+
168
191
class NB2WParameterProduct (NB2WProduct ):
169
- type_key = 'oda: WorkflowParameter'
192
+ type_key = 'http://odahub.io/ontology# WorkflowParameter'
170
193
171
194
ontology_path = None
172
195
@@ -248,7 +271,6 @@ def get_html_draw(self):
248
271
249
272
250
273
class NB2WProgressProduct (NB2WProduct ):
251
-
252
274
def __init__ (self , progress_html_data , out_dir = None , name = 'progress' ):
253
275
self .out_dir = out_dir
254
276
self .name = name
@@ -315,7 +337,7 @@ def get_html_draw(self):
315
337
return {'image' : {'div' : '<br><br>' + parser .tabcode ,
316
338
'script' : f"<script>{ script_text } </script>" } }
317
339
318
- class NB2WLightCurveProduct (NB2WProduct ):
340
+ class NB2WLightCurveProduct (NB2WNumpyDataProduct ):
319
341
type_key = 'http://odahub.io/ontology#LightCurve'
320
342
321
343
def __init__ (self ,
@@ -366,7 +388,7 @@ def get_html_draw(self, unit_id=None):
366
388
)
367
389
return im_dic
368
390
369
- class NB2WSpectrumProduct (NB2WProduct ):
391
+ class NB2WSpectrumProduct (NB2WNumpyDataProduct ):
370
392
type_key = 'http://odahub.io/ontology#Spectrum'
371
393
372
394
def __init__ (self ,
@@ -379,15 +401,16 @@ def __init__(self,
379
401
out_dir = out_dir , name = name ,
380
402
extra_metadata = extra_metadata )
381
403
382
- class NB2WImageProduct (NB2WProduct ):
404
+ class NB2WImageProduct (NB2WNumpyDataProduct ):
383
405
type_key = 'http://odahub.io/ontology#Image'
384
406
385
407
def __init__ (self ,
386
408
encoded_data ,
387
409
out_dir = './' ,
388
410
name = 'image' ,
389
411
extra_metadata = {}):
390
- super ().__init__ (encoded_data ,
412
+
413
+ super ().__init__ (encoded_data ,
391
414
data_product_type = ImageProduct ,
392
415
out_dir = out_dir ,
393
416
name = name ,
0 commit comments