File: test_climetlab.py

package info (click to toggle)
ecmwflibs 2%3A0.6.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 388 kB
  • sloc: python: 720; sh: 536; cpp: 30; ansic: 16; makefile: 10
file content (183 lines) | stat: -rw-r--r-- 5,435 bytes parent folder | download
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
#!/usr/bin/env python3
import pytest
from Magics import macro


def test_climetlab_grib():
    actions = [
        macro.output(
            output_formats=["png"],
            output_name="climetlab_grib_1",
            output_name_first_page_number=False,
            output_width=680,
            page_frame=False,
            page_id_line=False,
            page_x_length=10.0,
            page_y_length=5.555555555555555,
            subpage_x_length=10.0,
            subpage_x_position=0.0,
            subpage_y_length=5.555555555555555,
            subpage_y_position=0.0,
            super_page_x_length=10.0,
            super_page_y_length=5.555555555555555,
        ),
        macro.mmap(
            subpage_lower_left_latitude=33.0,
            subpage_lower_left_longitude=-27.0,
            subpage_map_projection="cylindrical",
            subpage_upper_right_latitude=73.0,
            subpage_upper_right_longitude=45.0,
        ),
        macro.mcoast(
            map_boundaries=True,
            map_coastline_colour="tan",
            map_coastline_land_shade=True,
            map_coastline_land_shade_colour="cream",
            map_grid=False,
            map_grid_colour="tan",
            map_grid_frame=True,
            map_grid_frame_thickness=5,
            map_label=False,
        ),
        macro.mgrib(
            grib_field_position=0,
            grib_file_address_mode="byte_offset",
            grib_input_file_name="climetlab.grib",
        ),
        macro.mcont(
            contour_automatic_setting="climetlab",
            legend=False,
        ),
        macro.mcoast(
            map_grid=False,
            map_grid_frame=True,
            map_grid_frame_thickness=5,
            map_label=False,
        ),
    ]

    print(actions)

    macro.plot(*actions)

    actions = [
        macro.output(
            output_formats=["png"],
            output_name="climetlab_grib_2",
            output_name_first_page_number=False,
            output_width=680,
            page_frame=False,
            page_id_line=False,
            page_x_length=10.0,
            page_y_length=5.555555555555555,
            subpage_x_length=10.0,
            subpage_x_position=0.0,
            subpage_y_length=5.555555555555555,
            subpage_y_position=0.0,
            super_page_x_length=10.0,
            super_page_y_length=5.555555555555555,
        ),
        macro.mmap(
            subpage_lower_left_latitude=33.0,
            subpage_lower_left_longitude=-27.0,
            subpage_map_projection="cylindrical",
            subpage_upper_right_latitude=73.0,
            subpage_upper_right_longitude=45.0,
        ),
        macro.mcoast(
            map_boundaries=True,
            map_coastline_colour="tan",
            map_coastline_land_shade=True,
            map_coastline_land_shade_colour="cream",
            map_grid=False,
            map_grid_colour="tan",
            map_grid_frame=True,
            map_grid_frame_thickness=5,
            map_label=False,
        ),
        macro.mgrib(
            grib_field_position=526,
            grib_file_address_mode="byte_offset",
            grib_input_file_name="climetlab.grib",
        ),
        macro.mcont(
            contour_automatic_setting="climetlab",
            legend=False,
        ),
        macro.mcoast(
            map_grid=False,
            map_grid_frame=True,
            map_grid_frame_thickness=5,
            map_label=False,
        ),
    ]

    print(actions)
    macro.plot(*actions)


@pytest.mark.parametrize("filename", ["climetlab.nc", "test.nc4"])
def test_climetlab_netcdf(filename):
    from Magics import macro

    output = filename.replace(".", "-") + ".png"

    actions = [
        macro.output(
            output_file=output,
            output_width=680,
            page_frame=False,
            page_id_line=False,
            page_x_length=10,
            page_y_length=5.555555555555555,
            subpage_frame=False,
            subpage_x_length=10,
            subpage_x_position=0.0,
            subpage_y_length=5.555555555555555,
            subpage_y_position=0.0,
            super_page_frame=False,
            super_page_x_length=10,
            super_page_y_length=5.555555555555555,
        ),
        macro.mmap(
            subpage_lower_left_latitude=33.0,
            subpage_lower_left_longitude=-27.0,
            subpage_map_projection="cylindrical",
            subpage_upper_right_latitude=73.0,
            subpage_upper_right_longitude=45.0,
        ),
        macro.mcoast(
            map_boundaries=True,
            map_coastline_colour="tan",
            map_coastline_land_shade=True,
            map_coastline_land_shade_colour="cream",
            map_grid=False,
            map_grid_colour="tan",
            map_grid_frame=True,
            map_grid_frame_thickness=5,
            map_label=False,
        ),
        macro.mnetcdf(
            netcdf_filename=filename,
            netcdf_value_variable="t2m",
        ),
        macro.mcont(
            contour_automatic_setting="climetlab",
            legend=False,
        ),
        macro.mcoast(
            map_grid=False,
            map_grid_frame=True,
            map_grid_frame_thickness=5,
            map_label=False,
        ),
    ]

    print(actions)

    macro.plot(*actions)


if __name__ == "__main__":
    test_climetlab_netcdf()
    # test_climetlab_grib()