Utility Functions#

The pygeostat.utility module provides utility functions for file management, logging, and deprecation warnings.

File Management#

mkdir#

pygeostat.utility.mkdir(dirnames, verbose=False)[source]#

Make directory(s).

Parameters:
  • dirnames (str or list) – directory(s) to create

  • verbose (bool) – print to screen if an error is encountered, including if the dirnames already exists

rmdir#

pygeostat.utility.rmdir(dirnames, verbose=False)[source]#

Remove directory(s).

Parameters:
  • dirnames (str or list) – directory(s) to remove

  • verbose (bool) – print to screen if an error is encountered, including if the dirnames has already been removed

rmfile#

pygeostat.utility.rmfile(filenames, verbose=False)[source]#

Remove file(s).

Parameters:
  • filenames (str) – file to remove

  • verbose (bool) – print to screen if an error is encountered, including if the file has already been removed

get_executable#

pygeostat.utility.get_executable(source='gslib', access_token=None, clean=False)[source]#

Gets a collection of executable files from a protected repository using an access token. Note that in order to use this function, git needs to be installed on the target computer.

Parameters:
  • source (str) – gslib or CCG as the source of software.

  • access_token (str) – An access token to authorize access to the target private repository for CCG software. Access token is available for CCG members and can be found at CCG knowledge base.

  • clean (bool) – Option to clean the executable directory prior to upload the files from the target private repository. Note that choosing this option will delete the existing executable files.

Examples

Installing GSLIB executable files

import pygeostat as gs
gs.get_executable(source='GSLIB')
api/figures/GslibGetFiles.png

Installing CCG software

import pygeostat as gs
gs.get_executable(source='CCG', clean=True)
api/figures/CcgGetFiles.png

Using the installed software

# Load example data included in pygeostat
data_file = gs.ExampleData('cluster')

# Initialize the Program object
nscore = gs.Program('nscore', getpar=True)

# Run normal score transformation
parstr = """ Parameters for NSCORE
             *********************
START OF PARAMETERS:
{datafile}                -  file with data
3  1  2  3                -  number of variables and columns
5                         -  column for weight, 0 if none
0                         -  column for category, 0 if none
0                         -  number of records if known, 0 if unknown
-1.0e21   1.0e21          -  trimming limits
0                         -transform using a reference distribution, 1=yes
../histsmth/histsmth.out  -file with reference distribution.
1   2   0                 -  columns for variable, weight, and category
101                       -maximum number of quantiles, 0 for all
{outfl}                   -file for output
{trnfl}                   -file for output transformation table
"""

pars = dict(datafile=data_file.flname,
            outfl = 'nscore.out',
            trnfl = 'nscore.trn')
nscore.run(parstr=parstr.format(**pars), liveoutput=True)

list_executable#

pygeostat.utility.list_executable()[source]#

PRovides a list installed executable files under pygeostat

Logging#

printerr#

pygeostat.utility.printerr(text, width=80, errtype=None)[source]#

Small utility to print custom errors with proper indentation and text wrapping. The only error types coded are error and warning.

Parameters:
  • text (str) – String of text without the preceding error flag that will be formated

  • width (int) – The maximum length of wrapped lines

  • errtype (str) – Indicate which type of error to format the string as. The default value of None will only text wrap the string to the specified width.

Code author: pygeostat development team 2015-11-01

log_progress#

pygeostat.utility.log_progress(sequence, size=None, name='Items')[source]#
Parameters:

sequence – The thing that is being iterated over

Example

>>> from pygeostat import log_progress
>>> from time import sleep
>>> for i in log_progress(range(200)):
...     sleep(0.1)
api/figures/log_progress.gif