~ubuntu-branches/debian/jessie/eso-midas/jessie

« back to all changes in this revision

Viewing changes to contrib/baches/proc/baches_dark_substaction.prg

  • Committer: Package Import Robot
  • Author(s): Ole Streicher
  • Date: 2014-04-22 14:44:58 UTC
  • Revision ID: package-import@ubuntu.com-20140422144458-okiwi1assxkkiz39
Tags: upstream-13.09pl1.2+dfsg
ImportĀ upstreamĀ versionĀ 13.09pl1.2+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
! $Id
 
2
!
 
3
! AUTHOR: C. Guirao
 
4
!
 
5
! NAME: baches_dark_subtraction.prg
 
6
!   Procedure to subtract dark current from a FITS or BDF frame
 
7
!   If the input file is a FITS it is converted to BDF with COMPUTE/BACHES
 
8
!   and bias_subtracted if master_bias exists.
 
9
!   It requires that a table master_dark.tbl exists and the 
 
10
!   master dark frames refered in master_dark.tbl. This master_dark.tbl is
 
11
!   generated with the command 
 
12
!     "DARK/BACHES master_dark10,master_dark20"
 
13
!
 
14
! INPUT: 
 
15
!   - Frame in FITS or BDF format with a spectrum in rows
 
16
!   - Frame in BDF format with result
 
17
!
 
18
! OUTPUT: 
 
19
!   A new frame_dark.bdf = frame.bdf - master_dark.bdf
 
20
!
 
21
! USAGE: DARK/BACHES frame.bdf frame_dark.bdf
 
22
!    or: DARK/BACHES frame.fit frame_dark.bdf
 
23
!
 
24
!*******************************************************************************
 
25
! ECHO/FULL
 
26
!
 
27
! INPUT PARAMS:
 
28
! p1 REQUIRED: BDF or FITS frame containing an spectrum in rows
 
29
! p2 OPTIONAL: BDF frame with result of subtraction (default: frame_dark)
 
30
!
 
31
! Edit here to change defaults:
 
32
!
 
33
 DEFINE/PARA p1 ?       IMA "ENTER frame to be dark subtracted: "
 
34
 DEFINE/PARA p2 ?       IMA "ENTER name for result frame:"
 
35
!
 
36
! Convert paramaters into variables:
 
37
!
 
38
 DEFINE/LOCA cmd/c/1/20         "dark_subtraction"
 
39
 DEFINE/LOCA input/c/1/40       {p1}
 
40
 DEFINE/LOCA output/c/1/40      {p2}
 
41
 DEFINE/LOCA frame/c/1/40
 
42
 DEFINE/LOCA master_table/c/1/40 "master_dark.tbl"
 
43
 DEFINE/LOCA bias/c/1/40        "master_bias.bdf"
 
44
 DEFINE/LOCA dark/c/1/40        
 
45
 DEFINE/LOCA exposure/i/1/1 0
 
46
 DEFINE/LOCA frame_exposure/i/1/1 0
 
47
 DEFINE/LOCA dark_exposure/i/1/1  0
 
48
 DEFINE/LOCA coeficient/r/1/1 0.
 
49
 DEFINE/LOCA best_coef/r/1/1 0.
 
50
 DEFINE/LOCA current_coef/r/1/1 0.
 
51
 DEFINE/LOCA nrow/i/1/1       0
 
52
 DEFINE/LOCA loop/i/1/1       0
 
53
 DEFINE/LOCA best_row/i/1/1   0
 
54
 DEFINE/LOCA basename/c/1/40    "" ? +lower_levels
 
55
 DEFINE/LOCA ext/c/1/10         "" ? +lower_levels
 
56
!
 
57
! Check if master dark_current table 
 
58
!
 
59
IF m$exist(master_table) .eq. 0 THEN
 
60
  WRITE/OUT "{cmd}: ERROR: {master_table} does not exist!!"
 
61
  WRITE/OUT "{cmd}: recreate it with MDARK/BACHES dark*.bdf"
 
62
  ECHO/OFF
 
63
  RETURN/EXIT
 
64
ENDIF
 
65
!
 
66
! Gets basename and extension of input file
 
67
!
 
68
 FILE/BACHES {input}
 
69
 frame = basename
 
70
!
 
71
! Convert FITS format into MIDAS BDF format
 
72
!
 
73
 IF ext .ne. ".bdf" THEN
 
74
   WRITE/OUT "{cmd}: converting {input} into {frame}"
 
75
   COMPUTE/BACHESfits {input} {frame}
 
76
   !
 
77
   ! Bias subtraction
 
78
   !
 
79
   IF m$exist(bias) .eq. 1 THEN
 
80
     COMPUTE/IMA {frame}b = {frame} - {bias}
 
81
     RENAME {frame}b {frame}
 
82
     WRITE/OUT "{cmd}: creating {frame} with {bias} subtracted"
 
83
   ELSE
 
84
     WRITE/OUT "{cmd}: {bias} not found. No bias substructed"
 
85
   ENDIF
 
86
 ENDIF
 
87
!
 
88
! Check number of entries in  master dark_current table 
 
89
!
 
90
 SHOW/TAB {master_table} >NULL
 
91
 nrow = OUTPUTI(2)
 
92
 WRITE/OUT "{cmd}: number of entries in {master_table} = {nrow}" 
 
93
!
 
94
! Get the exposure time
 
95
!
 
96
 frame_exposure = m$value({frame},O_TIME(7))
 
97
 WRITE/OUT "{cmd}: exposure time for {frame}: {frame_exposure}"
 
98
!
 
99
! Find the closest dark_current to our frame 
 
100
!
 
101
current_coef = 0.
 
102
DO loop = 1 {nrow}
 
103
  exposure = {{master_table},:EXPOSURE,@{loop}}
 
104
  IF exposure .gt. frame_exposure THEN 
 
105
   current_coef = exposure / frame_exposure
 
106
 ELSE
 
107
   current_coef = frame_exposure / exposure 
 
108
 ENDIF
 
109
  dark = "{{master_table},:FRAME,@{loop}}"
 
110
  WRITE/OUT "{cmd}: file {dark}, exposure {exposure}, coeficient {current_coef}"
 
111
  IF {loop} .eq. 1 THEN
 
112
    best_coef = current_coef
 
113
    best_row = loop
 
114
  ENDIF
 
115
  IF best_coef .gt. current_coef THEN
 
116
    best_coef = current_coef
 
117
    best_row = loop
 
118
  ENDIF
 
119
ENDDO
 
120
!
 
121
! Best dark 
 
122
!
 
123
dark = "{{master_table},:FRAME,@{best_row}}"
 
124
WRITE/OUT "{cmd}: best dark in file {dark} with coeficient {best_coef}"
 
125
!
 
126
 dark_exposure = m$value({dark},O_TIME(7))
 
127
 coeficient = frame_exposure / dark_exposure
 
128
 COMPUTE/IMAG my_master_dark = ({dark} * {coeficient})
 
129
 COMPUTE/IMAG {output} = ({frame} - my_master_dark)
 
130
 DELETE/IMA my_master_dark NO
 
131
!
 
132
WRITE/OUT "{cmd}: Exposure value in {frame} = {frame_exposure}"
 
133
WRITE/OUT "{cmd}: Exposure value in {dark} = {dark_exposure}"
 
134
WRITE/OUT "{cmd}: Coeficient for my_master_dark = {coeficient}"
 
135
!
 
136
 ECHO/OFF