rfits 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile.rb +92 -0
- data/lib/rfits.rb +1 -0
- data/lib/rfits/ext/extconf.rb +7 -0
- data/lib/rfits/ext/rfitsio.c +2797 -0
- data/lib/rfits/rfits.rb +1328 -0
- data/test/rfits_test.rb +310 -0
- data/test/rfitsio_test.rb +315 -0
- data/test/test.1.fits +7522 -2
- data/test/test.2.fits +1796 -0
- metadata +55 -0
data/test/rfits_test.rb
ADDED
@@ -0,0 +1,310 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'fileutils'
|
3
|
+
require 'rubygems' rescue LoadError
|
4
|
+
|
5
|
+
require 'rfits'
|
6
|
+
|
7
|
+
class RFitsTest < Test::Unit::TestCase
|
8
|
+
def setup
|
9
|
+
@fits = RFits::File.new('!test/readwrite.test.fits', 'rw')
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_all
|
13
|
+
assert_equal 'test/readwrite.test.fits', @fits.path
|
14
|
+
assert_equal RFits::IO::Proxy::READWRITE, @fits.mode
|
15
|
+
assert_equal 'file://', @fits.url_type
|
16
|
+
|
17
|
+
hdu()
|
18
|
+
header()
|
19
|
+
image_data()
|
20
|
+
table_data()
|
21
|
+
end
|
22
|
+
|
23
|
+
def hdu()
|
24
|
+
assert_equal 0, @fits.length
|
25
|
+
im1 = RFits::Image.new(@fits, nil, RFits::IO::Proxy::LONG_IMG, [4, 4],
|
26
|
+
:compression_type => :hcompress,
|
27
|
+
:tile_dim => [4, 4],
|
28
|
+
:hcomp_scale => 1,
|
29
|
+
:hcomp_smooth => 1
|
30
|
+
)
|
31
|
+
btbl = RFits::BinaryTable.new(@fits, nil,
|
32
|
+
['column_1', 'column_2', 'column_3', 'column_4'],
|
33
|
+
['I', '10A', 'E', 'C'], 'Binary_Table_Test')
|
34
|
+
im2 = RFits::Image.new(@fits, nil, RFits::IO::Proxy::FLOAT_IMG, [3, 3])
|
35
|
+
im3 = RFits::Image.new(@fits, nil, RFits::IO::Proxy::LONG_IMG, [2, 2],
|
36
|
+
:compression_type => :rice,
|
37
|
+
:tile_dim => [2, 2]
|
38
|
+
)
|
39
|
+
|
40
|
+
@fits[0] = im1
|
41
|
+
@fits[2] = btbl
|
42
|
+
@fits << im2
|
43
|
+
@fits << im3
|
44
|
+
|
45
|
+
img1 = @fits[1]
|
46
|
+
assert_equal :image, img1.hdu_type
|
47
|
+
assert_kind_of RFits::Image, img1
|
48
|
+
assert_equal 1, img1.position
|
49
|
+
assert_equal [4, 4], img1.naxes
|
50
|
+
assert_equal 2, img1.naxis
|
51
|
+
assert_equal :long, img1.image_type
|
52
|
+
assert_equal RFits::IO::Proxy::LONG_IMG, img1.bitpix
|
53
|
+
assert_equal true, img1.compressed?
|
54
|
+
assert_equal :hcompress, img1.compression_type
|
55
|
+
assert_equal [4, 4], img1.tile_dim
|
56
|
+
assert_equal nil, img1.noise_bits
|
57
|
+
assert_equal 1, img1.hcomp_scale
|
58
|
+
assert_equal 1, img1.hcomp_smooth
|
59
|
+
|
60
|
+
tbl2 = @fits[2]
|
61
|
+
assert_equal :binary_tbl, tbl2.hdu_type
|
62
|
+
assert_kind_of RFits::BinaryTable, tbl2
|
63
|
+
assert_equal 2, tbl2.position
|
64
|
+
|
65
|
+
img3 = @fits[3]
|
66
|
+
assert_equal :image, img3.hdu_type
|
67
|
+
assert_kind_of RFits::Image, img3
|
68
|
+
assert_equal 3, img3.position
|
69
|
+
assert_equal [3, 3], img3.naxes
|
70
|
+
assert_equal 2, img3.naxis
|
71
|
+
assert_equal :float, img3.image_type
|
72
|
+
assert_equal RFits::IO::Proxy::FLOAT_IMG, img3.bitpix
|
73
|
+
assert_equal false, img3.compressed?
|
74
|
+
|
75
|
+
img4 = @fits[4]
|
76
|
+
assert_equal :image, img4.hdu_type
|
77
|
+
assert_kind_of RFits::Image, img4
|
78
|
+
assert_equal 4, img4.position
|
79
|
+
assert_equal [2, 2], img4.naxes
|
80
|
+
assert_equal 2, img4.naxis
|
81
|
+
assert_equal :long, img4.image_type
|
82
|
+
assert_equal RFits::IO::Proxy::LONG_IMG, img4.bitpix
|
83
|
+
assert_equal true, img4.compressed?
|
84
|
+
assert_equal :rice, img4.compression_type
|
85
|
+
assert_equal [2, 2], img4.tile_dim
|
86
|
+
assert_equal nil, img4.noise_bits
|
87
|
+
end
|
88
|
+
|
89
|
+
def header
|
90
|
+
hdr = @fits[1].header
|
91
|
+
assert_equal 22, hdr.length
|
92
|
+
|
93
|
+
# integer
|
94
|
+
hdr['TEST'] = [123, 'A test']
|
95
|
+
assert_equal [123, 'A test'], hdr['TEST', true]
|
96
|
+
|
97
|
+
# floating point
|
98
|
+
hdr['TEST'] = 12.3
|
99
|
+
assert_equal 12.3, hdr['TEST']
|
100
|
+
|
101
|
+
# string
|
102
|
+
hdr['TEST'] = 'Hello, world!'
|
103
|
+
assert_equal 'Hello, world!', hdr['TEST']
|
104
|
+
|
105
|
+
# boolean
|
106
|
+
hdr['TEST'] = true
|
107
|
+
assert_equal true, hdr['TEST']
|
108
|
+
|
109
|
+
# complex
|
110
|
+
hdr['TEST'] = Complex.new(12.3, 3.1)
|
111
|
+
assert_equal Complex.new(12.3, 3.1), hdr['TEST']
|
112
|
+
|
113
|
+
assert_equal 23, hdr.length
|
114
|
+
|
115
|
+
hdr.delete('TEST')
|
116
|
+
assert_equal 22, hdr.length
|
117
|
+
|
118
|
+
hdr.comment = "NOAO test comment"
|
119
|
+
assert_equal "NOAO test comment", hdr.comment
|
120
|
+
|
121
|
+
hdr.history = "NOAO test history"
|
122
|
+
assert_equal "NOAO test history", hdr.history
|
123
|
+
end
|
124
|
+
|
125
|
+
def image_data
|
126
|
+
pix = @fits[1].data
|
127
|
+
int_array = [
|
128
|
+
1, 2, 3, 4,
|
129
|
+
4, 3, 2, 1,
|
130
|
+
5, 6, 7, 8,
|
131
|
+
9, 8, 7, 6
|
132
|
+
]
|
133
|
+
pix[0] = int_array
|
134
|
+
assert_equal 16, pix.length
|
135
|
+
assert_equal int_array, pix[0..16]
|
136
|
+
assert_equal [5, 6, 7, 8], pix.row(2)
|
137
|
+
assert_equal [3, 2, 7, 7], pix.column(2)
|
138
|
+
assert_equal 1, pix.first
|
139
|
+
assert_equal 6, pix.last
|
140
|
+
|
141
|
+
pix = @fits[3].data
|
142
|
+
float_array = [
|
143
|
+
1.1, 2.2, 3.3,
|
144
|
+
4.4, 5.5, 4.4,
|
145
|
+
3.3, 2.2, 1.1
|
146
|
+
]
|
147
|
+
pix[0] = float_array
|
148
|
+
assert_equal 9, pix.length
|
149
|
+
float_array.each_with_index do |val, i|
|
150
|
+
assert_in_delta val, pix[i], 0.1
|
151
|
+
end
|
152
|
+
|
153
|
+
pix = @fits[1].data
|
154
|
+
|
155
|
+
pix[1] = 7
|
156
|
+
assert_equal 7, pix[1]
|
157
|
+
|
158
|
+
pix[0..4] = [1, 2, 3, 4]
|
159
|
+
assert_equal [1, 2, 3, 4], pix[0..4]
|
160
|
+
|
161
|
+
pix[[0, 0]] = [2, 4, 6, 8]
|
162
|
+
assert_equal [2, 4, 6, 8], pix[[0, 0], 4]
|
163
|
+
|
164
|
+
pix[0, 0] = [3, 4, 5, 6]
|
165
|
+
assert_equal [3, 4, 5, 6], pix[[0, 0], 4]
|
166
|
+
|
167
|
+
pix[[0, 0], 2] = [2, 2]
|
168
|
+
assert_equal [2, 2], pix[[0, 0], 2]
|
169
|
+
|
170
|
+
pix[[0, 0], [1, 1]] = [-1, 0, 1, 2]
|
171
|
+
assert_equal [-1, 0, 1, 2], pix[[0, 0], [1, 1]]
|
172
|
+
|
173
|
+
pix.set_row(1, [5, 5, 5, 5])
|
174
|
+
assert_equal pix.row(1), [5, 5, 5, 5]
|
175
|
+
|
176
|
+
pix.set_column(2, [9, 9, 9, 9])
|
177
|
+
assert_equal pix.column(2), [9, 9, 9, 9]
|
178
|
+
|
179
|
+
assert_raise(ArgumentError){ pix['blah'] = 2 }
|
180
|
+
assert_raise(ArgumentError){ pix['blah1', 'blah2'] = 3 }
|
181
|
+
end
|
182
|
+
|
183
|
+
def table_data
|
184
|
+
tbl = @fits[2]
|
185
|
+
|
186
|
+
assert_equal 4, tbl.column_information.size
|
187
|
+
|
188
|
+
cinfo = tbl.column_information[0]
|
189
|
+
assert_equal 'column_1', cinfo.name
|
190
|
+
assert_equal :short, cinfo.data_type
|
191
|
+
assert_equal 1, cinfo.repeat
|
192
|
+
assert_equal 2, cinfo.width
|
193
|
+
assert_equal 6, cinfo.display_width
|
194
|
+
assert_equal 1, cinfo.dim
|
195
|
+
assert_equal [1], cinfo.size
|
196
|
+
|
197
|
+
cinfo = tbl.column_information[1]
|
198
|
+
assert_equal 'column_2', cinfo.name
|
199
|
+
assert_equal :string, cinfo.data_type
|
200
|
+
assert_equal 10, cinfo.repeat
|
201
|
+
assert_equal 10, cinfo.width
|
202
|
+
assert_equal 10, cinfo.display_width
|
203
|
+
assert_equal 1, cinfo.dim
|
204
|
+
assert_equal [10], cinfo.size
|
205
|
+
|
206
|
+
cinfo = tbl.column_information[2]
|
207
|
+
assert_equal 'column_3', cinfo.name
|
208
|
+
assert_equal :float, cinfo.data_type
|
209
|
+
assert_equal 1, cinfo.repeat
|
210
|
+
assert_equal 4, cinfo.width
|
211
|
+
assert_equal 14, cinfo.display_width
|
212
|
+
assert_equal 1, cinfo.dim
|
213
|
+
assert_equal [1], cinfo.size
|
214
|
+
|
215
|
+
cinfo = tbl.column_information[3]
|
216
|
+
assert_equal 'column_4', cinfo.name
|
217
|
+
assert_equal :complex, cinfo.data_type
|
218
|
+
assert_equal 1, cinfo.repeat
|
219
|
+
assert_equal 8, cinfo.width
|
220
|
+
assert_equal 31, cinfo.display_width
|
221
|
+
assert_equal 1, cinfo.dim
|
222
|
+
assert_equal [1], cinfo.size
|
223
|
+
|
224
|
+
tbl.column_information[2] = {:name => 'column_5', :format => 'A15'}
|
225
|
+
tbl.column_information << {:name => 'column_6', :format => 'I'}
|
226
|
+
assert_equal 6, tbl.column_information.size
|
227
|
+
|
228
|
+
tbl.column_information.delete(5)
|
229
|
+
tbl.column_information.delete(2)
|
230
|
+
|
231
|
+
assert_equal 4, tbl.column_information.size
|
232
|
+
|
233
|
+
data = tbl.data
|
234
|
+
|
235
|
+
int_array = [1, 2, 3, 4, 5]
|
236
|
+
data.set_column(0, int_array)
|
237
|
+
assert_equal int_array, data.column(0)
|
238
|
+
|
239
|
+
string_array = ['a1', 'b2', 'c3', 'd4', 'e5']
|
240
|
+
data.set_column(1, string_array)
|
241
|
+
assert_equal string_array, data.column(1)
|
242
|
+
|
243
|
+
float_array = [1.2, 2.3, 3.4, 4.5, 5.5]
|
244
|
+
data.set_column(2, float_array)
|
245
|
+
data.column(2).each_with_index do |val, i|
|
246
|
+
assert_in_delta float_array[i], val, 0.01
|
247
|
+
end
|
248
|
+
|
249
|
+
complex_array = [Complex.new(1, 2), Complex.new(2, 3), Complex.new(3, 4), Complex.new(4, 5), Complex.new(5, 6)]
|
250
|
+
data.set_column(3, complex_array)
|
251
|
+
assert_equal complex_array, data.column(3)
|
252
|
+
|
253
|
+
row = data[0]
|
254
|
+
assert_equal 1, row[0]
|
255
|
+
assert_equal 'a1', row[1]
|
256
|
+
assert_in_delta 1.2, row[2], 0.01
|
257
|
+
assert_equal Complex.new(1, 2), row[3]
|
258
|
+
|
259
|
+
row = data[2]
|
260
|
+
assert_equal 3, row[0]
|
261
|
+
assert_equal 'c3', row[1]
|
262
|
+
assert_in_delta 3.4, row[2], 0.01
|
263
|
+
assert_equal Complex.new(3, 4), row[3]
|
264
|
+
|
265
|
+
assert_equal 5, data.size
|
266
|
+
|
267
|
+
data[5] = [9, 'new1', 2.2, Complex.new(1, 1)]
|
268
|
+
row = data[5]
|
269
|
+
assert_equal 9, row[0]
|
270
|
+
assert_equal 'new1', row[1]
|
271
|
+
assert_in_delta 2.2, row[2], 0.01
|
272
|
+
assert_equal Complex.new(1, 1), row[3]
|
273
|
+
|
274
|
+
data[5, 1] = 'new3'
|
275
|
+
assert_equal 'new3', data[5,1]
|
276
|
+
|
277
|
+
assert_equal 6, data.size
|
278
|
+
data.delete(5)
|
279
|
+
assert_equal 5, data.size
|
280
|
+
|
281
|
+
first = data.first
|
282
|
+
assert_equal int_array[0], first[0]
|
283
|
+
assert_equal string_array[0], first[1]
|
284
|
+
assert_in_delta float_array[0], first[2], 0.01
|
285
|
+
assert_equal complex_array[0], first[3]
|
286
|
+
|
287
|
+
last = data.last
|
288
|
+
assert_equal int_array[-1], last[0]
|
289
|
+
assert_equal string_array[-1], last[1]
|
290
|
+
assert_in_delta float_array[-1], last[2], 0.01
|
291
|
+
assert_equal complex_array[-1], last[3]
|
292
|
+
|
293
|
+
data << [9, 'new1', 2.2, Complex.new(1, 1)]
|
294
|
+
last = data.last
|
295
|
+
assert_equal 9, last[0]
|
296
|
+
assert_equal 'new1', last[1]
|
297
|
+
assert_in_delta 2.2, last[2], 0.01
|
298
|
+
assert_equal Complex.new(1, 1), last[3]
|
299
|
+
|
300
|
+
data.delete(5)
|
301
|
+
|
302
|
+
assert_equal 1, data[0, 0]
|
303
|
+
assert_equal 'c3', data[2, 1]
|
304
|
+
end
|
305
|
+
|
306
|
+
def teardown
|
307
|
+
@fits.close
|
308
|
+
FileUtils.rm('test/readwrite.test.fits')
|
309
|
+
end
|
310
|
+
end
|
@@ -0,0 +1,315 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'fileutils'
|
3
|
+
|
4
|
+
require 'rfits/ext/rfitsio'
|
5
|
+
include RFits::IO
|
6
|
+
|
7
|
+
class RFitsCompressionTest < Test::Unit::TestCase
|
8
|
+
def setup
|
9
|
+
@fits = Proxy.fits_create_file('!test/test.1.working.fits')
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_compression
|
13
|
+
Proxy.fits_set_compression_type(@fits, Proxy::RICE_1)
|
14
|
+
Proxy.fits_insert_img(@fits, Proxy::FLOAT_IMG, 2, [5, 5])
|
15
|
+
Proxy.fits_write_subset(@fits, Proxy::TFLOAT, [1, 1], [5, 5], [
|
16
|
+
1.0, 2.1, 3.2, 4.3, 5.4,
|
17
|
+
6.5, 7.6, 8.7, 9.8, 10.9,
|
18
|
+
11.0, 12.1, 13.2, 14.3, 15.4,
|
19
|
+
16.5, 17.6, 18.7, 19.8, 20.9,
|
20
|
+
21.0, 22.1, 23.2, 24.3, 25.4
|
21
|
+
])
|
22
|
+
assert_equal 1, Proxy.fits_is_compressed_image(@fits)
|
23
|
+
|
24
|
+
Proxy.fits_set_compression_type(@fits, 0)
|
25
|
+
Proxy.fits_insert_img(@fits, Proxy::LONG_IMG, 2, [4, 4])
|
26
|
+
Proxy.fits_write_subset(@fits, Proxy::TLONG, [1, 1], [4, 4], [
|
27
|
+
1, 2, 3, 4,
|
28
|
+
4, 3, 2, 1,
|
29
|
+
2, 2, 2, 2,
|
30
|
+
3, 3, 3, 3
|
31
|
+
])
|
32
|
+
assert_equal 0, Proxy.fits_is_compressed_image(@fits)
|
33
|
+
|
34
|
+
Proxy.fits_set_compression_type(@fits, Proxy::GZIP_1)
|
35
|
+
Proxy.fits_insert_img(@fits, Proxy::LONG_IMG, 2, [3, 3])
|
36
|
+
Proxy.fits_write_subset(@fits, Proxy::TLONG, [1, 1], [3, 3], [
|
37
|
+
1, 5, 9,
|
38
|
+
2, 6, 8,
|
39
|
+
3, 7, 7
|
40
|
+
])
|
41
|
+
assert_equal 1, Proxy.fits_is_compressed_image(@fits)
|
42
|
+
|
43
|
+
assert_equal 4, Proxy.fits_get_num_hdus(@fits)
|
44
|
+
end
|
45
|
+
|
46
|
+
def teardown
|
47
|
+
Proxy.fits_close_file(@fits)
|
48
|
+
FileUtils.rm('test/test.1.working.fits')
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
class RFitsIOWriteTest < Test::Unit::TestCase
|
53
|
+
def setup
|
54
|
+
@fits = Proxy.fits_create_file('!test/test.3.working.fits')
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_rfitsio
|
58
|
+
image_writing()
|
59
|
+
table_writing()
|
60
|
+
keyword_writing()
|
61
|
+
end
|
62
|
+
|
63
|
+
def image_writing
|
64
|
+
ipixels = [
|
65
|
+
1, 2, 3, 4, 5,
|
66
|
+
2, 3, 4, 5, 1,
|
67
|
+
3, 4, 5, 1, 2,
|
68
|
+
4, 5, 1, 2, 3,
|
69
|
+
5, 1, 2, 3, 4
|
70
|
+
]
|
71
|
+
|
72
|
+
fpixels = [
|
73
|
+
1.0, 2.1, 3.2, 4.3, 5.4,
|
74
|
+
6.5, 7.6, 8.7, 9.8, 10.9,
|
75
|
+
11.0, 12.1, 13.2, 14.3, 15.4,
|
76
|
+
16.5, 17.6, 18.7, 19.8, 20.9,
|
77
|
+
21.0, 22.1, 23.2, 24.3, 25.4
|
78
|
+
]
|
79
|
+
|
80
|
+
Proxy.fits_create_img(@fits, Proxy::LONG_IMG, 2, [5, 5])
|
81
|
+
Proxy.fits_write_subset(@fits, Proxy::TLONG, [1, 1], [5, 5], ipixels)
|
82
|
+
assert_equal [ipixels, 0], Proxy.fits_read_subset(@fits, Proxy::TLONG, [1, 1], [5, 5], [1, 1], 0)
|
83
|
+
|
84
|
+
Proxy.fits_create_img(@fits, Proxy::SHORT_IMG, 2, [5, 5])
|
85
|
+
Proxy.fits_write_img(@fits, Proxy::TSHORT, 1, 25, ipixels)
|
86
|
+
assert_equal [ipixels, 0], Proxy.fits_read_img(@fits, Proxy::TLONG, 1, 25, nil)
|
87
|
+
Proxy.fits_delete_hdu(@fits)
|
88
|
+
|
89
|
+
Proxy.fits_set_compression_type(@fits, Proxy::HCOMPRESS_1)
|
90
|
+
assert_equal Proxy::HCOMPRESS_1, Proxy.fits_get_compression_type(@fits)
|
91
|
+
Proxy.fits_set_tile_dim(@fits, 2, [1, 1])
|
92
|
+
assert_equal [1, 1], Proxy.fits_get_tile_dim(@fits, 2)
|
93
|
+
Proxy.fits_set_noise_bits(@fits, 5)
|
94
|
+
assert_equal 5, Proxy.fits_get_noise_bits(@fits)
|
95
|
+
Proxy.fits_set_hcomp_scale(@fits, 2)
|
96
|
+
assert_equal 2, Proxy.fits_get_hcomp_scale(@fits)
|
97
|
+
Proxy.fits_set_hcomp_smooth(@fits, 2)
|
98
|
+
assert_equal 2, Proxy.fits_get_hcomp_smooth(@fits)
|
99
|
+
|
100
|
+
Proxy.fits_create_img(@fits, Proxy::FLOAT_IMG, 2, [5, 5])
|
101
|
+
Proxy.fits_write_pixnull(@fits, Proxy::TFLOAT, [1, 1], 25, fpixels, 0.0)
|
102
|
+
Proxy.fits_read_pix(@fits, Proxy::TFLOAT, [1, 1], 25, nil).first.each_with_index do |p, i|
|
103
|
+
assert_in_delta fpixels[i], p, 0.0001
|
104
|
+
end
|
105
|
+
Proxy.fits_delete_hdu(@fits)
|
106
|
+
end
|
107
|
+
|
108
|
+
def table_writing
|
109
|
+
Proxy.fits_create_tbl(@fits, Proxy::BINARY_TBL, 0, 5,
|
110
|
+
['column_a', 'column_b', 'column_c', 'column_d', 'column_e'],
|
111
|
+
['I', '10A', 'E', 'C', 'D'],
|
112
|
+
nil,
|
113
|
+
"Binary table test")
|
114
|
+
|
115
|
+
assert_equal 5, Proxy.fits_get_num_cols(@fits)
|
116
|
+
assert_equal 3, Proxy.fits_get_colnum(@fits, Proxy::CASEINSEN, 'column_c')
|
117
|
+
assert_equal ['column_d', 4], Proxy.fits_get_colname(@fits, Proxy::CASEINSEN, 'column_d')
|
118
|
+
|
119
|
+
assert_equal [Proxy::TSHORT, 1, 2], Proxy.fits_get_coltype(@fits, 1)
|
120
|
+
assert_equal [Proxy::TSTRING, 10, 10], Proxy.fits_get_coltype(@fits, 2)
|
121
|
+
assert_equal [Proxy::TFLOAT, 1, 4], Proxy.fits_get_coltype(@fits, 3)
|
122
|
+
assert_equal [Proxy::TCOMPLEX, 1, 8], Proxy.fits_get_coltype(@fits, 4)
|
123
|
+
assert_equal [Proxy::TDOUBLE, 1, 8], Proxy.fits_get_coltype(@fits, 5)
|
124
|
+
|
125
|
+
assert_equal [Proxy::TSHORT, 1, 2], Proxy.fits_get_eqcoltype(@fits, 1)
|
126
|
+
assert_equal [Proxy::TSTRING, 10, 10], Proxy.fits_get_eqcoltype(@fits, 2)
|
127
|
+
assert_equal [Proxy::TFLOAT, 1, 4], Proxy.fits_get_eqcoltype(@fits, 3)
|
128
|
+
assert_equal [Proxy::TCOMPLEX, 1, 8], Proxy.fits_get_eqcoltype(@fits, 4)
|
129
|
+
assert_equal [Proxy::TDOUBLE, 1, 8], Proxy.fits_get_eqcoltype(@fits, 5)
|
130
|
+
|
131
|
+
assert_equal 6, Proxy.fits_get_col_display_width(@fits, 1)
|
132
|
+
assert_equal 10, Proxy.fits_get_col_display_width(@fits, 2)
|
133
|
+
assert_equal 14, Proxy.fits_get_col_display_width(@fits, 3)
|
134
|
+
assert_equal 31, Proxy.fits_get_col_display_width(@fits, 4)
|
135
|
+
assert_equal 23, Proxy.fits_get_col_display_width(@fits, 5)
|
136
|
+
|
137
|
+
assert_equal [1, [10]], Proxy.fits_read_tdim(@fits, 2, 1)
|
138
|
+
|
139
|
+
Proxy.fits_insert_rows(@fits, 0, 5)
|
140
|
+
assert_equal 5, Proxy.fits_get_num_rows(@fits)
|
141
|
+
Proxy.fits_delete_rows(@fits, 2, 2)
|
142
|
+
assert_equal 3, Proxy.fits_get_num_rows(@fits)
|
143
|
+
Proxy.fits_insert_rows(@fits, 2, 2);
|
144
|
+
Proxy.fits_delete_rowrange(@fits, '2-4')
|
145
|
+
assert_equal 2, Proxy.fits_get_num_rows(@fits)
|
146
|
+
Proxy.fits_insert_rows(@fits, 2, 3);
|
147
|
+
Proxy.fits_delete_rowlist(@fits, [1, 3, 5], 3)
|
148
|
+
assert_equal 2, Proxy.fits_get_num_rows(@fits)
|
149
|
+
Proxy.fits_delete_rows(@fits, 1, 2)
|
150
|
+
|
151
|
+
Proxy.fits_insert_cols(@fits, 6, 2, ['column_f', 'column_g'], ['I', 'I'])
|
152
|
+
assert_equal 7, Proxy.fits_get_num_cols(@fits)
|
153
|
+
Proxy.fits_delete_col(@fits, 7)
|
154
|
+
Proxy.fits_delete_col(@fits, 6)
|
155
|
+
assert_equal 5, Proxy.fits_get_num_cols(@fits)
|
156
|
+
|
157
|
+
Proxy.fits_modify_vector_len(@fits, 2, 15)
|
158
|
+
assert_equal [Proxy::TSTRING, 15, 15], Proxy.fits_get_eqcoltype(@fits, 2)
|
159
|
+
|
160
|
+
short_list = [5, 4, 3, 2, 1]
|
161
|
+
Proxy.fits_write_colnull(@fits, Proxy::TSHORT, 1, 1, 1, 5, short_list, nil)
|
162
|
+
assert_equal [short_list, 0], Proxy.fits_read_col(@fits, Proxy::TSHORT, 1, 1, 1, 5, nil)
|
163
|
+
|
164
|
+
string_list = ['a1', 'b2', 'c3', 'd4', 'e5']
|
165
|
+
Proxy.fits_write_colnull(@fits, Proxy::TSTRING, 2, 1, 1, 5, string_list, nil)
|
166
|
+
assert_equal [string_list, 0], Proxy.fits_read_col(@fits, Proxy::TSTRING, 2, 1, 1, 5, nil)
|
167
|
+
|
168
|
+
float_list = [1.1, 2.2, 3.3, 4.4, 5.5]
|
169
|
+
Proxy.fits_write_colnull(@fits, Proxy::TFLOAT, 3, 1, 1, 5, float_list, nil)
|
170
|
+
Proxy.fits_read_col(@fits, Proxy::TFLOAT, 3, 1, 1, 5, nil).first.each_with_index do |f, i|
|
171
|
+
assert_in_delta float_list[i], f, 0.001
|
172
|
+
end
|
173
|
+
|
174
|
+
complex_list = [Complex.new(1.1, 2.2), Complex.new(2.2, 3.3), Complex.new(3.3, 4.4), Complex.new(4.4, 5.5), Complex.new(5.5, 6.5)]
|
175
|
+
Proxy.fits_write_colnull(@fits, Proxy::TCOMPLEX, 4, 1, 1, 5, complex_list, nil)
|
176
|
+
Proxy.fits_read_col(@fits, Proxy::TCOMPLEX, 4, 1, 1, 5, nil).first.each_with_index do |rc, i|
|
177
|
+
assert_in_delta complex_list[i].real, rc.real, 0.001
|
178
|
+
assert_in_delta complex_list[i].image, rc.image, 0.001
|
179
|
+
end
|
180
|
+
|
181
|
+
double_list = [10.5, 9.4, 8.3, 7.2, 6.1]
|
182
|
+
Proxy.fits_write_colnull(@fits, Proxy::TDOUBLE, 5, 1, 1, 5, double_list, nil)
|
183
|
+
Proxy.fits_read_col(@fits, Proxy::TDOUBLE, 5, 1, 1, 5, nil).first.each_with_index do |d, i|
|
184
|
+
assert_in_delta double_list[i], d, 0.001
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
def keyword_writing
|
189
|
+
Proxy.fits_movabs_hdu(@fits, 1)
|
190
|
+
|
191
|
+
Proxy.fits_update_key(@fits, Proxy::TSTRING, 'TEST1', 'Hello!', 'A testing string')
|
192
|
+
assert_equal ["'Hello! '", 'A testing string'], Proxy.fits_read_keyword(@fits, 'TEST1')
|
193
|
+
|
194
|
+
Proxy.fits_update_key(@fits, Proxy::TLOGICAL, 'TEST2', true, 'A testing logical');
|
195
|
+
assert_equal ['T', 'A testing logical'], Proxy.fits_read_keyword(@fits, 'TEST2')
|
196
|
+
|
197
|
+
Proxy.fits_update_key(@fits, Proxy::TLOGICAL, 'TEST3', false, 'A testing logical');
|
198
|
+
assert_equal ['F', 'A testing logical'], Proxy.fits_read_keyword(@fits, 'TEST3')
|
199
|
+
|
200
|
+
Proxy.fits_update_key(@fits, Proxy::TINT, 'TEST4', 999999, 'A testing integer')
|
201
|
+
assert_equal ['999999', 'A testing integer'], Proxy.fits_read_keyword(@fits, 'TEST4')
|
202
|
+
|
203
|
+
Proxy.fits_update_key(@fits, Proxy::TDOUBLE, 'TEST5', 345.78, 'A testing double')
|
204
|
+
assert_equal ['345.78', 'A testing double'], Proxy.fits_read_keyword(@fits, 'TEST5')
|
205
|
+
|
206
|
+
Proxy.fits_update_key(@fits, Proxy::TCOMPLEX, 'TEST6', Complex.new(4.1, 5.2), 'A testing complex')
|
207
|
+
assert_equal ['(4.1, 5.2)', 'A testing complex'], Proxy.fits_read_keyword(@fits, 'TEST6')
|
208
|
+
|
209
|
+
Proxy.fits_update_key_null(@fits, 'TEST7', 'A testing null')
|
210
|
+
assert_equal ['', 'A testing null'], Proxy.fits_read_keyword(@fits, 'TEST7')
|
211
|
+
end
|
212
|
+
|
213
|
+
def teardown
|
214
|
+
Proxy.fits_close_file(@fits)
|
215
|
+
FileUtils.rm('test/test.3.working.fits')
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
219
|
+
class RFitsIOReadTest < Test::Unit::TestCase
|
220
|
+
def setup
|
221
|
+
FileUtils.cp('test/test.2.fits', 'test/test.2.working.fits')
|
222
|
+
@fits = Proxy.fits_open_file('test/test.2.working.fits', Proxy::READWRITE)
|
223
|
+
end
|
224
|
+
|
225
|
+
def test_rfitsio
|
226
|
+
file_access()
|
227
|
+
hdu_access()
|
228
|
+
keyword_reading()
|
229
|
+
image_routines()
|
230
|
+
compression()
|
231
|
+
end
|
232
|
+
|
233
|
+
def file_access
|
234
|
+
assert_equal 'test/test.2.working.fits', Proxy.fits_file_name(@fits)
|
235
|
+
assert_equal Proxy::READWRITE, Proxy.fits_file_mode(@fits)
|
236
|
+
assert_equal 'file://', Proxy.fits_url_type(@fits)
|
237
|
+
end
|
238
|
+
|
239
|
+
def hdu_access
|
240
|
+
assert_equal 9, Proxy.fits_get_num_hdus(@fits)
|
241
|
+
assert_equal Proxy::IMAGE_HDU, Proxy.fits_movabs_hdu(@fits, 3)
|
242
|
+
assert_equal 3, Proxy.fits_get_hdu_num(@fits)
|
243
|
+
assert_equal Proxy::IMAGE_HDU, Proxy.fits_get_hdu_type(@fits)
|
244
|
+
end
|
245
|
+
|
246
|
+
def keyword_reading
|
247
|
+
Proxy.fits_movabs_hdu(@fits, 1)
|
248
|
+
|
249
|
+
assert_equal 62, Proxy.fits_get_hdrspace(@fits).first
|
250
|
+
|
251
|
+
ra_obj = Proxy.fits_read_keyword(@fits, 'RA_OBJ')
|
252
|
+
assert_equal ['182.635454000001', 'R.A. of the object (degrees)'], ra_obj
|
253
|
+
assert_equal [182.635454000001, 'R.A. of the object (degrees)'], Proxy.fits_read_key(@fits, Proxy::TDOUBLE, 'RA_OBJ')
|
254
|
+
assert_equal 'F', Proxy.fits_get_keytype(ra_obj.first)
|
255
|
+
assert_equal ['RA_OBJ', '182.635454000001', 'R.A. of the object (degrees)'], Proxy.fits_read_keyn(@fits, 11)
|
256
|
+
|
257
|
+
object = Proxy.fits_read_keyword(@fits, 'OBJECT')
|
258
|
+
assert_equal ["'NGC 4151'", 'Name of observed object'], object
|
259
|
+
assert_equal ["NGC 4151", 'Name of observed object'], Proxy.fits_read_key(@fits, Proxy::TSTRING, 'OBJECT')
|
260
|
+
assert_equal 'C', Proxy.fits_get_keytype(object.first)
|
261
|
+
assert_equal ['OBJECT', "'NGC 4151'", 'Name of observed object'], Proxy.fits_read_keyn(@fits, 10)
|
262
|
+
|
263
|
+
off_axis = Proxy.fits_read_keyword(@fits, 'OFF-AXIS')
|
264
|
+
assert_equal ['T', 'Was this pointing done off-axis'], off_axis
|
265
|
+
assert_equal [true, 'Was this pointing done off-axis'], Proxy.fits_read_key(@fits, Proxy::TLOGICAL, 'OFF-AXIS')
|
266
|
+
assert_equal 'L', Proxy.fits_get_keytype(off_axis.first)
|
267
|
+
assert_equal ['OFF-AXIS', 'T', 'Was this pointing done off-axis'], Proxy.fits_read_keyn(@fits, 25)
|
268
|
+
|
269
|
+
bitpix = Proxy.fits_read_keyword(@fits, 'BITPIX')
|
270
|
+
assert_equal ['8', 'Character information'], bitpix
|
271
|
+
assert_equal [8, 'Character information'], Proxy.fits_read_key(@fits, Proxy::TINT, 'BITPIX')
|
272
|
+
assert_equal 'I', Proxy.fits_get_keytype(bitpix.first)
|
273
|
+
assert_equal ['BITPIX', '8', 'Character information'], Proxy.fits_read_keyn(@fits, 2)
|
274
|
+
end
|
275
|
+
|
276
|
+
def image_routines
|
277
|
+
Proxy.fits_movabs_hdu(@fits, 3)
|
278
|
+
|
279
|
+
assert_equal Proxy::SHORT_IMG, Proxy.fits_get_img_type(@fits)
|
280
|
+
assert_equal Proxy::SHORT_IMG, Proxy.fits_get_img_equivtype(@fits)
|
281
|
+
assert_equal 2, Proxy.fits_get_img_dim(@fits)
|
282
|
+
assert_equal [2048, 300], Proxy.fits_get_img_size(@fits, 2)
|
283
|
+
assert_equal [Proxy::SHORT_IMG, 2, [2048, 300]], Proxy.fits_get_img_param(@fits, 2)
|
284
|
+
|
285
|
+
assert_equal [[17.0, 15.0, 7.0, 15.0, 5.0, 4.0, 5.0, 5.0, 11.0, 4.0], 0], Proxy.fits_read_img(@fits, Proxy::TDOUBLE, 112, 10, 0)
|
286
|
+
assert_equal [[17, 15, 7, 15, 5, 4, 5, 5, 11, 4], 0], Proxy.fits_read_img(@fits, Proxy::TLONG, 112, 10, 0)
|
287
|
+
|
288
|
+
assert_equal [[1.0, 1.0, 3.0, 0.0, 0.0, 2.0, 0.0, 1.0, 0.0], 0],
|
289
|
+
Proxy.fits_read_subset(@fits, Proxy::TDOUBLE, [902, 122], [910, 122], [1, 1], 0)
|
290
|
+
assert_equal [[1, 1, 3, 0, 0, 2, 0, 1, 0], 0],
|
291
|
+
Proxy.fits_read_subset(@fits, Proxy::TLONG, [902, 122], [910, 122], [1, 1], 0)
|
292
|
+
|
293
|
+
assert_equal [[1.0, 1.0, 3.0, 0.0, 0.0, 2.0, 0.0, 1.0, 0.0], 0],
|
294
|
+
Proxy.fits_read_pix(@fits, Proxy::TDOUBLE, [902, 122], 9, 0)
|
295
|
+
assert_equal [[1, 1, 3, 0, 0, 2, 0, 1, 0], 0],
|
296
|
+
Proxy.fits_read_pix(@fits, Proxy::TLONG, [902, 122], 9, 0)
|
297
|
+
end
|
298
|
+
|
299
|
+
def compression
|
300
|
+
Proxy.fits_movabs_hdu(@fits, 3)
|
301
|
+
|
302
|
+
# Image is not compressed, so this is sort of boring.
|
303
|
+
assert_equal 0, Proxy.fits_is_compressed_image(@fits)
|
304
|
+
assert_equal 0, Proxy.fits_get_compression_type(@fits)
|
305
|
+
assert_equal [0, 0], Proxy.fits_get_tile_dim(@fits, 2)
|
306
|
+
assert_equal 0, Proxy.fits_get_noise_bits(@fits)
|
307
|
+
assert_equal 0, Proxy.fits_get_hcomp_scale(@fits)
|
308
|
+
assert_equal 0, Proxy.fits_get_hcomp_smooth(@fits)
|
309
|
+
end
|
310
|
+
|
311
|
+
def teardown
|
312
|
+
Proxy.fits_close_file(@fits)
|
313
|
+
FileUtils.rm('test/test.2.working.fits')
|
314
|
+
end
|
315
|
+
end
|