Utils#

class Utils#

Bases: object

Collection of general-purpose utility methods used throughout Scarabaeus.

Provides static helpers for array manipulation and file I/O.

See also

scarabaeus.EpochArray

Time-tag array type accepted by several helpers.

Methods

check_slices_equal(arr)

Checks if all slices are equal across an array.

equal_along_rows(arr)

Check equality along rows of the given array.

find_date_indices_in_epochs(epochsTDB, ...)

Find the index or indices of target date(s) in a numpy array of epochs, accounting for floating-point precision.

load_json(dir[, print_flag])

Load and parse a JSON file from disk.

make_dir(dir)

Generate a folder in the given directory.

max_of_last_slice(arr)

Finds the maximum value of the last slice of an array.

open_pickle(dir)

Return a pickle object handle from dir.

tile_array(arr, desired_shape)

Construct an array by repeating A the number of times given by reps.

static check_slices_equal(arr: ndarray)#

Checks if all slices are equal across an array.

Parameters:

arr (numpy.ndarray) – The array to examine.

Returns:

are_equal – Indicates if all slices are equal or not.

Return type:

bool

static equal_along_rows(arr: ndarray) bool#

Check equality along rows of the given array.

Parameters:

arr (numpy.ndarray) – The array to examine.

Returns:

are_equal – Returns True if all values are equal along rows. Returns False if they are not.

Return type:

bool

static find_date_indices_in_epochs(epochsTDB, target_dates, rtol=1e-06)#

Find the index or indices of target date(s) in a numpy array of epochs, accounting for floating-point precision.

Parameters:
  • epochsTDB (EpochArray) – Reference epoch array to search within.

  • target_dates (EpochArray or list of EpochArray) – Target epoch(s) to locate inside epochsTDB.

  • rtol (float, optional) – Relative tolerance for comparing the dates. Defaults to 1e-6.

Returns:

ind – The index or indices of the target date(s), or None if not found.

Return type:

int or list of ints

static load_json(dir: str, print_flag: bool = False) dict#

Load and parse a JSON file from disk.

Parameters:
  • dir (str) – Path to the .json file to load.

  • print_flag (bool, optional) – When True, prints a confirmation message after a successful read. Defaults to False.

Returns:

data – Parsed JSON content.

Return type:

dict or list

static make_dir(dir: str) None#

Generate a folder in the given directory.

Parameters:

dir (str) – The directory path to a generate a folder in.

Return type:

None

static max_of_last_slice(arr: ndarray)#

Finds the maximum value of the last slice of an array.

Parameters:

arr (numpy.ndarray) – The array to examine.

Returns:

max_vals – The max value of the last slice.

Return type:

Any

static open_pickle(dir: str)#

Return a pickle object handle from dir.

Parameters:

dir (str) – Directory + name of the pickle object.

Returns:

pickle_handle – The Python object deserialised from the pickle file.

Return type:

object

static tile_array(arr, desired_shape)#

Construct an array by repeating A the number of times given by reps.

Parameters:
  • arr (numpy.ndarray) – The array to examine.

  • desired_shape (tuple of int) – Target shape of the output array. The last dimension must equal len(arr); all preceding dimensions specify how many times to repeat the array along each axis.

Returns:

tiled – The new tiled array.

Return type:

numpy.ndarray