dither
– Dither file parser¶
Parse or create a dither file.
Create a dither file with DitherCreator
or create_dither_file()
.
Fake an empty dither (EmptyDither
) or parse a dither file like the
following (ParseDither
)
# basename modelbase ditherx dithery seeing norm airmass
SIMDEX-obs-1_D1_046 SIMDEX-obs-1_D1_046 0.00 0.00 1.60 1.00 1.22
SIMDEX-obs-1_D2_046 SIMDEX-obs-1_D2_046 0.61 1.07 1.60 1.00 1.22
SIMDEX-obs-1_D3_046 SIMDEX-obs-1_D3_046 1.23 0.00 1.60 1.00 1.22
The create_dither_file()
function is exposed via the dither_file
executable
-
exception
pyhetdex.het.dither.
DitherParseError
[source]¶ Bases:
ValueError
Custom error
-
exception
pyhetdex.het.dither.
DitherCreationError
[source]¶ Bases:
ValueError
Raised when something fails while creating the dither file
-
exception
pyhetdex.het.dither.
DitherPositionError
[source]¶ Bases:
RuntimeError
Fail to parse the ditherpos file
-
class
pyhetdex.het.dither.
_BaseDither
[source]¶ Bases:
object
Base class for the dither object. Just defines the common public variables
Attributes: - basename : dictionary
basenames of the dither files; key : dither; value: basename
- dx, dy : dictionaries
dither relative x and y position; key : dither; value: dx, dy
- seeing : dictionary
dither image quality; key dither; value : image quality
- norm : dictionary
relative flux normalisation among dithers; key dither; value : normalisation
- airmass : dictionary
dither airmass; key dither; value : airmass
-
dithers
¶ List of dithers
-
absfname
¶ Absolute file name
-
abspath
¶ Absolute file path
-
filename
¶ Absolute file path
-
class
pyhetdex.het.dither.
EmptyDither
[source]¶ Bases:
pyhetdex.het.dither._BaseDither
Creates a dither object with only one entry.
The dither key is D1,
basename
andabsfname
are left empty,dx
anddy
are set to 0 and image quality, illumination and airmass are set to 1. It is provided as a stub dither object in case the real one does not exists.
-
class
pyhetdex.het.dither.
ParseDither
(dither_file)[source]¶ Bases:
pyhetdex.het.dither._BaseDither
Parse the dither file and store the information in dictionaries with the string
Di
, with i=1,2,3, as keyParameters: - dither_file : string
file containing the dither relative position.
Raises: - DitherParseError
if the key
Di
is not found in the base name
-
class
pyhetdex.het.dither.
DitherCreator
(fplane_file, shot, dither_positions=[['000', 0.0, -1.27, -1.27, 0.0, 0.73, -0.73]])[source]¶ Bases:
object
Class to create dither files
Initialize the dither file creator for this shot
Read in the locations of the dithers for each IFU from dither_positions.
Parameters: - fplane_file : str
path the focal plane file; it is parsed using
FPlane
- shot :
pyhetdex.het.telescope.Shot
instance a
shot
instance that contains info on the image quality and normalization- dither_positions : list of lists, optional
list of lists with 2*n+1 elements: the first element is the
id_
, used in, e.g.,create_dither()
, then there are the n x-positions of the dithers and finally their n y-positions
Raises: - DitherPositionError
if the number of x and y dither shifts for one id does not match
Attributes: - ifu_dxs, ifu_dys : dictionaries
key: ihmpid; key: x and y shifts for the dithers
- shot :
pyhetdex.het.telescope.Shot
instance - fplane :
FPlane
instance
-
classmethod
from_file
(fplane_file, shot, dither_positions_file)[source]¶ Create an instance of the class reading the dither positions from a file.
Parameters: - fplane_file : str
path the focal plane file; it is parsed using
FPlane
- shot :
pyhetdex.het.telescope.Shot
instance a
shot
instance that contains info on the image quality and normalization- dither_positions_file : str
path to file containing the positions of the dithers for each IHMPID; the file must have the following format:
ihmpid x1 x2 ... xn y1 y2 ... yn
-
_store_dither_positions
(dither_positions)[source]¶ Store the dither positions into the
ifu_dxs
andifu_dys
dictionaries
-
dxs
(id_, idtype='ifuslot')[source]¶ Returns the x shifts for the given
id_
Parameters: - id_ : str
the id of the IFU
- idtype : str, optional
type of the id; must be one of
'ifuid'
,'ihmpid'
,'specid'
Returns: - ndarray
x shifts
-
dys
(id_, idtype='ifuslot')[source]¶ Returns the y shifts for the given
id_
Parameters: - id_ : str
the id of the IFU
- idtype : str, optional
type of the id; must be one of
'ifuid'
,'ihmpid'
,'specid'
Returns: - ndarray
y shifts
-
create_dither
(id_, basenames, modelbases, outfile, idtype='ifuid')[source]¶ Create a dither file
Parameters: - id_ : str
the id of the IFU
- basenames, modelnames : list of strings
the root of the file and model (distortion, fiber etc); their lengths must be the same as
ifu_dxs
- outfile : str
the output filename
- idtype : str, optional
type of the id; must be one of
'ifuid'
,'ifuslot'
,'specid'
-
pyhetdex.het.dither.
create_dither_file
(argv=None)[source]¶ Function that creates the dither file
Parameters: - argv : list of strings
if not provided sys.argv is used
-
pyhetdex.het.dither.
check_dithers
(n_dithers, basenames, modelbases)[source]¶ Check that the number of base names and model base names are either one or the number of dithers
Parameters: - n_dithers : int
number of dithers
- basenames, modelbases : list of strings
list of bases for the file names
Returns: - bool
True
is the check passed,False
otherwise
-
pyhetdex.het.dither.
format_names
(names, n_dithers, id_)[source]¶ Expand and format the names. If there is only one name, replicate it len(dxs) times, then format the names using the dither number and the
id_
.Parameters: - names : list of strings
name to format
- n_dithers : integer
number of dithers
Returns: - out_names : list of strings
list of length
n_dithers
containing formatted names
-
pyhetdex.het.dither.
sort_basenames
(basenames, extension, headerkey)[source]¶ For each
basenames[i]+extension
extract theheaderkey
and sort basenames according to the key valueParameters: - basenames : list of string
list of basenames
- extension : list
add to each basename to build a file name
- headerkey : string
name of the header key containing the values to use for sorting
Returns: - sorted_basenames : list of strings
basenames sorted according to the value of
headerkey