sigpyproc.utils#
Utility functions for sigpyproc.
This module contains utility functions for sigpyproc.
Classes
A class to handle frequency channels. |
Functions
Apply a 1D function along one or more axes. |
|
Detect file type based on file extension. |
|
Convert duration in seconds to human readable string. |
|
Generate a Gaussian profile. |
|
Get the name of the function that called the current function. |
|
Get a fancy configured logger. |
|
Calculate the factor of |
|
Find the next power of 2 greater than or equal to |
|
Return the smallest multiple of |
|
Pad an array with zeros up to the target_length. |
|
Validate a path based on various criteria. |
- class sigpyproc.utils.FrequencyChannels(freqs)[source]#
Bases:
objectA class to handle frequency channels.
- Parameters:
- freqs
ArrayLike Central frequencies of the channels in MHz.
- freqs
- Attributes:
- freqs
ndarray Central frequencies of the channels in MHz.
- array
Quantity Frequency array in Astropy Quantity format.
nchansNumber of frequency channels.
fch1Central frequency of the first channel.
foffFrequency offset between channels.
ftopEdge frequency of the top channel.
fcenterCentral frequency of the entire band.
fbottomEdge frequency of the bottom channel.
bandwidthBandwidth of the entire band.
- freqs
Methods
from_pfits(fcenter, bandwidth, nchans)Create from pfits parameters.
from_sig(fch1, foff, nchans)Create from sigproc parameters.
- freqs#
- array#
- property fch1#
Central frequency of the first channel.
- Returns:
QuantityCentral frequency of the first channel in MHz.
- property foff#
Frequency offset between channels.
- Returns:
QuantityFrequency offset between channels in MHz.
- property ftop#
Edge frequency of the top channel.
- Returns:
QuantityEdge frequency of the top channel in MHz.
- property fcenter#
Central frequency of the entire band.
- Returns:
QuantityCentral frequency of the entire band in MHz.
- property fbottom#
Edge frequency of the bottom channel.
- Returns:
QuantityEdge frequency of the bottom channel in MHz.
- classmethod from_sig(fch1, foff, nchans)[source]#
Create from sigproc parameters.
- Parameters:
- Returns:
FrequencyChannelsFrequencyChannels object.
- sigpyproc.utils.apply_along_axes(func, data, axis=None)[source]#
Apply a 1D function along one or more axes.
- sigpyproc.utils.detect_file_type(filename)[source]#
Detect file type based on file extension.
Supported extensions:
sigproc (.fil).
pfits (.fits, .sf).
fbh5 (.h5).
- sigpyproc.utils.duration_string(duration)[source]#
Convert duration in seconds to human readable string.
- sigpyproc.utils.get_callerfunc(stack)[source]#
Get the name of the function that called the current function.
- Parameters:
- stack
list[inspect.FrameInfo] Stack trace from
stack().
- stack
- Returns:
strName of the calling function.
- sigpyproc.utils.get_logger(name, *, level=logging.INFO, quiet=False, log_file=None)[source]#
Get a fancy configured logger.
- Parameters:
- name
str Logger name.
- level
intorstr, optional Logging level, by default
logging.INFO.- quiet
bool, optional If True set
levelaslogging.WARNING, by default False.- log_file
str, optional Path to log file, by default None.
- name
- Returns:
logging.LoggerA logging object.
- sigpyproc.utils.next2_to_n(x)[source]#
Find the next power of 2 greater than or equal to
x.- Parameters:
- x
int Number to find the next power of 2 for.
- x
- Returns:
intNext power of 2 greater than or equal to
x.
- Raises:
ValueErrorIf
xis not positive.
- sigpyproc.utils.next_multiple(x, y)[source]#
Return the smallest multiple of
ythat is greater than or equal tox.- Parameters:
- Returns:
intThe smallest multiple of
ythat is greater than or equal tox.
- Raises:
ValueErrorIf
yis not positive.
- sigpyproc.utils.pad_centre(array, target_length)[source]#
Pad an array with zeros up to the target_length.
- Parameters:
- array
np.ndarray N-D numpy array to pad
- target_length
int Target length along last axis
- array
- Returns:
np.ndarrayPadded array
- Raises:
ValueErrorIf target_length is less than the last axis length of the array
- sigpyproc.utils.validate_path(path, *, exists=True, file_okay=True, dir_okay=False, readable=True, writable=False, resolve_path=True)[source]#
Validate a path based on various criteria.
- Parameters:
- path
str|Path Path to validate.
- exists
bool, optional Whether the path must exist, by default True.
- file_okay
bool, optional Whether a file path is acceptable, by default True.
- dir_okay
bool, optional Whether a directory path is acceptable, by default False.
- readable
bool, optional Whether the path must be readable, by default True.
- writable
bool, optional Whether the path must be writable, by default False.
- resolve_path
bool, optional Whether to resolve the path to an absolute path, by default True.
- path
- Returns:
PathValidated path.
- Raises:
ValueErrorIf neither
file_okaynordir_okayis True.FileNotFoundErrorIf
existsis True and the path does not exist.NotADirectoryErrorIf a directory path is expected but a file path was found.
IsADirectoryErrorIf a file path is expected but a directory path was found.
PermissionErrorIf the path lacks the required permissions.