-
Notifications
You must be signed in to change notification settings - Fork 284
/
test_seviri_l1b_native.py
1412 lines (1271 loc) · 57.6 KB
/
test_seviri_l1b_native.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (c) 2017-2019 Satpy developers
#
# This file is part of satpy.
#
# satpy is free software: you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation, either version 3 of the License, or (at your option) any later
# version.
#
# satpy is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# satpy. If not, see <http://www.gnu.org/licenses/>.
"""Unittesting the Native SEVIRI reader."""
from __future__ import annotations
import os
import unittest
import warnings
from datetime import datetime
from unittest import mock
import dask.array as da
import numpy as np
import pytest
import xarray as xr
from satpy.readers.eum_base import time_cds_short
from satpy.readers.seviri_l1b_native import ImageBoundaries, NativeMSGFileHandler, Padder, get_available_channels
from satpy.tests.reader_tests.test_seviri_base import ORBIT_POLYNOMIALS, ORBIT_POLYNOMIALS_INVALID
from satpy.tests.reader_tests.test_seviri_l1b_calibration import TestFileHandlerCalibrationBase
from satpy.tests.utils import assert_attrs_equal, make_dataid
CHANNEL_INDEX_LIST = ['VIS006', 'VIS008', 'IR_016', 'IR_039',
'WV_062', 'WV_073', 'IR_087', 'IR_097',
'IR_108', 'IR_120', 'IR_134', 'HRV']
AVAILABLE_CHANNELS = {}
for item in CHANNEL_INDEX_LIST:
AVAILABLE_CHANNELS[item] = True
SEC15HDR = '15_SECONDARY_PRODUCT_HEADER'
IDS = 'SelectedBandIDs'
TEST1_HEADER_CHNLIST: dict[str, dict[str, dict]] = {SEC15HDR: {IDS: {}}}
TEST1_HEADER_CHNLIST[SEC15HDR][IDS]['Value'] = 'XX--XX--XX--'
TEST2_HEADER_CHNLIST: dict[str, dict[str, dict]] = {SEC15HDR: {IDS: {}}}
TEST2_HEADER_CHNLIST[SEC15HDR][IDS]['Value'] = 'XX-XXXX----X'
TEST3_HEADER_CHNLIST: dict[str, dict[str, dict]] = {SEC15HDR: {IDS: {}}}
TEST3_HEADER_CHNLIST[SEC15HDR][IDS]['Value'] = 'XXXXXXXXXXXX'
TEST_AREA_EXTENT_EARTHMODEL1_VISIR_FULLDISK = {
'earth_model': 1,
'dataset_id': make_dataid(name='VIS006', resolution=3000),
'is_full_disk': True,
'is_rapid_scan': 0,
'fill_disk': False,
'expected_area_def': {
'Area ID': 'msg_seviri_fes_3km',
'Projection': {'a': '6378169000', 'b': '6356583800', 'h': '35785831',
'lon_0': '0', 'no_defs': 'None', 'proj': 'geos',
'type': 'crs', 'units': 'm', 'x_0': '0', 'y_0': '0'},
'Number of columns': 3712,
'Number of rows': 3712,
'Area extent': (5568748.2758, 5568748.2758, -5568748.2758, -5568748.2758)
}
}
TEST_AREA_EXTENT_EARTHMODEL1_VISIR_RAPIDSCAN = {
'earth_model': 1,
'dataset_id': make_dataid(name='VIS006', resolution=3000),
'is_full_disk': False,
'is_rapid_scan': 1,
'fill_disk': False,
'expected_area_def': {
'Area ID': 'msg_seviri_rss_3km',
'Projection': {'a': '6378169000', 'b': '6356583800', 'h': '35785831',
'lon_0': '9.5', 'no_defs': 'None', 'proj': 'geos',
'type': 'crs', 'units': 'm', 'x_0': '0', 'y_0': '0'},
'Number of columns': 3712,
'Number of rows': 1392,
'Area extent': (5568748.275756836, 5568748.275756836, -5568748.275756836, 1392187.068939209)
}
}
TEST_AREA_EXTENT_EARTHMODEL1_VISIR_RAPIDSCAN_FILL = {
'earth_model': 1,
'dataset_id': make_dataid(name='VIS006', resolution=3000),
'is_full_disk': False,
'is_rapid_scan': 1,
'fill_disk': True,
'expected_area_def': {
'Area ID': 'msg_seviri_rss_3km',
'Projection': {'a': '6378169000', 'b': '6356583800', 'h': '35785831',
'lon_0': '9.5', 'no_defs': 'None', 'proj': 'geos',
'type': 'crs', 'units': 'm', 'x_0': '0', 'y_0': '0'},
'Number of columns': 3712,
'Number of rows': 3712,
'Area extent': (5568748.2758, 5568748.2758, -5568748.2758, -5568748.2758)
}
}
TEST_AREA_EXTENT_EARTHMODEL1_VISIR_ROI = {
'earth_model': 1,
'dataset_id': make_dataid(name='VIS006', resolution=3000),
'is_full_disk': False,
'is_rapid_scan': 0,
'fill_disk': False,
'expected_area_def': {
'Area ID': 'msg_seviri_fes_3km',
'Projection': {'a': '6378169000', 'b': '6356583800', 'h': '35785831',
'lon_0': '0', 'no_defs': 'None', 'proj': 'geos',
'type': 'crs', 'units': 'm', 'x_0': '0', 'y_0': '0'},
'Number of columns': 2516,
'Number of rows': 1829,
'Area extent': (5337717.232, 5154692.6389, -2211297.1332, -333044.7514)
}
}
TEST_AREA_EXTENT_EARTHMODEL1_VISIR_ROI_FILL = {
'earth_model': 1,
'dataset_id': make_dataid(name='VIS006', resolution=3000),
'is_full_disk': False,
'is_rapid_scan': 0,
'fill_disk': True,
'expected_area_def': {
'Area ID': 'msg_seviri_fes_3km',
'Projection': {'a': '6378169000', 'b': '6356583800', 'h': '35785831',
'lon_0': '0', 'no_defs': 'None', 'proj': 'geos',
'type': 'crs', 'units': 'm', 'x_0': '0', 'y_0': '0'},
'Number of columns': 3712,
'Number of rows': 3712,
'Area extent': (5568748.2758, 5568748.2758, -5568748.2758, -5568748.2758)
}
}
TEST_AREA_EXTENT_EARTHMODEL1_HRV_FULLDISK = {
'earth_model': 1,
'dataset_id': make_dataid(name='HRV', resolution=1000),
'is_full_disk': True,
'is_rapid_scan': 0,
'fill_disk': False,
'expected_area_def': {
'Area ID': 'msg_seviri_fes_1km',
'Projection': {'a': '6378169000', 'b': '6356583800', 'h': '35785831',
'lon_0': '0', 'no_defs': 'None', 'proj': 'geos',
'type': 'crs', 'units': 'm', 'x_0': '0', 'y_0': '0'},
'Number of columns': 5568,
'Number of rows': 11136,
'Area extent 0': (5567747.920155525, 2625352.665781975, -1000.1343488693237, -5567747.920155525),
'Area extent 1': (3602483.924627304, 5569748.188853264, -1966264.1298770905, 2625352.665781975)
}
}
TEST_AREA_EXTENT_EARTHMODEL1_HRV_FULLDISK_FILL = {
'earth_model': 1,
'dataset_id': make_dataid(name='HRV', resolution=1000),
'is_full_disk': True,
'is_rapid_scan': 0,
'fill_disk': True,
'expected_area_def': {
'Area ID': 'msg_seviri_fes_1km',
'Projection': {'a': '6378169000', 'b': '6356583800', 'h': '35785831',
'lon_0': '0', 'no_defs': 'None', 'proj': 'geos',
'type': 'crs', 'units': 'm', 'x_0': '0', 'y_0': '0'},
'Number of columns': 11136,
'Number of rows': 11136,
'Area extent': (5567747.920155525, 5569748.188853264, -5569748.188853264, -5567747.920155525)
}
}
TEST_AREA_EXTENT_EARTHMODEL1_HRV_RAPIDSCAN = {
'earth_model': 1,
'dataset_id': make_dataid(name='HRV', resolution=1000),
'is_full_disk': False,
'is_rapid_scan': 1,
'fill_disk': False,
'expected_area_def': {
'Area ID': 'msg_seviri_rss_1km',
'Projection': {'a': '6378169000', 'b': '6356583800', 'h': '35785831',
'lon_0': '9.5', 'no_defs': 'None', 'proj': 'geos',
'type': 'crs', 'units': 'm', 'x_0': '0', 'y_0': '0'},
'Number of columns': 5568,
'Number of rows': 8192,
'Area extent': (5567747.920155525, 2625352.665781975, -1000.1343488693237, -5567747.920155525)
}
}
TEST_AREA_EXTENT_EARTHMODEL1_HRV_RAPIDSCAN_FILL = {
'earth_model': 1,
'dataset_id': make_dataid(name='HRV', resolution=1000),
'is_full_disk': False,
'is_rapid_scan': 1,
'fill_disk': True,
'expected_area_def': {
'Area ID': 'msg_seviri_rss_1km',
'Projection': {'a': '6378169000', 'b': '6356583800', 'h': '35785831',
'lon_0': '9.5', 'no_defs': 'None', 'proj': 'geos',
'type': 'crs', 'units': 'm', 'x_0': '0', 'y_0': '0'},
'Number of columns': 11136,
'Number of rows': 11136,
'Area extent': (5567747.920155525, 5569748.188853264, -5569748.188853264, -5567747.920155525)
}
}
TEST_AREA_EXTENT_EARTHMODEL1_HRV_ROI = {
'earth_model': 1,
'dataset_id': make_dataid(name='HRV', resolution=1000),
'is_full_disk': False,
'is_rapid_scan': 0,
'fill_disk': False,
'expected_area_def': {
'Area ID': 'msg_seviri_fes_1km',
'Projection': {'a': '6378169000', 'b': '6356583800', 'h': '35785831',
'lon_0': '0', 'no_defs': 'None', 'proj': 'geos',
'type': 'crs', 'units': 'm', 'x_0': '0', 'y_0': '0'},
'Number of columns': 7548,
'Number of rows': 5487,
'Area extent': (5336716.885566711, 5155692.568421364, -2212297.179698944, -332044.6038246155)
}
}
TEST_AREA_EXTENT_EARTHMODEL1_HRV_ROI_FILL = {
'earth_model': 1,
'dataset_id': make_dataid(name='HRV', resolution=1000),
'is_full_disk': False,
'is_rapid_scan': 0,
'fill_disk': True,
'expected_area_def': {
'Area ID': 'msg_seviri_fes_1km',
'Projection': {'a': '6378169000', 'b': '6356583800', 'h': '35785831',
'lon_0': '0', 'no_defs': 'None', 'proj': 'geos',
'type': 'crs', 'units': 'm', 'x_0': '0', 'y_0': '0'},
'Number of columns': 11136,
'Number of rows': 11136,
'Area extent': (5567747.920155525, 5569748.188853264, -5569748.188853264, -5567747.920155525)
}
}
TEST_AREA_EXTENT_EARTHMODEL2_VISIR_FULLDISK = {
'earth_model': 2,
'dataset_id': make_dataid(name='VIS006', resolution=3000),
'is_full_disk': True,
'is_rapid_scan': 0,
'fill_disk': False,
'expected_area_def': {
'Area ID': 'msg_seviri_fes_3km',
'Projection': {'a': '6378169000', 'b': '6356583800', 'h': '35785831',
'lon_0': '0', 'no_defs': 'None', 'proj': 'geos',
'type': 'crs', 'units': 'm', 'x_0': '0', 'y_0': '0'},
'Number of columns': 3712,
'Number of rows': 3712,
'Area extent': (5567248.0742, 5570248.4773, -5570248.4773, -5567248.0742)
}
}
TEST_AREA_EXTENT_EARTHMODEL2_HRV_FULLDISK = {
'earth_model': 2,
'dataset_id': make_dataid(name='HRV', resolution=1000),
'is_full_disk': True,
'is_rapid_scan': 0,
'fill_disk': False,
'expected_area_def': {
'Area ID': 'msg_seviri_fes_1km',
'Projection': {'a': '6378169000', 'b': '6356583800', 'h': '35785831',
'lon_0': '0', 'no_defs': 'None', 'proj': 'geos',
'type': 'crs', 'units': 'm', 'x_0': '0', 'y_0': '0'},
'Number of columns': 5568,
'Number of rows': 11136,
'Area extent 0': (5566247.718632221, 2626852.867305279, -2500.3358721733093, -5566247.718632221),
'Area extent 1': (3600983.723104, 5571248.390376568, -1967764.3314003944, 2626852.867305279)
}
}
TEST_AREA_EXTENT_EARTHMODEL2_HRV_FULLDISK_FILL = {
'earth_model': 2,
'dataset_id': make_dataid(name='HRV', resolution=1000),
'is_full_disk': True,
'is_rapid_scan': 0,
'fill_disk': True,
'expected_area_def': {
'Area ID': 'msg_seviri_fes_1km',
'Projection': {'a': '6378169000', 'b': '6356583800', 'h': '35785831',
'lon_0': '0', 'no_defs': 'None', 'proj': 'geos',
'type': 'crs', 'units': 'm', 'x_0': '0', 'y_0': '0'},
'Number of columns': 11136,
'Number of rows': 11136,
'Area extent': (5566247.718632221, 5571248.390376568, -5571248.390376568, -5566247.718632221)
}
}
TEST_AREA_EXTENT_EARTHMODEL2_VISIR_RAPIDSCAN = {
'earth_model': 2,
'dataset_id': make_dataid(name='VIS006', resolution=3000),
'is_full_disk': False,
'is_rapid_scan': 1,
'fill_disk': False,
'expected_area_def': {
'Area ID': 'msg_seviri_rss_3km',
'Projection': {'a': '6378169000', 'b': '6356583800', 'h': '35785831',
'lon_0': '9.5', 'no_defs': 'None', 'proj': 'geos',
'type': 'crs', 'units': 'm', 'x_0': '0', 'y_0': '0'},
'Number of columns': 3712,
'Number of rows': 1392,
'Area extent': (5567248.074173927, 5570248.477339745, -5570248.477339745, 1393687.2705221176)
}
}
TEST_AREA_EXTENT_EARTHMODEL2_VISIR_RAPIDSCAN_FILL = {
'earth_model': 2,
'dataset_id': make_dataid(name='VIS006', resolution=3000),
'is_full_disk': False,
'is_rapid_scan': 1,
'fill_disk': True,
'expected_area_def': {
'Area ID': 'msg_seviri_rss_3km',
'Projection': {'a': '6378169000', 'b': '6356583800', 'h': '35785831',
'lon_0': '9.5', 'no_defs': 'None', 'proj': 'geos',
'type': 'crs', 'units': 'm', 'x_0': '0', 'y_0': '0'},
'Number of columns': 3712,
'Number of rows': 3712,
'Area extent': (5567248.0742, 5570248.4773, -5570248.4773, -5567248.0742)
}
}
TEST_AREA_EXTENT_EARTHMODEL2_HRV_RAPIDSCAN = {
'earth_model': 2,
'dataset_id': make_dataid(name='HRV', resolution=1000),
'is_full_disk': False,
'is_rapid_scan': 1,
'fill_disk': False,
'expected_area_def': {
'Area ID': 'msg_seviri_rss_1km',
'Projection': {'a': '6378169000', 'b': '6356583800', 'h': '35785831',
'lon_0': '0', 'no_defs': 'None', 'proj': 'geos',
'type': 'crs', 'units': 'm', 'x_0': '0', 'y_0': '0'},
'Number of columns': 5568,
'Number of rows': 8192,
'Area extent': (5566247.718632221, 2626852.867305279, -2500.3358721733093, -5566247.718632221)
}
}
TEST_AREA_EXTENT_EARTHMODEL2_HRV_RAPIDSCAN_FILL = {
'earth_model': 2,
'dataset_id': make_dataid(name='HRV', resolution=1000),
'is_full_disk': False,
'is_rapid_scan': 1,
'fill_disk': True,
'expected_area_def': {
'Area ID': 'msg_seviri_rss_1km',
'Projection': {'a': '6378169000', 'b': '6356583800', 'h': '35785831',
'lon_0': '0', 'no_defs': 'None', 'proj': 'geos',
'type': 'crs', 'units': 'm', 'x_0': '0', 'y_0': '0'},
'Number of columns': 11136,
'Number of rows': 11136,
'Area extent': (5566247.718632221, 5571248.390376568, -5571248.390376568, -5566247.718632221)
}
}
TEST_AREA_EXTENT_EARTHMODEL2_VISIR_ROI = {
'earth_model': 2,
'dataset_id': make_dataid(name='VIS006', resolution=3000),
'is_full_disk': False,
'is_rapid_scan': 0,
'fill_disk': False,
'expected_area_def': {
'Area ID': 'msg_seviri_fes_3km',
'Projection': {'a': '6378169000', 'b': '6356583800', 'h': '35785831',
'lon_0': '0', 'no_defs': 'None', 'proj': 'geos',
'type': 'crs', 'units': 'm', 'x_0': '0', 'y_0': '0'},
'Number of columns': 2516,
'Number of rows': 1829,
'Area extent': (5336217.0304, 5156192.8405, -2212797.3348, -331544.5498)
}
}
TEST_AREA_EXTENT_EARTHMODEL2_VISIR_ROI_FILL = {
'earth_model': 2,
'dataset_id': make_dataid(name='VIS006', resolution=3000),
'is_full_disk': False,
'is_rapid_scan': 0,
'fill_disk': True,
'expected_area_def': {
'Area ID': 'msg_seviri_fes_3km',
'Projection': {'a': '6378169000', 'b': '6356583800', 'h': '35785831',
'lon_0': '0', 'no_defs': 'None', 'proj': 'geos',
'type': 'crs', 'units': 'm', 'x_0': '0', 'y_0': '0'},
'Number of columns': 3712,
'Number of rows': 3712,
'Area extent': (5567248.0742, 5570248.4773, -5570248.4773, -5567248.0742)
}
}
TEST_AREA_EXTENT_EARTHMODEL2_HRV_ROI = {
'earth_model': 2,
'dataset_id': make_dataid(name='HRV', resolution=1000),
'is_full_disk': False,
'is_rapid_scan': 0,
'fill_disk': False,
'expected_area_def': {
'Area ID': 'msg_seviri_fes_1km',
'Projection': {'a': '6378169000', 'b': '6356583800', 'h': '35785831',
'lon_0': '0', 'no_defs': 'None', 'proj': 'geos',
'type': 'crs', 'units': 'm', 'x_0': '0', 'y_0': '0'},
'Number of columns': 7548,
'Number of rows': 5487,
'Area extent': (5335216.684043407, 5157192.769944668, -2213797.381222248, -330544.4023013115)
}
}
TEST_AREA_EXTENT_EARTHMODEL2_HRV_ROI_FILL = {
'earth_model': 2,
'dataset_id': make_dataid(name='HRV', resolution=1000),
'is_full_disk': False,
'is_rapid_scan': 0,
'fill_disk': True,
'expected_area_def': {
'Area ID': 'msg_seviri_fes_1km',
'Projection': {'a': '6378169000', 'b': '6356583800', 'h': '35785831',
'lon_0': '0', 'no_defs': 'None', 'proj': 'geos',
'type': 'crs', 'units': 'm', 'x_0': '0', 'y_0': '0'},
'Number of columns': 11136,
'Number of rows': 11136,
'Area extent': (5566247.718632221, 5571248.390376568, -5571248.390376568, -5566247.718632221)
}
}
TEST_IS_ROI_FULLDISK = {
'is_full_disk': True,
'is_rapid_scan': 0,
'is_roi': False
}
TEST_IS_ROI_RAPIDSCAN = {
'is_full_disk': False,
'is_rapid_scan': 1,
'is_roi': False
}
TEST_IS_ROI_ROI = {
'is_full_disk': False,
'is_rapid_scan': 0,
'is_roi': True
}
TEST_CALIBRATION_MODE = {
'earth_model': 1,
'dataset_id': make_dataid(name='IR_108', calibration='radiance'),
'is_full_disk': True,
'is_rapid_scan': 0,
'calibration': 'radiance',
'CalSlope': [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 0.95, 0.96, 0.97],
'CalOffset': [-1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0],
'GSICSCalCoeff': [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 0.95, 0.96, 0.97],
'GSICSOffsetCount': [-51.0, -51.0, -51.0, -51.0, -51.0, -51.0, -51.0, -51.0, -51.0, -51.0, -51.0, -51.0]
}
TEST_PADDER_RSS_ROI = {
'img_bounds': {'south': [2], 'north': [4], 'east': [2], 'west': [3]},
'is_full_disk': False,
'dataset_id': make_dataid(name='VIS006'),
'dataset': xr.DataArray(np.ones((3, 2)), dims=['y', 'x']).astype(np.float32),
'final_shape': (5, 5),
'expected_padded_data': xr.DataArray(np.array([[np.nan, np.nan, np.nan, np.nan, np.nan],
[np.nan, 1.0, 1.0, np.nan, np.nan],
[np.nan, 1.0, 1.0, np.nan, np.nan],
[np.nan, 1.0, 1.0, np.nan, np.nan],
[np.nan, np.nan, np.nan, np.nan, np.nan]]),
dims=['y', 'x']).astype(np.float32)
}
TEST_PADDER_FES_HRV = {
'img_bounds': {'south': [1, 4], 'north': [3, 5], 'east': [2, 3], 'west': [3, 4]},
'is_full_disk': True,
'dataset_id': make_dataid(name='HRV'),
'dataset': xr.DataArray(np.ones((5, 2)), dims=['y', 'x']).astype(np.float32),
'final_shape': (5, 5),
'expected_padded_data': xr.DataArray(np.array([[np.nan, 1.0, 1.0, np.nan, np.nan],
[np.nan, 1.0, 1.0, np.nan, np.nan],
[np.nan, 1.0, 1.0, np.nan, np.nan],
[np.nan, np.nan, 1.0, 1.0, np.nan],
[np.nan, np.nan, 1.0, 1.0, np.nan]]),
dims=['y', 'x']).astype(np.float32)
}
class TestNativeMSGFileHandler(unittest.TestCase):
"""Test the NativeMSGFileHandler."""
def test_get_available_channels(self):
"""Test the derivation of the available channel list."""
available_chs = get_available_channels(TEST1_HEADER_CHNLIST)
trues = ['WV_062', 'WV_073', 'IR_108', 'VIS006', 'VIS008', 'IR_120']
for bandname in AVAILABLE_CHANNELS:
if bandname in trues:
self.assertTrue(available_chs[bandname])
else:
self.assertFalse(available_chs[bandname])
available_chs = get_available_channels(TEST2_HEADER_CHNLIST)
trues = ['VIS006', 'VIS008', 'IR_039', 'WV_062', 'WV_073', 'IR_087', 'HRV']
for bandname in AVAILABLE_CHANNELS:
if bandname in trues:
self.assertTrue(available_chs[bandname])
else:
self.assertFalse(available_chs[bandname])
available_chs = get_available_channels(TEST3_HEADER_CHNLIST)
for bandname in AVAILABLE_CHANNELS:
self.assertTrue(available_chs[bandname])
class TestNativeMSGArea(unittest.TestCase):
"""Test NativeMSGFileHandler.get_area_extent.
The expected results have been verified by manually
inspecting the output of geoferenced imagery.
"""
@staticmethod
def create_test_header(earth_model, dataset_id, is_full_disk, is_rapid_scan, good_qual='OK'):
"""Create mocked NativeMSGFileHandler.
Contains sufficient attributes for NativeMSGFileHandler.get_area_extent to be able to execute.
"""
if dataset_id['name'] == 'HRV':
reference_grid = 'ReferenceGridHRV'
column_dir_grid_step = 1.0001343488693237
line_dir_grid_step = 1.0001343488693237
else:
reference_grid = 'ReferenceGridVIS_IR'
column_dir_grid_step = 3.0004031658172607
line_dir_grid_step = 3.0004031658172607
if is_full_disk:
north = 3712
east = 1
west = 3712
south = 1
n_visir_cols = 3712
n_visir_lines = 3712
n_hrv_cols = 11136
n_hrv_lines = 11136
ssp_lon = 0
elif is_rapid_scan:
north = 3712
east = 1
west = 3712
south = 2321
n_visir_cols = 3712
n_visir_lines = 1392
n_hrv_cols = 11136
n_hrv_lines = 4176
ssp_lon = 9.5
else:
north = 3574
east = 78
west = 2591
south = 1746
n_visir_cols = 2516
n_visir_lines = north - south + 1
n_hrv_cols = n_visir_cols * 3
n_hrv_lines = n_visir_lines * 3
ssp_lon = 0
header = {
'15_MAIN_PRODUCT_HEADER': {
'QQOV': {'Name': 'QQOV',
'Value': good_qual}
},
'15_DATA_HEADER': {
'ImageDescription': {
reference_grid: {
'ColumnDirGridStep': column_dir_grid_step,
'LineDirGridStep': line_dir_grid_step,
'GridOrigin': 2, # south-east corner
},
'ProjectionDescription': {
'LongitudeOfSSP': ssp_lon
}
},
'GeometricProcessing': {
'EarthModel': {
'TypeOfEarthModel': earth_model,
'EquatorialRadius': 6378169.0,
'NorthPolarRadius': 6356583.800000001,
'SouthPolarRadius': 6356583.800000001,
}
},
'SatelliteStatus': {
'SatelliteDefinition': {
'SatelliteId': 324
}
}
},
'15_SECONDARY_PRODUCT_HEADER': {
'NorthLineSelectedRectangle': {'Value': north},
'EastColumnSelectedRectangle': {'Value': east},
'WestColumnSelectedRectangle': {'Value': west},
'SouthLineSelectedRectangle': {'Value': south},
'SelectedBandIDs': {'Value': 'xxxxxxxxxxxx'},
'NumberColumnsVISIR': {'Value': n_visir_cols},
'NumberLinesVISIR': {'Value': n_visir_lines},
'NumberColumnsHRV': {'Value': n_hrv_cols},
'NumberLinesHRV': {'Value': n_hrv_lines},
}
}
return header
@staticmethod
def create_test_trailer(is_rapid_scan):
"""Create Test Trailer.
Mocked Trailer with sufficient attributes for
NativeMSGFileHandler.get_area_extent to be able to execute.
"""
trailer = {
'15TRAILER': {
'ImageProductionStats': {
'ActualL15CoverageHRV': {
'UpperNorthLineActual': 11136,
'UpperWestColumnActual': 7533,
'UpperSouthLineActual': 8193,
'UpperEastColumnActual': 1966,
'LowerNorthLineActual': 8192,
'LowerWestColumnActual': 5568,
'LowerSouthLineActual': 1,
'LowerEastColumnActual': 1
},
'ActualScanningSummary': {
'ReducedScan': is_rapid_scan
}
}
}
}
return trailer
def prepare_area_defs(self, test_dict):
"""Prepare calculated and expected area definitions for equal checking."""
earth_model = test_dict['earth_model']
dataset_id = test_dict['dataset_id']
is_full_disk = test_dict['is_full_disk']
is_rapid_scan = test_dict['is_rapid_scan']
fill_disk = test_dict['fill_disk']
header = self.create_test_header(earth_model, dataset_id, is_full_disk, is_rapid_scan)
trailer = self.create_test_trailer(is_rapid_scan)
expected_area_def = test_dict['expected_area_def']
with mock.patch('satpy.readers.seviri_l1b_native.np.fromfile') as fromfile, \
mock.patch('satpy.readers.seviri_l1b_native.recarray2dict') as recarray2dict, \
mock.patch('satpy.readers.seviri_l1b_native.NativeMSGFileHandler._get_memmap') as _get_memmap, \
mock.patch('satpy.readers.seviri_l1b_native.NativeMSGFileHandler._read_trailer'), \
mock.patch(
'satpy.readers.seviri_l1b_native.NativeMSGFileHandler._has_archive_header'
) as _has_archive_header:
_has_archive_header.return_value = True
fromfile.return_value = header
recarray2dict.side_effect = (lambda x: x)
_get_memmap.return_value = np.arange(3)
fh = NativeMSGFileHandler(None, {}, None)
fh.fill_disk = fill_disk
fh.header = header
fh.trailer = trailer
fh.image_boundaries = ImageBoundaries(header, trailer, fh.mda)
calc_area_def = fh.get_area_def(dataset_id)
return (calc_area_def, expected_area_def)
# Earth model 1 tests
def test_earthmodel1_visir_fulldisk(self):
"""Test the VISIR FES with the EarthModel 1."""
calculated, expected = self.prepare_area_defs(
TEST_AREA_EXTENT_EARTHMODEL1_VISIR_FULLDISK
)
np.testing.assert_allclose(np.array(calculated.area_extent),
np.array(expected['Area extent']))
self.assertEqual(calculated.width, expected['Number of columns'])
self.assertEqual(calculated.height, expected['Number of rows'])
self.assertEqual(calculated.area_id, expected['Area ID'])
def test_earthmodel1_hrv_fulldisk(self):
"""Test the HRV FES with the EarthModel 1."""
calculated, expected = self.prepare_area_defs(
TEST_AREA_EXTENT_EARTHMODEL1_HRV_FULLDISK
)
np.testing.assert_allclose(np.array(calculated.defs[0].area_extent),
np.array(expected['Area extent 0']))
np.testing.assert_allclose(np.array(calculated.defs[1].area_extent),
np.array(expected['Area extent 1']))
self.assertEqual(calculated.width, expected['Number of columns'])
self.assertEqual(calculated.height, expected['Number of rows'])
self.assertEqual(calculated.defs[0].area_id, expected['Area ID'])
self.assertEqual(calculated.defs[1].area_id, expected['Area ID'])
def test_earthmodel1_hrv_fulldisk_fill(self):
"""Test the HRV FES padded to fulldisk with the EarthModel 1."""
calculated, expected = self.prepare_area_defs(
TEST_AREA_EXTENT_EARTHMODEL1_HRV_FULLDISK_FILL
)
np.testing.assert_allclose(np.array(calculated.area_extent),
np.array(expected['Area extent']))
self.assertEqual(calculated.width, expected['Number of columns'])
self.assertEqual(calculated.height, expected['Number of rows'])
self.assertEqual(calculated.area_id, expected['Area ID'])
def test_earthmodel1_visir_rapidscan(self):
"""Test the VISIR RSS with the EarthModel 1."""
calculated, expected = self.prepare_area_defs(
TEST_AREA_EXTENT_EARTHMODEL1_VISIR_RAPIDSCAN
)
np.testing.assert_allclose(np.array(calculated.area_extent),
np.array(expected['Area extent']))
self.assertEqual(calculated.width, expected['Number of columns'])
self.assertEqual(calculated.height, expected['Number of rows'])
self.assertEqual(calculated.area_id, expected['Area ID'])
def test_earthmodel1_visir_rapidscan_fill(self):
"""Test the VISIR RSS padded to fulldisk with the EarthModel 1."""
calculated, expected = self.prepare_area_defs(
TEST_AREA_EXTENT_EARTHMODEL1_VISIR_RAPIDSCAN_FILL
)
np.testing.assert_allclose(np.array(calculated.area_extent),
np.array(expected['Area extent']))
self.assertEqual(calculated.width, expected['Number of columns'])
self.assertEqual(calculated.height, expected['Number of rows'])
self.assertEqual(calculated.area_id, expected['Area ID'])
def test_earthmodel1_hrv_rapidscan(self):
"""Test the HRV RSS with the EarthModel 1."""
calculated, expected = self.prepare_area_defs(
TEST_AREA_EXTENT_EARTHMODEL1_HRV_RAPIDSCAN
)
np.testing.assert_allclose(np.array(calculated.area_extent),
np.array(expected['Area extent']))
self.assertEqual(calculated.width, expected['Number of columns'])
self.assertEqual(calculated.height, expected['Number of rows'])
self.assertEqual(calculated.area_id, expected['Area ID'])
def test_earthmodel1_hrv_rapidscan_fill(self):
"""Test the HRV RSS padded to fulldisk with the EarthModel 1."""
calculated, expected = self.prepare_area_defs(
TEST_AREA_EXTENT_EARTHMODEL1_HRV_RAPIDSCAN_FILL
)
np.testing.assert_allclose(np.array(calculated.area_extent),
np.array(expected['Area extent']))
self.assertEqual(calculated.width, expected['Number of columns'])
self.assertEqual(calculated.height, expected['Number of rows'])
self.assertEqual(calculated.area_id, expected['Area ID'])
def test_earthmodel1_visir_roi(self):
"""Test the VISIR ROI with the EarthModel 1."""
calculated, expected = self.prepare_area_defs(
TEST_AREA_EXTENT_EARTHMODEL1_VISIR_ROI
)
np.testing.assert_allclose(np.array(calculated.area_extent),
np.array(expected['Area extent']))
self.assertEqual(calculated.width, expected['Number of columns'])
self.assertEqual(calculated.height, expected['Number of rows'])
self.assertEqual(calculated.area_id, expected['Area ID'])
def test_earthmodel1_visir_roi_fill(self):
"""Test the VISIR ROI padded to fulldisk with the EarthModel 1."""
calculated, expected = self.prepare_area_defs(
TEST_AREA_EXTENT_EARTHMODEL1_VISIR_ROI_FILL
)
np.testing.assert_allclose(np.array(calculated.area_extent),
np.array(expected['Area extent']))
self.assertEqual(calculated.width, expected['Number of columns'])
self.assertEqual(calculated.height, expected['Number of rows'])
self.assertEqual(calculated.area_id, expected['Area ID'])
def test_earthmodel1_hrv_roi(self):
"""Test the HRV ROI with the EarthModel 1."""
calculated, expected = self.prepare_area_defs(
TEST_AREA_EXTENT_EARTHMODEL1_HRV_ROI
)
np.testing.assert_allclose(np.array(calculated.area_extent),
np.array(expected['Area extent']))
self.assertEqual(calculated.width, expected['Number of columns'])
self.assertEqual(calculated.height, expected['Number of rows'])
self.assertEqual(calculated.area_id, expected['Area ID'])
def test_earthmodel1_hrv_roi_fill(self):
"""Test the HRV ROI padded to fulldisk with the EarthModel 1."""
calculated, expected = self.prepare_area_defs(
TEST_AREA_EXTENT_EARTHMODEL1_HRV_ROI_FILL
)
np.testing.assert_allclose(np.array(calculated.area_extent),
np.array(expected['Area extent']))
self.assertEqual(calculated.width, expected['Number of columns'])
self.assertEqual(calculated.height, expected['Number of rows'])
self.assertEqual(calculated.area_id, expected['Area ID'])
# Earth model 2 tests
def test_earthmodel2_visir_fulldisk(self):
"""Test the VISIR FES with the EarthModel 2."""
calculated, expected = self.prepare_area_defs(
TEST_AREA_EXTENT_EARTHMODEL2_VISIR_FULLDISK
)
np.testing.assert_allclose(np.array(calculated.area_extent),
np.array(expected['Area extent']))
self.assertEqual(calculated.width, expected['Number of columns'])
self.assertEqual(calculated.height, expected['Number of rows'])
self.assertEqual(calculated.area_id, expected['Area ID'])
def test_earthmodel2_hrv_fulldisk(self):
"""Test the HRV FES with the EarthModel 2."""
calculated, expected = self.prepare_area_defs(
TEST_AREA_EXTENT_EARTHMODEL2_HRV_FULLDISK
)
np.testing.assert_allclose(np.array(calculated.defs[0].area_extent),
np.array(expected['Area extent 0']))
np.testing.assert_allclose(np.array(calculated.defs[1].area_extent),
np.array(expected['Area extent 1']))
self.assertEqual(calculated.width, expected['Number of columns'])
self.assertEqual(calculated.height, expected['Number of rows'])
self.assertEqual(calculated.defs[0].area_id, expected['Area ID'])
self.assertEqual(calculated.defs[1].area_id, expected['Area ID'])
def test_earthmodel2_hrv_fulldisk_fill(self):
"""Test the HRV FES padded to fulldisk with the EarthModel 2."""
calculated, expected = self.prepare_area_defs(
TEST_AREA_EXTENT_EARTHMODEL2_HRV_FULLDISK_FILL
)
np.testing.assert_allclose(np.array(calculated.area_extent),
np.array(expected['Area extent']))
self.assertEqual(calculated.width, expected['Number of columns'])
self.assertEqual(calculated.height, expected['Number of rows'])
self.assertEqual(calculated.area_id, expected['Area ID'])
def test_earthmodel2_visir_rapidscan(self):
"""Test the VISIR RSS with the EarthModel 2."""
calculated, expected = self.prepare_area_defs(
TEST_AREA_EXTENT_EARTHMODEL2_VISIR_RAPIDSCAN
)
np.testing.assert_allclose(np.array(calculated.area_extent),
np.array(expected['Area extent']))
self.assertEqual(calculated.width, expected['Number of columns'])
self.assertEqual(calculated.height, expected['Number of rows'])
self.assertEqual(calculated.area_id, expected['Area ID'])
def test_earthmodel2_visir_rapidscan_fill(self):
"""Test the VISIR RSS padded to fulldisk with the EarthModel 2."""
calculated, expected = self.prepare_area_defs(
TEST_AREA_EXTENT_EARTHMODEL2_VISIR_RAPIDSCAN_FILL
)
np.testing.assert_allclose(np.array(calculated.area_extent),
np.array(expected['Area extent']))
self.assertEqual(calculated.width, expected['Number of columns'])
self.assertEqual(calculated.height, expected['Number of rows'])
self.assertEqual(calculated.area_id, expected['Area ID'])
def test_earthmodel2_hrv_rapidscan(self):
"""Test the HRV RSS with the EarthModel 2."""
calculated, expected = self.prepare_area_defs(
TEST_AREA_EXTENT_EARTHMODEL2_HRV_RAPIDSCAN
)
np.testing.assert_allclose(np.array(calculated.area_extent),
np.array(expected['Area extent']))
self.assertEqual(calculated.width, expected['Number of columns'])
self.assertEqual(calculated.height, expected['Number of rows'])
self.assertEqual(calculated.area_id, expected['Area ID'])
def test_earthmodel2_hrv_rapidscan_fill(self):
"""Test the HRV RSS padded to fulldisk with the EarthModel 2."""
calculated, expected = self.prepare_area_defs(
TEST_AREA_EXTENT_EARTHMODEL2_HRV_RAPIDSCAN_FILL
)
np.testing.assert_allclose(np.array(calculated.area_extent),
np.array(expected['Area extent']))
self.assertEqual(calculated.width, expected['Number of columns'])
self.assertEqual(calculated.height, expected['Number of rows'])
self.assertEqual(calculated.area_id, expected['Area ID'])
def test_earthmodel2_visir_roi(self):
"""Test the VISIR ROI with the EarthModel 2."""
calculated, expected = self.prepare_area_defs(
TEST_AREA_EXTENT_EARTHMODEL2_VISIR_ROI
)
np.testing.assert_allclose(np.array(calculated.area_extent),
np.array(expected['Area extent']))
self.assertEqual(calculated.width, expected['Number of columns'])
self.assertEqual(calculated.height, expected['Number of rows'])
self.assertEqual(calculated.area_id, expected['Area ID'])
def test_earthmodel2_visir_roi_fill(self):
"""Test the VISIR ROI padded to fulldisk with the EarthModel 2."""
calculated, expected = self.prepare_area_defs(
TEST_AREA_EXTENT_EARTHMODEL2_VISIR_ROI_FILL
)
np.testing.assert_allclose(np.array(calculated.area_extent),
np.array(expected['Area extent']))
self.assertEqual(calculated.width, expected['Number of columns'])
self.assertEqual(calculated.height, expected['Number of rows'])
self.assertEqual(calculated.area_id, expected['Area ID'])
def test_earthmodel2_hrv_roi(self):
"""Test the HRV ROI with the EarthModel 2."""
calculated, expected = self.prepare_area_defs(
TEST_AREA_EXTENT_EARTHMODEL2_HRV_ROI
)
np.testing.assert_allclose(np.array(calculated.area_extent),
np.array(expected['Area extent']))
self.assertEqual(calculated.width, expected['Number of columns'])
self.assertEqual(calculated.height, expected['Number of rows'])
self.assertEqual(calculated.area_id, expected['Area ID'])
def test_earthmodel2_hrv_roi_fill(self):
"""Test the HRV ROI padded to fulldisk with the EarthModel 2."""
calculated, expected = self.prepare_area_defs(
TEST_AREA_EXTENT_EARTHMODEL2_HRV_ROI_FILL
)
np.testing.assert_allclose(np.array(calculated.area_extent),
np.array(expected['Area extent']))
self.assertEqual(calculated.width, expected['Number of columns'])
self.assertEqual(calculated.height, expected['Number of rows'])
self.assertEqual(calculated.area_id, expected['Area ID'])
# Test check for Region Of Interest (ROI) data
def prepare_is_roi(self, test_dict):
"""Prepare calculated and expected check for region of interest data for equal checking."""
earth_model = 2
dataset_id = make_dataid(name='VIS006')
is_full_disk = test_dict['is_full_disk']
is_rapid_scan = test_dict['is_rapid_scan']
header = self.create_test_header(earth_model, dataset_id, is_full_disk, is_rapid_scan)
trailer = self.create_test_trailer(is_rapid_scan)
expected_is_roi = test_dict['is_roi']
with mock.patch('satpy.readers.seviri_l1b_native.np.fromfile') as fromfile, \
mock.patch('satpy.readers.seviri_l1b_native.recarray2dict') as recarray2dict, \
mock.patch('satpy.readers.seviri_l1b_native.NativeMSGFileHandler._get_memmap') as _get_memmap, \
mock.patch('satpy.readers.seviri_l1b_native.NativeMSGFileHandler._read_trailer'), \
mock.patch(
'satpy.readers.seviri_l1b_native.NativeMSGFileHandler._has_archive_header'
) as _has_archive_header:
_has_archive_header.return_value = True
fromfile.return_value = header
recarray2dict.side_effect = (lambda x: x)
_get_memmap.return_value = np.arange(3)
fh = NativeMSGFileHandler(None, {}, None)
fh.header = header
fh.trailer = trailer
calc_is_roi = fh.is_roi()
return (calc_is_roi, expected_is_roi)
def test_is_roi_fulldisk(self):
"""Test check for region of interest with FES data."""
calculated, expected = self.prepare_is_roi(TEST_IS_ROI_FULLDISK)
self.assertEqual(calculated, expected)
def test_is_roi_rapidscan(self):
"""Test check for region of interest with RSS data."""
calculated, expected = self.prepare_is_roi(TEST_IS_ROI_RAPIDSCAN)
self.assertEqual(calculated, expected)
def test_is_roi_roi(self):
"""Test check for region of interest with ROI data."""
calculated, expected = self.prepare_is_roi(TEST_IS_ROI_ROI)
self.assertEqual(calculated, expected)
TEST_HEADER_CALIB = {
'RadiometricProcessing': {
'Level15ImageCalibration': {
'CalSlope': TestFileHandlerCalibrationBase.gains_nominal,
'CalOffset': TestFileHandlerCalibrationBase.offsets_nominal,
},
'MPEFCalFeedback': {
'GSICSCalCoeff': TestFileHandlerCalibrationBase.gains_gsics,
'GSICSOffsetCount': TestFileHandlerCalibrationBase.offsets_gsics