Utilities

These methods are low-level utilities that are used in other mejiro modules and scripts, but are not necessarily intended to be called directly by end users, with the exception of mejiro.utils.lenstronomy_util which can be useful for building the kwargs_psf argument of a SyntheticImage.

lenstronomy_util

mejiro.utils.lenstronomy_util.get_gaussian_psf_kwargs(fwhm)[source]

Generate a dictionary for a Gaussian PSF that forms the keyword arguments for lenstronomy’s PSF class.

Parameters:

fwhm (float or astropy.units.Quantity) – Full width at half maximum of the Gaussian PSF. If an astropy Quantity is provided, its value will be extracted.

Returns:

A dictionary containing the PSF type and the FWHM value.

Return type:

dict

Examples

>>> from lenstronomy.Data.psf import PSF
>>> psf_kwargs = get_gaussian_psf_kwargs(fwhm)
>>> psf = PSF(**psf_kwargs)
mejiro.utils.lenstronomy_util.get_none_psf_kwargs()[source]

Generate a dictionary for a None PSF that forms the keyword arguments for lenstronomy’s PSF class.

Returns:

A dictionary containing the PSF type set to ‘NONE’.

Return type:

dict

Examples

>>> from lenstronomy.Data.psf import PSF
>>> psf_kwargs = get_none_psf_kwargs()
>>> psf = PSF(**psf_kwargs)
mejiro.utils.lenstronomy_util.get_pixel_psf_kwargs(kernel, supersampling_factor, kernel_point_source_normalisation=False)[source]

Generate a dictionary for a pixel PSF that forms the keyword arguments for lenstronomy’s PSF class.

Parameters:
  • kernel (array-like) – The PSF kernel array.

  • supersampling_factor (int) – The supersampling factor for the point source.

  • kernel_point_source_normalisation (bool, optional) – Whether to normalize the kernel for the point source, by default False.

Returns:

A dictionary containing the PSF keyword arguments.

Return type:

dict

Examples

>>> from lenstronomy.Data.psf import PSF
>>> psf_kwargs = get_pixel_psf_kwargs(kernel, supersampling_factor=5)
>>> psf = PSF(**psf_kwargs)

pipeline_helper

class mejiro.utils.pipeline_helper.PipelineHelper(args, prev_script_name, script_name, supported_instruments, delete_existing_output=False)[source]

Bases: object

calculate_process_count(count)[source]
create_roman_sca_output_directories()[source]
initialize_instrument_class()[source]
parse_roman_uids(prefix, suffix, extension)[source]
parse_sca_from_filename(filename)[source]
static patch_astropy_for_mejiro_v2_pickles()[source]

Install sys.modules aliases so that pickles produced under the mejiro-v2 conda environment can be loaded under mejiro-v3.

When this is needed

Pickles created under mejiro-v2 (which used astropy where astropy.cosmology.flrw was a package containing the submodules base, lambdacdm, w0cdm, w0wacdm, w0wzcdm, wcdm, wpwazpcdm, and the compiled scalar_inv_efuncs Cython extension) embed those fully-qualified module paths in the pickle stream. In mejiro-v3 (astropy 7.x), the public astropy.cosmology.flrw is a single flat module and the real submodules live under astropy.cosmology._src.flrw. Unpickling therefore fails with:

ModuleNotFoundError: No module named
'astropy.cosmology.flrw.lambdacdm';
'astropy.cosmology.flrw' is not a package

Call this function once, at the top of a pipeline script’s main (or before any unpickling), whenever that script consumes pickles produced by mejiro-v2. After re-pickling those artifacts under mejiro-v3, the call can be removed without further changes — it is a pure sys.modules shim with no other side effects.

retrieve_pickles(prefix='', suffix='', extension='.pkl')[source]
retrieve_roman_pickles(prefix, suffix, extension)[source]
retrieve_roman_sca_input()[source]
step_dir(step)[source]

Absolute path to a pipeline step’s directory, selecting the JAX variant (e.g. ‘04’ -> ‘04_jax’) when jaxtronomy.use_jax is True and one exists.

validate_instrument(instrument_name)[source]

roman_util

mejiro.utils.roman_util.divide_up_sca(sides)[source]

Divides the SCA into a grid of sub-arrays and calculates the center coordinates of each sub-array.

Parameters:

sides (int) – The number of divisions along one side of the SCA. Must be a positive integer.

Returns:

A list of tuples containing the (x, y) coordinates of the centers of the sub-arrays.

Return type:

list

Raises:

AssertionError – If sides is not a positive integer or if the SCA size (4088) cannot be evenly divided by sides.

mejiro.utils.roman_util.get_sca_int(sca)[source]

Convert a given SCA value to an integer.

Parameters:

sca (int, float, or str) – The SCA value to be converted. It can be an integer, a float, or a string. If it is a string, it can optionally start with ‘SCA’.

Returns:

The integer representation of the SCA value.

Return type:

int

Raises:

ValueError – If the input sca is not of type int, float, or str, or if the string format is not recognized.

mejiro.utils.roman_util.get_sca_string(sca)[source]

Converts an input value to a standardized SCA string format.

Parameters:

sca (int, float, or str) – The input value to be converted. It can be: - int: An integer value. - float: A floating-point value. - str: A string that may start with ‘SCA’ or be a numeric string.

Returns:

A string in the format ‘SCAxx’, where ‘xx’ is a zero-padded integer.

Return type:

str

Raises:

ValueError – If the input value is not of type int, float, or str, or if the string format is not recognized.

mejiro.utils.roman_util.translate_band(input)[source]

Translates a given band name or alias to its corresponding Roman filter band. This function takes an input band name or alias and translates it to the corresponding Roman filter band. The function supports various aliases for each band, including ground-based filter names.

Parameters:

input (str) – The input band name or alias to be translated.

Returns:

The corresponding Roman filter band name.

Return type:

str

Raises:

ValueError – If the input band name or alias is not recognized.

Examples

>>> translate_band('R')
'F062'
>>> translate_band('Z087')
'F087'
>>> translate_band('H/K')
'F184'
>>> translate_band('unknown')
Traceback (most recent call last):
    ...
ValueError: Band UNKNOWN not recognized. Valid bands (and aliases) are {'F062': ['F062', 'R', 'R062'], 'F087': ['F087', 'Z', 'Z087'], 'F106': ['F106', 'Y', 'Y106'], 'F129': ['F129', 'J', 'J129'], 'F158': ['F158', 'H', 'H158'], 'F184': ['F184', 'H/K'], 'F146': ['F146', 'WIDE', 'W146'], 'F213': ['F213', 'KS', 'K213']}.

slsim_util

mejiro.utils.slsim_util.remap_source_images(strong_lens, mapping)[source]

Override entries in strong_lens.kwargs_params['source_images'] by copying one band’s source-image array into another band’s slot.

The dict source_images is populated by GalaxyGalaxy.from_slsim (and equivalents) for catalog sources that ship per-band pixelated cutouts (e.g. SLSim’s COSMOS-Web). Whichever per-band image is sitting under a key at construction time defines the morphology that SyntheticImage will ray-shoot for that band. This helper lets the caller swap which cutout backs which band — useful for experimenting with alternative catalog→instrument band mappings without modifying the underlying catalog code.

Mutates strong_lens.kwargs_params['source_images'] in place.

Parameters:
  • strong_lens (mejiro.strong_lens.StrongLens) – StrongLens (e.g. GalaxyGalaxy, LensedSupernova) built from a SLSim catalog source. Must have a populated kwargs_params['source_images'] dict.

  • mapping (dict[str, str]) – {destination_band: source_band}. Both keys must be present in source_images before the call. After the call, source_images[destination_band] is the array previously stored under source_images[source_band]. Self-mappings are no-ops.

mejiro.utils.slsim_util.write_lens_population_to_csv(output_path, lens_population, snr_list, bands=None, show_progress_bar=False)[source]

Write list of SLSim galaxy-galaxy Lens objects to a CSV.

Parameters:
  • output_path (str) – The file path where the CSV file will be saved.

  • lens_population (list) – A list of SLSim galaxy-galaxy Lens objects.

  • snr_list (list) – A list of signal-to-noise ratio (SNR) values corresponding to each system.

  • bands (list) – A list of bands. If None, they will be parsed from the SLSim Deflector.

  • show_progress_bar (bool, optional) – If True, shows a progress bar during processing. Default is False.

util

mejiro.utils.util.all_arrays_equal(iterator)[source]

Check if all arrays in an iterator are equal.

Parameters:

iterator (iterable) – An iterable containing arrays to be compared.

Returns:

True if all arrays in the iterator are equal, False otherwise.

Return type:

bool

mejiro.utils.util.batch_list(list, n)[source]

Split a list into batches of size n. This method is used for parallel processing.

Parameters:
  • list (list) – The input list to be split into batches.

  • n (int) – The size of each batch.

Yields:

list – A batch of size n from the input list.

Examples

>>> my_list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
>>> for batch in batch_list(my_list, 3):
...     print(batch)
[1, 2, 3]
[4, 5, 6]
[7, 8, 9]
[10]
mejiro.utils.util.build_meshgrid(scene_size, pixel_scale)[source]

Build a meshgrid for a given scene size and pixel scale.

Parameters:
  • scene_size (float) – The physical size of the scene in angular units (often, arcseconds).

  • pixel_scale (float) – The size of each pixel.

Returns:

A 2D array of shape (num_pix, num_pix) containing the meshgrid coordinates.

Return type:

numpy.ndarray

mejiro.utils.util.calculate_execution_time(start, stop, unit='hms')[source]

Calculate the execution time between two given timestamps.

Parameters:
  • start (float) – The start timestamp (in seconds, e.g., from time.time()).

  • stop (float) – The stop timestamp (in seconds, e.g., from time.time()).

  • unit (str, optional) – The unit for the output. Use ‘hms’ for hours:minutes:seconds (default), or ‘s’ for seconds.

Returns:

The execution time as a formatted string. If unit=’hms’, returns “H:MM:SS”. If unit=’s’, returns the time in seconds as a string.

Return type:

str

Raises:

ValueError – If the unit is not ‘hms’ or ‘s’.

Examples

>>> import time
>>> start = time.time()
>>> # Some code to measure execution time
>>> stop = time.time()
>>> calculate_execution_time(start, stop)
'0:00:05'
>>> calculate_execution_time(start, stop, unit='s')
'5.123 s'
mejiro.utils.util.center_crop_image(array, shape)[source]

Crop the input array to the specified shape by centering the image.

Both the input array and the requested shape must have odd dimensions, so that the cropped block is unambiguously centered on a single pixel.

Parameters:
  • array (numpy.ndarray) – The input array to be cropped. Both dimensions must be odd.

  • shape (tuple) – The desired shape of the cropped array. Both dimensions must be odd and no larger than the corresponding dimension of array.

Returns:

The cropped array.

Return type:

numpy.ndarray

Raises:

ValueError – If either array or shape has an even dimension, or if shape is larger than array.shape along either axis.

Notes

If the input array already has the specified shape, it is returned as is.

Examples

>>> array = np.array([[1, 2, 3, 4, 5],
...                   [6, 7, 8, 9, 10],
...                   [11, 12, 13, 14, 15],
...                   [16, 17, 18, 19, 20],
...                   [21, 22, 23, 24, 25]])
>>> center_crop_image(array, (3, 3))
array([[ 7,  8,  9],
       [12, 13, 14],
       [17, 18, 19]])
mejiro.utils.util.check_negative_values(array)[source]

Check if there are any negative values in the given array or list of arrays.

Parameters:

array (array-like or list of array-like) – The input array or list of arrays to check for negative values.

Returns:

True if there are negative values, False otherwise.

Return type:

bool

Notes

This function uses numpy’s any function to check for negative values.

Examples

>>> check_negative_values([1, 2, -3, 4])
True
>>> check_negative_values([[1, 2], [3, -4]])
True
>>> check_negative_values([1, 2, 3, 4])
False
mejiro.utils.util.clear_directory(path)[source]

Clear all files and directories within the specified path.

Parameters:

path (str) – The path to the directory to be cleared.

Return type:

None

mejiro.utils.util.combine_all_csvs(path, prefix='', filename=None)[source]

Combine all CSV files in a directory into a single DataFrame.

Parameters:
  • path (str) – The path to the directory containing the CSV files.

  • prefix (str, optional) – The prefix of the CSV files to be combined. Default is an empty string.

  • filename (str, optional) – The name of the combined CSV file to save. If not provided, the DataFrame will not be saved.

Returns:

df_res – The combined DataFrame containing all the CSV data.

Return type:

pandas.DataFrame

Examples

>>> combine_all_csvs('/path/to/csvs', 'combined.csv')
Wrote combined CSV to combined.csv
<DataFrame object>
mejiro.utils.util.create_centered_box(N, box_size)[source]

Create an NxN array with a centered box of True values.

Parameters:
  • N (int) – The size of the outer array. Must be an odd number.

  • box_size (int) – The size of the centered box. Must be an odd number and less than or equal to N.

Returns:

An NxN array with a centered box of True values and the rest False.

Return type:

numpy.ndarray

Raises:

ValueError – If N is not an odd number. If box_size is not an odd number. If box_size is greater than N.

mejiro.utils.util.create_centered_circle(N, radius)[source]

Create an NxN boolean array with a centered circle of True values.

Parameters:
  • N (int) – The size of the NxN array. Must be an odd number.

  • radius (float) – The radius of the circle. Must be a positive number and less than or equal to N//2.

Returns:

An NxN boolean array with a centered circle of True values.

Return type:

numpy.ndarray

Raises:

ValueError – If N is not an odd number. If radius is not a positive number. If radius is greater than N//2.

mejiro.utils.util.create_directory_if_not_exists(path)[source]

Create a directory if it does not already exist.

Parameters:

path (str) – The path of the directory to be created.

Return type:

None

mejiro.utils.util.delete_if_exists(path)[source]

Delete a file if it exists.

Parameters:

path (str) – The path to the file to be deleted.

Return type:

None

mejiro.utils.util.get_gaussian_kernel(fwhm, size)[source]

Generate a 2D Gaussian kernel using scipy.ndimage.gaussian_filter.

Parameters:
  • fwhm (float) – Full Width at Half Maximum of the Gaussian.

  • size (int) – The size of the generated 2D array (size x size).

Returns:

2D array representing the Gaussian kernel.

Return type:

numpy.ndarray

mejiro.utils.util.get_kwargs_cosmo(astropy_cosmo)[source]

Get kwargs_cosmo for pyhalo from an Astropy cosmology object.

Parameters:

astropy_cosmo (astropy.cosmology.Cosmology) – An instance of an Astropy cosmology object.

Returns:

A dictionary containing the cosmological parameters:

  • H0float

    The Hubble constant at z=0 in km/s/Mpc.

  • Ob0float

    The density of baryonic matter in units of the critical density at z=0.

  • Om0float

    The density of non-relativistic matter in units of the critical density at z=0.

Return type:

dict

mejiro.utils.util.hydra_to_dict(config)[source]

Convert a Hydra configuration object to a dictionary.

Parameters:

config (OmegaConf.DictConfig) – The Hydra configuration object.

Returns:

A dictionary representation of the Hydra configuration.

Return type:

dict

mejiro.utils.util.load_skypy_config(path)[source]

Load a SkyPy configuration file, ignoring unknown YAML tags.

This function reads a YAML file from the specified path and loads its content into a Python dictionary. It uses a custom YAML loader that ignores any unknown tags in the YAML file.

Parameters:

path (str) – The file path to the SkyPy configuration YAML file.

Returns:

A dictionary containing the loaded SkyPy configuration.

Return type:

dict

Notes

This function uses a custom YAML loader (SafeLoaderIgnoreUnknown) that ignores unknown tags in the YAML file. This can be useful when the YAML file contains tags that are not recognized by the default YAML loader.

mejiro.utils.util.load_synthetic_image(path)[source]

Load a SyntheticImage written by step 04, in either pickle or lightweight format.

Auto-detects the on-disk format from the file extension:

Parameters:

path (str) – Path to the on-disk synthetic image file.

Return type:

SyntheticImage or LightweightSyntheticImage

mejiro.utils.util.make_grid(side_length, num_points)[source]

Generate a 2D grid of evenly spaced points within a square.

Parameters:
  • side_length (float) – The length of the sides of the square.

  • num_points (int) – The number of points along each axis.

Returns:

A 2D array of shape (num_points*num_points, 2) containing the (x, y) coordinates of the grid points.

Return type:

numpy.ndarray

mejiro.utils.util.percent_change(old, new)[source]

Calculate the percent change between two values.

Parameters:
  • old (float) – The initial value.

  • new (float) – The new value.

Returns:

The percent change from the old value to the new value.

Return type:

float

Examples

>>> percent_change(50, 75)
50.0
>>> percent_change(100, 80)
-20.0
mejiro.utils.util.percent_difference(a, b)[source]

Calculate the percentage difference between two values.

Parameters:
  • a (float) – The first value.

  • b (float) – The second value.

Returns:

The percentage difference between the two values.

Return type:

float

Examples

>>> percent_difference(10, 10)
0.0
>>> percent_difference(10, 15)
40.0
mejiro.utils.util.pickle(path, thing)[source]

Use the pickle module to serialize an object and save it to a file. Note that the file will be overwritten if it already exists.

Parameters:
  • path (str) – The path to the file where the object will be saved.

  • thing (object) – The object to be pickled and saved.

Return type:

None

Examples

>>> pickle('/path/to/file.pkl', {'key': 'value'})
mejiro.utils.util.polar_to_cartesian(r, theta)[source]

Convert polar coordinates to Cartesian coordinates.

Parameters:
  • r (float) – The radial distance from the origin.

  • theta (float) – The angle in radians from the positive x-axis.

Returns:

  • x (float) – The x-coordinate in Cartesian coordinates.

  • y (float) – The y-coordinate in Cartesian coordinates.

mejiro.utils.util.print_execution_time(start, stop, return_string=False)[source]

Print the execution time between two given timestamps.

Parameters:
  • start (float) – The start timestamp.

  • stop (float) – The stop timestamp.

Return type:

None

Examples

>>> start = time.time()
>>> # Some code to measure execution time
>>> stop = time.time()
>>> print_execution_time(start, stop)
Execution time: 0:00:05
mejiro.utils.util.print_key_structure(d, indent=0)[source]

Print the structure of a dictionary, showing keys and nested keys.

Parameters:
  • d (dict) – The dictionary whose structure is to be printed.

  • indent (int, optional) – The indentation level for nested keys. Default is 0.

Return type:

None

Examples

>>> d = {'a': 1, 'b': {'c': 2, 'd': {'e': 3}}}
>>> print_key_structure(d)
a
b
  c
  d
    e
mejiro.utils.util.replace_negatives(array, replacement=0)[source]

Replace negative values in an array with a specified replacement value.

Parameters:
  • array (numpy.ndarray) – The input array in which negative values will be replaced.

  • replacement (int or float, optional) – The value to replace negative values with. Default is 0.

Returns:

The array with negative values replaced by the specified replacement value.

Return type:

numpy.ndarray

Warns:

UserWarning – If any negative values are found and replaced in the array.

Examples

>>> import numpy as np
>>> from mejiro.utils.util import replace_negatives
>>> arr = np.array([-1, 2, -3, 4])
>>> replace_negatives(arr)
array([0, 2, 0, 4])
mejiro.utils.util.replace_negatives_with_zeros(array)[source]

Replace negative values in the input array with zeros.

Parameters:

array (numpy.ndarray) – Input array.

Returns:

Array with negative values replaced by zeros.

Return type:

numpy.ndarray

mejiro.utils.util.resize_with_pixels_centered(array, oversample_factor)[source]

Resize the input array with centered pixels using the specified oversample factor.

Parameters:
  • array (numpy.ndarray) – The input array to be resized.

  • oversample_factor (int) – The factor by which to oversample the array. Must be odd.

Returns:

The resized array with centered pixels.

Return type:

numpy.ndarray

Raises:
  • Exception – If the oversample factor is not odd.

  • Exception – If the array is not square.

mejiro.utils.util.return_qtable(path)[source]

Reads a QTable from a given file path.

Parameters:

path (str) – The file path or pattern to read the QTable from.

Returns:

The QTable read from the specified file path.

Return type:

Astropy.table.QTable

mejiro.utils.util.return_table(path)[source]

Reads a table from the given file path.

Parameters:

path (str) – The file path or pattern to read the table from.

Returns:

The table read from the specified file path.

Return type:

Astropy.table.Table

mejiro.utils.util.return_yaml(path)[source]

Reads a YAML file from the given path and returns its contents as a dictionary.

Parameters:

path (str) – The path to the YAML file. This can include glob patterns.

Returns:

The contents of the YAML file as a dictionary.

Return type:

dict

Raises:
  • FileNotFoundError – If the file does not exist.

  • yaml.YAMLError – If there is an error parsing the YAML file.

mejiro.utils.util.rotate_array(array, angle, fillcolor='white')[source]

Rotate a 2D numpy array by a given angle.

Parameters:
  • array (numpy.ndarray) – The input array to be rotated.

  • angle (float) – The angle of rotation in degrees.

Returns:

The rotated array.

Return type:

numpy.ndarray

mejiro.utils.util.save_skypy_config(skypy_config, path)[source]

Save the SkyPy configuration to a YAML file.

Parameters:
  • skypy_config (dict) – The SkyPy configuration dictionary to be saved.

  • path (str) – The file path where the configuration will be saved.

Notes

This function currently does not handle serialization of complex objects such as numpy arrays. Future improvements should include handling such cases.

mejiro.utils.util.scientific_notation_string(input)[source]

Convert a number to a string representation in scientific notation.

Parameters:

input (float) – The number to be converted.

Returns:

The string representation of the number in scientific notation.

Return type:

str

Examples

>>> scientific_notation_string(1000000)
'1.00e+06'
>>> scientific_notation_string(0.000001)
'1.00e-06'
mejiro.utils.util.set_odd_num_pix(scene_size, pixel_scale)[source]

Set the number of pixels to be odd for a given scene size and pixel scale.

Parameters:
  • scene_size (float) – The physical size of the scene in angular units (often, arcseconds).

  • pixel_scale (float) – The size of each pixel.

Returns:

The number of pixels, guaranteed to be odd.

Return type:

int

mejiro.utils.util.smallest_non_negative_element(array)[source]

Find the smallest non-negative element in a given array.

Parameters:

array (numpy.ndarray) – Input array containing numerical elements.

Returns:

The smallest non-negative element in the array. If no non-negative elements are found, returns None.

Return type:

float or None

mejiro.utils.util.smooth_nan_pixels(image, kernel_size=3)[source]

Replace NaN pixels in an image with local median values.

This function identifies NaN pixels in an image and replaces them with the median value computed from a local neighborhood around each NaN pixel. Non-NaN pixels remain unchanged.

Parameters:
  • image (ndarray) – Input image array that may contain NaN pixels.

  • kernel_size (int, optional) – Size of the square kernel used to compute local median values. Default is 3, meaning a 3x3 neighborhood.

Returns:

Image array with NaN pixels replaced by local median values. The original array is modified in-place.

Return type:

ndarray

mejiro.utils.util.smooth_negative_pixels(image, kernel_size=3)[source]

Replace negative pixels in an image with local median values.

This function identifies negative pixels in an image and replaces them with the median value computed from a local neighborhood around each negative pixel. Positive pixels remain unchanged.

Parameters:
  • image (ndarray) – Input image array that may contain negative pixels.

  • kernel_size (int, optional) – Size of the square kernel used to compute local median values. Default is 3, meaning a 3x3 neighborhood.

Returns:

Image array with negative pixels replaced by local median values. The original array is modified in-place.

Return type:

ndarray

Notes

  • The function uses scipy.ndimage.generic_filter with np.nanmedian to compute the local median, treating NaN values as missing data.

  • Pixels with values >= 0 are not modified.

  • The kernel_size determines the neighborhood size for median computation.

Examples

>>> import numpy as np
>>> image = np.array([[-1, 2, 3], [4, -2, 6], [7, 8, 9]], dtype=float)
>>> smoothed = smooth_negative_pixels(image, kernel_size=3)
mejiro.utils.util.smooth_pixels(image, kernel_size=3)[source]

Replace NaN and negative pixels in an image with local median values.

This function first replaces NaN pixels, then replaces negative pixels, each using the median value computed from a local neighborhood.

Parameters:
  • image (ndarray) – Input image array that may contain NaN and/or negative pixels.

  • kernel_size (int, optional) – Size of the square kernel used to compute local median values. Default is 3, meaning a 3x3 neighborhood.

Returns:

Image array with NaN and negative pixels replaced by local median values. The original array is modified in-place.

Return type:

ndarray

mejiro.utils.util.unpickle(path)[source]

Unpickle the object stored in the given file path and return it. If the file path does not exist, it is interpreted as a glob pattern.

Parameters:

path (str) – The path to the file containing the pickled object.

Returns:

The unpickled object.

Return type:

object

mejiro.utils.util.unpickle_all(dir_path, prefix='', suffix='', limit=None)[source]

Load and unpickle all files in a directory.

Parameters:
  • dir_path (str) – The path to the directory containing the files.

  • prefix (str, optional) – The prefix of the files to be loaded. Default is an empty string.

  • suffix (str, optional) – The suffix of the files to be loaded. Default is an empty string.

  • limit (int, optional) – The maximum number of files to be loaded. Default is None.

Returns:

A list of unpickled objects.

Return type:

list

mejiro.utils.util.write_execution_time(time, script_name, filepath)[source]

Write the execution time of a script to a file.

Parameters:
  • time (float) – The execution time in seconds.

  • script_name (str) – The name of the script.

  • filepath (str) – The path to the file where the execution time will be written.

Return type:

None