Utility Functions¶
Welcome to the documentation for the ‘wifes_utils.py’ module, which contains a number of utility functions for WiFeS data.
- pywifes.wifes_utils.arguments()¶
Report current functions source file and as-called arguments.
Adapted from http://kbyanc.blogspot.com/2007/07/python-aggregating-function-arguments.html
- pywifes.wifes_utils.copy_files(src_dir_path, destination_dir_path, filenames)¶
Copy files from the source directory to the destination directory.
- Parameters:
src_dir_path (str) – The path to the source directory.
destination_dir_path (str) – The path to the destination directory.
filenames (list) – A list of filenames to be copied.
- Raises:
Exception – If there is an error while copying the files.
- pywifes.wifes_utils.fits_scale_from_bitpix(bitpix)¶
Map common BITPIX header value to astropy.io.fits ‘scale’ argument.
- pywifes.wifes_utils.get_associated_calib(metadata, this_fn, type)¶
Get the associated calibration file for a given data file.
- Parameters:
metadata (dict) – The metadata dictionary containing information about the observations.
this_fn (str) – The filename of the data file for which to find the associated calibration file.
type (str) – The type of calibration file to search for.
- Returns:
The filename of the associated calibration file if found, or False if not found.
- Return type:
str or bool
- pywifes.wifes_utils.get_file_names(src_dir_path, glob_pattern)¶
Get the names of files in a directory that match a given search query in a glob pattern. Does not search in subfolders.
- Parameters:
src_dir_path (str) – The path to the source directory.
glob_pattern (str) – The glob pattern (search query) to match the filenames.
- Returns:
A list of filenames that match the glob pattern.
- Return type:
list
- pywifes.wifes_utils.get_full_obs_list(metadata, exclude=None)¶
Get the full observation list from the given metadata.
- Parameters:
metadata (dict) – A dictionary containing metadata information.
exclude (list) – A list of imagetypes to exclude from the returned observation list. Default: None.
- Returns:
The full observation list.
- Return type:
list
- pywifes.wifes_utils.get_primary_sci_obs_list(metadata)¶
Get the list of primary science observations from the metadata.
- Parameters:
metadata (dict) – The metadata containing information about the observations.
- Returns:
The list of primary science observations.
- Return type:
list
- pywifes.wifes_utils.get_primary_std_obs_list(metadata, stdtype='all')¶
Get the list of primary standard observations based on the given metadata and type.
- Parameters:
metadata (dict) – The metadata containing information about the observations.
stdtype (str, optional) – The type of standard star observations to include in the list. Options: ‘all’, ‘telluric’, ‘flux’. Default: ‘all’.
- Returns:
The list of primary standard observations.
- Return type:
list
- Raises:
ValueError – If the standard star type is not understood.
- pywifes.wifes_utils.get_sci_obs_list(metadata)¶
Get a list of science observations from the metadata.
- Parameters:
metadata (dict) – The metadata containing information about the observations.
- Returns:
A list of science observation filenames.
- Return type:
list
- pywifes.wifes_utils.get_sky_obs_list(metadata)¶
Get a list of sky observations from the metadata.
- Parameters:
metadata (dict) – The metadata containing information about the observations.
- Returns:
A list of sky observation filenames.
- Return type:
list
- pywifes.wifes_utils.get_std_obs_list(metadata, type='all')¶
Get a list of standard observations.
- Parameters:
metadata (-) – The metadata containing information about the observations.
type (-) – The type of observations to include in the list. Options: ‘all’, ‘flux’, ‘telluric’. Default: ‘all’.
- Returns:
- std_obs_list – A list of standard observation filenames.
- Return type:
list
- pywifes.wifes_utils.hl_envelopes_idx(s, dmin=1, dmax=1, split=False, as_bool=False)¶
Inputs:
- s1d-array
data signal from which to extract high and low envelopes
- dmin, dmaxint, optional
size of chunks, use this if the size of the input signal is too big
- splitbool, optional
if True, split the signal in half along its mean, might help to generate the envelope in some cases
- as_boolbool, optional
whether to return boolean arrays indicating if each element is a min or max value
Output: lmin, lmax : low/high envelope idx of input signal s, or if as_bool=True, then boolean arrays where min/max
Adapted from https://stackoverflow.com/questions/34235530/how-to-get-high-and-low-envelope-of-a-signal/60402647#60402647
- pywifes.wifes_utils.is_halfframe(inimg, data_hdu=0)¶
Report whether this exposure (filename or HDUList) is a half-frame (a.k.a. Stellar mode) image.
- pywifes.wifes_utils.is_nodshuffle(inimg)¶
Report whether this exposure is a Nod & Shuffle frame.
- pywifes.wifes_utils.is_standard(inimg, data_hdu=0)¶
Report whether this exposure is a Nod & Shuffle frame.
- pywifes.wifes_utils.is_subnodshuffle(inimg, data_hdu=0)¶
Report whether this exposure is a SubNodAndShuffle frame.
- pywifes.wifes_utils.is_taros(inimg)¶
Report whether this exposure was taken with TAROS. Useful for determining whether last slit of half-frame readouts is truncated.
- pywifes.wifes_utils.load_config_file(filename)¶
Load a configuration file in JSON5 format.
- Parameters:
filename (str) – The name of the configuration file.
- Returns:
A dictionary containing the loaded configuration data.
- Return type:
dict
- pywifes.wifes_utils.move_files(src_dir_path, destination_dir_path, filenames)¶
Move files from the source directory to the destination directory.
- Parameters:
src_dir_path (str) – The path of the source directory.
destination_dir_path (str) – The path of the destination directory.
filenames (list of str) – The list of filenames to be moved.
- Raises:
Exception – If an error occurs while moving the files.
- pywifes.wifes_utils.nan_helper(y)¶
Helper to handle indices and logical indices of NaNs.
- Input:
y, 1d numpy array with possible NaNs
- Output:
nans, logical indices of NaNs
index, a function, with signature indices= index(logical_indices), to convert logical indices of NaNs to ‘equivalent’ indices
Example
>>> # linear interpolation of NaNs >>> nans, x= nan_helper(y) >>> y[nans]= numpy.interp(x(nans), x(~nans), y[~nans])
https://stackoverflow.com/questions/6518811/interpolate-nan-values-in-a-numpy-array
- pywifes.wifes_utils.set_header(filename, kw, kw_value, data_hdu=0)¶