crikit.utils package — CRIKit2 0.4.3 documentation

# crikit.utils package

## Subpackages

- crikit.utils.tests package
  - Submodules
  - crikit.utils.tests.test_breadcrumb module
  - crikit.utils.tests.test_general module
  - crikit.utils.tests.test_pad_edge_mean module
  - Module contents

## Submodules

## crikit.utils.breadcrumb module

### Breadcrumb Module

> BCPre : Container describing pre-processing steps

#### Class Methods

> HDFtoClass(filename [str], datasetname [str])Load dataset in HDF

>   file into the HSI Class

class crikit.utils.breadcrumb.BCPre(offset=0)

  Bases: `object`

  Container that describes processing steps (ie it contains “breadcrumbs”)

  offsetint

    Instead of starting at Step 0, start at offset (0 + offset)

  process_list

    A list-of-lists. Each contained list follows the format [‘Process Name’, ‘Var1 Name’, Val1, ‘Var2 Name’, Val2, …]. The variable names and values may be input values to the pre-processing step. Only the Process Name is mnadatory: the rest are optional.

    Type

      list

  backed_flag

    Flag identifying which steps were backed-up to disk (e.g., for undo)

    Type

      list

  id_list

    Unique identifier for each step. Can be used to name back-up/undo files

    Type

      list (read-only)

  cut_list

    Identifier of id’s cut with pop_to_last method

    Type

      list (read-only)

  num_steps

    Number of processing steps

    Type

      int

  attr_dict

    Dictionary-version of process_list that can be written to HDF5 dataset metadata (properties)

    Type

      dict

  add_step : Add a new processing step
  backed_up : Mark most recent process step as backed up in backed_flag list
  pop_to_last : Remove entries until nearest backup point (excluding current step).
  PREFIX = 'Processing.Steps'
  add_step(process_desc)

    Adds a steps to the list

    Parameters

      process_desc (list) – List containing elements of new process with format: [‘Process Name’, ‘Var1 Name’, Val1, ‘Var2 Name’, Val2, …]. The variable names and values may be input values to the pre-processing step. Only the Process Name is mnadatory: the rest are optional.

    Returns

      None

    Return type

      None

  property attr_dict
  backed_up()

    Marks most recent process step as backed up in backed_flag list

    Parameters

      None (None) –

    Returns

      None

    Return type

      None

  static backup_pickle(data, fname, addl_attr=None)

    Dump current state of data (class of type crikit.data.spectra or subclass)to pickle file (filename= fname).

    Can append additional attributes (addl_attr) to attribute dictionary (self.attr)

  property cut_list
  property dset_name_suffix
  property id_list
  static load_pickle(fname)

    Static method.

    Return a loaded pickled version of this class (filename= fname).

  property num_steps
  pop_to_last(all=False)

    Remove entries until nearest backup point (excluding current step). That is, if current step IS a backup point, moves to previous one. If current step is NOT a backup point, moves to nearest point.

    If all = True, will cut everything

## crikit.utils.datacheck module

Functions to check and (if needed) convert input variables

Created on Sat Jun 18 00:16:27 2016

@author: chc

## crikit.utils.general module

General utilities

> expand_1d_to_ndim_data : Match 1D data array dimensionality to that of another array

> expand_1d_to_ndim : Expand 1D data array dimensionality to ndim

> find_nearestGiven a vector and a value, find the index and value

>   of the closest match

> padWrapper around numpy.pad that also returns a window defining the

>   original signal

Notes

crikit.utils.general.arange_nonzero(start, stop, dtype=<class 'float'>)

  Similar to numpy arange but only returns non-zero elements

crikit.utils.general.expand_1d_to_ndim(data, ndim)

  Make 1D array into ndim dimensions

crikit.utils.general.expand_1d_to_ndim_data(data, data_to_match)

  Make 1D data array equal in dimensions to data_to_match

crikit.utils.general.find_nearest(np_vec, to_find=0)

  Given a vector and a value (or list/vector of values), find the index and value of the closest match

  Parameters

    - np_vec (numpy.ndarray) – Numpy array (list) of values

    - to_find (int, float, numpy.ndarray, or list) –

  Returns

    out – Closest value (nearest_value) and index (index)

  Return type

    tuple (nearest_value(s), index(es))

crikit.utils.general.lin_from_row_col(row, col, sh)

  Convert a col and row counter to 1D linear count

crikit.utils.general.mean_nd_to_1d(data, axis=- 1)

  Take the mean of an nd array, except axis, returning a 1D array

crikit.utils.general.np_fcn_nd_to_1d(fcn, data, axis=- 1)

  Take in an n-dimensional array and return a 1D version operated on by fcn. Works with many numpy functions that can take an “axis” parameter

crikit.utils.general.pad(y, pad_width, mode)

  Pad array with either constants or edge values.

  Note: For N-D arrays, pads the -1 axis

  Parameters

    - y (ndarray) – Input array

    - pad_width (int) – Size of padding on each side of y

    - mode (str) – ‘constant’ (0), ‘edge’ currently accepted

  Returns

    Padded array and window. Window defines the region of the original signal

  Return type

    y_pad, window

crikit.utils.general.pad_dual(y, edge_pad_width, constant_pad_width)

  Pad array with edge values followed by constant 0’s.

  Note: For N-D arrays, pads the -1 axis

  Parameters

    - y (ndarray) – Input array

    - edge_pad_width (int) – Size of edge-value padding on each side of y

    - constant_pad_width (int) – Size of 0-padding on each side of y after edge-value padding

  Returns

    Padded array and window. Window defines the region of the original signal

  Return type

    y_pad, window

crikit.utils.general.pad_edge_mean(y, pad_width, n_edge=1, axis=- 1)

  Pad data y with edge-values or near-edge mean values along axis

  Parameters

    - y (ndarray) – Input array

    - pad_width (int) – Size of padding on each side of y

    - n_edge (int) – Number of edge points to average for the pad value

    - axis (int) – Axis to pad

  Returns

    - (y_pad, window)

    - y_pad (ndarray) – Padded y

    - window (ndarray (1D)) – Mask with 0’s for pad regions, 1’s for original size

crikit.utils.general.row_col_from_lin(ct, sh)

  Convert a 1D counter into a col and row counter

crikit.utils.general.std_nd_to_1d(data, axis=- 1)

  Take the mean of an nd array, except axis, returning a 1D array

## crikit.utils.roi module

Created on Wed Jun 15 23:33:41 2016

@author: chc

crikit.utils.roi.pts_in_path(path)

  Return points (pixels) that fall within path (but not on boundary)

crikit.utils.roi.pts_to_verts(xvec, yvec)

  Convert points to vertices, i.e., convert from 2 1D arrays (or list) of x- and y-coordinates to a list-of-lists of [x,y] pairs

crikit.utils.roi.verts_to_path(verts, isclosed=True)

  Convert vertices to paths

crikit.utils.roi.verts_to_points_in_roi(verts)

  Vertice list defining ROI in, points within returned.

## Module contents