-
Notifications
You must be signed in to change notification settings - Fork 6
/
trace.py
96 lines (72 loc) · 3.02 KB
/
trace.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#
# Copyright 2011-2015 Universidad Complutense de Madrid
#
# This file is part of Megara DRP
#
# Megara DRP is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Megara DRP is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Megara DRP. If not, see <http://www.gnu.org/licenses/>.
#
"""Fiber tracing Recipe."""
from __future__ import division, print_function
import logging
import numpy
from astropy.io import fits
from numina.array.trace.traces import trace
from numina.core import Product
from numina.core.requirements import ObservationResultRequirement
from megaradrp.products import MasterFiberFlat, TraceMap
from megaradrp.core.recipe import MegaraBaseRecipe
from megaradrp.requirements import MasterBiasRequirement, MasterBPMRequirement
from megaradrp.requirements import MasterDarkRequirement
from megaradrp.trace.traces import init_traces
_logger = logging.getLogger('numina.recipes.megara')
class TraceMapRecipe(MegaraBaseRecipe):
obresult = ObservationResultRequirement()
master_bias = MasterBiasRequirement()
master_dark = MasterDarkRequirement()
master_bpm = MasterBPMRequirement()
fiberflat_frame = Product(MasterFiberFlat)
traces = Product(TraceMap)
def __init__(self):
super(TraceMapRecipe, self).__init__(
version="0.1.0"
)
def run(self, rinput):
parameters = self.get_parameters(rinput)
reduced = self.bias_process_common(rinput.obresult, parameters)
data = reduced[0].data
cstart = 2000
hs = 3
step1 = 2
background1 = 150.0
maxdis1 = 2.0
_logger.info('find peaks in column %i', cstart)
central_peaks = init_traces(data, center=cstart, hs=hs,
background=background1)
_logger.info(' %i peaks found', len(central_peaks))
# The byteswapping is required by the cython module
if data.dtype.byteorder != '=':
_logger.debug('byteswapping image')
image2 = data.byteswap().newbyteorder()
else:
image2 = data
tracelist = []
_logger.info('trace peaks')
for dtrace in central_peaks.values():
mm = trace(image2, x=cstart, y=dtrace.start[1], step=step1,
hs=hs, background=background1, maxdis=maxdis1)
pfit = numpy.polyfit(mm[:,0], mm[:,1], deg=5)
tracelist.append({'fibid': dtrace.fibid, 'boxid': dtrace.boxid,
'start':0, 'stop':4095,
'fitparms': pfit.tolist()})
return self.create_result(fiberflat_frame=reduced, traces=tracelist)