pymtg.io.
get_filenames_in_dir
(dir_name, keyword='*', skip_foldername='', match_case=True, verbose=False)[source]¶TODO: better document this function TODO: does a python 3 version of this function exist?
Parameters: | |
---|---|
Returns: |
|
Return type: | (tuple) |
Examples
>>> get_filenames_in_dir('/path/to/dir/', '*.mp3') #doctest: +SKIP
(['/path/to/dir/file1.mp3', '/path/to/dir/folder1/file2.mp3'], ['/path/to/dir/', '/path/to/dir/folder1'], ['file1.mp3', 'file2.mp3'])
pymtg.io.
json_dump
(path, data, indent=4, verbose=False)[source]¶Save python dictionary data
to JSON file at path
.
Parameters: |
---|
pymtg.processing.
WorkParallelizer
(use_ipywidgets=False, use_threads=False)[source]¶Utility class to parallelize tasks using either Threads or Processes.
This utility class is based on concurrent.futures. See https://docs.python.org/3/library/concurrent.futures.html.
# Inititalize the work parallelizer
wp = WorkParallelizer()
# Add tasks to the work parallelizer
for i in range(30):
wp.add_task(my_function, i, i + 1, kwarg1='one', kwarg2='two')
# Start running the tasks with the specified number of workers
# This function will show periodic updates of the status of the tasks and block the main thread
# Check WorkParallelizer.start() to get tasks running in the background.
wp.run(num_workers=4)
# Show errors after computing all tasks (if any)
if wp.num_tasks_failed > 0:
wp.show_errors()
pymtg.signal.
linear_approximation
(x, include_coeffs=False)[source]¶Compute the first degree least squares polynomial fit of x (linear approximation).
This function returns the linear approximation as a signal of the same length of x. If requested, the function can also return the linear approximation coefficients as returned by Numpy’s ‘polyfit’ function. For more details in the method used for the linear approximation, see https://docs.scipy.org/doc/numpy/reference/generated/numpy.polyfit.html.
Parameters: |
|
---|---|
Returns: | The linear approximation of then input signal |
Return type: | (array) |
Examples
>>> linear_approximation([1, 1, 1])
array([ 1., 1., 1.])
>>> linear_approximation([0, 1, 2, 3, 4, 5])
array([ 0., 1., 2., 3., 4., 5.])
>>> linear_approximation([1, 2, 4, 8, 16])
array([ -1. , 2.6, 6.2, 9.8, 13.4])
>>> linear_approximation([1, 2, 4, 8, 16], include_coeffs=True)
(array([ -1. , 2.6, 6.2, 9.8, 13.4]), (3.6000000000000001, -0.99999999999999778))
pymtg.signal.
smooth
(x, window_len=11, window='hanning', preserve_length=True)[source]¶Smooth the data using a window with requested size.
This method is based on the convolution of a scaled window with the signal. The signal is prepared by introducing reflected copies of the signal (with the window size) in both ends so that transient parts are minimized in the beginning and end part of the output signal.
The code here is an adaptation of the smoothing code from Scipy Cookbook: http://scipy-cookbook.readthedocs.io/items/SignalSmooth.html
Parameters: |
|
---|---|
Returns: | The smoothed signal |
Return type: | (array) |
Examples
>>> smooth([0, 1, 0, 1, 0, 1], 4)
array([ 0.5, 0.5, 0.5, 0.5, 0.5, 0.5])
pymtg.time.
datetime_range
(start_datetime, end_datetime=None, step_interval=None, n_steps=1, snap_to_date=False, return_pairs=False)[source]¶Return a list of dates inside the date range between start_datetime
and end_datetime
,
equally spaced in step
time intervals.
Parameters: |
|
---|---|
Returns: | List of |
Return type: | (list) |
Examples
>>> datetime_range(datetime.datetime(2017,1,1), datetime.datetime(2017,1,3))
[datetime.datetime(2017, 1, 1, 0, 0), datetime.datetime(2017, 1, 2, 0, 0), datetime.datetime(2017, 1, 3, 0, 0)]
>>> datetime_range(datetime.datetime(2017,1,1,10,21,45), datetime.datetime(2017,1,3,10,30,54), snap_to_date=True)
[datetime.datetime(2017, 1, 1, 0, 0), datetime.datetime(2017, 1, 2, 0, 0), datetime.datetime(2017, 1, 3, 0, 0)]
>>> datetime_range(datetime.datetime(2017,1,1,11,0,0), datetime.datetime(2017,1,1,11,2,0), step_interval='minute')
[datetime.datetime(2017, 1, 1, 11, 0), datetime.datetime(2017, 1, 1, 11, 1), datetime.datetime(2017, 1, 1, 11, 2)]
>>> datetime_range(datetime.datetime(2017,1,1,11,0,0), datetime.datetime(2017,1,1,11,20,0), step_interval='minute', n_steps=10)
[datetime.datetime(2017, 1, 1, 11, 0), datetime.datetime(2017, 1, 1, 11, 10), datetime.datetime(2017, 1, 1, 11, 20)]
>>> datetime_range(datetime.datetime(2017,1,1), datetime.datetime(2017,1,3), return_pairs=True)
[(datetime.datetime(2017, 1, 1, 0, 0), datetime.datetime(2017, 1, 2, 0, 0)), (datetime.datetime(2017, 1, 2, 0, 0), datetime.datetime(2017, 1, 3, 0, 0))]
pymtg.time.
time_stats
(done, total, starttime)[source]¶Count how far through a repeated operation you are.
Use this method if you are performing a repeated operation over a list of items and you want to check progress and time remaining after each iteration.
Parameters: | |
---|---|
Returns: | A tuple of (time elapsed, time remaining), as a string representation of a timedelta |