5.4. tools package

5.4.1. Submodules

5.4.2. tools.grid module

5.4.3. tools.homog module

5.4.4. tools.parameters module

Created on 6 de Dez de 2013

@author: julio

class tools.parameters.ParametersFile(field_sep, value_sep, par_set=None, par_file=None, text=None, real_n=None, int_n=None, boolean=None, opt_text=None, opt_real=None, opt_int=None, opt_boolean=None, parpath=None, order=None)[source]

Bases: object

Base class to construct a ParametersClass.

Each parameter is defined by the following pair:
  • field: the name of the parameter which will be used both as an

    attribute of this class, and;

  • value: which is the value of that same parameter.

Fields are separated into lists of predetermined types: str (text), float (real_n), int (int_n) and bool (boolean).

Fields can be mandatory or optional (opt_).

Fields are separated from values with a given separator (field_sep). Values can be a single value or a list of values, which are separated with yet another given separator (values_sep).

Only one field per line will be parsed. This allows values containing field_sep.

load(par_path)[source]

Load a parameter file.

TODO: load ordered

save(par_path=None)[source]

Write the parameters file.

set_field(field, value)[source]

Create or update the value of an attr called field, given the desired object type.

template(par_path)[source]

Write a parameter file with the template to follow, which must have been defined in the constructor docstring.

update(fields, values, save=False, par_path=None)[source]

Updates a list of existing fields with the corresponding values.

5.4.5. tools.scores module

5.4.6. tools.utils module

Collection of some useful general purpose functions.

Created on 6 de Nov de 2013

@author: julio

tools.utils.dms2dec(d, m, s)[source]

Convert coordinates in the format (Degrees, Minutes, Seconds) to decimal.

Parameters:

d : number

Degrees.

m : number

Minutes.

s : number

Seconds.

Returns:

float

Coordinates in decimal format.

Notes

Assumes that data is signalled. The conversion is done by the formula

\operatorname{DEC} = \operatorname{DEG} + \operatorname{MIN}/60
+ \operatorname{SEC}/3600.

tools.utils.filename_indexing(file_id, n)[source]

Insert an index in a filename.

Parameters:

file_id : string

File name.

n : number

Index to insert.

Returns:

fname : string

File name.

tools.utils.filename_seq(file_id, n)[source]

Generator to create a sequence of numbered filenames.

Parameters:

file_id : string

Initial file name.

n : int

Number of names to generate.

Returns:

fname : string

File name.

tools.utils.is_number(s)[source]

Check if s is a number.

Parameters:

s : string or number

Input to check if is a number.

Returns:

boolean

True if s is a number.

tools.utils.number_to_month(months)[source]

Convert numbers from 1 to 12 to the corresponding month in the abbreviated written form (e.g, 3 corresponds to 'Mar').

Parameters:

months : list

Numbers to convert to

Returns:

list

The corresponding months.

tools.utils.path_up(path, nlevels)[source]

Go up n levels in the path tree.

Parameters:

path : string

Folder or file path.

nlevels : int

Number of levels to go up.

Returns:

head : string

Target directory.

tail : string

The remaining part of the path tree.

tools.utils.seconds_convert(seconds)[source]

Convert seconds to months, days and HH:MM:ss.

Parameters:

seconds : int

Number of seconds.

Returns:

string

A formatted string with the result of the conversion.

tools.utils.skip_lines(file_id, nlines)[source]

Skip the next n lines from a file.

Parameters:

file_id : file handle

Input file.

nlines : int

Number of lines to skip.

tools.utils.yes_no(yn)[source]

Parse a string containing ‘Y’(es) or ‘N’(o).

Parameters:

yn : string

Input string.

Returns:

boolean

Returns True if yn is equal to ‘y’ or to ‘yes’, otherwise returns False.

5.4.7. Module contents