Coverage for spectractor/parameters.py: 94%
Shortcuts on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1import numpy as np
2import os
3import astropy.units as units
4from astropy import constants as const
5import matplotlib as mpl
8# These parameters are the default values adapted to CTIO
9# To modify them, please create a new config file and load it.
12def __getattr__(name):
13 """Method to allow querying items without them existing.
15 NB: This breaks hasattr(parameters, name), as that is implemented by
16 calling __getattr__() and checking it raises an AttributeError, so
17 hasattr() for parameters will now always return True.
19 If necessary this can be worked around by instead doing:
20 `if name in dir(parameters):`
22 Examples
23 --------
24 >>> from spectractor import parameters
25 >>> print(parameters.CCD_IMSIZE)
26 2048
27 >>> print(parameters.DUMMY)
28 False
29 """
30 if name in locals(): 30 ↛ 31line 30 didn't jump to line 31, because the condition on line 30 was never true
31 return locals()[name]
32 else:
33 return False
36# Pipeline
37SPECTRACTOR_FIT_TARGET_CENTROID = "fit" # method to get target centroid, choose among: guess, fit, WCS
38SPECTRACTOR_COMPUTE_ROTATION_ANGLE = "hessian" # method to get image rotation angle: False, disperser, hessian
39SPECTRACTOR_DECONVOLUTION_PSF2D = True # deconvolve spectrogram with simple 2D PSF analysis: False, True
40SPECTRACTOR_DECONVOLUTION_FFM = True # deconvolve spectrogram with full forward model: False, True
42# Paths
43mypath = os.path.dirname(__file__)
44DISPERSER_DIR = os.path.join(mypath, "extractor/dispersers/")
45CONFIG_DIR = os.path.join(mypath, "../config/")
46THROUGHPUT_DIR = os.path.join(mypath, "simulation/CTIOThroughput/")
47if 'ASTROMETRYNET_DIR' in os.environ: 47 ↛ 48line 47 didn't jump to line 48, because the condition on line 47 was never true
48 ASTROMETRYNET_DIR = os.getenv('ASTROMETRYNET_DIR') + '/'
49else:
50 ASTROMETRYNET_DIR = ''
51if 'LIBRADTRAN_DIR' in os.environ: 51 ↛ 52line 51 didn't jump to line 52, because the condition on line 51 was never true
52 LIBRADTRAN_DIR = os.getenv('LIBRADTRAN_DIR') + '/'
53else:
54 LIBRADTRAN_DIR = ''
56# CCD characteristics
57CCD_IMSIZE = 2048 # size of the image in pixel
58CCD_PIXEL2MM = 24e-3 # pixel size in mm
59CCD_PIXEL2ARCSEC = 0.401 # pixel size in arcsec
60CCD_ARCSEC2RADIANS = np.pi / (180. * 3600.) # conversion factor from arcsec to radians
61CCD_MAXADU = 60000 # approximate maximum ADU output of the CCD
62CCD_GAIN = 3. # electronic gain : elec/ADU
63CCD_REBIN = 1 # rebinning of the image in pixel
65# Instrument characteristics
66OBS_NAME = 'CTIO'
67OBS_ALTITUDE = 2.200 # CTIO altitude in k meters from astropy package (Cerro Pachon)
68OBS_LATITUDE = '-30 10 07.90' # CTIO latitude
69OBS_DIAMETER = 0.9 * units.m # Diameter of the telescope
70OBS_SURFACE = np.pi * OBS_DIAMETER ** 2 / 4. # Surface of telescope
71OBS_EPOCH = "J2000.0"
72OBS_TRANSMISSION_SYSTEMATICS = 0.005
73OBS_OBJECT_TYPE = 'STAR' # To choose between STAR, HG-AR, MONOCHROMATOR
74OBS_TELESCOPE_TRANSMISSION = 'ctio_throughput.txt' # telescope transmission file
75OBS_FULL_INSTRUMENT_TRANSMISSON = 'ctio_throughput_300517_v1.txt' # full instrument transmission file
76OBS_QUANTUM_EFFICIENCY = "qecurve.txt" # quantum efficiency of the detector file
77OBS_CAMERA_ROTATION = 0 # Camera (x,y) rotation angle with respect to (north-up, east-left) system in degrees
78OBS_CAMERA_DEC_FLIP_SIGN = 1 # Camera (x,y) flip signs with respect to (north-up, east-left) system
79OBS_CAMERA_RA_FLIP_SIGN = 1 # Camera (x,y) flip signs with respect to (north-up, east-left) system
81# Filters
82HALPHA_CENTER = 655.9e-6 # center of the filter in mm
83HALPHA_WIDTH = 6.4e-6 # width of the filter in mm
84FGB37 = {'label': 'FGB37', 'min': 350, 'max': 750}
85RG715 = {'label': 'RG715', 'min': 690, 'max': 1100}
86HALPHA_FILTER = {'label': 'Halfa', 'min': HALPHA_CENTER - 2 * HALPHA_WIDTH, 'max': HALPHA_CENTER + 2 * HALPHA_WIDTH}
87ZGUNN = {'label': 'Z-Gunn', 'min': 800, 'max': 1100}
88FILTERS = [RG715, FGB37, HALPHA_FILTER, ZGUNN]
90# Spectrograph
91DISTANCE2CCD = 55.45 # distance between hologram and CCD in mm
92DISTANCE2CCD_ERR = 0.19 # uncertainty on distance between hologram and CCD in mm
93GRATING_ORDER_2OVER1 = 0.1 # default value for order 2 over order 1 transmission ratio
95# Search windows in images
96XWINDOW = 100 # window x size to search for the targeted object
97YWINDOW = 100 # window y size to search for the targeted object
98XWINDOW_ROT = 50 # window x size to search for the targeted object
99YWINDOW_ROT = 50 # window y size to search for the targeted object
100PIXSHIFT_PRIOR = 1 # prior on the reliability of the centroid estimate in pixels
102# Rotation parameters
103ROT_PREFILTER = True # must be set to true, otherwise create residuals and correlated noise
104ROT_ORDER = 5 # must be above 3
105ROT_ANGLE_MIN = -10
106ROT_ANGL_MAX = 10 # in the Hessian analysis to compute rotation angle, cut all angles outside this range [degrees]
108# Range for spectrum
109LAMBDA_MIN = 300 # minimum wavelength for spectrum extraction (in nm)
110LAMBDA_MAX = 1100 # maximum wavelength for spectrum extraction (in nm)
111LAMBDA_STEP = 0.2 # step size for the wavelength array (in nm)
112LAMBDAS = np.arange(LAMBDA_MIN, LAMBDA_MAX, LAMBDA_STEP)
113SPEC_ORDER = 1 # spectrum order to extract
115# Background subtraction parameters
116PIXWIDTH_SIGNAL = 10 # half transverse width of the signal rectangular window in pixels
117PIXDIST_BACKGROUND = 20 # distance from dispersion axis to analyse the background in pixels
118PIXWIDTH_BACKGROUND = 10 # transverse width of the background rectangular window in pixels
119PIXWIDTH_BOXSIZE = 20 # box size for sextractor evaluation of the background
120BGD_ORDER = 1 # the order of the polynomial background to fit in the transverse direction
122# PSF
123PSF_TYPE = "Moffat" # the PSF model: Moffat or MoffatGauss
124PSF_POLY_ORDER = 2 # the order of the polynomials to model wavelength dependence of the PSF shape parameters
125PSF_FIT_REG_PARAM = 0.01 # regularisation parameter for the chisq minimisation to extract the spectrum
126PSF_PIXEL_STEP_TRANSVERSE_FIT = 10 # step size in pixels for the first transverse PSF1D fit
127PSF_FWHM_CLIP = 2 # PSF is not evaluated outside a region larger than max(PIXWIDTH_SIGNAL, PSF_FWHM_CLIP*fwhm) pixels
129# Detection line algorithm
130CALIB_BGD_ORDER = 3 # order of the background polynome to fit
131CALIB_BGD_NPARAMS = CALIB_BGD_ORDER + 1 # number of unknown parameters for background
132CALIB_PEAK_WIDTH = 7 # half range to look for local extrema in pixels around tabulated line values
133CALIB_BGD_WIDTH = 10 # size of the peak sides to use to fit spectrum base line
134CALIB_SAVGOL_WINDOW = 5 # window size for the savgol filter in pixels
135CALIB_SAVGOL_ORDER = 2 # polynom order for the savgol filter
137# Conversion factor
138# Units of SEDs in flam (erg/s/cm2/nm) :
139SED_UNIT = 1 * units.erg / units.s / units.cm ** 2 / units.nanometer
140TIME_UNIT = 1 * units.s # flux for 1 second
141hc = const.h * const.c # h.c product of fontamental constants c and h
142wl_dwl_unit = units.nanometer ** 2 # lambda.dlambda in wavelength in nm
143FLAM_TO_ADURATE = ((OBS_SURFACE * SED_UNIT * TIME_UNIT * wl_dwl_unit / hc / CCD_GAIN).decompose()).value
145# fit workspace
146# FIT_WORKSPACE = None
148# Plotting
149PAPER = False
150LINEWIDTH = 2
151PLOT_DIR = 'plots'
152SAVE = False
154# Verbosity
155VERBOSE = False
156DEBUG = False
157DEBUG_LOGGING = False
158MY_FORMAT = "%(asctime)-20s %(name)-10s %(funcName)-20s %(levelname)-6s %(message)s"
160# Plots
161DISPLAY = True
162if os.environ.get('DISPLAY', '') == '': 162 ↛ 165line 162 didn't jump to line 165, because the condition on line 162 was never false
163 mpl.use('agg')
164 DISPLAY = False
165PLOT_XLABEL = r"$x$ [pixels]"
166PLOT_YLABEL = r"$y$ [pixels]"
167PLOT_ROT_LABEL = r"$\varphi_d$ [degrees]"