@@ -132,21 +132,21 @@ def get_test_spectra(self):
132
132
"""Get spectra from the test file spectra.csv"""
133
133
pass
134
134
135
- def get_all_pico_metadata (self ):
135
+ def get_all_pico_metadata (self , spectrafile ):
136
136
""" Gets all the metadata from the PICO JSON spectra files.
137
137
138
138
Returns:
139
139
A list of metadata dictionaries, four for each of the four spectra
140
140
"""
141
- return [specp .get_spectra_metadata (x ) for x in range (0 ,4 )]
141
+ return [spectrafile .get_spectra_metadata (x ) for x in range (0 ,4 )]
142
142
143
- def get_all_pico_spectra (self ):
143
+ def get_all_pico_spectra (self , spectrafile ):
144
144
"""Gets a spectra from the PICO json spectra files.
145
145
146
146
Returns an array of lists, because lists are not same lengths
147
147
(Not a 2D array, as might be expected)
148
148
"""
149
- return np .array ([specp .get_spectra_pixels (x ) for x in range (0 ,4 )])
149
+ return np .array ([spectrafile .get_spectra_pixels (x ) for x in range (0 ,4 )])
150
150
151
151
152
152
def get_single_pico_spectra (self , spectra_num ):
@@ -156,6 +156,8 @@ def get_single_pico_spectra(self, spectra_num):
156
156
def add_pico_metadata_for_spectra (self , smd , metadata , spectra_index ):
157
157
"""Adds the spectrometer-specific metadata to the spectra file"""
158
158
# Add plot number metaparameter
159
+ # TODO
160
+ return # Gives null pointer (I think because of the keys missing from DB)
159
161
for metadata_key in self .PICO_METADATA :
160
162
mp = metaparam .newInstance (
161
163
self .specchio_client .getAttributesNameHash ().get (
@@ -178,20 +180,22 @@ def add_ancillary_metadata_for_spectra(self, smd, ancil_metadata, spectra_index)
178
180
mp .setValue (str (ancil_metadata [spectra_index ][ancildata_key ]))
179
181
smd .addEntry (mp )
180
182
181
- def specchio_upload_pico_spectra (self , spectra_filename , spectra_filepath ):
183
+ def specchio_upload_pico_spectra (self , spectrafile ):
182
184
"""Upload the PICO type spectra.
183
185
186
+ Args:
187
+ spectrafile: a SpectraFile object
188
+
184
189
Remember, the specs are:
185
190
2 sets of Up and Down spectra (four in total)
186
191
Each have their own set of metadata
187
192
"""
188
- specp .set_spectra_file (spectra_filename , spectra_filepath )
189
193
# Create a spectra file object
190
194
spspectra_file_obj = sptypes .SpectralFile ()
191
- self .set_spectra_file_info (spspectra_file_obj , spectra_filename , spectra_filepath )
195
+ self .set_spectra_file_info (spspectra_file_obj , spectrafile . sfile , spectrafile . spath )
192
196
# as below.... loop through the four spectra
193
- spectra = self .get_all_pico_spectra ()
194
- metadata = self .get
197
+ spectra = self .get_all_pico_spectra (spectrafile )
198
+ metadata = self .get_all_pico_metadata ( spectrafile )
195
199
# Should be 4 for PICO file format
196
200
num_spectras = np .size (spectra )
197
201
# TODO: remove hard coding
@@ -212,13 +216,13 @@ def specchio_upload_pico_spectra(self, spectra_filename, spectra_filepath):
212
216
# Add wavelens
213
217
spspectra_file_obj .addWvls ([jp .java .lang .Float (x ) for x in dummy_wavelens ])
214
218
# Add filename: we add an automatic number here to make them distinct
215
- fname_spectra = spectra_filename + str (i )
219
+ fname_spectra = spectrafile . sfile + str (i )
216
220
spspectra_file_obj .addSpectrumFilename (fname_spectra )
217
221
218
222
# Metadata...FOR EACH SPECTRA (use dummy if needed)
219
223
#=-=-=-=-=-=
220
224
smd = sptypes .Metadata ()
221
- self .add_pico_metadata_for_spectra (smd , metadata )
225
+ self .add_pico_metadata_for_spectra (smd , metadata , i )
222
226
#self.add_ancillary_metadata_for_spectra(smd, metadata)
223
227
spspectra_file_obj .addEavMetadata (smd )
224
228
@@ -305,8 +309,10 @@ def specchio_uploader_test(self, filename, filepath, subhierarchy, use_dummy_spe
305
309
spectra_file_test = "QEP1USB1_b000000_s000002_light.pico"
306
310
307
311
subhierarchy = 'PlotScale'
308
-
309
- db_interface .specchio_upload_pico_spectra (spectra_filename = spectra_file_test , spectra_filepath = spectra_testpath )
312
+ # Create a file object to handle parsing of the files.
313
+ spectrafile = specp .SpectraFile (spectra_file_test , spectra_testpath )
314
+ # Create an interface object to handling interfaceing with SPECCHIO
315
+ db_interface .specchio_upload_pico_spectra (spectrafile )
310
316
311
317
312
318
0 commit comments