fuelcell.utils

File handling functions and miscellaneous auxilliary functions

fuelcell.utils.check_dict(var)

Checks if var is a python dictionary

Parameters

var – variable to be checked

Returns

result – True if var is a dict, False otherwise

Return type

bool

fuelcell.utils.check_export_type(filetype)

Check if the filetype is currently supported for export

fuelcell currently supports export of csv, xls, and xlsx files

Parameters

filetype (str) – Filetype to be checked

Returns

filetype – If the given filetype string is valid, it is returned in lowercase and stripped of ‘.’ characters. If the filetype is not valid, returns ‘csv’

Return type

str

fuelcell.utils.check_float(var)

Checks if var is a float

Parameters

var – variable to be checked

Returns

result – True if var is a float, False otherwise

Return type

bool

fuelcell.utils.check_int(var)

Checks if var is an integer

Parameters

var – variable to be checked

Returns

result – True if var is an int, False otherwise

Return type

bool

fuelcell.utils.check_labels(data)

Parses column labels to determine the data stored in each column

Current, voltage, time, etc. columns are determined from the units based on standard EC Lab conventions. If a column can be identified, its name is converted to the standard heading (‘i’ for current, ‘v’ for potential, etc.), otherwise, the namne is unchanged.

Parameters

data (DataFarame) – DataFrame in need of column identification

Returns

newcols – List containing the new column labels

Return type

list

fuelcell.utils.check_list(var)

Checks if var is a python list or numpy array

Parameters

var – variable to be checked

Returns

result – True if var is a list or numpy array, False otherwise

Return type

bool

fuelcell.utils.check_savedir(folder)

Check if the specified folder exists

Checks if the specified folder exists. If the folder does not exist and cannot be created, returns a path to a folder named ‘processed’ within the current directory

Parameters

folder (str, path object, or path-like) – Folder to be checked

Returns

path – Path to folder. Defaults to ‘processed’ if any errors occur.

Return type

str

fuelcell.utils.check_scalar(var)

Checks if var is a scalar

If the variable has a valid length (ie if len(var) is a valid call), it is considered not to be a scalar.

Parameters

var – variable to be checked.

Returns

result – True if var is a scalar, False otherwise

Return type

bool

fuelcell.utils.check_str(var)

Checks if var is a string

Parameters

var – variable to be checked

Returns

result – True if var is a string, False otherwise

Return type

bool

fuelcell.utils.check_type(filetype)

Check if the filetype is currently supported for import

fuelcell currently supports import of csv, xls, xlsx, and txt files

Parameters

filetype (str) – Filetype to be checked

Returns

filetype – If the given filetype string is valid, it is returned in lowercase and stripped of ‘.’ characters

Return type

str

fuelcell.utils.get_files(path=None, pattern='', filetype='', files=None)

Find all files matching the desired criteria

Determines which files in the specified directory match the given regular expression and/or are of the given filetype

Parameters
  • path (str, path object, or path-like (default=None)) – Directory in which files will be searched for. If unspecified, the current directory will be used.

  • patter (str (default='')) – Regular expression. Only files matching this regular will be found. If unspecified, this parameter is ignored.

  • filetype (str or regex (default='')) – Only files of this filetype will be found. If unspecified, filetype is ignored when finding files

Returns

files – List of all files in the specified directory matching the given criteria

Return type

list

fuelcell.utils.read_file(filename, dlm='\t')

Loads the specified file as a Datum object

The specified file must be of one of the types supported for import. fuelcell currently supports csv, xls, xlsx, and txt files. If the file has a valid filetype but cannot be imported for some reason, a warning is displayed.

Parameters
  • filename (str, path object, or path-like) – Name of a file in the current directory, or a complete path to the desired file.

  • dlm (str (default='t')) – Delimiting character if the file is a text file. Defaults to ‘t’ (tab-delimiting).

Returns

  • name (str) – Filename with the filetype removed.

  • data (Datum) – Datum object containing the data read from the file.

fuelcell.utils.save_data(data, filename=None, folder=None)

Save data to a local file

Saves data stored in a pandas DataFrame as an excel or csv file. Valid filetypes to save as are xls, xlsx, and csv (default is csv). If the specified filename already exists, the name is modified to avoid unintentionally overwriting data. If the specified folder does not exist and cannot be created, the file is saved to a folder named ‘processed’ within the current director.

Parameters
  • data (DataFrame) – Data to be saved

  • filename (str, path object, or file-like (default=None)) – Filename to save the data as. Either a full filename or complete path to an individual file. If the file already exists, the specified name is modified to avoid overwriting data. If unspecified, an arbitrary name is used.

  • folder (str, path obbject, or path-like (default=None)) – Folder in which data will be saved. If unspecified and folder cannot be determined from filename, or the specified folder is invalid and cannot be created, defaults to ‘processed’