|
Wasatch.PY
Python application driver for Wasatch Photonics spectrometers
|
Functions | |
| all_same (a) | |
| apply_boxcar (a, half_width) | |
| apply a boxcar convolution of the given half_width to input array 'a' | |
| area_under_peak (spectrum, x_axis, x_index, boxcar_half_width=0) | |
| integrate the 'area under the curve' for the given spectrum and x_axis, using the peak centered on x_axis, with optional smoothing given the boxcar width. | |
| ascii_spectrum (spectrum, rows, cols, x_axis, x_unit) | |
| render a spectrum as ASCII-art | |
| check_admin () | |
| clamp_to_int16 (n) | |
| clean_nan (a) | |
| coeffs_look_valid (coeffs, count=None) | |
| Can be used as a sanity-check for any set of coefficients. | |
| dict_get_norm (d, keys) | |
| Similar to dict.get(), but case-insensitive and normalizes-out spaces, underscores, periods and hyphens. | |
| dict_get_path (d, keys) | |
| Similar to dict.get(), but takes a list of keys to be traversed in sequence. | |
| dump (foo, indent=0) | |
| similar to Perl's Data.Dumper | |
| find_local_maxima (a, x_axis, center, tolerance=0) | |
| Given a spectrum (array 'a'), with an x_axis, a 'center' along that x_axis, and an allowed 'tolerance' (in same units as the x_axis), find the local maxima within 'tolerance' of 'center'. | |
| find_nearest_index (L, value) | |
| find_nearest_value (L, value) | |
| find_peak_feet_indices (spectrum, x_axis, x_index, boxcar_half_width=0) | |
| Given a spectrum and an x_axis, find the indexes of the left and right 'feet' of the peak centered on x_index. | |
| generate_excitation (wavelengths, wavenumbers) | |
| If we've loaded a CSV that had wavelength and wavenumber columns, but no metadata, use this to infer the excitation wavelength. | |
| generate_wavelengths (pixels, coeffs) | |
| expand 3rd-order wavelength polynomial into array of wavelengths | |
| generate_wavelengths_from_wavenumbers (excitation, wavenumbers) | |
| generate_wavenumbers (excitation, wavelengths, wavenumber_correction=0) | |
| convert wavelengths into Raman shifts in 1/cm wavenumbers from the given excitation wavelength | |
| get_pathnames_from_directory (rootdir, pattern=None, recursive=False) | |
| iterate down a directory, returning pathnames that match the given pattern | |
| interpolate_array (spectrum, old_axis, new_axis) | |
| Interpolate the passed spectrum over a fixed x-axis (e.g. | |
| interpolate_value (spectrum, old_axis, x) | |
| I might be making this more difficult than it needs to be. | |
| load_json (pathname) | |
| convenience wrapper to load a JSON file | |
| parabolic_approximation (pixel, x, y) | |
| Given an array of doubles and a peak index, use the peak and its two neighbors to form a parabola and return the interpolated maximum height of the parabola. | |
| peak_height_above_background (spectrum, x_axis, x_index, boxcar_half_width=0) | |
| pixel_to_wavelength (int x, list[float] coeffs) | |
| remove_unicode (s) | |
| convert unicode string to ascii | |
| resize_file (path, nbytes, ensure_no_overwrite=False) | |
| stomp_first (a, count) | |
| "Stomps" the first "count" elements with the first non-stomped value. | |
| stomp_last (a, count) | |
| "stomps" the last "count" elements with the last non-stomped value | |
| timestamp () | |
| to_bool (value) | |
| truthy (flag) | |
| twos_complement (val, bits) | |
| uint16_to_little_endian (values) | |
| update_obj_from_dict (obj, d) | |
| given a destination object and a source dictionary, update any existing attributes of the destination object from like-named keys in the source dictionary | |
| vercmp (a, b, delim=".") | |
| wavelength_to_wavenumber (wavelength, excitation) | |
| convert a single wavelength to wavenumber | |
| wavenumber_to_wavelength (excitation, wavenumber) | |
| convert a single (uncorrected) wavenumber to wavelength | |
Variables | |
| log = logging.getLogger(__name__) | |
| wasatch.utils.all_same | ( | a | ) |
| wasatch.utils.apply_boxcar | ( | a, | |
| half_width ) |
apply a boxcar convolution of the given half_width to input array 'a'
| wasatch.utils.area_under_peak | ( | spectrum, | |
| x_axis, | |||
| x_index, | |||
| boxcar_half_width = 0 ) |
integrate the 'area under the curve' for the given spectrum and x_axis, using the peak centered on x_axis, with optional smoothing given the boxcar width.
| wasatch.utils.ascii_spectrum | ( | spectrum, | |
| rows, | |||
| cols, | |||
| x_axis, | |||
| x_unit ) |
render a spectrum as ASCII-art
| wasatch.utils.check_admin | ( | ) |
| wasatch.utils.clamp_to_int16 | ( | n | ) |
| wasatch.utils.clean_nan | ( | a | ) |
| wasatch.utils.coeffs_look_valid | ( | coeffs, | |
| count = None ) |
Can be used as a sanity-check for any set of coefficients.
Checks that coeffs:
| wasatch.utils.dict_get_norm | ( | d, | |
| keys ) |
Similar to dict.get(), but case-insensitive and normalizes-out spaces, underscores, periods and hyphens.
| d | (input) dictionary |
| k | (input) case-insensitive key (can be prioritized list) |
Note that this function does not distiguish between the dictionary not having a key, and the value of the key being None.
| wasatch.utils.dict_get_path | ( | d, | |
| keys ) |
Similar to dict.get(), but takes a list of keys to be traversed in sequence.
| d | (input) dictionary |
| keys | (input) list of case-insensitive keys |
| wasatch.utils.dump | ( | foo, | |
| indent = 0 ) |
similar to Perl's Data.Dumper
| wasatch.utils.find_local_maxima | ( | a, | |
| x_axis, | |||
| center, | |||
| tolerance = 0 ) |
Given a spectrum (array 'a'), with an x_axis, a 'center' along that x_axis, and an allowed 'tolerance' (in same units as the x_axis), find the local maxima within 'tolerance' of 'center'.
| wasatch.utils.find_nearest_index | ( | L, | |
| value ) |
| wasatch.utils.find_nearest_value | ( | L, | |
| value ) |
| wasatch.utils.find_peak_feet_indices | ( | spectrum, | |
| x_axis, | |||
| x_index, | |||
| boxcar_half_width = 0 ) |
Given a spectrum and an x_axis, find the indexes of the left and right 'feet' of the peak centered on x_index.
Internally apply then given boxcar for added smoothing.
| wasatch.utils.generate_excitation | ( | wavelengths, | |
| wavenumbers ) |
If we've loaded a CSV that had wavelength and wavenumber columns, but no metadata, use this to infer the excitation wavelength.
Useful for interpolation.
| wasatch.utils.generate_wavelengths | ( | pixels, | |
| coeffs ) |
expand 3rd-order wavelength polynomial into array of wavelengths
| wasatch.utils.generate_wavelengths_from_wavenumbers | ( | excitation, | |
| wavenumbers ) |
| wasatch.utils.generate_wavenumbers | ( | excitation, | |
| wavelengths, | |||
| wavenumber_correction = 0 ) |
convert wavelengths into Raman shifts in 1/cm wavenumbers from the given excitation wavelength
| wasatch.utils.get_pathnames_from_directory | ( | rootdir, | |
| pattern = None, | |||
| recursive = False ) |
iterate down a directory, returning pathnames that match the given pattern
| wasatch.utils.interpolate_array | ( | spectrum, | |
| old_axis, | |||
| new_axis ) |
Interpolate the passed spectrum over a fixed x-axis (e.g.
integral wavelengths or wavenumbers).
| wasatch.utils.interpolate_value | ( | spectrum, | |
| old_axis, | |||
| x ) |
I might be making this more difficult than it needs to be.
| wasatch.utils.load_json | ( | pathname | ) |
convenience wrapper to load a JSON file
| wasatch.utils.parabolic_approximation | ( | pixel, | |
| x, | |||
| y ) |
Given an array of doubles and a peak index, use the peak and its two neighbors to form a parabola and return the interpolated maximum height of the parabola.
"pixel" is ideally the array index of the pinnacle of a previously- identified peak within the spectrum, although though this will technically generate a parabola through any pixel and its two neighbors.
| pixel | index of a point on the spectrum |
| x | x-axis (wavelengths or wavenumbers) |
| y | y-axis (intensity) |
| wasatch.utils.peak_height_above_background | ( | spectrum, | |
| x_axis, | |||
| x_index, | |||
| boxcar_half_width = 0 ) |
| wasatch.utils.pixel_to_wavelength | ( | int | x, |
| list[float] | coeffs ) |
| wasatch.utils.remove_unicode | ( | s | ) |
convert unicode string to ascii
| wasatch.utils.resize_file | ( | path, | |
| nbytes, | |||
| ensure_no_overwrite = False ) |
Keep only the last `nbytes` of a text file specified by `path`. This function is encoding (utf-8, utf-16, ascii) agnostic because it uses the line- continuation character '\n' as a boundary. It is system independent because it slices before that character. This was written to keep our default log file within a reasonable filesize, suitable for emailing. Call this on a file that is not yet opened. Expect the file to be closed and flushed by the time the function returns. returns True if the file was changed.
| wasatch.utils.stomp_first | ( | a, | |
| count ) |
"Stomps" the first "count" elements with the first non-stomped value.
| a | (Input) array to modify |
| count | (Input) HOW MANY leading elements to stomp, so the index of the first GOOD pixel should be one more than this |
| wasatch.utils.stomp_last | ( | a, | |
| count ) |
"stomps" the last "count" elements with the last non-stomped value
| wasatch.utils.timestamp | ( | ) |
| wasatch.utils.to_bool | ( | value | ) |
| wasatch.utils.truthy | ( | flag | ) |
| wasatch.utils.twos_complement | ( | val, | |
| bits ) |
| wasatch.utils.uint16_to_little_endian | ( | values | ) |
| wasatch.utils.update_obj_from_dict | ( | obj, | |
| d ) |
given a destination object and a source dictionary, update any existing attributes of the destination object from like-named keys in the source dictionary
| obj | (In/Out) the object whose attributes to update |
| d | (Input) the dictionary whose keys should be treated as attributes |
| wasatch.utils.vercmp | ( | a, | |
| b, | |||
| delim = "." ) |
vercmp("1.2.3.4", "1.2.4.3") -> -1
| wasatch.utils.wavelength_to_wavenumber | ( | wavelength, | |
| excitation ) |
convert a single wavelength to wavenumber
| wasatch.utils.wavenumber_to_wavelength | ( | excitation, | |
| wavenumber ) |
convert a single (uncorrected) wavenumber to wavelength
| wasatch.utils.log = logging.getLogger(__name__) |