FITSKeywordProvider.java
3.79 KB
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/*
* Copyright 2002 Association for Universities for Research in Astronomy, Inc.,
* Observatory Control System, Gemini Telescopes Project.
*
* $Id: FITSKeywordProvider.java,v 1.1.1.1 2009/02/17 22:24:15 abrighto Exp $
*/
package jsky.image.fits;
import jsky.coords.WCSKeywordProvider;
import jsky.image.fits.codec.FITSImage;
import nom.tam.fits.Header;
/**
* A simple class accessing FITS/WCS keywords, where keywords are inherited
* from an empty primary FITS extension, if present.
*
* @version $Revision: 1.1.1.1 $
* @author Allan Brighton
*/
public class FITSKeywordProvider implements WCSKeywordProvider {
private Header _primary;
private Header _header;
public FITSKeywordProvider(FITSImage fitsImage) {
_header = fitsImage.getHeader();
if (_header == null)
throw new IllegalArgumentException("No FITS header");
if (fitsImage.getNumHDUs() > 1) {
_primary = fitsImage.getHDU(0).getHeader();
if (_primary == null)
throw new IllegalArgumentException("No primary FITS extension header");
if (_primary.getIntValue("NAXIS") != 0) {
_primary = new Header(); // ignore if not an empty primary extension
}
} else {
_primary = new Header();
}
}
/** Return true if the given keyword was found */
public boolean findKey(String key) {
return _header.findKey(key) != null || _primary.findKey(key) != null;
}
/** Return the value of the given keyword as a String, or null if not found. */
public String getStringValue(String key) {
if (_header.findKey(key) != null)
return _header.getStringValue(key);
return _primary.getStringValue(key);
}
/** Return the value of the given keyword as a String, or null if not found. */
public String getStringValue(String key, String defaultValue) {
if (_header.findKey(key) != null)
return _header.getStringValue(key);
if (_primary.findKey(key) != null)
return _primary.getStringValue(key);
return defaultValue;
}
/** Return the value of the given keyword as a double, or 0.0 if not found. */
public double getDoubleValue(String key) {
if (_header.findKey(key) != null)
return _header.getDoubleValue(key);
return _primary.getDoubleValue(key);
}
/** Return the value of the given keyword as a double, or 0.0 if not found. */
public double getDoubleValue(String key, double defaultValue) {
if (_header.findKey(key) != null)
return _header.getDoubleValue(key, defaultValue);
return _primary.getDoubleValue(key, defaultValue);
}
/** Return the value of the given keyword as a double, or 0.0 if not found. */
public float getFloatValue(String key) {
if (_header.findKey(key) != null)
return _header.getFloatValue(key);
return _primary.getFloatValue(key);
}
/** Return the value of the given keyword as a double, or 0.0 if not found. */
public float getFloatValue(String key, float defaultValue) {
if (_header.findKey(key) != null)
return _header.getFloatValue(key, defaultValue);
return _primary.getFloatValue(key, defaultValue);
}
/** Return the value of the given keyword as an int, or 0 if not found. */
public int getIntValue(String key) {
if (_header.findKey(key) != null)
return _header.getIntValue(key);
return _primary.getIntValue(key);
}
/** Return the value of the given keyword as an int, or 0 if not found. */
public int getIntValue(String key, int defaultValue) {
if (_header.findKey(key) != null)
return _header.getIntValue(key, defaultValue);
return _primary.getIntValue(key, defaultValue);
}
}