2
2
* License information at https://github.com/Caltech-IPAC/firefly/blob/master/License.txt
3
3
*/
4
4
5
- import { makeDoubleHeaderParse , getHeader } from '../FitsHeaderUtil.js' ;
5
+ import { makeDoubleHeaderParse } from '../FitsHeaderUtil.js' ;
6
6
import { AWAV , F2W , LINEAR , LOG , PLANE , TAB , V2W , WAVE } from './Wavelength.js' ;
7
7
8
8
export function parseWavelengthHeaderInfo ( header , altWcs = '' , zeroHeader , wlTable ) {
9
9
const parse = makeDoubleHeaderParse ( header , zeroHeader , altWcs ) ;
10
10
const which = altWcs ?'1' :getWCSAXES ( parse ) ;
11
- const mijMatrixKeyRoot = getPC_ijKey ( header , zeroHeader , which ) ;
11
+ const mijMatrixKeyRoot = getPC_ijKey ( parse , which ) ;
12
12
return calculateWavelengthParams ( parse , altWcs , which , mijMatrixKeyRoot , wlTable ) ;
13
13
}
14
14
@@ -24,52 +24,26 @@ const L_10= Math.log(10);
24
24
/**
25
25
* According to A&A 395, 1061-1075 (2002) DOI: 10.1051/0004-6361:20021326
26
26
* Representations of world coordinates in FITS E. W. Greisen1 - M. R. Calabretta2
27
- * paper, the CD_ij is for the older FITs header. The newer FITs header has PC only.
27
+ * https://www.aanda.org/articles/aa/full/2002/45/aah3859/aah3859.html
28
+ * the CD_ij is for the older FITs header. The newer FITs header has PC only.
28
29
* 1. If both PC and CD exist, it is wrong. Exception is thrown
29
30
* 2. If PC is not exist, one or more CD is exist, use CD_ij (j=1..N); if any of CD_ij
30
31
* is not defined, the default is 0.0;
31
32
* 3. If any PC_ij is defined or neigther PC nor CD is defined, we use PC, the default
32
33
* is 0 for j!=i and 1 if j==i
33
34
*
34
- * @param header
35
- * @param zeroHeader
35
+ *
36
+ * @param parser
36
37
* @param which
37
- * @returns {string }
38
+ * @returns {* }
38
39
*/
39
- function getPC_ijKey ( header , zeroHeader , which ) {
40
-
41
- var key ;
42
- let hasPC = false , hasCD = false ;
43
- for ( key in header ) {
44
- if ( key . startsWith ( `PC${ which } _` ) ) {
45
- hasPC = true ;
46
- break ;
47
- }
48
- }
49
- if ( ! hasPC && zeroHeader ) {
50
- for ( key in zeroHeader ) {
51
- if ( key . startsWith ( `PC${ which } _` ) ) {
52
- hasPC = true ;
53
- break ;
54
- }
55
- }
56
- }
57
- for ( key in header ) {
58
- if ( key . startsWith ( `CD${ which } _` ) ) {
59
- hasCD = true ;
60
- break ;
61
- }
62
- }
63
- if ( ! hasCD && zeroHeader ) {
64
- for ( key in zeroHeader ) {
65
- if ( key . startsWith ( `CD${ which } _` ) ) {
66
- hasCD = true ;
67
- break ;
68
- }
69
- }
70
- }
40
+ function getPC_ijKey ( parser , which ) {
41
+
42
+ let hasPC = parser . hasKeyStartWith ( `PC${ which } _` ) ;
43
+ let hasCD = parser . hasKeyStartWith ( `CD${ which } _` ) ;
44
+
71
45
if ( hasPC && hasCD ) {
72
- throw Error ( 'The FITs header contains both PC_ij and CD_ij' ) ;
46
+ return undefined ;
73
47
}
74
48
if ( ! hasPC && hasCD ) {
75
49
return 'CD' ;
@@ -79,6 +53,10 @@ function getPC_ijKey(header, zeroHeader,which){
79
53
80
54
81
55
/**
56
+ * This method will return the value of the WCSAXES. NOTE: the WCSAXES can be any naxis, it does
57
+ * not have to be 3. In general, if the wavelength is depending on two dimensional images, it most likely
58
+ * is 3. But the axis 3 can also be other quantity such as Frequency etc.
59
+ *
82
60
* If the FITs header has 'WCSAXES', this will be the wavelength axis.
83
61
* If 'WCSAXES' is not defined, the default will be the larger of naxis and the j where j=1, 2, 3, ..)
84
62
* @param parse
@@ -101,18 +79,55 @@ function getWCSAXES(parse){
101
79
}
102
80
103
81
}
104
- function assignDefault ( inArr , keyRoot , which , N ) {
82
+
83
+ /**
84
+ *
85
+ * Reference: A&A 395, 1061-1075 (2002) DOI: 10.1051/0004-6361:20021326
86
+ * Representations of world coordinates in FITS E. W. Greisen1 - M. R. Calabretta2
87
+ * paper, the CD_ij is for the older FITs header. The newer FITs header has PC only.
88
+ *
89
+ * This method is checking the pc_ij and r_j array. If any of the values are undefined,
90
+ * the default are assigned. The default values are defined as following based on the reference
91
+ * paper above:
92
+ *
93
+ * PC_ij: an array defined in the FITs header. Fhe size of the dimension is N. N is defined by
94
+ * WCSAXES or naxis
95
+ * i: the wcsaxes's value, if the wcsaxes = 2, then i=2
96
+ * j: 0, ...N
97
+ * If any of the PC_ij is not defined in the header, the following default is assigned:
98
+ * 1. PC i_j = 1.0 when i = j
99
+ * 2. PC i_j = 0.0 when i!=j
100
+ *
101
+ * If instead of using PC, CD is used, the following default is assigned:
102
+ * CD i_j 0.0 NOTE: CD i_j's default is different from PC i_j
103
+ *
104
+ *
105
+ * r_j: An array of the CRPIX values, the size of the dimension is N. N is defined by
106
+ * WCSAXES or naxis
107
+ * j: 0,...N
108
+ *
109
+ * Default values:
110
+ * if r_j = value of CRPIXj, if it is not defined, the default value is 0.0
111
+ *
112
+ * @param inArr
113
+ * @param keyRoot
114
+ * @param which
115
+ * @param N
116
+ * @returns {Array }
117
+ */
118
+ function applyDefaultValues ( inArr , keyRoot , which , N ) {
105
119
let retAry = [ ] ;
106
120
for ( let i = 0 ; i < N ; i ++ ) {
107
121
if ( inArr && inArr [ i ] && ! isNaN ( inArr [ i ] ) ) {
122
+ //if inArr is defined and it has a valid value
108
123
retAry [ i ] = inArr [ i ] ;
109
124
continue ;
110
125
}
111
- switch ( keyRoot ) {
126
+ switch ( keyRoot ) { //either inArr is undefined, or inArr[i] is undefined
112
127
case 'PC' :
113
128
retAry [ i ] = ( i + 1 ) === parseInt ( which ) ? 1 :0 ;
114
129
break ;
115
- case 'CRPIX' :
130
+ case 'CRPIX' || 'CD' :
116
131
retAry [ i ] = 0.0 ;
117
132
break ;
118
133
} ;
@@ -146,7 +161,15 @@ function isWaveLength(ctype, pc_3j){
146
161
*/
147
162
function calculateWavelengthParams ( parse , altWcs , which , pc_3j_key , wlTable ) {
148
163
149
-
164
+ /*
165
+ * Base on the reference: A&A 395, 1061-1075 (2002) DOI: 10.1051/0004-6361:20021326
166
+ * Representations of world coordinates in FITS E. W. Greisen. The default values
167
+ * defined below:
168
+ * CDELT i 1.0
169
+ * CTYPE i ' ' (i.e. a linear undefined axis)
170
+ * CUNIT i ' ' (i.e. undefined)
171
+ * NOTE: i is the which variable here.
172
+ */
150
173
const ctype = parse . getValue ( `CTYPE${ which } ${ altWcs } ` , ' ' ) ;
151
174
const crpix = parse . getDoubleValue ( `CRPIX${ which } ${ altWcs } ` , 0.0 ) ;
152
175
const crval = parse . getDoubleValue ( `CRVAL${ which } ${ altWcs } ` , 0.0 ) ;
@@ -155,12 +178,12 @@ function calculateWavelengthParams(parse, altWcs, which, pc_3j_key,wlTable) {
155
178
const restWAV = parse . getDoubleValue ( 'RESTWAV' + altWcs , 0 ) ;
156
179
const nAxis = parse . getIntValue ( 'NAXIS' + altWcs ) ;
157
180
const N = parse . getIntOneOfValue ( [ 'WCSAXES' , 'WCSAXIS' , 'NAXIS' ] , - 1 ) ;
158
- let pc_3j = parse . getDoubleAry ( `${ pc_3j_key } ${ which } _` , altWcs , 1 , N ) ; //|| parse.getDoubleAry('CD3_',altWcs,1,N, which );
159
- let r_j = parse . getDoubleAry ( 'CRPIX' , altWcs , 1 , N ) ;
181
+ let pc_3j = parse . getDoubleAry ( `${ pc_3j_key } ${ which } _` , altWcs , 1 , N , undefined ) ;
182
+ let r_j = parse . getDoubleAry ( 'CRPIX' , altWcs , 1 , N , undefined ) ;
160
183
161
184
//check if any value is not defined, use default
162
- pc_3j = assignDefault ( pc_3j , pc_3j_key , which , N ) ;
163
- r_j = assignDefault ( r_j , 'CRPIX' , which , N ) ;
185
+ pc_3j = applyDefaultValues ( pc_3j , pc_3j_key , which , N ) ;
186
+ r_j = applyDefaultValues ( r_j , 'CRPIX' , which , N ) ;
164
187
165
188
const ps3_0 = parse . getValue ( `PS${ which } _0${ altWcs } ` , '' ) ;
166
189
const ps3_1 = parse . getValue ( `PS${ which } _1${ altWcs } ` , '' ) ;
@@ -178,14 +201,24 @@ function calculateWavelengthParams(parse, altWcs, which, pc_3j_key,wlTable) {
178
201
//ccc can be 'F2W', 'V2W', 'LOG', 'TAB' or empty that means linear. If the header does not have this kind
179
202
// CTYPEka defined, we check if the it is a spectra cube. If it is a spectra cube, we display the wavelength
180
203
// at each plane.
181
-
182
204
const isWL = isWaveLength ( ctype , pc_3j ) ;
205
+
206
+ //If it is a cube plane FITS, plot and display the wavelength at each plane
183
207
if ( canDoPlaneCalc && ! isWL && nAxis === 3 ) {
208
+ //The FITs has wavelength planes, and each plane has the same wavelength, ie. the third axis
209
+ //is wavelength
184
210
return makeSimplePlaneBased ( crpix , crval , cdelt , nAxis , wlType , units , 'use PLANE since is cube and parameters missing' ) ;
185
211
}
186
212
187
- //When one of three is not defined, we don't show the wavelength in the readout.
188
- if ( ! algorithm || ! wlType || ! isWL ) return ;
213
+ //Plot and display the wavelength as one of the mouse readout only if the FITs header
214
+ //contains the required parameters and the wavelength is depending on the image axes.
215
+ /* We don't show the wavelength in the mouse readout in following four situations:
216
+ * 1. Algorithm is not defined
217
+ * 2. wlType is not defined or the type is not supported
218
+ * 3. The FITs file is not wavelength type (may be plane)
219
+ * 4. It has both PC_ij and CD_ij, thus, we don't know which parameters to use
220
+ */
221
+ if ( ! algorithm || ! wlType || ! isWL || ! pc_3j_key ) return ;
189
222
190
223
191
224
if ( algorithm === LOG ) { //the values in CRPIXk and CDi_j (PC_i_j) are log based on 10 rather than natural log, so a factor is needed.
0 commit comments