Previous topic

Module tracesWriter

Next topic

Module tracesExceptions

This Page

Some tools for the package.

Module tracesUtil

traces.tracesUtil.isValidPathDirToWrite(pathDir)

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

Parameter :
pathDir: str

The directory path to be check.

traces.tracesUtil.isLeapYear(year)

Return True if year is a leap year

class traces.tracesUtil.listDateIterator(FirstDay, FirstYear, LastDay, LastYear)

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

Parameters :
FirstDay, FirstYear: int or str

The first day and first year to compose the first date year/day

LastDay, LastYear: int or str

The last day and last year to compose the last date year/day

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

Note

Requirement: The first date is suppose to be less than the last date.

class traces.tracesUtil.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].