Skip to content

Commit 69d6f16

Browse files
committed
OOP refactoring
1 parent 65cbed2 commit 69d6f16

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

pyspecchio/specchio_db_interface.py

+19-13
Original file line numberDiff line numberDiff line change
@@ -132,21 +132,21 @@ def get_test_spectra(self):
132132
"""Get spectra from the test file spectra.csv"""
133133
pass
134134

135-
def get_all_pico_metadata(self):
135+
def get_all_pico_metadata(self, spectrafile):
136136
""" Gets all the metadata from the PICO JSON spectra files.
137137
138138
Returns:
139139
A list of metadata dictionaries, four for each of the four spectra
140140
"""
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)]
142142

143-
def get_all_pico_spectra(self):
143+
def get_all_pico_spectra(self, spectrafile):
144144
"""Gets a spectra from the PICO json spectra files.
145145
146146
Returns an array of lists, because lists are not same lengths
147147
(Not a 2D array, as might be expected)
148148
"""
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)])
150150

151151

152152
def get_single_pico_spectra(self, spectra_num):
@@ -156,6 +156,8 @@ def get_single_pico_spectra(self, spectra_num):
156156
def add_pico_metadata_for_spectra(self, smd, metadata, spectra_index):
157157
"""Adds the spectrometer-specific metadata to the spectra file"""
158158
# Add plot number metaparameter
159+
# TODO
160+
return # Gives null pointer (I think because of the keys missing from DB)
159161
for metadata_key in self.PICO_METADATA:
160162
mp = metaparam.newInstance(
161163
self.specchio_client.getAttributesNameHash().get(
@@ -178,20 +180,22 @@ def add_ancillary_metadata_for_spectra(self, smd, ancil_metadata, spectra_index)
178180
mp.setValue(str(ancil_metadata[spectra_index][ancildata_key]))
179181
smd.addEntry(mp)
180182

181-
def specchio_upload_pico_spectra(self, spectra_filename, spectra_filepath):
183+
def specchio_upload_pico_spectra(self, spectrafile):
182184
"""Upload the PICO type spectra.
183185
186+
Args:
187+
spectrafile: a SpectraFile object
188+
184189
Remember, the specs are:
185190
2 sets of Up and Down spectra (four in total)
186191
Each have their own set of metadata
187192
"""
188-
specp.set_spectra_file(spectra_filename, spectra_filepath)
189193
# Create a spectra file object
190194
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)
192196
# 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)
195199
# Should be 4 for PICO file format
196200
num_spectras = np.size(spectra)
197201
# TODO: remove hard coding
@@ -212,13 +216,13 @@ def specchio_upload_pico_spectra(self, spectra_filename, spectra_filepath):
212216
# Add wavelens
213217
spspectra_file_obj.addWvls([jp.java.lang.Float(x) for x in dummy_wavelens])
214218
# 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)
216220
spspectra_file_obj.addSpectrumFilename(fname_spectra)
217221

218222
# Metadata...FOR EACH SPECTRA (use dummy if needed)
219223
#=-=-=-=-=-=
220224
smd = sptypes.Metadata()
221-
self.add_pico_metadata_for_spectra(smd, metadata)
225+
self.add_pico_metadata_for_spectra(smd, metadata, i)
222226
#self.add_ancillary_metadata_for_spectra(smd, metadata)
223227
spspectra_file_obj.addEavMetadata(smd)
224228

@@ -305,8 +309,10 @@ def specchio_uploader_test(self, filename, filepath, subhierarchy, use_dummy_spe
305309
spectra_file_test = "QEP1USB1_b000000_s000002_light.pico"
306310

307311
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)
310316

311317

312318

0 commit comments

Comments
 (0)