PyICe.lab_utils¶
Miscellaneous Utilities¶
Includes:
- database access toools
- servo delay loop
- string sanitization
- filters and other numeric transforms
- floating point number utilites
- email/SMS notification
Functions
bounded (value[, min_value, max_value, key]) |
|
clean_c (str) |
|
column_formatter (rows_of_columns[, padding, ...]) |
takes data of form: [[‘ID:’, ‘REL_NOW_TIME’, ‘DURATION’, ‘FMT’, ‘RAW ‘, ‘COUNT’], |
decadeListRange (decadePoints, decades) |
log step range function similar to python built-in range() |
decimate (rec_array, downsample_factor, **kwargs) |
Reduce row count by factor of downsample_factor. |
delete_file (filename[, max_tries, retry_delay]) |
Tries to delete a file, retrying if the file is locked (e.g. |
detrend_constant (rec_array, **kwargs) |
Remove data mean from all columns except first one (assumed x-axis) |
detrend_linear (rec_array, **kwargs) |
Remove data mean from all columns except first one (assumed x-axis) |
differential_nonlinearity (rec_array[, lsb_size]) |
transform (code, voltage) data into DNL. |
egg_timer (timeout[, message, length, ...]) |
Provides a blocking delay with a graphic to indicate progress so far so the computer doesn’t look idle optionally, display a message on the line above the timer graphic optionally, specify a display_callback function to insert extra progress information after the timer display. |
eng_string (x[, fmt, si]) |
Returns float/int value <x> formatted in a simplified engineering format - using an exponent that is a multiple of 3. |
expand_tabs (string, *column_widths, ...) |
like string.expandtabs, but works only on a single line and allows for varying column widths. |
floatRange (start[, stop, step]) |
Returns a list of numbers similar to python range() builtin but supports floats. |
floatRangeInc (start[, stop, step]) |
Same as float range, however it is inclusive of the last value |
float_distance (x, y) |
return signed difference between x and y expressed as distance between representable floating point numbers. |
float_next (val) |
return next Python double precision floating point nuber larger than x. |
float_prior (val) |
return next Python double precision floating point nuber smaller than x. |
integral_nonlinearity (rec_array[, lsb_size]) |
transform (code, voltage) data into INL |
isclose (a, b[, rel_tol, abs_tol]) |
returns True if a is close in value to b. False otherwise |
logRange (start, stop[, stepsPerDecade, ...]) |
log step range function similar to python built-in range() |
logger_time_str (datetime) |
return time string in same format as used by lab_core.logger. |
modulate (data1, data2) |
data1 and data2 are tuples of x and y data that may not have the same number of ‘x’ values. The result is interpolated up to the higher of the two. |
polyfit (rec_array[, degree]) |
returns polynomial fit coefficients list, highest order first |
ramer_douglas_peucker (rec_array, epsilon[, ...]) |
reduce number of points in line-sigment curve such that reduced line segment count approximates original curve within epsilon tolerance. |
remove_html (text) |
|
remove_non_ascii (text) |
|
scalar_transform (rec_array, ...[, column_names]) |
Transform column data by processing through user-supplied function column_scalar_functions is a list of functions for each column and should have a length equal to the number of columns. |
signedToTwosComplement (signed, bitCount) |
take python int and convert to two’s complement representation using specified number of bits |
smooth_filtfile (rec_array) |
somebody finish this. |
smooth_spline (rec_array, rms_error[, verbose]) |
uses http://scipy.github.io/devdocs/generated/scipy.interpolate.UnivariateSpline.html with movable knots |
str2num (str_in) |
|
swap_endian (word, elementCount[, elementSize]) |
reverse endianness of multi-byte word |
twosComplementToSigned (binary, bitCount) |
take two’s complement number with specified number of bits and convert to python int representation |
unit_least_precision (val[, increasing]) |
return positive increment/decrement to next representable floating point number above/below val |
vector_transform (rec_array, ...[, column_names]) |
Generic filter function. |
Classes
US_Eastern_Time () |
US Eastern time zone. |
US_Pacific_Time () |
US Pacific time zone. |
US_Time_Zone |
Generic Timezone parent class. |
UTC () |
UTC / GMT / Zulu time zone. |
csv_logger (output_file[, encoding]) |
set up columns, then pass results dictionary from logger or channel group to write() method. |
csv_writer () |
shared functions for higher level interfaces |
debug_log ([log_file_name, debug]) |
Log messages into a file and optionally print to screen. |
delay_loop ([strict, begin, no_drift]) |
make constant loop delay independent of loop processing time by measuring time at beginning |
dlog ([filename]) |
|
email (destination[, login, pw, domain]) |
sends email to specified destination from dedicated gmail account, or account of your choosing |
interpolator () |
|
ordered_pair |
|
oscilloscope_channel (time_points, channel_data) |
|
sms (mobile_number, carrier[, login, pw, domain]) |
Extends email class to send sms messages through several carriers’ email to sms gateways |
sqlite_data ([table_name, database_file, ...]) |
Produce iteratable object returning row sequence, where each column within each row is accessible by either column name or position. |
sqlite_to_csv (table_name[, database_file]) |
Formats data stored in an SQLite database so that it can be browsed interactively. |
sqlite_to_easylog (chart_name, table_name[, ...]) |
Wrapper to make specific format required by Easy Log Graph software. |
threaded_writer ([verbose]) |
helper to perform some task in parallel with test script at fixed rate |
ticker ([stock_list]) |
-
class
PyICe.lab_utils.
US_Eastern_Time
[source]¶ Bases:
PyICe.lab_utils.US_Time_Zone
US Eastern time zone. (NYC/BOS)
-
dst
(dt)¶ return DST offset from standard local time based on calendar date.
-
first_sunday_on_or_after
(dt)¶ return date of first Sunday on or after dt.
-
fromutc
()¶ datetime in UTC -> datetime in local time.
-
tzname
(dt)¶ return DST aware local time zone name based on calendar date.
-
utcoffset
(dt)¶ return DST aware offset from GMT/UTC based on calendar date.
-
-
class
PyICe.lab_utils.
US_Pacific_Time
[source]¶ Bases:
PyICe.lab_utils.US_Time_Zone
US Pacific time zone. (LAX/SMF)
-
dst
(dt)¶ return DST offset from standard local time based on calendar date.
-
first_sunday_on_or_after
(dt)¶ return date of first Sunday on or after dt.
-
fromutc
()¶ datetime in UTC -> datetime in local time.
-
tzname
(dt)¶ return DST aware local time zone name based on calendar date.
-
utcoffset
(dt)¶ return DST aware offset from GMT/UTC based on calendar date.
-
-
class
PyICe.lab_utils.
US_Time_Zone
[source]¶ Bases:
datetime.tzinfo
Generic Timezone parent class. Implements methods required by datetime.tzinfo with US DST rules (second Sunday of March and first Sunday of November). Requires subclass to define local timezone parameters:
self.tz_name self.tz_name_dst self.gmt_offset self.dst_offset-
fromutc
()¶ datetime in UTC -> datetime in local time.
-
-
class
PyICe.lab_utils.
UTC
[source]¶ Bases:
PyICe.lab_utils.US_Time_Zone
UTC / GMT / Zulu time zone.
-
dst
(dt)¶ return DST offset from standard local time based on calendar date.
-
first_sunday_on_or_after
(dt)¶ return date of first Sunday on or after dt.
-
fromutc
()¶ datetime in UTC -> datetime in local time.
-
tzname
(dt)¶ return DST aware local time zone name based on calendar date.
-
utcoffset
(dt)¶ return DST aware offset from GMT/UTC based on calendar date.
-
-
PyICe.lab_utils.
column_formatter
(rows_of_columns, padding=3, justification='left', fist_line_justification='center')[source]¶ - takes data of form: [[‘ID:’, ‘REL_NOW_TIME’, ‘DURATION’, ‘FMT’, ‘RAW ‘, ‘COUNT’],
- [u‘00:’, ‘-00:00:35.290 ‘, ‘ 00:00:00.431 ‘, u‘41.974488V’, 28438, 1], [u‘01:’, ‘-00:00:34.859 ‘, ‘ 00:00:07.216 ‘, u’-20.675808V’, 51528, 1], [u‘02:’, ‘-00:00:27.643 ‘, ‘ 00:00:00.586 ‘, u’-30.318516V’, 44995, 1], [u‘03:’, ‘-00:00:27.057 ‘, ‘ 00:00:17.777 ‘, u‘38.97378V’, 26405, 1], [u‘04:’, ‘-00:00:09.280 ‘, ‘ 00:00:00.897 ‘, u‘21.428568V’, 14518, 1], [u‘05:’, ‘-00:00:08.383 ‘, ‘ 00:00:08.383+’, u’-23.781312V’, 49424, 1]
]
- produces formatted output of form: ID: REL_NOW_TIME DURATION FMT RAW COUNT
- 00: -00:00:35.290 00:00:00.431 41.974488V 28438 1 01: -00:00:34.859 00:00:07.216 -20.675808V 51528 1 02: -00:00:27.643 00:00:00.586 -30.318516V 44995 1 03: -00:00:27.057 00:00:17.777 38.97378V 26405 1 04: -00:00:09.280 00:00:00.897 21.428568V 14518 1 05: -00:00:08.383 00:00:08.383+ -23.781312V 49424 1
padding sets spacing between columns first_line_justification and justification control aligment for first and subsequent lines respectively.
valid arguments are ‘left’,’right’ and ‘center’
-
class
PyICe.lab_utils.
csv_logger
(output_file, encoding='utf-8')[source]¶ Bases:
PyICe.lab_utils.csv_writer
set up columns, then pass results dictionary from logger or channel group to write() method. Can be used to provide automated test script ‘marching waves’ with a program such as Live Graph (http://www.live-graph.org/).
-
add_columns
(channel_list)[source]¶ set up output to include channel objects in channel_list as column data sources
-
add_comment
(comment_str, comment_character='#')¶ add comment line(s) to the top of the output file. Live Graph treats ‘@’ as a ‘description line’ and ‘#’ as a ‘comment line’. Neither has any effect on the data interpretation.
-
add_elapsed_days
(display_name='elapsed_days', format='')¶ computes elapsed days since first row of table
-
add_elapsed_hours
(display_name='elapsed_hours', format='')¶ computes elapsed hours since first row of table
-
add_elapsed_minutes
(display_name='elapsed_minutes', format='')¶ computes elapsed minutes since first row of table
-
add_elapsed_seconds
(display_name='elapsed_seconds', format='')¶ computes elapsed seconds since first row of table
-
register_logger_callback
(logger)[source]¶ register this csv_logger instance with a lab_core.logger instance for automatic data plotting
-
-
class
PyICe.lab_utils.
csv_writer
[source]¶ Bases:
object
shared functions for higher level interfaces
-
add_column
(query_name, display_name=None, format='', transform=None, query_function=None)[source]¶ add single column to output file. provides more customization options than addign a list of columns transform is a python function applied to the query results before formatting format is a format string to alter the column data. Ex: 3.2f. query function is a function that returns data directly from Python rather than from external data source. Ex: time
-
add_columns
(column_list, format='')[source]¶ Shortcut method to add multiple data columns at once. column_list selects additional data columns to output. format is a format string to alter the column data. Ex: 3.2f. For more flexibility, add columns individually using add_column() method.
-
add_comment
(comment_str, comment_character='#')[source]¶ add comment line(s) to the top of the output file. Live Graph treats ‘@’ as a ‘description line’ and ‘#’ as a ‘comment line’. Neither has any effect on the data interpretation.
-
add_elapsed_days
(display_name='elapsed_days', format='')[source]¶ computes elapsed days since first row of table
-
add_elapsed_hours
(display_name='elapsed_hours', format='')[source]¶ computes elapsed hours since first row of table
-
-
class
PyICe.lab_utils.
debug_log
(log_file_name='PyICe.lab_utils.log', debug=False)[source]¶ Bases:
object
Log messages into a file and optionally print to screen.
-
PyICe.lab_utils.
decadeListRange
(decadePoints, decades)[source]¶ log step range function similar to python built-in range() accepts list input of points in a single decade and repeats these points over the specified number of decades
-
PyICe.lab_utils.
decimate
(rec_array, downsample_factor, **kwargs)[source]¶ Reduce row count by factor of downsample_factor. By default an order 8 Chebyshev type I filter is used independently on each column. Set kwarg ftype=’fir’ to instead use a 30 point FIR filter with hamming window (recommended). http://docs.scipy.org/doc/scipy-0.16.1/reference/generated/scipy.signal.decimate.html
-
class
PyICe.lab_utils.
delay_loop
(strict=False, begin=True, no_drift=True)[source]¶ Bases:
object
make constant loop delay independent of loop processing time by measuring time at beginning and end of loop and adding extra delay as necessary
-
begin
(offset=0)[source]¶ make note of begin time for loop measurement. Use offset to adjust the begin time in case of overrun on last cycle.
-
-
PyICe.lab_utils.
delete_file
(filename, max_tries=20, retry_delay=5)[source]¶ Tries to delete a file, retrying if the file is locked (e.g. because it is open in Notepad++, SQLite Manager, or another program), failing gracefully if the file doesn’t (yet) exist. Gives up after a number of retries and raises RuntimeError. Good for removing stale sqlite DBs and log files from old runs.
-
PyICe.lab_utils.
detrend_constant
(rec_array, **kwargs)[source]¶ Remove data mean from all columns except first one (assumed x-axis) http://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.detrend.html
-
PyICe.lab_utils.
detrend_linear
(rec_array, **kwargs)[source]¶ Remove data mean from all columns except first one (assumed x-axis) http://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.detrend.html
-
PyICe.lab_utils.
differential_nonlinearity
(rec_array, lsb_size=1)[source]¶ transform (code, voltage) data into DNL. optional lsb_size argument scales y-axis data from real units to lsb count.
-
PyICe.lab_utils.
egg_timer
(timeout, message=None, length=30, display_callback=None)[source]¶ Provides a blocking delay with a graphic to indicate progress so far so the computer doesn’t look idle optionally, display a message on the line above the timer graphic optionally, specify a display_callback function to insert extra progress information after the timer display. display_callback function should accept a single dictionary argument and return a string.
-
class
PyICe.lab_utils.
email
(destination, login='ltlabboston', pw='PythonLab', domain='gmail.com')[source]¶ Bases:
object
sends email to specified destination from dedicated gmail account, or account of your choosing
-
PyICe.lab_utils.
eng_string
(x, fmt=':.3g', si=True)[source]¶ Returns float/int value <x> formatted in a simplified engineering format - using an exponent that is a multiple of 3.
format: printf-style string used to format the value before the exponent.
si: if true, use SI suffix for exponent, e.g. k instead of e3, n instead of e-9 etc.
- E.g. with format=’%.2f’:
- 1.23e-08 => 12.30e-9
- 123 => 123.00
1230.0 => 1.23e3
-1230000.0 => -1.23e6
- and with si=True:
- 1230.0 => 1.23k
-1230000.0 => -1.23M
-
PyICe.lab_utils.
expand_tabs
(string, *column_widths, **default_column_width)[source]¶ like string.expandtabs, but works only on a single line and allows for varying column widths. accepts variable number of positional arguments for each column width. accepts keyword argument “default_column_width” if not all column widths are specified. accepts keyword argument “verbose” to warn if column width is too narrow for contents.
-
PyICe.lab_utils.
floatRange
(start, stop=None, step=None)[source]¶ Returns a list of numbers similar to python range() builtin but supports floats. start is inclusive, stop is exclusive When called with a single argument, start=0 and the argument becomes stop.
-
PyICe.lab_utils.
floatRangeInc
(start, stop=None, step=None)[source]¶ Same as float range, however it is inclusive of the last value
-
PyICe.lab_utils.
float_distance
(x, y)[source]¶ return signed difference between x and y expressed as distance between representable floating point numbers.
-
PyICe.lab_utils.
float_next
(val)[source]¶ return next Python double precision floating point nuber larger than x.
-
PyICe.lab_utils.
float_prior
(val)[source]¶ return next Python double precision floating point nuber smaller than x.
-
PyICe.lab_utils.
integral_nonlinearity
(rec_array, lsb_size=1)[source]¶ transform (code, voltage) data into INL optional lsb_size argument scales y-axis data from real units to lsb count.
-
PyICe.lab_utils.
isclose
(a, b, rel_tol=1e-09, abs_tol=0.0)[source]¶ returns True if a is close in value to b. False otherwise :param a: one of the values to be tested :param b: the other value to be tested :param rel_tol=1e-9: The relative tolerance – the amount of error
allowed, relative to the absolute value of the larger input values.Parameters: abs_tol=0.0 – The minimum absolute tolerance level – useful for comparisons to zero. NOTES: -inf, inf and NaN behave similarly to the IEEE 754 Standard. That is, NaN is not close to anything, even itself. inf and -inf are only close to themselves. The function can be used with any type that supports comparison, substratcion and multiplication, including Decimal, Fraction, and Complex Complex values are compared based on their absolute value. See PEP-0485 for a detailed description
-
PyICe.lab_utils.
logRange
(start, stop, stepsPerDecade=None, stepsPerOctave=None)[source]¶ log step range function similar to python built-in range()
-
PyICe.lab_utils.
logger_time_str
(datetime)[source]¶ return time string in same format as used by lab_core.logger. Requires timezone-aware datetime object argument to correctly convert to UTC times used by logger. if datetime object is naieve of timezone, add it with datetime.replace(tzinfo=lab_utils.US_Eastern_Time()) or datetime.replace(tzinfo=lab_utils.UTC())
-
PyICe.lab_utils.
modulate
(data1, data2)[source]¶ data1 and data2 are tuples of x and y data that may not have the same number of ‘x’ values. The result is interpolated up to the higher of the two.
-
PyICe.lab_utils.
polyfit
(rec_array, degree=1)[source]¶ returns polynomial fit coefficients list, highest order first https://docs.scipy.org/doc/numpy/reference/generated/numpy.polyfit.html
-
PyICe.lab_utils.
ramer_douglas_peucker
(rec_array, epsilon, verbose=True)[source]¶ reduce number of points in line-sigment curve such that reduced line segment count approximates original curve within epsilon tolerance. https://en.wikipedia.org/wiki/Ramer%E2%80%93Douglas%E2%80%93Peucker_algorithm
-
PyICe.lab_utils.
scalar_transform
(rec_array, column_scalar_functions, column_names=None)[source]¶ Transform column data by processing through user-supplied function column_scalar_functions is a list of functions for each column and should have a length equal to the number of columns. To leave a column unchanged, set column scalar function to None. The column scalar function will be applied to each point in the column individually. Thus it is appropriate for scaling, offseting changing data type, etc. This function cannot be used for filtering or convolution operations that need access to adjacent data points. Instead, use vector_transform(). column_names is a list of names for each column in the returned record array. To leave a column name unchanged from input record array, set column name to None. To leave all column names unchanged from input record array, set column_names to None.
-
PyICe.lab_utils.
signedToTwosComplement
(signed, bitCount)[source]¶ take python int and convert to two’s complement representation using specified number of bits
-
PyICe.lab_utils.
smooth_filtfile
(rec_array)[source]¶ somebody finish this. https://docs.scipy.org/doc/scipy-0.18.1/reference/generated/scipy.signal.filtfilt.html
-
PyICe.lab_utils.
smooth_spline
(rec_array, rms_error, verbose=True, **kwargs)[source]¶ uses http://scipy.github.io/devdocs/generated/scipy.interpolate.UnivariateSpline.html with movable knots set rms_error to change number of knots to bound smoothed data rms deviation from original data points. rec_array is modified in place returns number of knots used to contstruct spline
-
class
PyICe.lab_utils.
sms
(mobile_number, carrier, login='ltlabboston', pw='PythonLab', domain='gmail.com')[source]¶ Bases:
PyICe.lab_utils.email
Extends email class to send sms messages through several carriers’ email to sms gateways
-
send
(body, subject=None, attachments=[])¶ compose MIME message with proper headers and send
-
-
class
PyICe.lab_utils.
sqlite_data
(table_name=None, database_file='data_log.sqlite', timezone=None)[source]¶ Bases:
_abcoll.Sequence
Produce iteratable object returning row sequence, where each column within each row is accessible by either column name or position. table_name can be an expression returning a synthetic non-table relation.
-
column_query
(column_list)[source]¶ return partial query string separating column names with comma characters.
-
count
(value) → integer -- return number of occurrences of value¶
-
csv
(output_file, elapsed_time_columns=False, append=False, encoding='utf-8')[source]¶ write data to csv output_file. set output_file to None to just return csv string.
-
expand_vector_data
(csv_filename=None, csv_append=False, csv_encoding='utf-8')[source]¶ Expand vector list data (from oscilloscope, network analyzer, etc) to full row-rank. Scalar data will be expanded to vector length. Returns numpy record array. Optionally write output to comma separated file if csv_filname argument is specified.
-
filter_change
(column_name_list, table_name=None, first_row=False, preceding_row=False)[source]¶ return tuple of rowid values where any column in column_name_list changed value. result tuple can be fed into a new query(“SELECT ... WHERE rowid in {}”.format(sqlite_data_obj.filter_change())). it table_name is omitted, instance default will be used. setting preceding_row to True will also return the rowid before the change occurred.
-
get_column_names
()[source]¶ return tuple of column names. Column names can be used for future queries or used to select column from query row results.
-
get_column_types
()[source]¶ Return dictionary of data types stored in each column. Note that SQLite does not enforce types within a column, nor does the PyICe logger. The types of data stored in the first row will be returned, which may not match data stored elsewhere in the relation. Used by numpy array conversion to define data stride.
-
get_distinct
(column_name, table_name=None)[source]¶ return one copy of each value (set) in specified column table_name can be an expression returning a synthetic non-table relation.
-
index
(value) → integer -- return first index of value.¶ Raises ValueError if the value is not present.
-
numpy_recarray
(force_float_dtype=False, data_types=None)[source]¶ return NumPy record array containing data. Rows can be accessed by index, ex arr[2]. Columns can be accessed by column name attribute, ex arr.vbat. Use with data filtering, smoothing, compressing, etc matrix operations provided by SciPy and lab_utils.transform, lab_utils.decimate. Use automaticic column names, but force data type to float with force_float_dtype boolean argument. Override automatic coulumn names and data types (first row) by specifying data_type iterable of (column_name,example_contents) for each column matching query order. http://docs.scipy.org/doc/numpy-1.10.1/reference/generated/numpy.recarray.html
-
optimize
()[source]¶ Defragment database file, reducing file size and speeding future queries. Also re-runs query plan optimizer to spped future queries. WARNING: May take a lot time to complete when operating on a large database. WARNING: May re-order rowid’s
-
query
(sql_query, *params)[source]¶ return iterable with query results. columns within each row can be accessed by column name or by position
-
time_delta_query
(time_div=1, column_name=None)[source]¶ return partial query string which will compute fractional delta seconds from first entry in the table as a column. Feed back into query to get elapsed time column. Ex “SELECT rowid, {}, * FROM ...”.format(sqlite_data_obj.time_delta_query()) Use time_div to convert from second to your choice of time scales, example: time_div=3600 would be hours.
-
-
class
PyICe.lab_utils.
sqlite_to_csv
(table_name, database_file='data_log.sqlite')[source]¶ Bases:
PyICe.lab_utils.csv_writer
Formats data stored in an SQLite database so that it can be browsed interactively. Use a program like Live Graph (www.www.live-graph.org) or KST (kst-plot.kde.org) to visualize data.
-
add_column
(query_name, display_name=None, format='', transform=None, query_function=None)¶ add single column to output file. provides more customization options than addign a list of columns transform is a python function applied to the query results before formatting format is a format string to alter the column data. Ex: 3.2f. query function is a function that returns data directly from Python rather than from external data source. Ex: time
-
add_columns
(column_list, format='')¶ Shortcut method to add multiple data columns at once. column_list selects additional data columns to output. format is a format string to alter the column data. Ex: 3.2f. For more flexibility, add columns individually using add_column() method.
-
add_comment
(comment_str, comment_character='#')¶ add comment line(s) to the top of the output file. Live Graph treats ‘@’ as a ‘description line’ and ‘#’ as a ‘comment line’. Neither has any effect on the data interpretation.
-
add_elapsed_days
(display_name='elapsed_days', format='')¶ computes elapsed days since first row of table
-
add_elapsed_hours
(display_name='elapsed_hours', format='')¶ computes elapsed hours since first row of table
-
add_elapsed_minutes
(display_name='elapsed_minutes', format='')¶ computes elapsed minutes since first row of table
-
add_elapsed_seconds
(display_name='elapsed_seconds', format='')¶ computes elapsed seconds since first row of table
-
-
class
PyICe.lab_utils.
sqlite_to_easylog
(chart_name, table_name, y1_axis_units='V', y2_axis_units='A', database_file='data_log.sqlite')[source]¶ Bases:
PyICe.lab_utils.sqlite_to_csv
Wrapper to make specific format required by Easy Log Graph software. Formats data stored in an SQLite database so that it can be browsed inteactively. Use EasyLogGraph (http://www.lascarelectronics.com/data-logger/easylogger-software.php) to visualize data.
-
add_column
(query_name, second_y_axis=False, display_name=None, format='', transform=None)[source]¶ query name is the name of the sqlite column second_y_axis is a boolean. Setting to True places data on the right-side y-axis scale display_name, if not None, sets csv column header title differently from database column name format controls appearance of queried data. Ex: “3.2f”
-
add_columns
(column_list, second_y_axis=False, format='')[source]¶ adds a list of sqlite column names at once all columns will be placed on left-side y-axis scale unless second_y_axis is True format controls appearance of queried data. Ex: “3.2f”
-
add_elapsed_days
(display_name='elapsed_days', format='')¶ computes elapsed days since first row of table
-
add_elapsed_hours
(display_name='elapsed_hours', format='')¶ computes elapsed hours since first row of table
-
add_elapsed_minutes
(display_name='elapsed_minutes', format='')¶ computes elapsed minutes since first row of table
-
add_elapsed_seconds
(display_name='elapsed_seconds', format='')¶ computes elapsed seconds since first row of table
-
add_timestamps
()¶ Add rowid and datetime columns to csv output.
-
-
PyICe.lab_utils.
swap_endian
(word, elementCount, elementSize=8)[source]¶ reverse endianness of multi-byte word elementCount is number of bytes, or other atomic memory block if not of elementSize 8 bits
to reverse bit order, set elementCount to the number of bits and set elementSize to 1.
-
class
PyICe.lab_utils.
threaded_writer
(verbose=False)[source]¶ Bases:
object
helper to perform some task in parallel with test script at fixed rate
-
add_function
(function, time_interval, start=True)[source]¶ Periodically execute function. No thread safety. Use caution with shared interfaces or use separate remote channel clients with each function. See example above.
-
connect_channel
(channel_name, time_interval, sequence=None, start=True, address='localhost', port=5001, authkey='ltc_lab')[source]¶ Write each element of sequence in turn to channel_name, waiting time_interval between writes. If sequence is None, Periodically read and re-write channel as keepalive. Thread safety provided by remote channel server infrastructure. First thread must call master.serve() and test script should call master.attach().
-
class
stop_thread
(stop_event, stopped_event, queue, group=None, target=None, name=None, args=(), kwargs={})[source]¶ Bases:
threading.Thread
Thread extended to have stop() method. Threads cannot be restarted after stopping. Make a new one to restart.
-
daemon
¶ A boolean value indicating whether this thread is a daemon thread (True) or not (False).
This must be set before start() is called, otherwise RuntimeError is raised. Its initial value is inherited from the creating thread; the main thread is not a daemon thread and therefore all threads created in the main thread default to daemon = False.
The entire Python program exits when no alive non-daemon threads are left.
-
ident
¶ Thread identifier of this thread or None if it has not been started.
This is a nonzero integer. See the thread.get_ident() function. Thread identifiers may be recycled when a thread exits and another thread is created. The identifier is available even after the thread has exited.
-
isAlive
()¶ Return whether the thread is alive.
This method returns True just before the run() method starts until just after the run() method terminates. The module function enumerate() returns a list of all alive threads.
-
is_alive
()¶ Return whether the thread is alive.
This method returns True just before the run() method starts until just after the run() method terminates. The module function enumerate() returns a list of all alive threads.
-
join
(timeout=None)¶ Wait until the thread terminates.
This blocks the calling thread until the thread whose join() method is called terminates – either normally or through an unhandled exception or until the optional timeout occurs.
When the timeout argument is present and not None, it should be a floating point number specifying a timeout for the operation in seconds (or fractions thereof). As join() always returns None, you must call isAlive() after join() to decide whether a timeout happened – if the thread is still alive, the join() call timed out.
When the timeout argument is not present or None, the operation will block until the thread terminates.
A thread can be join()ed many times.
join() raises a RuntimeError if an attempt is made to join the current thread as that would cause a deadlock. It is also an error to join() a thread before it has been started and attempts to do so raises the same exception.
-
name
¶ A string used for identification purposes only.
It has no semantics. Multiple threads may be given the same name. The initial name is set by the constructor.
-
run
()¶ Method representing the thread’s activity.
You may override this method in a subclass. The standard run() method invokes the callable object passed to the object’s constructor as the target argument, if any, with sequential and keyword arguments taken from the args and kwargs arguments, respectively.
-
start
()¶ Start the thread’s activity.
It must be called at most once per thread object. It arranges for the object’s run() method to be invoked in a separate thread of control.
This method will raise a RuntimeError if called more than once on the same thread object.
-
-
-
PyICe.lab_utils.
twosComplementToSigned
(binary, bitCount)[source]¶ take two’s complement number with specified number of bits and convert to python int representation
-
PyICe.lab_utils.
unit_least_precision
(val, increasing=True)[source]¶ return positive increment/decrement to next representable floating point number above/below val
-
PyICe.lab_utils.
vector_transform
(rec_array, column_vector_functions, column_names=None)[source]¶ Generic filter function. column_vector_functions is a list of functions for each column and should have a length equal to the number of columns. To leave a column unchanged, set column vector function to None. Each column vector function will be applied to the whole column vector. Thus it is appropriate for 1-d filtering and decimation where access to values in adjacent columns is not required. column_names is a list of names for each column in the returned record array. To leave a column name unchanged from input record array, set column name to None. To leave all column names unchanged from input record array, set column_names to None. To smooth data, use something like scipy.signal.filtfilt and scipy.signal.butter for the column_vector_functions http://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.filtfilt.html http://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.signal.butter.html