1
|
|
|
# -*- coding: utf-8 -*- |
2
|
|
|
# vim:fileencoding=utf-8 |
3
|
|
|
# |
4
|
|
|
# Copyright (c) 2018 Stefan Bender |
5
|
|
|
# |
6
|
|
|
# This module is part of sciapy. |
7
|
|
|
# sciapy is free software: you can redistribute it or modify |
8
|
|
|
# it under the terms of the GNU General Public License as published |
9
|
|
|
# by the Free Software Foundation, version 2. |
10
|
|
|
# See accompanying LICENSE file or http://www.gnu.org/licenses/gpl-2.0.html. |
11
|
|
|
"""SCIAMACHY level 1c tests |
12
|
|
|
""" |
13
|
|
|
import os |
14
|
|
|
|
15
|
|
|
import numpy as np |
16
|
|
|
|
17
|
|
|
import sciapy.level1c |
18
|
|
|
|
19
|
|
|
|
20
|
|
|
def test_module_object_structure(): |
21
|
|
|
assert sciapy.level1c |
22
|
|
|
assert sciapy.level1c.scia_limb |
23
|
|
|
assert sciapy.level1c.scia_limb.scia_limb_point |
24
|
|
|
assert sciapy.level1c.scia_limb.scia_limb_scan |
25
|
|
|
assert sciapy.level1c.scia_limb_point |
26
|
|
|
assert sciapy.level1c.scia_limb_scan |
27
|
|
|
assert sciapy.level1c.scia_solar |
28
|
|
|
|
29
|
|
|
|
30
|
|
|
def test_limbmodule_method_structure(): |
31
|
|
|
assert sciapy.level1c.scia_limb.scia_limb_point.from_limb_scan |
32
|
|
|
assert sciapy.level1c.scia_limb_point.from_limb_scan |
33
|
|
|
assert sciapy.level1c.scia_limb.scia_limb_scan.assemble_textheader |
34
|
|
|
assert sciapy.level1c.scia_limb.scia_limb_scan.local_solar_time |
35
|
|
|
assert sciapy.level1c.scia_limb.scia_limb_scan.parse_textheader |
36
|
|
|
assert sciapy.level1c.scia_limb.scia_limb_scan.read_from_file |
37
|
|
|
assert sciapy.level1c.scia_limb.scia_limb_scan.read_from_hdf5 |
38
|
|
|
assert sciapy.level1c.scia_limb.scia_limb_scan.read_from_mpl_binary |
39
|
|
|
assert sciapy.level1c.scia_limb.scia_limb_scan.read_from_netcdf |
40
|
|
|
assert sciapy.level1c.scia_limb.scia_limb_scan.read_from_textfile |
41
|
|
|
assert sciapy.level1c.scia_limb.scia_limb_scan.write_to_mpl_binary |
42
|
|
|
assert sciapy.level1c.scia_limb.scia_limb_scan.write_to_netcdf |
43
|
|
|
assert sciapy.level1c.scia_limb.scia_limb_scan.write_to_textfile |
44
|
|
|
assert sciapy.level1c.scia_limb_scan.assemble_textheader |
45
|
|
|
assert sciapy.level1c.scia_limb_scan.local_solar_time |
46
|
|
|
assert sciapy.level1c.scia_limb_scan.parse_textheader |
47
|
|
|
assert sciapy.level1c.scia_limb_scan.read_from_file |
48
|
|
|
assert sciapy.level1c.scia_limb_scan.read_from_hdf5 |
49
|
|
|
assert sciapy.level1c.scia_limb_scan.read_from_mpl_binary |
50
|
|
|
assert sciapy.level1c.scia_limb_scan.read_from_netcdf |
51
|
|
|
assert sciapy.level1c.scia_limb_scan.read_from_textfile |
52
|
|
|
assert sciapy.level1c.scia_limb_scan.write_to_mpl_binary |
53
|
|
|
assert sciapy.level1c.scia_limb_scan.write_to_netcdf |
54
|
|
|
assert sciapy.level1c.scia_limb_scan.write_to_textfile |
55
|
|
|
|
56
|
|
|
|
57
|
|
|
def test_solarmodule_method_structure(): |
58
|
|
|
assert sciapy.level1c.scia_solar.read_from_hdf5 |
59
|
|
|
assert sciapy.level1c.scia_solar.read_from_netcdf |
60
|
|
|
assert sciapy.level1c.scia_solar.read_from_textfile |
61
|
|
|
assert sciapy.level1c.scia_solar.read_from_file |
62
|
|
|
assert sciapy.level1c.scia_solar.write_to_netcdf |
63
|
|
|
assert sciapy.level1c.scia_solar.write_to_textfile |
64
|
|
|
|
65
|
|
|
|
66
|
|
|
DATADIR = os.path.join(".", "tests", "data", "l1c") |
67
|
|
|
IFILE = os.path.join( |
68
|
|
|
DATADIR, "2010", "20100203", |
69
|
|
|
"SCIA_limb_20100203_015238_1_0_41454.dat.l_mpl_binary", |
70
|
|
|
) |
71
|
|
|
IFILE_SOLAR = os.path.join( |
72
|
|
|
DATADIR, "2010", "20100203", |
73
|
|
|
"SCIA_solar_20100203_013027_D0_41454.dat", |
74
|
|
|
) |
75
|
|
|
|
76
|
|
|
|
77
|
|
|
def _assert_class_equal(l, r): |
78
|
|
|
for _k, _l in l.__dict__.items(): |
79
|
|
|
_r = r.__dict__[_k] |
80
|
|
|
assert np.all(_l == _r), (_k, _l, _r) |
81
|
|
|
|
82
|
|
|
|
83
|
|
|
def test_level1c_round_trip_mpl(tmpdir): |
84
|
|
|
obase = os.path.join(tmpdir, "test_l1c_t") |
85
|
|
|
ofmpl = obase + ".l_mpl_binary" |
86
|
|
|
l1c_o = sciapy.level1c.scia_limb_scan() |
87
|
|
|
l1c_o.read_from_file(IFILE) |
88
|
|
|
l1c_o.write_to_mpl_binary(ofmpl) |
89
|
|
|
l1c_t = sciapy.level1c.scia_limb_scan() |
90
|
|
|
l1c_t.read_from_mpl_binary(ofmpl) |
91
|
|
|
_assert_class_equal(l1c_o, l1c_t) |
92
|
|
|
|
93
|
|
|
|
94
|
|
|
def test_level1c_round_trip_nc(tmpdir): |
95
|
|
|
obase = os.path.join(tmpdir, "test_l1c_t") |
96
|
|
|
ofnc = obase + ".nc" |
97
|
|
|
l1c_o = sciapy.level1c.scia_limb_scan() |
98
|
|
|
l1c_o.read_from_file(IFILE) |
99
|
|
|
l1c_o.write_to_netcdf(ofnc) |
100
|
|
|
l1c_t = sciapy.level1c.scia_limb_scan() |
101
|
|
|
l1c_t.read_from_netcdf(ofnc) |
102
|
|
|
_assert_class_equal(l1c_o, l1c_t) |
103
|
|
|
|
104
|
|
|
|
105
|
|
|
def test_level1c_round_trip_txt(tmpdir): |
106
|
|
|
obase = os.path.join(tmpdir, "test_l1c_t") |
107
|
|
|
oftxt = obase + ".dat" |
108
|
|
|
l1c_o = sciapy.level1c.scia_limb_scan() |
109
|
|
|
l1c_o.read_from_file(IFILE) |
110
|
|
|
l1c_o.write_to_textfile(oftxt) |
111
|
|
|
l1c_t = sciapy.level1c.scia_limb_scan() |
112
|
|
|
l1c_t.read_from_textfile(oftxt) |
113
|
|
|
_assert_class_equal(l1c_o, l1c_t) |
114
|
|
|
|
115
|
|
|
|
116
|
|
|
def test_solar_round_trip_nc(tmpdir): |
117
|
|
|
obase = os.path.join(tmpdir, "test_l1c_sol_t") |
118
|
|
|
ofnc = obase + ".nc" |
119
|
|
|
l1c_o = sciapy.level1c.scia_solar() |
120
|
|
|
l1c_o.read_from_file(IFILE_SOLAR) |
121
|
|
|
# test original read |
122
|
|
|
np.testing.assert_allclose(l1c_o.wls, [230.0, 250.0]) |
123
|
|
|
np.testing.assert_allclose(l1c_o.rads, [3.57275e+12, 8.17662e+12]) |
124
|
|
|
# test round trip |
125
|
|
|
l1c_o.write_to_netcdf(ofnc) |
126
|
|
|
l1c_t = sciapy.level1c.scia_solar() |
127
|
|
|
l1c_t.read_from_netcdf(ofnc) |
128
|
|
|
_assert_class_equal(l1c_o, l1c_t) |
129
|
|
|
|
130
|
|
|
|
131
|
|
|
def test_solar_round_trip_txt(tmpdir): |
132
|
|
|
obase = os.path.join(tmpdir, "test_l1c_sol_t") |
133
|
|
|
oftxt = obase + ".dat" |
134
|
|
|
l1c_o = sciapy.level1c.scia_solar() |
135
|
|
|
l1c_o.read_from_file(IFILE_SOLAR) |
136
|
|
|
# test original read |
137
|
|
|
np.testing.assert_allclose(l1c_o.wls, [230.0, 250.0]) |
138
|
|
|
np.testing.assert_allclose(l1c_o.rads, [3.57275e+12, 8.17662e+12]) |
139
|
|
|
# test round trip |
140
|
|
|
l1c_o.write_to_textfile(oftxt) |
141
|
|
|
l1c_t = sciapy.level1c.scia_solar() |
142
|
|
|
l1c_t.read_from_textfile(oftxt) |
143
|
|
|
_assert_class_equal(l1c_o, l1c_t) |
144
|
|
|
|