ENLIGHTEN
Cross-platform desktop GUI for Wasatch Photonics spectrometers
Loading...
Searching...
No Matches
enlighten.measurement.Measurements.Measurements Class Reference

This class represents the set of Measurement objects which have been saved during this session via the Acquire button or BatchCollection, or which have been loaded from disk via the Load button. More...

Public Member Functions

 __deepcopy__ (self, memo)
 
 __init__ (self, ctl)
 
 add (self, measurement)
 Add the new measurement to our on-screen list.
 
 count (self)
 
 create_from_file (self, pathname)
 This is the callback which the FileManager will call, one at a time, with delays, with each pathname selected by the user.
 
 create_from_spectrometer (self, spec, label=None)
 Use the MeasurementFactory to instantiate a new Measurement, including ThumbnailWidget, from the given spectrometer's latest ProcessedReading.
 
 delete_measurement (self, measurement)
 The user has clicked the "trash" icon on a ThumbnailWidget, or the "eraser" icon at the top of the capture layout, or we're doing a massive collection and the ringbuffer overflowed, so the Measurement is being destroyed.
 
 delete_oldest (self)
 Delete the oldest Measurement (Thumbnail layout can be inverted, not array order).
 
 erase_all (self)
 Clears the list of Measurements (does not delete from disk).
 
 erase_all_callback (self)
 
 export_by_column (self, csv_writer, visible_only=False)
 Export each Measurement in turn in a columnar CSV.
 
 export_by_row (self, csv_writer, visible_only=False)
 In the row-based export, try to follow historical Dash conventions, as there's no obvious justification not to.
 
 export_callback (self)
 
 export_session (self, filename=None, prompt=True)
 The user clicked the "Export" button at the bottom of the Thumbnail layout and wants to export every current Measurement into a single CSV (either row- or column-ordered, per SaveOptions).
 
 export_session_csv (self, directory, filename, visible_only=False)
 
 export_session_json (self, directory, filename, export)
 Should this generate a JSON dict of Measurements (keyed on MeasurementID) or a JSON list of Measurements?
 
 export_session_spc (self, directory, filename, visible_only=False)
 
list[dict] generate_export_dict (self, visible_only=False)
 
 get (self, measurement_id)
 
 id_callback (self, measurement_id, declared_match)
 called by KnowItAll.Feature on receiving a MatchResponse from KIA.Wrapper which correponds to a MeasurementID.
 
 incompatible_axes (self, export_measurements)
 
 load_callback (self)
 display a file selection dialog, let the user select one or more files, then load them up (including thumbnail generation)
 
 read_measurements (self)
 
 register_observer (self, event, callback)
 Register the given callback (typically an instance method) if the named event occurs.
 
 rename_last_measurement (self)
 
 resize_callback (self)
 
 resort_callback (self)
 Essentially, cfu.verticalLayout_scope_capture_save.reverse()
 
 update_buttons (self)
 
 update_count (self)
 Update the "X spectra" label on the GUI, and dis/enable buttons.
 
 update_kia (self)
 Enable or disable the Identification button on all Measurement ThumbnailWidgets.
 

Public Attributes

 ctl = ctl
 
 erase_all_callback
 
 export_callback
 
bool insert_top = True
 
bool is_collapsed = False
 
 load_callback
 
list measurements = []
 
dict observers
 
 resize_callback
 
 resort_callback
 

Protected Member Functions

 _get_spectrometer_settings (self, visible_only=False)
 Returns a list of all SpectrometerSettings (unique by serial_number) contributing to our current set of saved measurements, in order of initial appearance.
 

Detailed Description

This class represents the set of Measurement objects which have been saved during this session via the Acquire button or BatchCollection, or which have been loaded from disk via the Load button.

It can be considered to be the set of ThumbnailWidgets which fill the left-hand capture column in the GUI.

Constructor & Destructor Documentation

◆ __init__()

enlighten.measurement.Measurements.Measurements.__init__ ( self,
ctl )

Member Function Documentation

◆ __deepcopy__()

enlighten.measurement.Measurements.Measurements.__deepcopy__ ( self,
memo )

◆ _get_spectrometer_settings()

enlighten.measurement.Measurements.Measurements._get_spectrometer_settings ( self,
visible_only = False )
protected

Returns a list of all SpectrometerSettings (unique by serial_number) contributing to our current set of saved measurements, in order of initial appearance.

To be perfectly clear, this returns a dictionary of wasatch.SpectrometerSettings by serial number. Be aware that different Measurement objects generated from the same spectrometer serial number may have different ROI and interpolation settings.

Note
This method has a fundamental weakness if something, say a plugin, changes the SpectrometerSettings (say wavelengths/wavenumbers) for some measurements OF THE SAME SERIAL NUMBER. We are fundamentally assuming that SpectrometerSettings (and x-axis) does not change FOR A GIVEN SERIAL NUMBER across the course of the export. What we really should do is track "unique x-axes" across all Measurements, regardless of serial number.

◆ add()

enlighten.measurement.Measurements.Measurements.add ( self,
measurement )

Add the new measurement to our on-screen list.

Kick-off old measurement if necessary.

◆ count()

enlighten.measurement.Measurements.Measurements.count ( self)

◆ create_from_file()

enlighten.measurement.Measurements.Measurements.create_from_file ( self,
pathname )

This is the callback which the FileManager will call, one at a time, with delays, with each pathname selected by the user.

Note that a given pathname may contain multiple spectra, which is why MeasurementFactory.create_from_file returns a list of Measurements rather than a single reference.

◆ create_from_spectrometer()

enlighten.measurement.Measurements.Measurements.create_from_spectrometer ( self,
spec,
label = None )

Use the MeasurementFactory to instantiate a new Measurement, including ThumbnailWidget, from the given spectrometer's latest ProcessedReading.

◆ delete_measurement()

enlighten.measurement.Measurements.Measurements.delete_measurement ( self,
measurement )

The user has clicked the "trash" icon on a ThumbnailWidget, or the "eraser" icon at the top of the capture layout, or we're doing a massive collection and the ringbuffer overflowed, so the Measurement is being destroyed.

It DOES NOT delete anything from disk.

Measurements can only be deleted from disk by clicking on their individual Trash icons, which logic is entirely encapsulated within Measurement and ThumbnailWidget.

See also
https://stackoverflow.com/a/20167458 re: deleteLater()

◆ delete_oldest()

enlighten.measurement.Measurements.Measurements.delete_oldest ( self)

Delete the oldest Measurement (Thumbnail layout can be inverted, not array order).

◆ erase_all()

enlighten.measurement.Measurements.Measurements.erase_all ( self)

Clears the list of Measurements (does not delete from disk).

◆ erase_all_callback()

enlighten.measurement.Measurements.Measurements.erase_all_callback ( self)

◆ export_by_column()

enlighten.measurement.Measurements.Measurements.export_by_column ( self,
csv_writer,
visible_only = False )

Export each Measurement in turn in a columnar CSV.

You might wonder if it's worth re-exporting every CSV_HEADER_FIELD atop each colujmn of spectra, given that so many of the values (wavecal coeffs, etc) don't change. The thing is, some do (integration time, note, detector and laser temperature, laser power, laser enabled etc). So bite the bullet and export them all for consistency.

If we're going to export data for 3 Measurements (A, B, C) taken from 2 spectrometers (S1 -> A, B; S2 -> C), and we're showing x-axis fields (px, wl) and ProcessedReading fields (proc, raw, dark), then we'd output this (m# indicating various metadata fields).

Enlighten ver
MeasID      A        B        C           <-- Measurement.measurement_id
Serial      S1       S1       S2
Label       Aa       Bb       Cc          <-- so good it's printed twice
m1          x        y        z
m2          x        y        z

S1    S2    Aa       Bb       Cc          <-- Measurement.label
px wl px wl pr rw dk pr rw dk pr rw dk
Note
If I'd known about Pandas when I wrote this, I might have done it differently :-/
Collated

By default, exports are "collated" (grouped by MEASUREMENT).

If NOT SaveOptions.save_collated(), then the columns are grouped by each "subspectrum" (processed, raw, dark, reference etc). This changes the basic layout above to:

Enlighten ver
MeasID         A  B  C     A  B  C     A  B  C    <-- metadata repeated for each subspectrum
Serial         S1 S1 S2    S1 S1 S2    S1 S1 S2
Label          Aa Bb Cc    Aa Bb Cc    Aa Bb Cc
m1             x  y  z     x  y  z     x  y  z
m2             x  y  z     x  y  z     x  y  z

S1    S2    Pr          Rw          Dk            <-- a "blank column" is inserted between each grouping, with the label of that subspectrum
px wl px wl    Aa Bb Cc    Aa Bb Cc    Aa Bb Cc   <-- the Measurement.label is used as the header within each grouping
Known Issues

There is a fundamental weakness here that we are assuming:

(1) SpectrometerSettings will not change for a given serial number over the course of the measurements, and (2) individual Measurement's ProcessedReading get_wavelengths() etc actually reflect the current SpectrometerSettings (and weren't trumped along the line by a plugin or whatever).

◆ export_by_row()

enlighten.measurement.Measurements.Measurements.export_by_row ( self,
csv_writer,
visible_only = False )

In the row-based export, try to follow historical Dash conventions, as there's no obvious justification not to.

Note that the Dash format didn't fully anticipate multiple spectrometers, so typically only listed one serial number on the file header. Just list them all.

A naive implementation of this would just be to re-save the first Measurement as csv_by_row, then forcibly append all the others atop it. However, that would go into the wrong directory, with the wrong filename. This is short enough that it doesn't matter.

It is believed that this exported file will match what you would have generated if you had initially saved the first Measurement as a row-ordered CSV, then appended subsequent Measurements.

◆ export_callback()

enlighten.measurement.Measurements.Measurements.export_callback ( self)

◆ export_session()

enlighten.measurement.Measurements.Measurements.export_session ( self,
filename = None,
prompt = True )

The user clicked the "Export" button at the bottom of the Thumbnail layout and wants to export every current Measurement into a single CSV (either row- or column-ordered, per SaveOptions).

(Can also be triggered at end of BatchCollection batch, or perhaps from a future plugin.)

Parameters
filenameBatchCollection generates one so we needn't prompt user
promptprompt for verification (False for unattended operation)

◆ export_session_csv()

enlighten.measurement.Measurements.Measurements.export_session_csv ( self,
directory,
filename,
visible_only = False )

◆ export_session_json()

enlighten.measurement.Measurements.Measurements.export_session_json ( self,
directory,
filename,
export )

Should this generate a JSON dict of Measurements (keyed on MeasurementID) or a JSON list of Measurements?

Could argue either way, but I'm defaulting to list as it's slightly simpler for sender and receiver both.

◆ export_session_spc()

enlighten.measurement.Measurements.Measurements.export_session_spc ( self,
directory,
filename,
visible_only = False )

◆ generate_export_dict()

list[dict] enlighten.measurement.Measurements.Measurements.generate_export_dict ( self,
visible_only = False )

◆ get()

enlighten.measurement.Measurements.Measurements.get ( self,
measurement_id )

◆ id_callback()

enlighten.measurement.Measurements.Measurements.id_callback ( self,
measurement_id,
declared_match )

called by KnowItAll.Feature on receiving a MatchResponse from KIA.Wrapper which correponds to a MeasurementID.

◆ incompatible_axes()

enlighten.measurement.Measurements.Measurements.incompatible_axes ( self,
export_measurements )

◆ load_callback()

enlighten.measurement.Measurements.Measurements.load_callback ( self)

display a file selection dialog, let the user select one or more files, then load them up (including thumbnail generation)

◆ read_measurements()

enlighten.measurement.Measurements.Measurements.read_measurements ( self)

◆ register_observer()

enlighten.measurement.Measurements.Measurements.register_observer ( self,
event,
callback )

Register the given callback (typically an instance method) if the named event occurs.

Parameters
event(Input) a string (supported values: Measurements.observers.keys())
callback(Input) a func or method to call if the named event occurs

◆ rename_last_measurement()

enlighten.measurement.Measurements.Measurements.rename_last_measurement ( self)

◆ resize_callback()

enlighten.measurement.Measurements.Measurements.resize_callback ( self)

◆ resort_callback()

enlighten.measurement.Measurements.Measurements.resort_callback ( self)

Essentially, cfu.verticalLayout_scope_capture_save.reverse()

◆ update_buttons()

enlighten.measurement.Measurements.Measurements.update_buttons ( self)

◆ update_count()

enlighten.measurement.Measurements.Measurements.update_count ( self)

Update the "X spectra" label on the GUI, and dis/enable buttons.

◆ update_kia()

enlighten.measurement.Measurements.Measurements.update_kia ( self)

Enable or disable the Identification button on all Measurement ThumbnailWidgets.

Todo
fold into observers?

Member Data Documentation

◆ ctl

enlighten.measurement.Measurements.Measurements.ctl = ctl

◆ erase_all_callback

enlighten.measurement.Measurements.Measurements.erase_all_callback

◆ export_callback

enlighten.measurement.Measurements.Measurements.export_callback

◆ insert_top

enlighten.measurement.Measurements.Measurements.insert_top = True

◆ is_collapsed

enlighten.measurement.Measurements.Measurements.is_collapsed = False

◆ load_callback

enlighten.measurement.Measurements.Measurements.load_callback

◆ measurements

enlighten.measurement.Measurements.Measurements.measurements = []

◆ observers

dict enlighten.measurement.Measurements.Measurements.observers
Initial value:
= {
"export": []
}

◆ resize_callback

enlighten.measurement.Measurements.Measurements.resize_callback

◆ resort_callback

enlighten.measurement.Measurements.Measurements.resort_callback

The documentation for this class was generated from the following file: