USGSCSM
U.S. flag

An official website of the United States government

Official websites use .gov
A .gov website belongs to an official government organization in the United States.

Secure .gov websites use HTTPS
A lock ( ) or https:// means you’ve safely connected to the .gov website. Share sensitive information only on official, secure websites.

utils.utils — Utilities

The utils.utils module provides generic I/O utilities .. versionadded:: 0.1.0

plio.utils.utils.convert_string_to_float(s)[source]

Attempt to convert a string to a float.

Parameters:

s (str) – The string to convert

Returns:

If successful, the converted value, else the argument is passed back out.

Return type:

float / str

plio.utils.utils.create_dir(basedir='')[source]

Create a unique, temporary directory in /tmp where processing will occur

Parameters:

basedir (str) – The PATH to create the temporary directory in.

plio.utils.utils.delete_dir(dir)[source]

Delete a directory

Parameters:

dir (str) – Remove a directory

Recursively search for files in the specified directory

Parameters:
  • searchdir (str) – The directory to be searched

  • searchstring (str) – The string to be searched for

Returns:

filelist – of files

Return type:

list

plio.utils.utils.find_in_dict(obj, key)[source]

Recursively find an entry in a dictionary

Parameters:
  • obj (dict) – The dictionary to search

  • key (str) – The key to find in the dictionary

Returns:

item – The value from the dictionary

Return type:

obj

plio.utils.utils.find_nested_in_dict(data, key_list)[source]

Traverse a list of keys into a dict.

Parameters:
  • data (dict) – The dictionary to be traversed

  • key_list (list) – The list of keys to be travered. Keys are traversed in the order they are entered in the list

Returns:

value – The value in the dict

Return type:

object

plio.utils.utils.is_number(s)[source]

Check if an argument is convertable to a number

Parameters:

s (object) – The argument to check for conversion

Returns:

True if conversion is possible, otherwise False.

Return type:

bool

plio.utils.utils.split_all_ext(path)[source]

General function for removeing all potential extensions from a file.

Parameters:

path (str) – Path or file name with potential extension

Returns:

base – Path or file name with all potnetial extensions removed

Return type:

str

plio.utils.utils.xstr(s)[source]

Return an empty string if the input is a NoneType. Otherwise cast to string and return

Parameters:

s (obj) – An input object castable to a string

Returns:

The input object cast to a string

Return type:

str