pysiral.core.helper

Created on Tue Jul 21 18:04:43 2015

@author: Stefan TODO: Is this still being used?

Classes

ProgressIndicator

SimpleTimer

Functions

get_multiprocessing_1d_array_chunks(...)

Break down an array in chunks for multiprocessing. The rule

parse_datetime_str(dtstr)

Converts a time string to a datetime object using dateutils

get_first_array_index(array, value)

Get the index in array of the first occurance of value

get_last_array_index(array, value)

Get the index in array of the last occurance of value

rle(inarray)

run length encoding. Partial credit to R rle function.

month_iterator(start_year, start_month, end_year, ...)

returns an iterator over months

days_iterator(year, month)

returns an iterator over all days in given month

get_month_time_range(year, month)

Returns the a start and stop datetime object for a given month

validate_year_month_list(year_month_list, label)

Module Contents

pysiral.core.helper.get_multiprocessing_1d_array_chunks(array_size: int, n_processes: int) Tuple[List[Tuple[int, int]], int]

Break down an array in chunks for multiprocessing. The rule is one chunk per process/CPU.

Parameters:
  • array_size – The number of elements to be distributed to chunks

  • n_processes – The number processes/CPU’s/chunks

Returns:

List with start and end index for each chunk and number of (viable) processes

pysiral.core.helper.parse_datetime_str(dtstr)

Converts a time string to a datetime object using dateutils

pysiral.core.helper.get_first_array_index(array, value)

Get the index in array of the first occurance of value

pysiral.core.helper.get_last_array_index(array, value)

Get the index in array of the last occurance of value

pysiral.core.helper.rle(inarray)

run length encoding. Partial credit to R rle function. Multi datatype arrays catered for including non Numpy returns: tuple (runlengths, startpositions, values)

from: http://stackoverflow.com/questions/1066758/find-length-of-sequences-

of-identical-values-in-a-numpy-array

pysiral.core.helper.month_iterator(start_year, start_month, end_year, end_month)

returns an iterator over months

pysiral.core.helper.days_iterator(year, month)

returns an iterator over all days in given month

pysiral.core.helper.get_month_time_range(year, month)

Returns the a start and stop datetime object for a given month

pysiral.core.helper.validate_year_month_list(year_month_list, label)
class pysiral.core.helper.ProgressIndicator(n_steps)

Bases: object

n_steps
index = None
reset()
get_status_report(i, fmt='{step} of {n_steps} ({percent:.2f}%)')
property step
property percent
class pysiral.core.helper.SimpleTimer(name='')

Bases: object

name = ''
start
last_event
property elapsed
property total
checkpoint(name='')
__enter__()
__exit__(type, value, traceback)