opticam.utils.helpers

Functions

camel_to_snake(string)

Convert a camelCase string to snake_case.

sort_dict_by_filters(d)

Attempt to sort a dictionary whose keys are filter names in order of increasing wavelength (e.g., u, g, r, i, z). If

sort_filters(filters)

Attempt to sort a list of filters in order of increasing wavelength (e.g., u, g, r, i, z). If unrecognised filters

delete_keys_from_nested_dict(d, keys)

Delete keys from a dictionary in-place.

match_dict_keys(d, d_ref)

Match the keys of d to those of d_ref.

propagate_errors(data, bias_var, dark_var, flat_var, ...)

Compute the propagated error image.

camera_and_filter_key(camera, fltr)

Create a unique camera:filter key. This unique key breaks degeneracies in multi-camera, multi-filter instruments,

camera_key(key)

Given a unique camera:filter key, get the camera. This is used to apply bias and dark noise corrections, which are

filter_key(key)

Given a unique camera:filter key, get the filter.

save_figure(fig, path)

Save a figure to the specified path.

Module Contents

opticam.utils.helpers.camel_to_snake(string)

Convert a camelCase string to snake_case.

Parameters

stringstr

The camelCase string to convert.

Returns

str

The converted snake_case string.

Parameters:

string (str)

Return type:

str

opticam.utils.helpers.sort_dict_by_filters(d)

Attempt to sort a dictionary whose keys are filter names in order of increasing wavelength (e.g., u, g, r, i, z). If unrecognised filters are passed, no sorting is performed.

Parameters

dDict[str, Any]

A dictionary with filter names as keys.

Returns

Dict[str, Any]

The sorted dictionary.

Parameters:

d (Dict[str, Any])

Return type:

Dict[str, Any]

opticam.utils.helpers.sort_filters(filters)

Attempt to sort a list of filters in order of increasing wavelength (e.g., u, g, r, i, z). If unrecognised filters are passed, no sorting is performed.

Parameters

filtersList[str]

The list of filters.

Returns

List[str]

The sorted list of filters.

Parameters:

filters (List[str])

Return type:

List[str]

opticam.utils.helpers.delete_keys_from_nested_dict(d, keys)

Delete keys from a dictionary in-place.

Parameters

ddict[str, Any]

The dictionary. May contain nested dictionaries.

keysset[str]

The keys to remove from the dictionary.

Parameters:
  • d (dict[str, Any])

  • keys (set[str])

Return type:

None

opticam.utils.helpers.match_dict_keys(d, d_ref)

Match the keys of d to those of d_ref.

Parameters

ddict[Any, Any]

The dictionary.

d_refdict[Any, Any]

The reference dictionary.

Returns

dict[Any, Any]

A copy of d whose keys match those of d_ref.

Parameters:
  • d (dict[Any, Any])

  • d_ref (dict[Any, Any])

Return type:

dict[Any, Any]

opticam.utils.helpers.propagate_errors(data, bias_var, dark_var, flat_var, background_rms, read_noise)

Compute the propagated error image.

Parameters

dataNDArray

The calibrated, background-subtracted image.

bias_varfloat | NDArray[np.float64]

The bias correction variance term.

dark_varfloat | NDArray[np.float64]

The dark noise correction variance term.

flat_varfloat | NDArray[np.float64]

The flat-field correction variance term scaled by the square of the calibrated image.

background_rmsfloat | NDArray

The background RMS.

read_noisefloat

The read noise [electrons/pixel].

Returns

NDArray[np.float64]

The propagated error image.

Parameters:
  • data (numpy.typing.NDArray)

  • bias_var (float | numpy.typing.NDArray[numpy.float64])

  • dark_var (float | numpy.typing.NDArray[numpy.float64])

  • flat_var (float | numpy.typing.NDArray[numpy.float64])

  • background_rms (float | numpy.typing.NDArray)

  • read_noise (float)

Return type:

numpy.typing.NDArray[numpy.float64]

opticam.utils.helpers.camera_and_filter_key(camera, fltr)

Create a unique camera:filter key. This unique key breaks degeneracies in multi-camera, multi-filter instruments, such that flat-field corrections can be applied properly.

Parameters

camerastr

The camera. For single-camera instruments, this can simply be the name of the instrument. For multi-camera instruments, however, this value should be unambiguous (e.g., the individual camera name or number).

fltrstr

The filter.

Returns

str

The unique camera:filter key.

Parameters:
  • camera (str)

  • fltr (str)

Return type:

str

opticam.utils.helpers.camera_key(key)

Given a unique camera:filter key, get the camera. This is used to apply bias and dark noise corrections, which are indifferent to the filter used.

Parameters

keystr

The unique camera:filter key.

Returns

str

The camera.

Parameters:

key (str)

Return type:

str

opticam.utils.helpers.filter_key(key)

Given a unique camera:filter key, get the filter.

Parameters

keystr

The unique camera:filter key.

Returns

str

The filter.

Parameters:

key (str)

Return type:

str

opticam.utils.helpers.save_figure(fig, path)

Save a figure to the specified path.

Parameters

figFigure

The figure.

pathPath | str

The path, including the file name and extension.

Parameters:
  • fig (matplotlib.figure.Figure)

  • path (pathlib.Path | str)

Return type:

None