Previous topic

Module correlationsLoader

Next topic

Module correlationsExceptions

This Page

Some tools for the package.

Module correlationsUtil

correlations.correlationsUtil.isValidPathDirToWrite(pathDir)
Parameter :
pathDir: string

the directory path to be check

Returns:

True if you can write on the path-directory or create it.

correlations.correlationsUtil.makeListOfSubListFromList(List, numberSubList=1)

Return a List of disjoint sublists of same length.

Parameters :
List: List

A List of object.

numberSubList: int (optional)

A number strictly positive of the sublists to be made from List, default is 1.

Returns:

Return a List of disjoints numberSubList sublists. All sublists have the same length (or -1 for the lastest), ordered with the order as List.

Note

  • If the number of sublist is greater than the length of the List, return only the not empty sublists, i.e. sublist with one element.
  • If the number of sublist is less than 1, it is set to 1.
Example :
>>> L=[7, 'h8', 78, 59.0, 'aze', 8, 6, 4]
>>> print makeListOfSubListFromList(L,3)
[[7, 'h8', 78], [59.0, 'aze', 8], [6, 4]]
>>> print makeListOfSubListFromList(L,10)
[[7], ['h8'], [78], [59.0], ['aze'], [8], [6], [4]]
correlations.correlationsUtil.isLeapYear(year)
Returns:True if year is a leap year
class correlations.correlationsUtil.listDateIterator(FirstDay, FirstYear, LastDay, LastYear)

Get an instance of an iterator of dates from the first year/day until the last year/day (both include)

Parameters :
FirstDay: int-like

The first day

FirstYear: int-like

The first year

LastDay: int-like

The last day

LastYear: int-like

The last year

Example :
>>> it = listDateIterator(360,2008,5,'2009')
>>> for date in it:
...   print date,
... 
2008/360 2008/361 2008/362 2008/363 2008/364 2008/365 2008/366 2009/001 2009/002
 2009/003 2009/004 2009/005
class correlations.correlationsUtil.LastNewValueGeneratorOfListIndex(Iterable, ListIndexTestYield, TypeYield='NoneValues')

A generator for filtering iterable.

Given a iterable and a sublist of indexes, generate only the values of the iterable for which the sublist of values defined by the the sublist of indexes are the last new values. Last new values are the values such that the future next values generate will be different.

In the cases of the sublist are not the new last values, yield values depend on the parameter TypeYield. There are 3 choices:

  • (default option) yield None values, set TypeYield=’NoneValues’
  • Do not yield anything, set TypeYield=’Nothing’
  • yield only others values, set TypeYield=’OtherValues’
Parameters :

Iterable: iterable

ListIndexTestYield: list or int

A sublist of indexes of the tuple generate by Generator.

TypeYield: str

The type of yield made (see above).

Example :

Given an iterable and an instance ‘it’:

ListNumber01 = [1,2,2,1,5,8,9,10,10, 4, 4,4,4,4,8,17,17]
ListNumber02 = [2,2,5,5,5,5,5, 8, 9,10,10,4,4,4,4, 9,12]
ListNumber03 = [2,8,8,8,8,8,5, 5, 8, 9,10,4,4,4,4, 9,12]
it=zip(ListNumber01, ListNumber02, ListNumber03)
>>> for n in it: print n,
... 
(1, 2, 2) (2, 2, 8) (2, 5, 8) (1, 5, 8) (5, 5, 8) (8, 5, 8) (9, 5, 5) (10, 8, 5)
 (10, 9, 8) (4, 10, 9) (4, 10, 10) (4, 4, 4) (4, 4, 4) (4, 4, 4) (8, 4, 4) (17, 9, 9) (17, 12, 12)
>>> NewGen= LastNewValueGeneratorOfListIndex(it, [0], 'NoneValues')
>>> for n in NewGen: print n,
... 
[1, 2, 2] [None, 2, 8] [2, 5, 8] [1, 5, 8] [5, 5, 8] [8, 5, 8] [9, 5, 5] [None, 
8, 5] [10, 9, 8] [None, 10, 9] [None, 10, 10] [None, 4, 4] [None, 4, 4] [4, 4, 4
] [8, 4, 4] [None, 9, 9] [17, 12, 12]
>>> NewGen= LastNewValueGeneratorOfListIndex(it, 0, 'OtherValues')
>>> for n in NewGen: print n,
... 
[1, 2, 2] [2, 8] [2, 5, 8] [1, 5, 8] [5, 5, 8] [8, 5, 8] [9, 5, 5] [8, 5] [10, 9
, 8] [10, 9] [10, 10] [4, 4] [4, 4] [4, 4, 4] [8, 4, 4] [9, 9] [17, 12, 12]
>>> NewGen= LastNewValueGeneratorOfListIndex(it, [0], 'Nothing')
>>> for n in NewGen: print n,
... 
[1, 2, 2] [2, 5, 8] [1, 5, 8] [5, 5, 8] [8, 5, 8] [9, 5, 5] [10, 9, 8] [4, 4, 4]
 [8, 4, 4] [17, 12, 12]
>>> NewGen= LastNewValueGeneratorOfListIndex(it, [0,2], 'NoneValues')
>>> for n in NewGen: print n,
... 
[1, 2, 2] [None, 2, None] [2, 5, 8] [1, 5, 8] [5, 5, 8] [8, 5, 8] [9, 5, 5] [10,
 8, 5] [10, 9, 8] [4, 10, 9] [4, 10, 10] [None, 4, None] [None, 4, None] [4, 4, 
 4] [8, 4, 4] [17, 9, 9] [17, 12, 12]
>>> NewGen= LastNewValueGeneratorOfListIndex(it, [0,1,2], 'NoneValues')
>>> for n in NewGen: print n,
... 
[1, 2, 2] [2, 2, 8] [2, 5, 8] [1, 5, 8] [5, 5, 8] [8, 5, 8] [9, 5, 5] [10, 8, 5]
 [10, 9, 8] [4, 10, 9] [4, 10, 10] [None, None, None] [None, None, None] [4, 4, 
 4] [8, 4, 4] [17, 9, 9] [17, 12, 12]

Note

Requirement: The elements must be able to be compared with ‘==’ operation.


Whisper project: FP7 ERC Advanced grant 227507 (WHISPER).
Codes are develop for the Whisper project (Seismic ambient noise).
If you use this code, specify it is provide by: Whisper project FP7 ERC Advanced grant 227507 (WHISPER).
Author: Xavier Briand. For questions, send email to xav.briand.whisper@gmail.com with subject begin exactly with [whisper].