-
Notifications
You must be signed in to change notification settings - Fork 107
/
test_image.py
3645 lines (3138 loc) · 164 KB
/
test_image.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Copyright (c) 2012-2023 by the GalSim developers team on GitHub
# https://github.com/GalSim-developers
#
# This file is part of GalSim: The modular galaxy image simulation toolkit.
# https://github.com/GalSim-developers/GalSim
#
# GalSim is free software: redistribution and use in source and binary forms,
# with or without modification, are permitted provided that the following
# conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions, and the disclaimer given in the accompanying LICENSE
# file.
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions, and the disclaimer given in the documentation
# and/or other materials provided with the distribution.
#
"""Unit tests for the Image class.
These tests use six externally generated (IDL + astrolib FITS writing tools) reference images for
the Image unit tests. These are in tests/data/.
Each image is 5x7 pixels^2 and if each pixel is labelled (x, y) then each pixel value is 10*x + y.
The array thus has values:
15 25 35 45 55 65 75
14 24 34 44 54 64 74
13 23 33 43 53 63 73 ^
12 22 32 42 52 62 72 |
11 21 31 41 51 61 71 y
x ->
With array directions as indicated. This hopefully will make it easy enough to perform sub-image
checks, etc.
Images are in US, UI, S, I, F, D, CF, and CD flavors.
There are also four FITS cubes, and four FITS multi-extension files for testing. Each is 12
images deep, with the first image being the reference above and each subsequent being the same
incremented by one.
"""
import os
import sys
import numpy as np
import galsim
from galsim_test_helpers import *
from galsim._pyfits import pyfits
# Setup info for tests, not likely to change
ntypes = 8 # Note: Most tests below only run through the first 8 types.
# test_Image_basic tests all 11 types including the aliases.
types = [np.int16, np.int32, np.uint16, np.uint32, np.float32, np.float64,
np.complex64, np.complex128, int, float, complex]
simple_types = [int, int, int, int, float, float, complex, complex, int, float, complex]
np_types = [np.int16, np.int32, np.uint16, np.uint32, np.float32, np.float64,
np.complex64, np.complex128, np.int32, np.float64, np.complex128]
tchar = ['S', 'I', 'US', 'UI', 'F', 'D', 'CF', 'CD', 'I', 'D', 'CD']
int_ntypes = 4 # The first four are the integer types for which we need to test &, |, ^.
ncol = 7
nrow = 5
test_shape = (ncol, nrow) # shape of image arrays for all tests
ref_array = np.array([
[11, 21, 31, 41, 51, 61, 71],
[12, 22, 32, 42, 52, 62, 72],
[13, 23, 33, 43, 53, 63, 73],
[14, 24, 34, 44, 54, 64, 74],
[15, 25, 35, 45, 55, 65, 75] ]).astype(np.int16)
large_array = np.zeros((ref_array.shape[0]*3, ref_array.shape[1]*2), dtype=np.int16)
large_array[::3,::2] = ref_array
# Depth of FITS datacubes and multi-extension FITS files
if __name__ == "__main__":
nimages = 12
else:
# There really are 12, but testing the first 3 should be plenty as a unit test, and
# it helps speed things up.
nimages = 3
datadir = os.path.join(".", "Image_comparison_images")
@timer
def test_Image_basic():
"""Test that all supported types perform basic Image operations correctly
"""
# Do all 10 types here, rather than just the 7 numpy types. i.e. Test the aliases.
for i in range(len(types)):
# Check basic constructor from ncol, nrow
array_type = types[i]
np_array_type = np_types[i]
print('array_type = ',array_type,np_array_type)
# Check basic constructor from ncol, nrow
im1 = galsim.Image(ncol,nrow,dtype=array_type)
# Check basic features of array built by Image
np.testing.assert_array_equal(im1.array, 0.)
assert im1.array.shape == (nrow,ncol)
assert im1.array.dtype.type == np_array_type
assert im1.array.flags.writeable == True
assert im1.array.flags.c_contiguous == True
assert im1.dtype == np_array_type
assert im1.ncol == ncol
assert im1.nrow == nrow
im1.fill(23)
np.testing.assert_array_equal(im1.array, 23.)
bounds = galsim.BoundsI(1,ncol,1,nrow)
assert im1.xmin == 1
assert im1.xmax == ncol
assert im1.ymin == 1
assert im1.ymax == nrow
assert im1.bounds == bounds
assert im1.outer_bounds == galsim.BoundsD(0.5, ncol+0.5, 0.5, nrow+0.5)
# Same thing if ncol,nrow are kwargs. Also can give init_value
im1b = galsim.Image(ncol=ncol, nrow=nrow, dtype=array_type, init_value=23)
np.testing.assert_array_equal(im1b.array, 23.)
assert im1 == im1b
# Adding on xmin, ymin allows you to set an origin other than (1,1)
im1a = galsim.Image(ncol, nrow, dtype=array_type, xmin=4, ymin=7)
im1b = galsim.Image(ncol=ncol, nrow=nrow, dtype=array_type, xmin=0, ymin=0)
assert im1a.xmin == 4
assert im1a.xmax == ncol+3
assert im1a.ymin == 7
assert im1a.ymax == nrow+6
assert im1a.bounds == galsim.BoundsI(4,ncol+3,7,nrow+6)
assert im1a.outer_bounds == galsim.BoundsD(3.5, ncol+3.5, 6.5, nrow+6.5)
assert im1b.xmin == 0
assert im1b.xmax == ncol-1
assert im1b.ymin == 0
assert im1b.ymax == nrow-1
assert im1b.bounds == galsim.BoundsI(0,ncol-1,0,nrow-1)
assert im1b.outer_bounds == galsim.BoundsD(-0.5, ncol-0.5, -0.5, nrow-0.5)
# Also test alternate name of image type: ImageD, ImageF, etc.
image_type = eval("galsim.Image"+tchar[i]) # Use handy eval() mimics use of ImageSIFD
im2 = image_type(bounds, init_value=23)
im2_view = im2.view()
im2_cview = im2.view(make_const=True)
im2_conj = im2.conjugate
assert im2_view.xmin == 1
assert im2_view.xmax == ncol
assert im2_view.ymin == 1
assert im2_view.ymax == nrow
assert im2_view.bounds == bounds
assert im2_view.array.dtype.type == np_array_type
assert im2_view.dtype == np_array_type
assert im2_cview.xmin == 1
assert im2_cview.xmax == ncol
assert im2_cview.ymin == 1
assert im2_cview.ymax == nrow
assert im2_cview.bounds == bounds
assert im2_cview.array.dtype.type == np_array_type
assert im2_cview.dtype == np_array_type
assert im1.real.bounds == bounds
assert im1.imag.bounds == bounds
assert im2.real.bounds == bounds
assert im2.imag.bounds == bounds
assert im2_view.real.bounds == bounds
assert im2_view.imag.bounds == bounds
assert im2_cview.real.bounds == bounds
assert im2_cview.imag.bounds == bounds
if tchar[i] == 'CF':
assert im1.real.dtype == np.float32
assert im1.imag.dtype == np.float32
elif tchar[i] == 'CD':
assert im1.real.dtype == np.float64
assert im1.imag.dtype == np.float64
else:
assert im1.real.dtype == np_array_type
assert im1.imag.dtype == np_array_type
# Check various ways to set and get values
for y in range(1,nrow+1):
for x in range(1,ncol+1):
im1.setValue(x, y, 100 + 10*x + y)
im1a.setValue(x+3, y+6, 100 + 10*x + y)
im1b.setValue(x=x-1, y=y-1, value=100 + 10*x + y)
im2_view._setValue(x, y, 100 + 10*x)
im2_view._addValue(x, y, y)
for y in range(1,nrow+1):
for x in range(1,ncol+1):
value = 100 + 10*x + y
assert im1(x,y) == value
assert im1(galsim.PositionI(x,y)) == value
assert im1a(x+3,y+6) == value
assert im1b(x-1,y-1) == value
assert im1.view()(x,y) == value
assert im1.view()(galsim.PositionI(x,y)) == value
assert im1.view(make_const=True)(x,y) == value
assert im2(x,y) == value
assert im2_view(x,y) == value
assert im2_cview(x,y) == value
assert im1.conjugate(x,y) == value
if tchar[i][0] == 'C':
# complex conjugate is not a view into the original.
assert im2_conj(x,y) == 23
assert im2.conjugate(x,y) == value
else:
assert im2_conj(x,y) == value
value2 = 53 + 12*x - 19*y
if tchar[i] in ['US', 'UI']:
value2 = abs(value2)
im1[x,y] = value2
im2_view[galsim.PositionI(x,y)] = value2
assert im1.getValue(x,y) == value2
assert im1.view().getValue(x=x, y=y) == value2
assert im1.view(make_const=True).getValue(x,y) == value2
assert im2.getValue(x=x, y=y) == value2
assert im2_view.getValue(x,y) == value2
assert im2_cview._getValue(x,y) == value2
assert im1.real(x,y) == value2
assert im1.view().real(x,y) == value2
assert im1.view(make_const=True).real(x,y) == value2.real
assert im2.real(x,y) == value2.real
assert im2_view.real(x,y) == value2.real
assert im2_cview.real(x,y) == value2.real
assert im1.imag(x,y) == 0
assert im1.view().imag(x,y) == 0
assert im1.view(make_const=True).imag(x,y) == 0
assert im2.imag(x,y) == 0
assert im2_view.imag(x,y) == 0
assert im2_cview.imag(x,y) == 0
value3 = 10*x + y
im1.addValue(x,y, np.int64(value3-value2))
im2_view[x,y] += np.int64(value3-value2)
assert im1[galsim.PositionI(x,y)] == value3
assert im1.view()[x,y] == value3
assert im1.view(make_const=True)[galsim.PositionI(x,y)] == value3
assert im2[x,y] == value3
assert im2_view[galsim.PositionI(x,y)] == value3
assert im2_cview[x,y] == value3
# Setting or getting the value outside the bounds should throw an exception.
assert_raises(galsim.GalSimBoundsError,im1.setValue,0,0,1)
assert_raises(galsim.GalSimBoundsError,im1.addValue,0,0,1)
assert_raises(galsim.GalSimBoundsError,im1.__call__,0,0)
assert_raises(galsim.GalSimBoundsError,im1.__getitem__,0,0)
assert_raises(galsim.GalSimBoundsError,im1.__setitem__,0,0,1)
assert_raises(galsim.GalSimBoundsError,im1.view().setValue,0,0,1)
assert_raises(galsim.GalSimBoundsError,im1.view().__call__,0,0)
assert_raises(galsim.GalSimBoundsError,im1.view().__getitem__,0,0)
assert_raises(galsim.GalSimBoundsError,im1.view().__setitem__,0,0,1)
assert_raises(galsim.GalSimBoundsError,im1.setValue,ncol+1,0,1)
assert_raises(galsim.GalSimBoundsError,im1.addValue,ncol+1,0,1)
assert_raises(galsim.GalSimBoundsError,im1.__call__,ncol+1,0)
assert_raises(galsim.GalSimBoundsError,im1.view().setValue,ncol+1,0,1)
assert_raises(galsim.GalSimBoundsError,im1.view().__call__,ncol+1,0)
assert_raises(galsim.GalSimBoundsError,im1.setValue,0,nrow+1,1)
assert_raises(galsim.GalSimBoundsError,im1.addValue,0,nrow+1,1)
assert_raises(galsim.GalSimBoundsError,im1.__call__,0,nrow+1)
assert_raises(galsim.GalSimBoundsError,im1.view().setValue,0,nrow+1,1)
assert_raises(galsim.GalSimBoundsError,im1.view().__call__,0,nrow+1)
assert_raises(galsim.GalSimBoundsError,im1.setValue,ncol+1,nrow+1,1)
assert_raises(galsim.GalSimBoundsError,im1.addValue,ncol+1,nrow+1,1)
assert_raises(galsim.GalSimBoundsError,im1.__call__,ncol+1,nrow+1)
assert_raises(galsim.GalSimBoundsError,im1.view().setValue,ncol+1,nrow+1,1)
assert_raises(galsim.GalSimBoundsError,im1.view().__call__,ncol+1,nrow+1)
assert_raises(galsim.GalSimBoundsError,im1.__getitem__,galsim.BoundsI(0,ncol,1,nrow))
assert_raises(galsim.GalSimBoundsError,im1.__getitem__,galsim.BoundsI(1,ncol,0,nrow))
assert_raises(galsim.GalSimBoundsError,im1.__getitem__,galsim.BoundsI(1,ncol+1,1,nrow))
assert_raises(galsim.GalSimBoundsError,im1.__getitem__,galsim.BoundsI(1,ncol,1,nrow+1))
assert_raises(galsim.GalSimBoundsError,im1.__getitem__,galsim.BoundsI(0,ncol+1,0,nrow+1))
assert_raises(galsim.GalSimBoundsError,im1.subImage,galsim.BoundsI(0,ncol,1,nrow))
assert_raises(galsim.GalSimBoundsError,im1.subImage,galsim.BoundsI(1,ncol,0,nrow))
assert_raises(galsim.GalSimBoundsError,im1.subImage,galsim.BoundsI(1,ncol+1,1,nrow))
assert_raises(galsim.GalSimBoundsError,im1.subImage,galsim.BoundsI(1,ncol,1,nrow+1))
assert_raises(galsim.GalSimBoundsError,im1.subImage,galsim.BoundsI(0,ncol+1,0,nrow+1))
assert_raises(galsim.GalSimBoundsError,im1.setSubImage,galsim.BoundsI(0,ncol,1,nrow),
galsim.Image(ncol+1,nrow, init_value=10))
assert_raises(galsim.GalSimBoundsError,im1.setSubImage,galsim.BoundsI(1,ncol,0,nrow),
galsim.Image(ncol+1,nrow, init_value=10))
assert_raises(galsim.GalSimBoundsError,im1.setSubImage,galsim.BoundsI(1,ncol+1,1,nrow),
galsim.Image(ncol+1,nrow, init_value=10))
assert_raises(galsim.GalSimBoundsError,im1.setSubImage,galsim.BoundsI(1,ncol,1,nrow+1),
galsim.Image(ncol+1,nrow, init_value=10))
assert_raises(galsim.GalSimBoundsError,im1.setSubImage,galsim.BoundsI(0,ncol+1,0,nrow+1),
galsim.Image(ncol+2,nrow+2, init_value=10))
assert_raises(galsim.GalSimBoundsError,im1.__setitem__,galsim.BoundsI(0,ncol,1,nrow),
galsim.Image(ncol+1,nrow, init_value=10))
assert_raises(galsim.GalSimBoundsError,im1.__setitem__,galsim.BoundsI(1,ncol,0,nrow),
galsim.Image(ncol+1,nrow, init_value=10))
assert_raises(galsim.GalSimBoundsError,im1.__setitem__,galsim.BoundsI(1,ncol+1,1,nrow),
galsim.Image(ncol+1,nrow, init_value=10))
assert_raises(galsim.GalSimBoundsError,im1.__setitem__,galsim.BoundsI(1,ncol,1,nrow+1),
galsim.Image(ncol+1,nrow, init_value=10))
assert_raises(galsim.GalSimBoundsError,im1.__setitem__,galsim.BoundsI(0,ncol+1,0,nrow+1),
galsim.Image(ncol+2,nrow+2, init_value=10))
# Also, setting values in something that should be const
assert_raises(galsim.GalSimImmutableError,im1.view(make_const=True).setValue,1,1,1)
assert_raises(galsim.GalSimImmutableError,im1.view(make_const=True).real.setValue,1,1,1)
assert_raises(galsim.GalSimImmutableError,im1.view(make_const=True).imag.setValue,1,1,1)
if tchar[i][0] != 'C':
assert_raises(galsim.GalSimImmutableError,im1.imag.setValue,1,1,1)
# Finally check for the wrong number of arguments in get/setitem
assert_raises(TypeError,im1.__getitem__,1)
assert_raises(TypeError,im1.__setitem__,1,1)
assert_raises(TypeError,im1.__getitem__,1,2,3)
assert_raises(TypeError,im1.__setitem__,1,2,3,4)
# Check view of given data
im3_view = galsim.Image(ref_array.astype(np_array_type))
slice_array = large_array.astype(np_array_type)[::3,::2]
im4_view = galsim.Image(slice_array)
im5_view = galsim.Image(ref_array.astype(np_array_type).tolist(), dtype=array_type)
im6_view = galsim.Image(ref_array.astype(np_array_type), xmin=4, ymin=7)
im7_view = galsim.Image(ref_array.astype(np_array_type), xmin=0, ymin=0)
im8_view = galsim.Image(ref_array).view(dtype=np_array_type)
for y in range(1,nrow+1):
for x in range(1,ncol+1):
value3 = 10*x+y
assert im3_view(x,y) == value3
assert im4_view(x,y) == value3
assert im5_view(x,y) == value3
assert im6_view(x+3,y+6) == value3
assert im7_view(x-1,y-1) == value3
assert im8_view(x,y) == value3
# Check shift ops
im1_view = im1.view() # View with old bounds
dx = 31
dy = 16
im1.shift(dx,dy)
im2_view.setOrigin(1+dx , 1+dy)
im3_view.setCenter((ncol+1)/2+dx , (nrow+1)/2+dy)
shifted_bounds = galsim.BoundsI(1+dx, ncol+dx, 1+dy, nrow+dy)
assert im1.bounds == shifted_bounds
assert im2_view.bounds == shifted_bounds
assert im3_view.bounds == shifted_bounds
# Others shouldn't have changed
assert im1_view.bounds == bounds
assert im2.bounds == bounds
for y in range(1,nrow+1):
for x in range(1,ncol+1):
value3 = 10*x+y
assert im1(x+dx,y+dy) == value3
assert im1_view(x,y) == value3
assert im2(x,y) == value3
assert im2_view(x+dx,y+dy) == value3
assert im3_view(x+dx,y+dy) == value3
assert_raises(TypeError, im1.shift, dx)
assert_raises(TypeError, im1.shift, dx=dx)
assert_raises(TypeError, im1.shift, x=dx, y=dy)
assert_raises(TypeError, im1.shift, dx, dy=dy)
assert_raises(TypeError, im1.shift, dx, dy, dy)
assert_raises(TypeError, im1.shift, dx, dy, invalid=True)
# Check picklability
check_pickle(im1)
check_pickle(im1_view)
check_pickle(im2)
check_pickle(im2_view)
check_pickle(im2_cview)
check_pickle(im3_view)
check_pickle(im4_view)
# Also check picklability of Bounds, Position here.
check_pickle(galsim.PositionI(2,3))
check_pickle(galsim.PositionD(2.2,3.3))
check_pickle(galsim.BoundsI(2,3,7,8))
check_pickle(galsim.BoundsD(2.1, 4.3, 6.5, 9.1))
@timer
def test_undefined_image():
"""Test various ways to construct an image with undefined bounds
"""
for i in range(len(types)):
im1 = galsim.Image(dtype=types[i])
assert not im1.bounds.isDefined()
assert im1.array.shape == (1,1)
assert im1 == im1
im2 = galsim.Image()
assert not im2.bounds.isDefined()
assert im2.array.shape == (1,1)
assert im2 == im2
if types[i] == np.float32:
assert im2 == im1
im3 = galsim.Image(array=np.array([[]],dtype=types[i]))
assert not im3.bounds.isDefined()
assert im3.array.shape == (1,1)
assert im3 == im1
im4 = galsim.Image(array=np.array([[]]), dtype=types[i])
assert not im4.bounds.isDefined()
assert im4.array.shape == (1,1)
assert im4 == im1
im5 = galsim.Image(array=np.array([[1]]), dtype=types[i], bounds=galsim.BoundsI())
assert not im5.bounds.isDefined()
assert im5.array.shape == (1,1)
assert im5 == im1
im6 = galsim.Image(array=np.array([[1]], dtype=types[i]), bounds=galsim.BoundsI())
assert not im6.bounds.isDefined()
assert im6.array.shape == (1,1)
assert im6 == im1
im7 = 1.0 * im1
assert not im7.bounds.isDefined()
assert im7.array.shape == (1,1)
if types[i] == np.float64:
assert im7 == im1
im8 = im1 + 1j * im3
assert not im8.bounds.isDefined()
assert im8.array.shape == (1,1)
if types[i] == np.complex128:
assert im8 == im1
im9 = galsim.Image(0, 0)
assert not im9.bounds.isDefined()
assert im9.array.shape == (1,1)
assert im9 == im1
im10 = galsim.Image(10, 0)
assert not im10.bounds.isDefined()
assert im10.array.shape == (1,1)
assert im10 == im1
im11 = galsim.Image(0, 19)
assert not im11.bounds.isDefined()
assert im11.array.shape == (1,1)
assert im11 == im1
assert_raises(galsim.GalSimUndefinedBoundsError,im1.setValue, 0, 0, 1)
assert_raises(galsim.GalSimUndefinedBoundsError,im1.__call__, 0, 0)
assert_raises(galsim.GalSimUndefinedBoundsError,im1.view().setValue, 0, 0, 1)
assert_raises(galsim.GalSimUndefinedBoundsError,im1.view().__call__, 0, 0)
assert_raises(galsim.GalSimUndefinedBoundsError,im1.view().addValue, 0, 0, 1)
assert_raises(galsim.GalSimUndefinedBoundsError,im1.fill, 3)
assert_raises(galsim.GalSimUndefinedBoundsError,im1.view().fill, 3)
assert_raises(galsim.GalSimUndefinedBoundsError,im1.invertSelf)
assert_raises(galsim.GalSimUndefinedBoundsError,im1.__getitem__,galsim.BoundsI(1,2,1,2))
assert_raises(galsim.GalSimUndefinedBoundsError,im1.subImage,galsim.BoundsI(1,2,1,2))
assert_raises(galsim.GalSimUndefinedBoundsError,im1.setSubImage,galsim.BoundsI(1,2,1,2),
galsim.Image(2,2, init_value=10))
assert_raises(galsim.GalSimUndefinedBoundsError,im1.__setitem__,galsim.BoundsI(1,2,1,2),
galsim.Image(2,2, init_value=10))
im1.scale = 1.
assert_raises(galsim.GalSimUndefinedBoundsError,im1.calculate_fft)
assert_raises(galsim.GalSimUndefinedBoundsError,im1.calculate_inverse_fft)
check_pickle(im1.bounds)
check_pickle(im1)
check_pickle(im1.view())
check_pickle(im1.view(make_const=True))
@timer
def test_Image_FITS_IO():
"""Test that all six FITS reference images are correctly read in by both PyFITS and our Image
wrappers.
"""
for i in range(ntypes):
array_type = types[i]
if tchar[i][0] == 'C':
# Cannot write complex Images to fits. Check for an exception and continue.
ref_image = galsim.Image(ref_array.astype(array_type))
test_file = os.path.join(datadir, "test"+tchar[i]+".fits")
with assert_raises(ValueError):
ref_image.write(test_file)
continue
#
# Test input from a single external FITS image
#
# Read the reference image to from an externally-generated fits file
test_file = os.path.join(datadir, "test"+tchar[i]+".fits")
# Check pyfits read for sanity
with pyfits.open(test_file) as fits:
test_array = fits[0].data
np.testing.assert_array_equal(ref_array.astype(types[i]), test_array,
err_msg="PyFITS failing to read reference image.")
# Then use galsim fits.read function
# First version: use pyfits HDUList
with pyfits.open(test_file) as hdu:
test_image = galsim.fits.read(hdu_list=hdu)
np.testing.assert_array_equal(ref_array.astype(types[i]), test_image.array,
err_msg="Failed reading from PyFITS PrimaryHDU input.")
# Second version: use file name
test_image = galsim.fits.read(test_file)
np.testing.assert_array_equal(ref_array.astype(types[i]), test_image.array,
err_msg="Image"+tchar[i]+" read failed reading from filename input.")
#
# Test full I/O on a single internally-generated FITS image
#
# Write the reference image to a fits file
ref_image = galsim.Image(ref_array.astype(array_type))
test_file = os.path.join(datadir, "test"+tchar[i]+"_internal.fits")
ref_image.write(test_file)
# Check pyfits read for sanity
with pyfits.open(test_file) as fits:
test_array = fits[0].data
np.testing.assert_array_equal(ref_array.astype(types[i]), test_array,
err_msg="Image"+tchar[i]+" write failed.")
# Then use galsim fits.read function
# First version: use pyfits HDUList
with pyfits.open(test_file) as hdu:
test_image = galsim.fits.read(hdu_list=hdu)
np.testing.assert_array_equal(ref_array.astype(types[i]), test_image.array,
err_msg="Failed reading from PyFITS PrimaryHDU input.")
# Second version: use file name
test_image = galsim.fits.read(test_file)
np.testing.assert_array_equal(ref_array.astype(types[i]), test_image.array,
err_msg="Image"+tchar[i]+" read failed reading from filename input.")
assert_raises(ValueError, galsim.fits.read, test_file, compression='invalid')
assert_raises(ValueError, ref_image.write, test_file, compression='invalid')
assert_raises(OSError, galsim.fits.read, test_file, compression='rice')
assert_raises(OSError, galsim.fits.read, 'invalid.fits')
assert_raises(OSError, galsim.fits.read, 'config_input/catalog.fits', hdu=1)
assert_raises(TypeError, galsim.fits.read)
assert_raises(TypeError, galsim.fits.read, test_file, hdu_list=hdu)
assert_raises(TypeError, ref_image.write)
assert_raises(TypeError, ref_image.write, file_name=test_file, hdu_list=hdu)
# If clobbert = False, then trying to overwrite will raise an OSError
assert_raises(OSError, ref_image.write, test_file, clobber=False)
#
# Test various compression schemes
#
# These tests are a bit slow, so we only bother to run them for the first dtype
# when doing the regular unit tests. When running python test_image.py, all of them
# will run, so when working on the code, it is a good idea to run the tests that way.
if i > 0 and __name__ != "__main__":
continue
test_file0 = test_file # Save the name of the uncompressed file.
# Test full-file gzip
test_file = os.path.join(datadir, "test"+tchar[i]+".fits.gz")
test_image = galsim.fits.read(test_file, compression='gzip')
np.testing.assert_array_equal(ref_array.astype(types[i]), test_image.array,
err_msg="Image"+tchar[i]+" read failed for explicit full-file gzip")
test_image = galsim.fits.read(test_file)
np.testing.assert_array_equal(ref_array.astype(types[i]), test_image.array,
err_msg="Image"+tchar[i]+" read failed for auto full-file gzip")
test_file = os.path.join(datadir, "test"+tchar[i]+"_internal.fits.gz")
ref_image.write(test_file, compression='gzip')
test_image = galsim.fits.read(test_file)
np.testing.assert_array_equal(ref_array.astype(types[i]), test_image.array,
err_msg="Image"+tchar[i]+" write failed for explicit full-file gzip")
ref_image.write(test_file)
test_image = galsim.fits.read(test_file)
np.testing.assert_array_equal(ref_array.astype(types[i]), test_image.array,
err_msg="Image"+tchar[i]+" write failed for auto full-file gzip")
# With compression = None or 'none', astropy automatically figures it out anyway.
test_image = galsim.fits.read(test_file, compression=None)
np.testing.assert_array_equal(ref_array.astype(types[i]), test_image.array,
err_msg="Image"+tchar[i]+" write failed for auto full-file gzip")
assert_raises(OSError, galsim.fits.read, test_file0, compression='gzip')
# Test full-file bzip2
test_file = os.path.join(datadir, "test"+tchar[i]+".fits.bz2")
test_image = galsim.fits.read(test_file, compression='bzip2')
np.testing.assert_array_equal(ref_array.astype(types[i]), test_image.array,
err_msg="Image"+tchar[i]+" read failed for explicit full-file bzip2")
test_image = galsim.fits.read(test_file)
np.testing.assert_array_equal(ref_array.astype(types[i]), test_image.array,
err_msg="Image"+tchar[i]+" read failed for auto full-file bzip2")
test_file = os.path.join(datadir, "test"+tchar[i]+"_internal.fits.bz2")
ref_image.write(test_file, compression='bzip2')
test_image = galsim.fits.read(test_file)
np.testing.assert_array_equal(ref_array.astype(types[i]), test_image.array,
err_msg="Image"+tchar[i]+" write failed for explicit full-file bzip2")
ref_image.write(test_file)
test_image = galsim.fits.read(test_file)
np.testing.assert_array_equal(ref_array.astype(types[i]), test_image.array,
err_msg="Image"+tchar[i]+" write failed for auto full-file bzip2")
# With compression = None or 'none', astropy automatically figures it out anyway.
test_image = galsim.fits.read(test_file, compression=None)
np.testing.assert_array_equal(ref_array.astype(types[i]), test_image.array,
err_msg="Image"+tchar[i]+" write failed for auto full-file gzip")
assert_raises(OSError, galsim.fits.read, test_file0, compression='bzip2')
# Test rice
# Avoid astropy 5.3 issue reading rice-compressed file.
# cf. https://github.com/astropy/astropy/issues/15477
# Hopefull they will fix it before 5.4 comes out...
import astropy
if astropy.__version__ >= "5.3" and astropy.__version__ < "5.4": continue
test_file = os.path.join(datadir, "test"+tchar[i]+".fits.fz")
test_image = galsim.fits.read(test_file, compression='rice')
np.testing.assert_array_equal(ref_array.astype(types[i]), test_image.array,
err_msg="Image"+tchar[i]+" read failed for explicit rice")
test_image = galsim.fits.read(test_file)
np.testing.assert_array_equal(ref_array.astype(types[i]), test_image.array,
err_msg="Image"+tchar[i]+" read failed for auto rice")
test_file = os.path.join(datadir, "test"+tchar[i]+"_internal.fits.fz")
ref_image.write(test_file, compression='rice')
test_image = galsim.fits.read(test_file)
np.testing.assert_array_equal(ref_array.astype(types[i]), test_image.array,
err_msg="Image"+tchar[i]+" write failed for explicit rice")
ref_image.write(test_file)
test_image = galsim.fits.read(test_file)
np.testing.assert_array_equal(ref_array.astype(types[i]), test_image.array,
err_msg="Image"+tchar[i]+" write failed for auto rice")
assert_raises(OSError, galsim.fits.read, test_file0, compression='rice')
assert_raises(OSError, galsim.fits.read, test_file, compression='none')
# Test gzip_tile
test_file = os.path.join(datadir, "test"+tchar[i]+"_internal.fits.gzt")
ref_image.write(test_file, compression='gzip_tile')
test_image = galsim.fits.read(test_file, compression='gzip_tile')
np.testing.assert_array_equal(ref_array.astype(types[i]), test_image.array,
err_msg="Image"+tchar[i]+" write failed for gzip_tile")
assert_raises(OSError, galsim.fits.read, test_file0, compression='gzip_tile')
assert_raises(OSError, galsim.fits.read, test_file, compression='none')
# Test hcompress
# Note: hcompress is a lossy algorithm, and starting with astropy 2.0.5,
# the fidelity of the reconstruction is really quite poor, so only test with
# rtol=0.1. I'm not sure if this is a bug in astropy, or just the nature
# of the hcompress algorithm. But I'm ignoring it for now, since I don't
# think too many people use hcompress anyway.
test_file = os.path.join(datadir, "test"+tchar[i]+"_internal.fits.hc")
ref_image.write(test_file, compression='hcompress')
test_image = galsim.fits.read(test_file, compression='hcompress')
np.testing.assert_allclose(ref_array.astype(types[i]), test_image.array, rtol=0.1,
err_msg="Image"+tchar[i]+" write failed for hcompress")
assert_raises(OSError, galsim.fits.read, test_file0, compression='hcompress')
assert_raises(OSError, galsim.fits.read, test_file, compression='none')
# Test plio (only valid on positive integer values)
if tchar[i] in ['S', 'I']:
test_file = os.path.join(datadir, "test"+tchar[i]+"_internal.fits.plio")
ref_image.write(test_file, compression='plio')
test_image = galsim.fits.read(test_file, compression='plio')
np.testing.assert_array_equal(ref_array.astype(types[i]), test_image.array,
err_msg="Image"+tchar[i]+" write failed for plio")
assert_raises(OSError, galsim.fits.read, test_file0, compression='plio')
assert_raises(OSError, galsim.fits.read, test_file, compression='none')
# Check a file with no WCS information
nowcs_file = 'fits_files/blankimg.fits'
im = galsim.fits.read(nowcs_file)
assert im.wcs == galsim.PixelScale(1.0)
# If desired, can get a warning about this
with assert_warns(galsim.GalSimWarning):
im = galsim.fits.read(nowcs_file, suppress_warning=False)
assert im.wcs == galsim.PixelScale(1.0)
@timer
def test_Image_MultiFITS_IO():
"""Test that all six FITS reference images are correctly read in by both PyFITS and our Image
wrappers.
"""
for i in range(ntypes):
array_type = types[i]
if tchar[i][0] == 'C':
# Cannot write complex Images to fits. Check for an exception and continue.
ref_image = galsim.Image(ref_array.astype(array_type))
image_list = []
for k in range(nimages):
image_list.append(ref_image + k)
test_multi_file = os.path.join(datadir, "test_multi"+tchar[i]+".fits")
with assert_raises(ValueError):
galsim.fits.writeMulti(image_list, test_multi_file)
continue
#
# Test input from an external multi-extension fits file
#
test_multi_file = os.path.join(datadir, "test_multi"+tchar[i]+".fits")
# Check pyfits read for sanity
with pyfits.open(test_multi_file) as fits:
test_array = fits[0].data
np.testing.assert_array_equal(ref_array.astype(types[i]), test_array,
err_msg="PyFITS failing to read multi file.")
# Then use galsim fits.readMulti function
# First version: use pyfits HDUList
with pyfits.open(test_multi_file) as hdu:
test_image_list = galsim.fits.readMulti(hdu_list=hdu)
for k in range(nimages):
np.testing.assert_array_equal((ref_array+k).astype(types[i]),
test_image_list[k].array,
err_msg="Failed reading from PyFITS PrimaryHDU input.")
# Second version: use file name
test_image_list = galsim.fits.readMulti(test_multi_file)
for k in range(nimages):
np.testing.assert_array_equal((ref_array+k).astype(types[i]),
test_image_list[k].array,
err_msg="Image"+tchar[i]+" readMulti failed reading from filename input.")
#
# Test full I/O for an internally-generated multi-extension fits file
#
# Build a list of images with different values
ref_image = galsim.Image(ref_array.astype(array_type))
image_list = []
for k in range(nimages):
image_list.append(ref_image + k)
# Write the list to a multi-extension fits file
test_multi_file = os.path.join(datadir, "test_multi"+tchar[i]+"_internal.fits")
galsim.fits.writeMulti(image_list,test_multi_file)
# Check pyfits read for sanity
with pyfits.open(test_multi_file) as fits:
test_array = fits[0].data
np.testing.assert_array_equal(ref_array.astype(types[i]), test_array,
err_msg="PyFITS failing to read multi file.")
# Then use galsim fits.readMulti function
# First version: use pyfits HDUList
with pyfits.open(test_multi_file) as hdu:
test_image_list = galsim.fits.readMulti(hdu_list=hdu)
for k in range(nimages):
np.testing.assert_array_equal((ref_array+k).astype(types[i]),
test_image_list[k].array,
err_msg="Failed reading from PyFITS PrimaryHDU input.")
# Second version: use file name
test_image_list = galsim.fits.readMulti(test_multi_file)
for k in range(nimages):
np.testing.assert_array_equal((ref_array+k).astype(types[i]),
test_image_list[k].array,
err_msg="Image"+tchar[i]+" readMulti failed reading from filename input.")
#
# Test writing to hdu_list directly and then writing to file.
#
# Start with empty hdu_list
hdu_list = pyfits.HDUList()
# Add each image one at a time
for k in range(nimages):
image = ref_image + k
galsim.fits.write(image, hdu_list=hdu_list)
# Write it out with writeFile
galsim.fits.writeFile(test_multi_file, hdu_list)
# Check that reading it back in gives the same values
test_image_list = galsim.fits.readMulti(test_multi_file)
for k in range(nimages):
np.testing.assert_array_equal((ref_array+k).astype(types[i]),
test_image_list[k].array,
err_msg="Image"+tchar[i]+" readMulti failed after using writeFile")
# Can also use writeMulti to write directly to an hdu list
hdu_list = pyfits.HDUList()
galsim.fits.writeMulti(image_list, hdu_list=hdu_list)
galsim.fits.writeFile(test_multi_file, hdu_list)
test_image_list = galsim.fits.readMulti(test_multi_file)
for k in range(nimages):
np.testing.assert_array_equal((ref_array+k).astype(types[i]),
test_image_list[k].array,
err_msg="Image"+tchar[i]+" readMulti failed after using writeFile")
assert_raises(ValueError, galsim.fits.readMulti, test_multi_file, compression='invalid')
assert_raises(ValueError, galsim.fits.writeMulti, image_list, test_multi_file,
compression='invalid')
assert_raises(ValueError, galsim.fits.writeFile, image_list, test_multi_file,
compression='invalid')
assert_raises(OSError, galsim.fits.readMulti, test_multi_file, compression='rice')
assert_raises(OSError, galsim.fits.readFile, test_multi_file, compression='rice')
assert_raises(OSError, galsim.fits.readMulti, hdu_list=pyfits.HDUList())
assert_raises(OSError, galsim.fits.readMulti, hdu_list=pyfits.HDUList(), compression='rice')
assert_raises(OSError, galsim.fits.readMulti, 'invalid.fits')
assert_raises(OSError, galsim.fits.readFile, 'invalid.fits')
assert_raises(TypeError, galsim.fits.readMulti)
assert_raises(TypeError, galsim.fits.readMulti, test_multi_file, hdu_list=hdu)
assert_raises(TypeError, galsim.fits.readMulti, hdu_list=test_multi_file)
assert_raises(TypeError, galsim.fits.writeMulti)
assert_raises(TypeError, galsim.fits.writeMulti, image_list)
assert_raises(TypeError, galsim.fits.writeMulti, image_list,
file_name=test_multi_file, hdu_list=hdu)
assert_raises(OSError, galsim.fits.writeMulti, image_list, test_multi_file, clobber=False)
assert_raises(TypeError, galsim.fits.writeFile)
assert_raises(TypeError, galsim.fits.writeFile, image_list)
assert_raises(ValueError, galsim.fits.writeFile, test_multi_file, image_list,
compression='invalid')
assert_raises(ValueError, galsim.fits.writeFile, test_multi_file, image_list,
compression='rice')
assert_raises(ValueError, galsim.fits.writeFile, test_multi_file, image_list,
compression='gzip_tile')
assert_raises(ValueError, galsim.fits.writeFile, test_multi_file, image_list,
compression='hcompress')
assert_raises(ValueError, galsim.fits.writeFile, test_multi_file, image_list,
compression='plio')
galsim.fits.writeFile(test_multi_file, hdu_list)
assert_raises(OSError, galsim.fits.writeFile, test_multi_file, image_list, clobber=False)
#
# Test various compression schemes
#
# These tests are a bit slow, so we only bother to run them for the first dtype
# when doing the regular unit tests. When running python test_image.py, all of them
# will run, so when working on the code, it is a good idea to run the tests that way.
if i > 0 and __name__ != "__main__":
continue
test_multi_file0 = test_multi_file
# Test full-file gzip
test_multi_file = os.path.join(datadir, "test_multi"+tchar[i]+".fits.gz")
test_image_list = galsim.fits.readMulti(test_multi_file, compression='gzip')
for k in range(nimages):
np.testing.assert_array_equal((ref_array+k).astype(types[i]),
test_image_list[k].array,
err_msg="Image"+tchar[i]+" readMulti failed for explicit full-file gzip")
test_image_list = galsim.fits.readMulti(test_multi_file)
for k in range(nimages):
np.testing.assert_array_equal((ref_array+k).astype(types[i]),
test_image_list[k].array,
err_msg="Image"+tchar[i]+" readMulti failed for auto full-file gzip")
test_multi_file = os.path.join(datadir, "test_multi"+tchar[i]+"_internal.fits.gz")
galsim.fits.writeMulti(image_list,test_multi_file, compression='gzip')
test_image_list = galsim.fits.readMulti(test_multi_file)
for k in range(nimages):
np.testing.assert_array_equal((ref_array+k).astype(types[i]),
test_image_list[k].array,
err_msg="Image"+tchar[i]+" writeMulti failed for explicit full-file gzip")
galsim.fits.writeMulti(image_list,test_multi_file)
test_image_list = galsim.fits.readMulti(test_multi_file)
for k in range(nimages):
np.testing.assert_array_equal((ref_array+k).astype(types[i]),
test_image_list[k].array,
err_msg="Image"+tchar[i]+" writeMulti failed for auto full-file gzip")
# With compression = None or 'none', astropy automatically figures it out anyway.
test_image_list = galsim.fits.readMulti(test_multi_file, compression=None)
for k in range(nimages):
np.testing.assert_array_equal((ref_array+k).astype(types[i]),
test_image_list[k].array,
err_msg="Image"+tchar[i]+" writeMulti failed for auto full-file gzip")
assert_raises(OSError, galsim.fits.readMulti, test_multi_file0, compression='gzip')
# Test full-file bzip2
test_multi_file = os.path.join(datadir, "test_multi"+tchar[i]+".fits.bz2")
test_image_list = galsim.fits.readMulti(test_multi_file, compression='bzip2')
for k in range(nimages):
np.testing.assert_array_equal((ref_array+k).astype(types[i]),
test_image_list[k].array,
err_msg="Image"+tchar[i]+" readMulti failed for explicit full-file bzip2")
test_image_list = galsim.fits.readMulti(test_multi_file)
for k in range(nimages):
np.testing.assert_array_equal((ref_array+k).astype(types[i]),
test_image_list[k].array,
err_msg="Image"+tchar[i]+" readMulti failed for auto full-file bzip2")
test_multi_file = os.path.join(datadir, "test_multi"+tchar[i]+"_internal.fits.bz2")
galsim.fits.writeMulti(image_list,test_multi_file, compression='bzip2')
test_image_list = galsim.fits.readMulti(test_multi_file)
for k in range(nimages):
np.testing.assert_array_equal((ref_array+k).astype(types[i]),
test_image_list[k].array,
err_msg="Image"+tchar[i]+" writeMulti failed for explicit full-file bzip2")
galsim.fits.writeMulti(image_list,test_multi_file)
test_image_list = galsim.fits.readMulti(test_multi_file)
for k in range(nimages):
np.testing.assert_array_equal((ref_array+k).astype(types[i]),
test_image_list[k].array,
err_msg="Image"+tchar[i]+" writeMulti failed for auto full-file bzip2")
# With compression = None or 'none', astropy automatically figures it out anyway.
test_image_list = galsim.fits.readMulti(test_multi_file, compression=None)
for k in range(nimages):
np.testing.assert_array_equal((ref_array+k).astype(types[i]),
test_image_list[k].array,
err_msg="Image"+tchar[i]+" writeMulti failed for auto full-file gzip")
assert_raises(OSError, galsim.fits.readMulti, test_multi_file0, compression='bzip2')
# Test rice
# Avoid astropy 5.3 issue reading rice-compressed file.
# cf. https://github.com/astropy/astropy/issues/15477
# Hopefull they will fix it before 5.4 comes out...
import astropy
if astropy.__version__ >= "5.3" and astropy.__version__ < "5.4": continue
test_multi_file = os.path.join(datadir, "test_multi"+tchar[i]+".fits.fz")
test_image_list = galsim.fits.readMulti(test_multi_file, compression='rice')
for k in range(nimages):
np.testing.assert_array_equal((ref_array+k).astype(types[i]),
test_image_list[k].array,
err_msg="Image"+tchar[i]+" readMulti failed for explicit rice")
test_image_list = galsim.fits.readMulti(test_multi_file)
for k in range(nimages):
np.testing.assert_array_equal((ref_array+k).astype(types[i]),
test_image_list[k].array,
err_msg="Image"+tchar[i]+" readMulti failed for auto rice")
test_multi_file = os.path.join(datadir, "test_multi"+tchar[i]+"_internal.fits.fz")
galsim.fits.writeMulti(image_list,test_multi_file, compression='rice')
test_image_list = galsim.fits.readMulti(test_multi_file)
for k in range(nimages):
np.testing.assert_array_equal((ref_array+k).astype(types[i]),
test_image_list[k].array,
err_msg="Image"+tchar[i]+" writeMulti failed for explicit rice")
galsim.fits.writeMulti(image_list,test_multi_file)
test_image_list = galsim.fits.readMulti(test_multi_file)
for k in range(nimages):
np.testing.assert_array_equal((ref_array+k).astype(types[i]),
test_image_list[k].array,
err_msg="Image"+tchar[i]+" writeMulti failed for auto rice")
assert_raises(OSError, galsim.fits.readMulti, test_multi_file0, compression='rice')
assert_raises(OSError, galsim.fits.readMulti, test_multi_file, compression='none')
# Test gzip_tile
test_multi_file = os.path.join(datadir, "test_multi"+tchar[i]+"_internal.fits.gzt")
galsim.fits.writeMulti(image_list,test_multi_file, compression='gzip_tile')
test_image_list = galsim.fits.readMulti(test_multi_file, compression='gzip_tile')
for k in range(nimages):
np.testing.assert_array_equal((ref_array+k).astype(types[i]),
test_image_list[k].array,
err_msg="Image"+tchar[i]+" writeMulti failed for gzip_tile")
assert_raises(OSError, galsim.fits.readMulti, test_multi_file0, compression='gzip_tile')
assert_raises(OSError, galsim.fits.readMulti, test_multi_file, compression='none')
# Test hcompress
test_multi_file = os.path.join(datadir, "test_multi"+tchar[i]+"_internal.fits.hc")
galsim.fits.writeMulti(image_list,test_multi_file, compression='hcompress')
test_image_list = galsim.fits.readMulti(test_multi_file, compression='hcompress')
for k in range(nimages):
np.testing.assert_allclose((ref_array+k).astype(types[i]),
test_image_list[k].array, rtol=0.1,