pypeit.core.parse module
parse module.
- pypeit.core.parse.binning2string(binspectral, binspatial)[source]
Convert the binning from integers to a string following the PypeIt convention order, spectral then spatial.
- Parameters:
- Returns:
Comma-separated binning along the spectral and spatial directions; e.g.,
2,1
- Return type:
- pypeit.core.parse.get_dnum(det, caps=False, prefix=True)[source]
Convert a detector index into a string used by the settings dictionary or other bits of code. Best to keep at two digits
- pypeit.core.parse.load_sections(string, fmt_iraf=True)[source]
From the input string, return the coordinate sections. In IRAF format (1 index) or Python
- pypeit.core.parse.parse_binning(binning: str)[source]
Parse input binning into binspectral, binspatial
Note that for some instruments, the meaning will be swapped if parsed directly from the Header. The developer needs to react accordingly..
- Parameters:
binning (
str
, numpy.ndarray,tuple
) –The spectral and spatial binning. Several formats are supported, including the following examples. Note that in all examples, the binning in the spectral direction is 2, and the binning in the spatial direction is 1:
string format
comma delimited string (e.g.
2,1
)x delimited string (e.g.
2x1
)space delimited string (e.g.
2 1
)'None'
will always assume 1x1 binning
tuple format
this must be of the form of tuple, for example:
(2,1)
numpy array
this must be of the form of tuple, for example:
np.array([2,1])
- Returns:
binspectral, binspatial as integers
- Return type:
- pypeit.core.parse.parse_slitspatnum(slitspatnum)[source]
Parse the
slitspatnum
into a list of detectors and SPAT_IDs.- Parameters:
slitspatnum (
str
,list
) – A single string or list of strings to parse.- Returns:
Two arrays with the list of 1-indexed detectors (str) and spatial pixels coordinates for each slit. The shape of each array is
(nslits,)
, wherenslits
is the number ofslitspatnum
entries parsed (1 if only a single string is provided).- Return type:
- pypeit.core.parse.sec2slice(subarray, one_indexed=False, include_end=False, require_dim=None, binning=None)[source]
Convert a string representation of an array subsection (slice) into a list of slice objects.
- Parameters:
subarray (
str
) – The string to convert. Should have the form of normal slice operation, ‘start:stop:step’. The parser ignores whether or not the string has the brackets ‘[]’, but the string must contain the appropriate ‘:’ and ‘,’ characters.one_indexed (
bool
, optional) – The string should be interpreted as 1-indexed. Default is to assume python indexing.include_end (
bool
, optional) – If the end is defined, adjust the slice such that the last element is included. Default is to exclude the last element as with normal python slicing.require_dim (
int
, optional) – Test if the string indicates the slice along the proper number of dimensions.binning (
str
, optional) – Assume the slice is for an unbinned array and adjust the returned slice for this binning in each dimension. If two dimensional, the format of this string must be, e.g., 1,2 for unbinned rows and a factor of 2 binning along columns.
- Returns:
A tuple of slice objects, one per dimension of the prospective array.
- Return type:
- Raises:
TypeError – Raised if the input subarray is not a string.
ValueError – Raised if the string does not match the required dimensionality or if the string does not look like a slice.
- pypeit.core.parse.str2list(inp, length=None)[source]
Expand a string with a comma-separated set of integers and slices into a list of the relevant integers.
Setting a maximum length of the list to 10, examples of the allowed syntax and result are:
‘all’: [0,1,2,3,4,5,6,7,8,9]
‘:4’: [0,1,2,3]
‘3:5,8:’: [3,4,8,9]
‘3,1:5,6’: [1,2,3,4,6]
Note the function removes any non-unique integers (see the last example).
- Parameters:
- Returns:
List of parsed integers.
- Return type: