├── .github
└── workflows
│ └── ci.yaml
├── .gitignore
├── .stickler.yml
├── .travis.yml
├── AUTHORS.md
├── LICENSE.txt
├── MANIFEST.in
├── README.rst
├── continuous_integration
└── environment.yaml
├── doc
├── Makefile
└── source
│ ├── algorithms.rst
│ ├── conf.py
│ ├── filters.rst
│ ├── fogcolbar.png
│ ├── fogpy_docu_example_1.png
│ ├── fogpy_docu_example_10.png
│ ├── fogpy_docu_example_11.png
│ ├── fogpy_docu_example_12.png
│ ├── fogpy_docu_example_13.png
│ ├── fogpy_docu_example_14.png
│ ├── fogpy_docu_example_15.png
│ ├── fogpy_docu_example_16.png
│ ├── fogpy_docu_example_17.png
│ ├── fogpy_docu_example_2.png
│ ├── fogpy_docu_example_3.png
│ ├── fogpy_docu_example_4.png
│ ├── fogpy_docu_example_5.png
│ ├── fogpy_docu_example_6.png
│ ├── fogpy_docu_example_7.png
│ ├── fogpy_docu_example_8.png
│ ├── fogpy_docu_example_9.png
│ ├── fogpy_docu_nexample_1.png
│ ├── fogpy_docu_nexample_2.png
│ ├── fogpy_docu_nexample_3.png
│ ├── fogpy_docu_nexample_4.png
│ ├── fogpy_fls_algo.png
│ ├── fogpy_logo.png
│ ├── index.rst
│ ├── install.rst
│ ├── lowcloud.rst
│ └── quickstart.rst
├── fogpy
├── __init__.py
├── algorithms.py
├── composites.py
├── data
│ └── DEM
│ │ └── .gitignore
├── etc
│ ├── composites
│ │ ├── abi.yaml
│ │ └── seviri.yaml
│ ├── elevation_1km.npy
│ ├── fog_testdata.npy
│ ├── fog_testdata2.npy
│ ├── fog_testdata_fogmask.npy
│ ├── fog_testdata_hrv.npy
│ ├── fog_testdata_night.npy
│ ├── fog_testdata_night2.npy
│ ├── fog_testdata_pre.npy
│ ├── result_20131112.bufr
│ ├── result_20131112_metar.bufr
│ ├── result_20131112_swis.bufr
│ ├── result_20140827.bufr
│ └── testarea.txt
├── filters.py
├── lowwatercloud.py
├── test
│ ├── __init__.py
│ ├── conftest.py
│ ├── test_algorithms.py
│ ├── test_composites.py
│ ├── test_filters.py
│ ├── test_lowwatercloud.py
│ └── test_utils.py
└── utils
│ ├── __init__.py
│ ├── add_synop.py
│ ├── export_synop.py
│ ├── import_synop.py
│ └── reproj_testdata.py
├── setup.cfg
└── setup.py
/.github/workflows/ci.yaml:
--------------------------------------------------------------------------------
1 | name: Python package
2 |
3 | on:
4 | - push
5 | - pull_request
6 |
7 |
8 | jobs:
9 | build:
10 |
11 | runs-on: ubuntu-latest
12 | strategy:
13 | matrix:
14 | python-version: [3.8, 3.9]
15 | steps:
16 | - uses: actions/checkout@v2
17 | - name: Setup Conda Environment
18 | uses: conda-incubator/setup-miniconda@v2
19 | with:
20 | miniconda-version: "latest"
21 | python-version: ${{ matrix.python-version }}
22 | mamba-version: "*"
23 | channels: conda-forge,defaults
24 | environment-file: continuous_integration/environment.yaml
25 | activate-environment: test-environment
26 | - name: Install fogpy
27 | shell: bash -l {0}
28 | run: |
29 | pip install --no-deps -e .
30 | - name: Install test dependencies
31 | shell: bash -l {0}
32 | run: |
33 | pip install pytest pytest-cov
34 | - name: Test with pytest
35 | shell: bash -l {0}
36 | run: |
37 | pytest --cov=fogpy fogpy/test --cov-report=xml
38 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | build
2 | doc/build
3 | *.so
4 | *.pyc
5 | *~
6 | RELEASE-VERSION
7 | dist
8 | fogpy.egg-info
9 | fogpy/version.py
10 |
--------------------------------------------------------------------------------
/.stickler.yml:
--------------------------------------------------------------------------------
1 | linters:
2 | flake8:
3 | python: 3
4 | config: setup.cfg
5 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | dist: xenial
2 | language: python
3 | python:
4 | - '3.7'
5 | env:
6 | global:
7 | - PYTHON_VERSION=$TRAVIS_PYTHON_VERSION
8 | - MAIN_CMD='pytest'
9 | - CONDA_DEPENDENCIES='numpy scipy matplotlib satpy pyresample opencv coverage appdirs requests'
10 | - PIP_DEPENDENCIES='trollimage pyorbital trollbufr opencv-contrib-python'
11 | - SETUP_XVFB=False
12 | - EVENT_TYPE='push pull_request'
13 | - SETUP_CMD='--cov=fogpy fogpy/test'
14 | - CONDA_CHANNELS='conda-forge'
15 | - CONDA_CHANNEL_PRIORITY='True'
16 | install:
17 | - git clone --depth 1 git://github.com/astropy/ci-helpers.git
18 | - source ci-helpers/travis/setup_conda.sh
19 | script:
20 | - travis_wait 45 $MAIN_CMD $SETUP_CMD
21 | after_success:
22 | - coveralls
23 | - codecov
24 |
--------------------------------------------------------------------------------
/AUTHORS.md:
--------------------------------------------------------------------------------
1 | # Project Contributors
2 |
3 | The following people have made contributions to this project:
4 |
5 |
6 |
7 |
8 |
9 |
10 | - [Gerrit Holl (gerritholl)](https://github.com/gerritholl)
11 | - [Thomas Leppelt (m4sth0)](https://github.com/m4sth0)
12 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 | {one line to give the program's name and a brief idea of what it does.}
635 | Copyright (C) {year} {name of author}
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | {project} Copyright (C) {year} {fullname}
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------
/MANIFEST.in:
--------------------------------------------------------------------------------
1 | include LICENSE.txt
2 | include README.rst
3 | include MANIFEST.in
4 | include etc/*
5 |
--------------------------------------------------------------------------------
/README.rst:
--------------------------------------------------------------------------------
1 | Fogpy
2 | =====
3 |
4 | .. image:: https://api.travis-ci.com/pytroll/fogpy.svg?branch=master
5 | :target: https://travis-ci.org/pytroll/fogpy
6 |
7 | .. image:: https://coveralls.io/repos/github/pytroll/fogpy/badge.svg?branch=master
8 | :target: https://coveralls.io/github/pytroll/fogpy?branch=master
9 |
10 | This is a package for satellite based detection and nowcasting of fog and low stratus clouds (FogPy).
11 |
12 | The documentation is available at http://fogpy.readthedocs.io/en/latest
13 |
14 | The implementation is based on the following publications:
15 |
16 | * Cermak, J., & Bendix, J. (2011). Detecting ground fog from space–a microphysics-based approach. International Journal of Remote Sensing, 32(12), 3345-3371. doi:10.1016/j.atmosres.2007.11.009
17 | * Cermak, J., & Bendix, J. (2007). Dynamical nighttime fog/low stratus detection based on Meteosat SEVIRI data: A feasibility study. Pure and applied Geophysics, 164(6-7), 1179-1192. doi:10.1007/s00024-007-0213-8
18 | * Cermak, J., & Bendix, J. (2008). A novel approach to fog/low stratus detection using Meteosat 8 data. Atmospheric Research, 87(3-4), 279-292. doi:10.1016/j.atmosres.2007.11.009
19 | * Cermak, J. (2006). SOFOS-a new satellite-based operational fog observation scheme. (PhD thesis), Philipps-Universität Marburg, Marburg, Germany. doi:doi.org/10.17192/z2006.0149
20 |
--------------------------------------------------------------------------------
/continuous_integration/environment.yaml:
--------------------------------------------------------------------------------
1 | name: test-environment
2 | channels:
3 | - conda-forge
4 | dependencies:
5 | - numpy
6 | - scipy
7 | - matplotlib
8 | - satpy
9 | - pyresample
10 | - opencv
11 | - coverage
12 | - appdirs
13 | - requests
14 | - pip:
15 | - flake8
16 | - pytest
17 | - trollimage
18 | - pyorbital
19 | - trollbufr
20 | - opencv-contrib-python
21 |
--------------------------------------------------------------------------------
/doc/Makefile:
--------------------------------------------------------------------------------
1 | # Makefile for Sphinx documentation
2 | #
3 |
4 | # You can set these variables from the command line.
5 | SPHINXOPTS =
6 | SPHINXBUILD = sphinx-build
7 | PAPER =
8 | BUILDDIR = build
9 |
10 | # Internal variables.
11 | PAPEROPT_a4 = -D latex_paper_size=a4
12 | PAPEROPT_letter = -D latex_paper_size=letter
13 | ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) source
14 | # the i18n builder cannot share the environment and doctrees with the others
15 | I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) source
16 |
17 | .PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext
18 |
19 | help:
20 | @echo "Please use \`make ' where is one of"
21 | @echo " html to make standalone HTML files"
22 | @echo " dirhtml to make HTML files named index.html in directories"
23 | @echo " singlehtml to make a single large HTML file"
24 | @echo " pickle to make pickle files"
25 | @echo " json to make JSON files"
26 | @echo " htmlhelp to make HTML files and a HTML help project"
27 | @echo " qthelp to make HTML files and a qthelp project"
28 | @echo " devhelp to make HTML files and a Devhelp project"
29 | @echo " epub to make an epub"
30 | @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter"
31 | @echo " latexpdf to make LaTeX files and run them through pdflatex"
32 | @echo " text to make text files"
33 | @echo " man to make manual pages"
34 | @echo " texinfo to make Texinfo files"
35 | @echo " info to make Texinfo files and run them through makeinfo"
36 | @echo " gettext to make PO message catalogs"
37 | @echo " changes to make an overview of all changed/added/deprecated items"
38 | @echo " linkcheck to check all external links for integrity"
39 | @echo " doctest to run all doctests embedded in the documentation (if enabled)"
40 |
41 | clean:
42 | -rm -rf $(BUILDDIR)/*
43 |
44 | html:
45 | $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
46 | @echo
47 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
48 |
49 | dirhtml:
50 | $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml
51 | @echo
52 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml."
53 |
54 | singlehtml:
55 | $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml
56 | @echo
57 | @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml."
58 |
59 | pickle:
60 | $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle
61 | @echo
62 | @echo "Build finished; now you can process the pickle files."
63 |
64 | json:
65 | $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json
66 | @echo
67 | @echo "Build finished; now you can process the JSON files."
68 |
69 | htmlhelp:
70 | $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp
71 | @echo
72 | @echo "Build finished; now you can run HTML Help Workshop with the" \
73 | ".hhp project file in $(BUILDDIR)/htmlhelp."
74 |
75 | qthelp:
76 | $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp
77 | @echo
78 | @echo "Build finished; now you can run "qcollectiongenerator" with the" \
79 | ".qhcp project file in $(BUILDDIR)/qthelp, like this:"
80 | @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/fogpy.qhcp"
81 | @echo "To view the help file:"
82 | @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/fogpy.qhc"
83 |
84 | devhelp:
85 | $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp
86 | @echo
87 | @echo "Build finished."
88 | @echo "To view the help file:"
89 | @echo "# mkdir -p $$HOME/.local/share/devhelp/fogpy"
90 | @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/fogpy"
91 | @echo "# devhelp"
92 |
93 | epub:
94 | $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub
95 | @echo
96 | @echo "Build finished. The epub file is in $(BUILDDIR)/epub."
97 |
98 | latex:
99 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
100 | @echo
101 | @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex."
102 | @echo "Run \`make' in that directory to run these through (pdf)latex" \
103 | "(use \`make latexpdf' here to do that automatically)."
104 |
105 | latexpdf:
106 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
107 | @echo "Running LaTeX files through pdflatex..."
108 | $(MAKE) -C $(BUILDDIR)/latex all-pdf
109 | @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex."
110 |
111 | text:
112 | $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text
113 | @echo
114 | @echo "Build finished. The text files are in $(BUILDDIR)/text."
115 |
116 | man:
117 | $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man
118 | @echo
119 | @echo "Build finished. The manual pages are in $(BUILDDIR)/man."
120 |
121 | texinfo:
122 | $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
123 | @echo
124 | @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo."
125 | @echo "Run \`make' in that directory to run these through makeinfo" \
126 | "(use \`make info' here to do that automatically)."
127 |
128 | info:
129 | $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
130 | @echo "Running Texinfo files through makeinfo..."
131 | make -C $(BUILDDIR)/texinfo info
132 | @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo."
133 |
134 | gettext:
135 | $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale
136 | @echo
137 | @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale."
138 |
139 | changes:
140 | $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes
141 | @echo
142 | @echo "The overview file is in $(BUILDDIR)/changes."
143 |
144 | linkcheck:
145 | $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck
146 | @echo
147 | @echo "Link check complete; look for any errors in the above output " \
148 | "or in $(BUILDDIR)/linkcheck/output.txt."
149 |
150 | doctest:
151 | $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest
152 | @echo "Testing of doctests in the sources finished, look at the " \
153 | "results in $(BUILDDIR)/doctest/output.txt."
154 |
--------------------------------------------------------------------------------
/doc/source/algorithms.rst:
--------------------------------------------------------------------------------
1 | .. _algorithms:
2 |
3 | ===================
4 | Algorithms in fogpy
5 | ===================
6 |
7 | The package provide different algorithms for fog and low stratus cloud
8 | detection and nowcasting. The implemented fog algorithms are inherited
9 | from a base algorithm class, which defines basic common functionalities for
10 | remote sensing procedures.
11 |
12 | The fog and low stratus detection algorithm consists of a sequence of different
13 | filter approaches that are successively applicated to the given satellite images.
14 | The sequence of filters and required inputs are shown in the scheme below:
15 |
16 | .. image:: ./fogpy_fls_algo.png
17 | :scale: 50 %
18 |
19 | The cloud microphysical products liquid water path (LWP), cloud optical depth (COD)
20 | and effective droplet radius (Reff) can be obtained from the software provided by the
21 | Nowcasting Satellite Application Facility (NWCSAF) for example.
22 |
23 | Fogpy algorithms
24 | ----------------
25 |
26 | .. automodule:: fogpy.algorithms
27 | :members:
28 | :undoc-members:
--------------------------------------------------------------------------------
/doc/source/conf.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | #
3 | # fogpy documentation build configuration file, created by
4 | # sphinx-quickstart on Thu Apr 20 12:31:41 2017.
5 | #
6 | # This file is execfile()d with the current directory set to its containing dir.
7 | #
8 | # Note that not all possible configuration values are present in this
9 | # autogenerated file.
10 | #
11 | # All configuration values have a default; values that are commented out
12 | # serve to show the default.
13 |
14 | import sys, os
15 |
16 | # If extensions (or modules to document with autodoc) are in another directory,
17 | # add these directories to sys.path here. If the directory is relative to the
18 | # documentation root, use os.path.abspath to make it absolute, like shown here.
19 | # sys.path.insert(0, os.path.abspath('.'))
20 | # sys.path.insert(0, os.path.abspath('../'))
21 | sys.path.append(os.path.abspath('../../'))
22 |
23 |
24 | class Mock(object):
25 | def __init__(self, *args, **kwargs):
26 | pass
27 |
28 | def __call__(self, *args, **kwargs):
29 | return Mock()
30 |
31 | @classmethod
32 | def __getattr__(cls, name):
33 | if name in ('__file__', '__path__'):
34 | return '/dev/null'
35 | elif name[0] == name[0].upper():
36 | mockType = type(name, (), {})
37 | mockType.__module__ = __name__
38 | return mockType
39 | elif name == "inf":
40 | return 0
41 | else:
42 | return Mock()
43 |
44 | MOCK_MODULES = ['matplotlib', 'matplotlib.pyplot', 'matplotlib.cm',
45 | 'scipy', 'scipy.signal', 'scipy.optimize', 'scipy.ndimage',
46 | 'scipy.stats', 'pyresample', 'pyorbital', 'numpy', 'numpy.core',
47 | 'numpy.lib', 'numpy.lib.stride_tricks',
48 | 'pyresample.utils', 'pyresample.geometry',
49 | 'h5py', 'trollbufr', 'trollbufr.bufr']
50 |
51 | for mod_name in MOCK_MODULES:
52 | sys.modules[mod_name] = Mock()
53 |
54 | # -- General configuration -----------------------------------------------------
55 |
56 | # If your documentation needs a minimal Sphinx version, state it here.
57 | #needs_sphinx = '1.0'
58 |
59 | # Add any Sphinx extension module names here, as strings. They can be extensions
60 | # coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
61 | extensions = ['sphinx.ext.autodoc', 'sphinx.ext.viewcode']
62 |
63 | # Add any paths that contain templates here, relative to this directory.
64 | templates_path = ['_templates']
65 |
66 | # The suffix of source filenames.
67 | source_suffix = '.rst'
68 |
69 | # The encoding of source files.
70 | #source_encoding = 'utf-8-sig'
71 |
72 | # The master toctree document.
73 | master_doc = 'index'
74 |
75 | # General information about the project.
76 | project = u'fogpy'
77 | copyright = '2017-2020, Fogpy developers'
78 |
79 | # The version info for the project you're documenting, acts as replacement for
80 | # |version| and |release|, also used in various other places throughout the
81 | # built documents.
82 | #
83 | # The short X.Y version.
84 |
85 | # import fogpy.version as current_version
86 |
87 | # The full version, including alpha/beta/rc tags.
88 | # release = current_version.__version__
89 | # The short X.Y version.
90 | # version = ".".join(release.split(".")[:2])
91 | version = '1.2.0'
92 | # The full version, including alpha/beta/rc tags.
93 | release = '1.2.0'
94 |
95 | # The language for content autogenerated by Sphinx. Refer to documentation
96 | # for a list of supported languages.
97 | #language = None
98 |
99 | # There are two options for replacing |today|: either, you set today to some
100 | # non-false value, then it is used:
101 | #today = ''
102 | # Else, today_fmt is used as the format for a strftime call.
103 | #today_fmt = '%B %d, %Y'
104 |
105 | # List of patterns, relative to source directory, that match files and
106 | # directories to ignore when looking for source files.
107 | exclude_patterns = []
108 |
109 | # The reST default role (used for this markup: `text`) to use for all documents.
110 | #default_role = None
111 |
112 | # If true, '()' will be appended to :func: etc. cross-reference text.
113 | #add_function_parentheses = True
114 |
115 | # If true, the current module name will be prepended to all description
116 | # unit titles (such as .. function::).
117 | #add_module_names = True
118 |
119 | # If true, sectionauthor and moduleauthor directives will be shown in the
120 | # output. They are ignored by default.
121 | #show_authors = False
122 |
123 | # The name of the Pygments (syntax highlighting) style to use.
124 | pygments_style = 'sphinx'
125 |
126 | # A list of ignored prefixes for module index sorting.
127 | #modindex_common_prefix = []
128 |
129 |
130 | # -- Options for HTML output ---------------------------------------------------
131 |
132 | # The theme to use for HTML and HTML Help pages. See the documentation for
133 | # a list of builtin themes.
134 | html_theme = 'default'
135 |
136 | # Theme options are theme-specific and customize the look and feel of a theme
137 | # further. For a list of options available for each theme, see the
138 | # documentation.
139 | #html_theme_options = {}
140 |
141 | # Add any paths that contain custom themes here, relative to this directory.
142 | #html_theme_path = []
143 |
144 | # The name for this set of Sphinx documents. If None, it defaults to
145 | # " v documentation".
146 | #html_title = None
147 |
148 | # A shorter title for the navigation bar. Default is the same as html_title.
149 | #html_short_title = None
150 |
151 | # The name of an image file (relative to this directory) to place at the top
152 | # of the sidebar.
153 | #html_logo = None
154 |
155 | # The name of an image file (within the static path) to use as favicon of the
156 | # docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
157 | # pixels large.
158 | #html_favicon = None
159 |
160 | # Add any paths that contain custom static files (such as style sheets) here,
161 | # relative to this directory. They are copied after the builtin static files,
162 | # so a file named "default.css" will overwrite the builtin "default.css".
163 | html_static_path = ['_static']
164 |
165 | # If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
166 | # using the given strftime format.
167 | #html_last_updated_fmt = '%b %d, %Y'
168 |
169 | # If true, SmartyPants will be used to convert quotes and dashes to
170 | # typographically correct entities.
171 | #html_use_smartypants = True
172 |
173 | # Custom sidebar templates, maps document names to template names.
174 | #html_sidebars = {}
175 |
176 | # Additional templates that should be rendered to pages, maps page names to
177 | # template names.
178 | #html_additional_pages = {}
179 |
180 | # If false, no module index is generated.
181 | #html_domain_indices = True
182 |
183 | # If false, no index is generated.
184 | #html_use_index = True
185 |
186 | # If true, the index is split into individual pages for each letter.
187 | #html_split_index = False
188 |
189 | # If true, links to the reST sources are added to the pages.
190 | #html_show_sourcelink = True
191 |
192 | # If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
193 | #html_show_sphinx = True
194 |
195 | # If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
196 | #html_show_copyright = True
197 |
198 | # If true, an OpenSearch description file will be output, and all pages will
199 | # contain a tag referring to it. The value of this option must be the
200 | # base URL from which the finished HTML is served.
201 | #html_use_opensearch = ''
202 |
203 | # This is the file name suffix for HTML files (e.g. ".xhtml").
204 | #html_file_suffix = None
205 |
206 | # Output file base name for HTML help builder.
207 | htmlhelp_basename = 'fogpydoc'
208 |
209 |
210 | # -- Options for LaTeX output --------------------------------------------------
211 |
212 | latex_elements = {
213 | # The paper size ('letterpaper' or 'a4paper').
214 | #'papersize': 'letterpaper',
215 |
216 | # The font size ('10pt', '11pt' or '12pt').
217 | #'pointsize': '10pt',
218 |
219 | # Additional stuff for the LaTeX preamble.
220 | #'preamble': '',
221 | }
222 |
223 | # Grouping the document tree into LaTeX files. List of tuples
224 | # (source start file, target name, title, author, documentclass [howto/manual]).
225 | latex_documents = [
226 | ('index', 'fogpy.tex', u'fogpy Documentation',
227 | 'Fogpy developers', 'manual'),
228 | ]
229 |
230 | # The name of an image file (relative to this directory) to place at the top of
231 | # the title page.
232 | #latex_logo = None
233 |
234 | # For "manual" documents, if this is true, then toplevel headings are parts,
235 | # not chapters.
236 | #latex_use_parts = False
237 |
238 | # If true, show page references after internal links.
239 | #latex_show_pagerefs = False
240 |
241 | # If true, show URL addresses after external links.
242 | #latex_show_urls = False
243 |
244 | # Documents to append as an appendix to all manuals.
245 | #latex_appendices = []
246 |
247 | # If false, no module index is generated.
248 | #latex_domain_indices = True
249 |
250 |
251 | # -- Options for manual page output --------------------------------------------
252 |
253 | # One entry per manual page. List of tuples
254 | # (source start file, name, description, authors, manual section).
255 | man_pages = [
256 | ('index', 'fogpy', u'fogpy Documentation',
257 | [u'Fogpy developers'], 1)
258 | ]
259 |
260 | # If true, show URL addresses after external links.
261 | #man_show_urls = False
262 |
263 |
264 | # -- Options for Texinfo output ------------------------------------------------
265 |
266 | # Grouping the document tree into Texinfo files. List of tuples
267 | # (source start file, target name, title, author,
268 | # dir menu entry, description, category)
269 | texinfo_documents = [
270 | ('index', 'fogpy', u'fogpy Documentation',
271 | u'Fogpy developers', 'fogpy', 'One line description of project.',
272 | 'Miscellaneous'),
273 | ]
274 |
275 | # Documents to append as an appendix to all manuals.
276 | #texinfo_appendices = []
277 |
278 | # If false, no module index is generated.
279 | #texinfo_domain_indices = True
280 |
281 | # How to display URL addresses: 'footnote', 'no', or 'inline'.
282 | #texinfo_show_urls = 'footnote'
283 |
--------------------------------------------------------------------------------
/doc/source/filters.rst:
--------------------------------------------------------------------------------
1 | .. _filters:
2 |
3 | =================
4 | Filters in fogpy
5 | =================
6 |
7 | The FLS algorithms are based on filter methods for different meteorlogical
8 | phenomena or physical variables. All implemented filter methods are inherited
9 | from a base filter class, which defines basic common filter functionalities.
10 |
11 | Fogpy filters
12 | ----------------
13 |
14 | .. automodule:: fogpy.filters
15 | :members:
16 | :undoc-members:
17 |
18 |
19 |
--------------------------------------------------------------------------------
/doc/source/fogcolbar.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pytroll/fogpy/4883d2198da770d2e95911b792cc764b33d15568/doc/source/fogcolbar.png
--------------------------------------------------------------------------------
/doc/source/fogpy_docu_example_1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pytroll/fogpy/4883d2198da770d2e95911b792cc764b33d15568/doc/source/fogpy_docu_example_1.png
--------------------------------------------------------------------------------
/doc/source/fogpy_docu_example_10.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pytroll/fogpy/4883d2198da770d2e95911b792cc764b33d15568/doc/source/fogpy_docu_example_10.png
--------------------------------------------------------------------------------
/doc/source/fogpy_docu_example_11.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pytroll/fogpy/4883d2198da770d2e95911b792cc764b33d15568/doc/source/fogpy_docu_example_11.png
--------------------------------------------------------------------------------
/doc/source/fogpy_docu_example_12.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pytroll/fogpy/4883d2198da770d2e95911b792cc764b33d15568/doc/source/fogpy_docu_example_12.png
--------------------------------------------------------------------------------
/doc/source/fogpy_docu_example_13.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pytroll/fogpy/4883d2198da770d2e95911b792cc764b33d15568/doc/source/fogpy_docu_example_13.png
--------------------------------------------------------------------------------
/doc/source/fogpy_docu_example_14.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pytroll/fogpy/4883d2198da770d2e95911b792cc764b33d15568/doc/source/fogpy_docu_example_14.png
--------------------------------------------------------------------------------
/doc/source/fogpy_docu_example_15.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pytroll/fogpy/4883d2198da770d2e95911b792cc764b33d15568/doc/source/fogpy_docu_example_15.png
--------------------------------------------------------------------------------
/doc/source/fogpy_docu_example_16.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pytroll/fogpy/4883d2198da770d2e95911b792cc764b33d15568/doc/source/fogpy_docu_example_16.png
--------------------------------------------------------------------------------
/doc/source/fogpy_docu_example_17.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pytroll/fogpy/4883d2198da770d2e95911b792cc764b33d15568/doc/source/fogpy_docu_example_17.png
--------------------------------------------------------------------------------
/doc/source/fogpy_docu_example_2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pytroll/fogpy/4883d2198da770d2e95911b792cc764b33d15568/doc/source/fogpy_docu_example_2.png
--------------------------------------------------------------------------------
/doc/source/fogpy_docu_example_3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pytroll/fogpy/4883d2198da770d2e95911b792cc764b33d15568/doc/source/fogpy_docu_example_3.png
--------------------------------------------------------------------------------
/doc/source/fogpy_docu_example_4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pytroll/fogpy/4883d2198da770d2e95911b792cc764b33d15568/doc/source/fogpy_docu_example_4.png
--------------------------------------------------------------------------------
/doc/source/fogpy_docu_example_5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pytroll/fogpy/4883d2198da770d2e95911b792cc764b33d15568/doc/source/fogpy_docu_example_5.png
--------------------------------------------------------------------------------
/doc/source/fogpy_docu_example_6.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pytroll/fogpy/4883d2198da770d2e95911b792cc764b33d15568/doc/source/fogpy_docu_example_6.png
--------------------------------------------------------------------------------
/doc/source/fogpy_docu_example_7.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pytroll/fogpy/4883d2198da770d2e95911b792cc764b33d15568/doc/source/fogpy_docu_example_7.png
--------------------------------------------------------------------------------
/doc/source/fogpy_docu_example_8.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pytroll/fogpy/4883d2198da770d2e95911b792cc764b33d15568/doc/source/fogpy_docu_example_8.png
--------------------------------------------------------------------------------
/doc/source/fogpy_docu_example_9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pytroll/fogpy/4883d2198da770d2e95911b792cc764b33d15568/doc/source/fogpy_docu_example_9.png
--------------------------------------------------------------------------------
/doc/source/fogpy_docu_nexample_1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pytroll/fogpy/4883d2198da770d2e95911b792cc764b33d15568/doc/source/fogpy_docu_nexample_1.png
--------------------------------------------------------------------------------
/doc/source/fogpy_docu_nexample_2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pytroll/fogpy/4883d2198da770d2e95911b792cc764b33d15568/doc/source/fogpy_docu_nexample_2.png
--------------------------------------------------------------------------------
/doc/source/fogpy_docu_nexample_3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pytroll/fogpy/4883d2198da770d2e95911b792cc764b33d15568/doc/source/fogpy_docu_nexample_3.png
--------------------------------------------------------------------------------
/doc/source/fogpy_docu_nexample_4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pytroll/fogpy/4883d2198da770d2e95911b792cc764b33d15568/doc/source/fogpy_docu_nexample_4.png
--------------------------------------------------------------------------------
/doc/source/fogpy_fls_algo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pytroll/fogpy/4883d2198da770d2e95911b792cc764b33d15568/doc/source/fogpy_fls_algo.png
--------------------------------------------------------------------------------
/doc/source/fogpy_logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pytroll/fogpy/4883d2198da770d2e95911b792cc764b33d15568/doc/source/fogpy_logo.png
--------------------------------------------------------------------------------
/doc/source/index.rst:
--------------------------------------------------------------------------------
1 | .. fogpy documentation master file, created by
2 | sphinx-quickstart on Thu Apr 20 12:31:41 2017.
3 | You can adapt this file completely to your liking, but it should at least
4 | contain the root `toctree` directive.
5 |
6 | =================================
7 | Welcome to fogpy's documentation!
8 | =================================
9 |
10 | .. image:: ./fogpy_logo.png
11 |
12 | This package provide algorithmns and methods for satellite based detection and
13 | nowcasting of fog and low stratus clouds (FLS).
14 |
15 | Related FogPy Version: 1.1.3
16 |
17 | It utilizes several functionalities from the pytroll_ project for weather
18 | satellite data processing in Python. The remote sensing algorithmns are
19 | currently implemented for the geostationary Meteosat Second Generation (MSG)
20 | satellites. But it is designed to be easly extendable to support other
21 | meteorological satellites in future.
22 |
23 | Contents:
24 |
25 | .. _pytroll: http://pytroll.org/
26 | .. toctree::
27 | :maxdepth: 2
28 |
29 | install
30 | quickstart
31 | algorithms
32 | filters
33 | lowcloud
34 |
35 |
36 |
37 | Indices and tables
38 | ==================
39 |
40 | * :ref:`genindex`
41 | * :ref:`modindex`
42 | * :ref:`search`
43 |
44 |
--------------------------------------------------------------------------------
/doc/source/install.rst:
--------------------------------------------------------------------------------
1 | ===========================
2 | Installation instructions
3 | ===========================
4 |
5 | Getting the files and installing them
6 | =====================================
7 |
8 | First you need to get the files from github::
9 |
10 | cd /path/to/my/source/directory/
11 | git clone https://github.com/m4sth0/fogpy
12 |
13 | You can also retreive a tarball from there if you prefer, then run::
14 |
15 | tar zxvf tarball.tar.gz
16 |
17 | Then you need to install fogpy on you computer::
18 |
19 | cd fogpy
20 | python setup.py install [--prefix=/my/custom/installation/directory]
21 |
22 | You can also install it in develop mode to make it easier to hack::
23 |
24 | python setup.py develop [--prefix=/my/custom/installation/directory]
25 |
26 |
--------------------------------------------------------------------------------
/doc/source/lowcloud.rst:
--------------------------------------------------------------------------------
1 | =================================
2 | Low cloud model in fogpy
3 | =================================
4 | A low water cloud model has been implemented to derive the cloud base height
5 | from satellite retrievable variables like liquid water path, cloud top height
6 | and temperature.
7 |
8 | Low water cloud model
9 | ---------------------
10 |
11 | .. automodule:: fogpy.lowwatercloud
12 | :members:
13 | :undoc-members:
--------------------------------------------------------------------------------
/doc/source/quickstart.rst:
--------------------------------------------------------------------------------
1 | ============
2 | Fogpy usage in a nutshell
3 | ============
4 |
5 | The package uses OOP extensively, to allow higher level metaobject handling.
6 |
7 | For this tutorial, we will use a MSG scene for creating different
8 | fog products.
9 |
10 | Import satellite data first
11 | ===========================
12 |
13 | We start with the PyTroll package *satpy*. This package provide all functionalities
14 | to import and calibrate a MSG scene from HRIT files. Therefore you should make sure
15 | that mpop is properly configured and all environment variables like *PPP_CONFIG_DIR*
16 | are set and the HRIT files are in the given search path. For more guidance look up
17 | in the `satpy`_ documentation
18 |
19 | .. _satpy: http://satpy.readthedocs.io/en/latest/install.html#getting-the-files-and-installing-them/
20 |
21 | .. note::
22 | Make sure *satpy* is correctly configured!
23 |
24 | Ok, let's get it on::
25 |
26 | >>> from satpy import Scene
27 | >>> from glob import glob
28 | >>> filenames = glob("/path/to/seviri/H-000*20131212000*")
29 | >>> msg_scene = Scene(reader="seviri_l1b_hrit", filenames=filenames)
30 | >>> msg_scene.load([10.8])
31 | >>> msg_scene.load(["fog"])
32 |
33 | We imported a MSG scene from 12. December 2013 and loaded the 10.8 µm channel
34 | and the built-in simple fog composite into the scene object.
35 |
36 | Now we want to look at the IR 10.8 channel::
37 |
38 | >>> msg_scene.show(10.8)
39 |
40 | .. image:: ./fogpy_docu_example_1.png
41 |
42 | Everything seems correctly imported. We see a full disk image. So lets see if we can resample it to a central European region::
43 |
44 | >>> eu_scene = msg_scene.resample("eurol")
45 | >>> eu_scene.show(10.8)
46 |
47 | .. image:: ./fogpy_docu_example_2.png
48 |
49 | A lot of clouds are present over central Europe. Let's test a fog RGB composite to find some low clouds::
50 |
51 | >>> eu_scene.show("fog")
52 |
53 | .. image:: ./fogpy_docu_example_3.png
54 |
55 | The reddish and dark colored clouds represent cold and high altitude clouds,
56 | whereas the yellow-greenish color over central and eastern Europe is an indication for low clouds and fog.
57 |
58 | Continue with more metadata
59 | ===========================
60 |
61 | In the next step we want to create a fog and low stratus (FLS) composite
62 | for the imported scene. For this we need:
63 |
64 | * Seviri L1B data, read by Satpy with the ``seviri_l1b_hrit`` reader.
65 | * Cloud microphysical data, read by Satpy with the ``nwcsaf-geo`` reader.
66 | In principle, `CMSAF`_ data could also be used, but as of May 2019, there
67 | is no CM-SAF reader within Satpy.
68 | * A digital elevation model. This can derived from data available from
69 | the European Environmental Agency (`EEA`_).
70 | Although this can be read by Satpy using
71 | the ``generic_image`` reader, the Fogpy composite reads this as a static
72 | image. The path to this image needs to be defined in the Fogpy
73 | ``etc/composites/seviri.yaml`` file.
74 |
75 | We create a scene in which we load
76 | datasets using both the ``seviri_l1b_hrit`` and ``nwcsaf-geo`` readers.
77 | Here we choose to load all required channels and datasets explicitly::
78 |
79 | >>> fn_nwcsaf = glob("/media/nas/x21308/scratch/NWCSAF/*100000Z.nc")
80 | >>> fn_sev = glob("/media/nas/x21308/scratch/SEVIRI/*201904151000*")
81 | >>> sc = Scene(filenames={"seviri_l1b_hrit": fn_sev, "nwcsaf-geo": fn_nwcsaf})
82 | >>> sc.load(["cmic_reff", "IR_108", "IR_087", "cmic_cot", "IR_016", "VIS006",
83 | "IR_120", "VIS008", "cmic_lwp", "IR_039"])
84 |
85 |
86 | .. _EEA: https://www.eea.europa.eu/data-and-maps/data/copernicus-land-monitoring-service-eu-dem
87 | .. _satpy: https://github.com/pytroll/satpy
88 |
89 | .. image:: ./fogpy_docu_example_5.png
90 | :scale: 74 %
91 |
92 | We can now visualise any of those datasets using the regular pytroll
93 | visualisation toolkit. Let's first resample the scene again::
94 |
95 | >>> ls = sc.resample("eurol")
96 |
97 | And then inspect the cloud optical thickness product::
98 |
99 | >>> from trollimage.xrimage import XRImage
100 | >>> from trollimage.colormap import set3
101 | >>> xrim = XRImage(ls["cmic_cot"])
102 | >>> set3.set_range(0, 100)
103 | >>> xrim.palettize(set3)
104 | >>> xrim.show()
105 |
106 | .. _CMSAF: www.cmsaf.eu
107 | .. _pyresample: https://github.com/pytroll/pyresample
108 | .. _trollimage: http://trollimage.readthedocs.io/en/latest/
109 |
110 | .. image:: ./fogpy_docu_example_6.png
111 |
112 | Get hands-on fogpy at daytime
113 | =================================
114 |
115 | After we imported all required metadata we can continue with a fogpy composite.
116 |
117 | .. note::
118 | Make sure that the ``PPP_CONFIG_DIR`` includes ``fogpy/etc/`` directory!
119 |
120 | Fogpy comes with its own ``etc/composites/seviri.yaml``.
121 | By setting ``PPP_CONFIG_DIR=/path/to/fogpy/etc``, Satpy will find the fogpy
122 | composites and all fogpy composites can be used directly in Satpy.
123 |
124 | Let's try it with the *fls_day* composite. This composite determines
125 | low clouds and ground fog cells from a satellite scene. It is limited
126 | to daytime because it requires channels in the visible spectrum to be
127 | successfully applicable. We create a fogpy composite for the resampled
128 | MSG scene::
129 |
130 | >>> ls.load(["fls_day"])
131 |
132 | This may take a while to complete.
133 | You see that we don't have to import the fogpy package manually.
134 | It's done automagically in the background after the satpy configuration.
135 |
136 | The *fls_day* composite function calculates a new dataset, that is now
137 | available like any other Satpy dataset, such as by ``ls["fls_day"]``
138 | or ``ls.show("fls_day")``.
139 | The dataset has two bands:
140 |
141 | - Band ``L`` is an image of a selected channel (Default is the 10.8 IR channel) where only the detected ground fog cells are displayed
142 | - Band ``A`` is an image for the fog mask
143 |
144 | .. image:: ./fogpy_docu_example_10.png
145 |
146 | The result image shows the area with potential ground fog calculated
147 | by the algorithm, fine. But the remaining areas are missing... maybe
148 | a different visualization could be helpful. We can improve the image
149 | output by colorize the fog mask and blending it over an overview composite
150 | using trollimage:
151 |
152 | .. Wait for this composite to work correctly
153 | ..
154 | .. Fogpy comes with a Satpy enhancement file in
155 | .. ``etc/enhancements/generic.yaml``, which defines an enhanced visualisation
156 | .. for the Fogpy ``fls_day`` composite, which we will use::
157 |
158 | ::
159 |
160 | >>> ov = satpy.writers.get_enhanced_image(ls["overview"]).convert("RGBA")
161 | >>> A = ls["fls_day"].sel(bands="A")
162 | >>> Ap = (1-A).where(1-A==0, 0.5)
163 | >>> im = XRImage(Ap)
164 | >>> im.stretch()
165 | >>> im.colorize(fogcol)
166 | >>> RGBA = xr.concat([im.data, Ap], dim="bands")
167 | >>> blend = ov.blend(XRImage(RGBA))
168 |
169 | .. note::
170 | Images not yet updated!
171 |
172 | .. image:: ./fogpy_docu_example_11.png
173 |
174 | Here are some example algorithm results for the given MSG scene.
175 | As described above, the different masks are blendes over the overview RGB composite in yellow, except the right image where the fog RGB is in the background:
176 |
177 | +----------------------------------------+----------------------------------------+----------------------------------------+
178 | | .. image:: ./fogpy_docu_example_13.png | .. image:: ./fogpy_docu_example_12.png | .. image:: ./fogpy_docu_example_14.png |
179 | +----------------------------------------+----------------------------------------+----------------------------------------+
180 | | Cloud mask | Low cloud mask | Low cloud mask + Fog RGB |
181 | +----------------------------------------+----------------------------------------+----------------------------------------+
182 |
183 | It looks like the cloud mask works correctly, except of some missclassified snow pixels in the Alps.
184 | But this is not a problem due to the snow filter which successfully masked them out later in the algorithm.
185 | Interestingly low cloud areas that are found by the algorithm fit quite good to the fog RGB yellowish areas.
186 |
187 | On a foggy night ...
188 | =================================
189 |
190 | We saw how daytime fog detection can be realized with the fogpy *fls_day* composite.
191 | But mostly fog occuring during nighttime. So let's continue with another composite
192 | for nighttime fog detection **fls_night**:.
193 |
194 | .. note::
195 | Again make sure that the fogpy composites are made available in satpy!
196 |
197 | .. fixme::
198 | This part of documentation needs updating!
199 |
200 | First we need the nighttime MSG scene::
201 |
202 | >>> fn_nwcsaf = glob("/media/nas/x21308/scratch/NWCSAF/*100000Z.nc") # FIXME: UPDATE!
203 | >>> fn_sev = glob("/media/nas/x21308/scratch/SEVIRI/*201904151000*") # FIXME: UPDATE!
204 | >>> sc = Scene(filenames={"seviri_l1b_hrit": fn_sev, "nwcsaf-geo": fn_nwcsaf})
205 | >>> sc.load(["IR_108, "IR_039", "night_fog"])
206 |
207 | Reproject it to the central European section from above and have a look at the infrared channel::
208 |
209 | >>> ls = sc.resample("eurol")
210 | >>> ls.show(10.8)
211 |
212 | .. image:: ./fogpy_docu_nexample_1.png
213 |
214 | We took the same day (12. December 2017) as above. Now we could check whether the low
215 | clouds, that are present at 10 am, already can be seen early in the the morning (4 am) before sun rise.
216 |
217 | So let's look at the nighttime fog RGB product::
218 |
219 | >>> ls.show("night_fog")
220 |
221 | .. image:: ./fogpy_docu_nexample_2.png
222 |
223 | As we see, a lot of greenish-yellow colored pixels are present in the night scene.
224 | This is a clear indication for low clouds and fog. In addition these areas have a similar form and
225 | distribution as the low clouds in the daytime scene.
226 | We can conclude that these low clouds should have formed during the night.
227 |
228 | So let's create the fogpy nighttime composite.
229 | Fogpy will use the PyTroll package `pyorbital`_ for solar zenith angle
230 | calculations, so make sure this one is installed.
231 | The nightime composite for the resampled MSG scene
232 | is generated in the same way like the daytime composite with `satpy`_::
233 |
234 | >>> ls.load(["fls_night"])
235 | >>> ls.show("fls_night")
236 |
237 | .. image:: ./fogpy_docu_nexample_3.png
238 |
239 | .. _pyorbital: https://github.com/pytroll/pyorbital
240 |
241 | It seems, the detected low cloud cells in the composite overestimate the presence of low clouds,
242 | if we compare the RGB product to it. In general, the nighttime algorithm exhibit higher uncertainty for the detection of low
243 | clouds than the daytime approach. Therefore a comparison with weather station data could be useful.
244 |
245 | Gimme some ground truth!
246 | ========================
247 |
248 | Fogpy features some additional utilities for validation and comparison attempts.
249 | This include methods to plot weather station data from Bufr files over the FLS image results.
250 | The Bufr data is thereby processed by the `trollbufr`_ PyTroll package and the images are generated with `trollimage`_.
251 | Here we load visibility data from German weather stations for the nighttime scene::
252 |
253 | >>> import os
254 | >>> from fogpy.utils import add_synop
255 | # Define search path for bufr file
256 | >>> bufr_dir = '/path/to/bufr/file/'
257 | >>> nbufr_file = "result_{}_synop.bufr".format(ntime.strftime("%Y%m%d%H%M"))
258 | >>> inbufrn = os.path.join(bufr_dir, nbufr_file)
259 | # Create station image
260 | >>> station_nimg = add_synop.add_to_image(nfls_img, tiffarea, ntime, inbufrn, ptsize=4)
261 | >>> station_nimg.show()
262 |
263 | .. image:: ./fogpy_docu_nexample_4.png
264 | |
265 | .. image:: ./fogcolbar.png
266 | :scale: 60 %
267 |
268 | .. _trollbufr: https://github.com/alexmaul/trollbufr
269 |
270 | The red dots represent fog reports with visibilities below 1000 meters (compare with legend),
271 | whereas green dots show high visibility situations at ground level.
272 | We see that low clouds, classified by the nighttime algorithm not always correspond to ground fog.
273 | Here the station data is a useful addition to distinguish between ground fog and low stratus.
274 |
275 | At daytime we can make the same comparison with station data::
276 |
277 | >>> bufr_file = "result_{}_synop.bufr".format(time.strftime("%Y%m%d%H%M"))
278 | >>> inbufr = os.path.join(bufr_dir, bufr_file)
279 | # Create station image
280 | >>> station_img = add_synop.add_to_image(fls_img, tiffarea, time, inbufr, ptsize=4)
281 | >>> station_img.show()
282 |
283 | .. image:: ./fogpy_docu_example_15.png
284 |
285 | We see that the low cloud area in Northern Germany has not been classified as ground fog by the algorithm,
286 | whereas the southern part fits quite good to the station data.
287 | Furthermore some mountain stations within the area of the ground fog mask exhibit high visibilities.
288 | This difference is induced by the averaged evelation from the DEM, the deviated lower cloud height and the
289 | real altitude of the station which could lie above the expected cloud top.
290 | In addition the low cloud top height assignment can exhibit uncertainty in cases where a elevation
291 | based height assignment is not possible and a fixed temperature gradient approach is applied.
292 | These missclassifications could be improved by using ground station visibility data
293 | as algorithm input. The usage of station data as additional filter could refine the ground fog mask.
294 |
295 | Luckily we can use the StationFusionFilter class from fogpy to combine the satellite mask with ground
296 | station visibility data. We use several dataset that had been calculated through out the tour as filter input
297 | and plot the filter result::
298 |
299 | >>> from fogpy.filters import StationFusionFilter
300 | # Define filter input
301 | >>> flsoutmask = np.array(fogmask.channels[0], dtype=bool)
302 | >>> filterinput = {'ir108': dem_scene[10.8].data,
303 | >>> 'ir039': dem_scene[3.9].data,
304 | >>> 'lowcloudmask': flsoutask,
305 | >>> 'elev': elevation.image_data,
306 | >>> 'bufrfile': inbufr,
307 | >>> 'time': time,
308 | >>> 'area': tiffarea}
309 | # Create fusion filter
310 | >>> stationfilter = StationFusionFilter(dem_scene[10.8].data, **filterinput)
311 | >>> stationfilter.apply()
312 | >>> stationfilter.plot_filter()
313 |
314 | .. image:: ./fogpy_docu_example_16.png
315 |
316 | The data fusion revise the low cloud clusters in Northern Germany and East Europe as ground fog again.
317 | The filter uses ground station data to correct false classification and add missing ground fog cases
318 | by utilising a DEM based interpolation. Furthermore cases under high clouds are also extrapolated by
319 | elevation information. This cloud lead to low cloud confidence levels. For example the fog mask over
320 | France and England. The applicatin of this filter should be limited to a region for which station data
321 | is available to achieve a high qualitiy data fusion product. In this case the area should be cropped to
322 | Germany, which can be done by setting the *limit* attribute to *True*::
323 |
324 | >>> filterinput['limit'] = True
325 | # Create fusion filter with limited region
326 | >>> stationfilter = StationFusionFilter(dem_scene[10.8].data, **filterinput)
327 | >>> stationfilter.apply()
328 | >>> stationfilter.plot_filter()
329 |
330 | .. image:: ./fogpy_docu_example_17.png
331 | :scale: 120 %
332 |
333 | The output is now limited automagically to the area for which station data is available.
334 |
335 | The above station fusion filter example can be used to code any other filter application in fogpy.
336 | The command sequence more or less looks like the same:
337 |
338 | - Prepare filter input
339 | - Instantiate filter class object
340 | - Run the filter
341 | - Enjoy the results
342 |
343 | All available filters are listed in the chapter :ref:`filters`. Whereas the algorithms that can be directly
344 | applied to PyTroll *Scene* objects can be found in the :ref:`algorithms` section.
345 |
--------------------------------------------------------------------------------
/fogpy/__init__.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | # -*- coding: utf-8 -*-
3 | # Copyright (c) 2017-2020 Fogpy developers
4 |
5 | # This file is part of the fogpy package.
6 |
7 | # fogpy is free software: you can redistribute it and/or modify it
8 | # under the terms of the GNU General Public License as published by
9 | # the Free Software Foundation, either version 3 of the License, or
10 | # (at your option) any later version.
11 |
12 | # fogpy is distributed in the hope that it will be useful, but
13 | # WITHOUT ANY WARRANTY; without even the implied warranty of
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 | # General Public License for more details.
16 |
17 | # You should have received a copy of the GNU General Public License
18 | # along with fogpy. If not, see .
19 |
20 | """PP Package initializer.
21 | """
22 |
23 | import os
24 |
25 | BASE_PATH = os.path.sep.join(os.path.dirname(
26 | os.path.realpath(__file__)).split(os.path.sep)[:-1])
27 |
--------------------------------------------------------------------------------
/fogpy/composites.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | # -*- coding: utf-8 -*-
3 | # Copyright (c) 2017-2020 Fogpy developers
4 |
5 | # This file is part of the fogpy package.
6 |
7 | # This program is free software: you can redistribute it and/or modify
8 | # it under the terms of the GNU General Public License as published by
9 | # the Free Software Foundation, either version 3 of the License, or
10 | # (at your option) any later version.
11 |
12 | # This program is distributed in the hope that it will be useful,
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | # GNU General Public License for more details.
16 |
17 | # You should have received a copy of the GNU General Public License
18 | # along with this program. If not, see .
19 |
20 | """Interface Fogpy functionality as Satpy composite.
21 |
22 | This module implements satellite image based fog and low stratus
23 | detection and forecasting algorithm as a Satpy custom composite object.
24 | """
25 |
26 | import logging
27 | import numpy
28 | import xarray
29 | import pathlib
30 |
31 | import appdirs
32 | import satpy
33 | import satpy.composites
34 | import satpy.dataset
35 | import pyorbital.astronomy
36 | import pkg_resources
37 |
38 | from .algorithms import DayFogLowStratusAlgorithm
39 | from .algorithms import NightFogLowStratusAlgorithm
40 | from .utils import dl_dem
41 |
42 |
43 | logger = logging.getLogger(__name__)
44 |
45 |
46 | class FogCompositor(satpy.composites.GenericCompositor):
47 | """A compositor for fog.
48 |
49 | FIXME DOC
50 | """
51 |
52 | def __init__(self, name,
53 | prerequisites=None,
54 | optional_prerequisites=None,
55 | **kwargs):
56 | return super().__init__(
57 | name,
58 | prerequisites=prerequisites,
59 | optional_prerequisites=optional_prerequisites,
60 | **kwargs)
61 |
62 | def _get_area_lat_lon(self, projectables):
63 | projectables = self.check_areas(projectables)
64 |
65 | # Get central lon/lat coordinates for the image
66 | area = projectables[0].area
67 | lon, lat = area.get_lonlats()
68 |
69 | return (area, lat, lon)
70 |
71 | @staticmethod
72 | def _convert_xr_to_ma(projectables):
73 | """Convert projectables to masked arrays
74 |
75 | fogpy is still working with masked arrays and does not yet support
76 | xarray / dask (see #6). For now, convert to masked arrays. This
77 | function takes a list (or other iterable) of
78 | ``:class:xarray.DataArray`` instances and converts this to a list
79 | of masked arrays. The mask corresponds to any non-finite data in
80 | each input data array.
81 |
82 | Args:
83 | projectables (iterable): Iterable with xarray.DataArray
84 | instances, such as `:func:satpy.Scene._generate_composite`
85 | passes on to the ``__call__`` method of each Compositor
86 | class.
87 |
88 | Returns:
89 | List of masked arrays, of the same length as ``projectables``,
90 | each projectable converted to a masked array.
91 | """
92 |
93 | return [numpy.ma.masked_invalid(p.values, copy=False)
94 | for p in projectables]
95 |
96 | @staticmethod
97 | def _convert_ma_to_xr(projectables, *args):
98 | """Convert fogpy algorithm result to xarray images
99 |
100 | The fogpy algorithms return numpy masked arrays, but satpy
101 | compositors expect xarray DataArry objects. This method
102 | takes the output of the fogpy algorithm routine and converts
103 | it to an xarray DataArray, with the attributes corresponding
104 | to a Satpy composite.
105 |
106 | Args:
107 | projectables (iterable): Iterable with xarray.DataArray
108 | instances, such as `:func:satpy.Scene._generate_composite`
109 | passes on to the ``__call__`` method of each Compositor
110 | class.
111 | fls (masked_array): Masked array such as returned by
112 | ``fogpy.algorithms.BaseSatelliteAlgorithm.run`` or its
113 | subclasses
114 | mask (masked_array): Mask corresponding to fls.
115 |
116 | Returns:
117 | List[xarray.DataArray] list of xarray DataArrays, corresponding
118 | to the ``*args`` inputs passed. If an image and a mask, those
119 | can be passed to ``GenericCompositor.__call__`` to get a LA image
120 | ``xarray.DataArray``, or the latter can be constructed directly.
121 | """
122 |
123 | fv = numpy.nan
124 | # convert to xarray images
125 | dims = projectables[0].dims
126 | coords = projectables[0].coords
127 | attrs = {k: projectables[0].attrs[k]
128 | for k in {"satellite_longitude", "satellite_latitude",
129 | "satellite_altitude", "sensor", "platform_name",
130 | "orbital_parameters", "georef_offset_corrected",
131 | "start_time", "end_time", "area", "resolution"} &
132 | projectables[0].attrs.keys()}
133 |
134 | das = [xarray.DataArray(
135 | ma.data if isinstance(ma, numpy.ma.MaskedArray) else ma,
136 | dims=dims, coords=coords, attrs=attrs)
137 | for ma in args]
138 | for (ma, da) in zip(args, das):
139 | try:
140 | da.values[ma.mask] = fv
141 | except AttributeError: # no mask
142 | pass
143 | da.encoding["_FillValue"] = fv
144 |
145 | return das
146 |
147 |
148 | class _IntermediateFogCompositorDay(FogCompositor):
149 | def __init__(self, path_dem, *args, **kwargs):
150 | dem = pathlib.Path(appdirs.user_data_dir("fogpy")) / path_dem
151 | if not dem.exists():
152 | dl_dem(dem)
153 | filenames = [dem]
154 | self.elevation = satpy.Scene(reader="generic_image",
155 | filenames=filenames)
156 | self.elevation.load(["image"])
157 | return super().__init__(*args, **kwargs)
158 |
159 | def _verify_requirements(self, optional_datasets):
160 | """Verify that required cloud microphysics present
161 |
162 | Can be either cmic_cot/cmic_lwp/cmic_reff or cot/lwp/reff.
163 | """
164 | D = {}
165 | needs = {"cot": {"cot", "cmic_cot"},
166 | "lwp": {"lwp", "cwp", "cmic_lwp"},
167 | "reff": {"reff", "cmic_lwp"}}
168 | for x in optional_datasets:
169 | for (n, p) in needs.items():
170 | if x.attrs["name"] in p:
171 | D[n] = x
172 | continue
173 | missing = needs.keys() - D.keys()
174 | if missing:
175 | raise ValueError("Missing fog inputs: " + ", ".join(missing))
176 | return D
177 |
178 | def __call__(self, projectables, *args, optional_datasets, **kwargs):
179 | D = self._verify_requirements(optional_datasets)
180 | (area, lat, lon) = self._get_area_lat_lon(projectables)
181 |
182 | # fogpy is still working with masked arrays and does not yet support
183 | # xarray / dask (see #6). For now, convert to masked arrays.
184 | maskproj = self._convert_xr_to_ma(projectables)
185 | D = dict(zip(D.keys(), self._convert_xr_to_ma(D.values())))
186 |
187 | elev = self.elevation.resample(area)
188 | flsinput = {'vis006': maskproj[0],
189 | 'vis008': maskproj[1],
190 | 'ir108': maskproj[5],
191 | 'nir016': maskproj[2],
192 | 'ir039': maskproj[3],
193 | 'ir120': maskproj[6],
194 | 'ir087': maskproj[4],
195 | 'lat': lat,
196 | 'lon': lon,
197 | 'time': projectables[0].start_time,
198 | 'elev': numpy.ma.masked_invalid(
199 | elev["image"].sel(bands="L").values, copy=False),
200 | 'cot': D["cot"],
201 | 'reff': D["reff"],
202 | 'lwp': D["lwp"],
203 | "cwp": D["lwp"]}
204 | # Compute fog mask
205 | flsalgo = DayFogLowStratusAlgorithm(**flsinput)
206 | fls, mask = flsalgo.run()
207 |
208 | (xrfls, xrmsk, xrvmask, xrcbh, xrfbh, xrlcth) = self._convert_ma_to_xr(
209 | projectables, fls, mask, flsalgo.vcloudmask, flsalgo.cbh,
210 | flsalgo.fbh, flsalgo.lcth)
211 |
212 | ds = xarray.Dataset({
213 | "fls_day": xrfls,
214 | "fls_mask": xrmsk,
215 | "vmask": xrvmask,
216 | "cbh": xrcbh,
217 | "fbh": xrfbh,
218 | "lcthimg": xrlcth})
219 |
220 | ds.attrs.update(satpy.dataset.combine_metadata(
221 | xrfls.attrs, xrmsk.attrs, xrvmask.attrs,
222 | xrcbh.attrs, xrfbh.attrs, xrlcth.attrs))
223 |
224 | # NB: isn't this done somewhere more generically?
225 | for k in ("standard_name", "name", "resolution"):
226 | ds.attrs[k] = self.attrs.get(k)
227 |
228 | return ds
229 |
230 |
231 | class FogCompositorDay(satpy.composites.GenericCompositor):
232 | def __call__(self, projectables, *args, **kwargs):
233 | # in the yaml file, fls_day has as a single prerequisite
234 | # _intermediate_fls_day. Therefore, the first and only
235 | # projectable is actually a Dataset, and pass a DataArray
236 | # to the superclass.__call__ method.
237 | ds = projectables[0]
238 | # the fogpy algorithm has the mask as True where fog is absent and
239 | # False where fog is present, although that is OK for a masked array,
240 | # we want the opposite interpretation when visualising it as the A band
241 | # on a LA-type image, therefore invert the truthiness with a unary
242 |
243 | # normally we'd invert this with ~x, but due ta a bug this loses the
244 | # attributes: see https://github.com/pydata/xarray/issues/4065
245 | # True^x is equivalent to ~x for booleans
246 | with xarray.set_options(keep_attrs=True):
247 | return super().__call__((ds["fls_day"], True ^ ds["fls_mask"]), *args, **kwargs)
248 |
249 |
250 | class FogCompositorDayExtra(satpy.composites.GenericCompositor):
251 | def __call__(self, projectables, *args, **kwargs):
252 | ds = projectables[0]
253 | ds.attrs["standard_name"] = ds.attrs["name"] = "fls_day_extra"
254 | return ds
255 |
256 |
257 | class FogCompositorNight(FogCompositor):
258 |
259 | def __call__(self, projectables, *args, **kwargs):
260 | (area, lat, lon) = self._get_area_lat_lon(projectables)
261 |
262 | sza = pyorbital.astronomy.sun_zenith_angle(
263 | projectables[0].start_time, lon, lat)
264 |
265 | maskproj = self._convert_xr_to_ma(projectables)
266 |
267 | flsinput = {'ir108': maskproj[1],
268 | 'ir039': maskproj[0],
269 | 'sza': sza,
270 | 'lat': lat,
271 | 'lon': lon,
272 | 'time': projectables[0].start_time
273 | }
274 |
275 | # Compute fog mask
276 | flsalgo = NightFogLowStratusAlgorithm(**flsinput)
277 | fls, mask = flsalgo.run()
278 |
279 | (xrfls, xrmsk) = self._convert_ma_to_xr(projectables, fls, mask)
280 |
281 | return super().__call__((xrfls, xrmsk), *args, **kwargs)
282 |
283 |
284 | def save_extras(sc, fn):
285 | """Save the `fls_days_extra` dataset to NetCDF
286 |
287 | The ``fls_day_extra`` dataset as produced by the `FogCompositorDayExtra` and
288 | loaded using ``.load(["fls_day_extra"])`` is unique in the sense that it is
289 | an `xarray.Dataset` rather than an `xarray.DataArray`. This means it can't
290 | be stored with the usual satpy routines. Because some of its attributes
291 | contain special types, it can`t be stored with `Dataset.to_netcdf` either.
292 |
293 | This function transfers the data variables as direct members of a new
294 | `Scene` object and then use the `cf_writer` to write those to a NetCDF file.
295 |
296 | Args:
297 | sc : Scene
298 | Scene object with the already loaded ``fls_day_extra`` "composite"
299 | fn : str-like or path
300 | Path to which to write NetCDF
301 | """
302 | s = satpy.Scene()
303 | ds = sc["fls_day_extra"]
304 | for k in ds.data_vars:
305 | s[k] = ds[k]
306 | s.save_datasets(
307 | writer="cf",
308 | datasets=ds.data_vars.keys(),
309 | filename=str(fn))
310 |
--------------------------------------------------------------------------------
/fogpy/data/DEM/.gitignore:
--------------------------------------------------------------------------------
1 | eu-1km.tif
2 | new-england-500m.tif
3 |
--------------------------------------------------------------------------------
/fogpy/etc/composites/abi.yaml:
--------------------------------------------------------------------------------
1 | sensor_name: visir/abi
2 |
3 | composites:
4 |
5 | fls_night:
6 | compositor: !!python/name:fogpy.composites.FogCompositorNight
7 | prerequisites:
8 | - C07
9 | - C14
10 | standard_name: fls_night
11 |
12 | _intermediate_fls_day:
13 | compositor: !!python/name:fogpy.composites._IntermediateFogCompositorDay
14 | prerequisites:
15 | - C02
16 | - C03
17 | - C05
18 | - C07
19 | - C11
20 | - C14
21 | - C15
22 | optional_prerequisites:
23 | - cmic_cot
24 | - cmic_lwp
25 | - cmic_reff
26 | - cot
27 | - cwp
28 | - reff
29 | standard_name: _intermediate_fls_day
30 | path_dem: data/DEM/new-england-500m.tif
31 |
32 | fls_day:
33 | compositor: !!python/name:fogpy.composites.FogCompositorDay
34 | prerequisites:
35 | - _intermediate_fls_day
36 | standard_name: fls_day
37 |
38 | fls_day_extra:
39 | compositor: !!python/name:fogpy.composites.FogCompositorDayExtra
40 | prerequisites:
41 | - _intermediate_fls_day
42 | standard_name: fls_day_extra
43 |
--------------------------------------------------------------------------------
/fogpy/etc/composites/seviri.yaml:
--------------------------------------------------------------------------------
1 | sensor_name: visir/seviri
2 |
3 | composites:
4 |
5 | fls_night:
6 | compositor: !!python/name:fogpy.composites.FogCompositorNight
7 | prerequisites:
8 | - IR_039
9 | - IR_108
10 | standard_name: fls_night
11 |
12 | _intermediate_fls_day:
13 | compositor: !!python/name:fogpy.composites._IntermediateFogCompositorDay
14 | prerequisites:
15 | - VIS006
16 | - VIS008
17 | - IR_016
18 | - IR_039
19 | - IR_087
20 | - IR_108
21 | - IR_120
22 | optional_prerequisites:
23 | - cmic_cot
24 | - cmic_lwp
25 | - cmic_reff
26 | - cot
27 | - cwp
28 | - reff
29 | standard_name: _intermediate_fls_day
30 | path_dem: data/DEM/eu-1km.tif
31 |
32 | fls_day:
33 | compositor: !!python/name:fogpy.composites.FogCompositorDay
34 | prerequisites:
35 | - _intermediate_fls_day
36 | standard_name: fls_day
37 |
38 | fls_day_extra:
39 | compositor: !!python/name:fogpy.composites.FogCompositorDayExtra
40 | prerequisites:
41 | - _intermediate_fls_day
42 | standard_name: fls_day_extra
43 |
--------------------------------------------------------------------------------
/fogpy/etc/elevation_1km.npy:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pytroll/fogpy/4883d2198da770d2e95911b792cc764b33d15568/fogpy/etc/elevation_1km.npy
--------------------------------------------------------------------------------
/fogpy/etc/fog_testdata.npy:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pytroll/fogpy/4883d2198da770d2e95911b792cc764b33d15568/fogpy/etc/fog_testdata.npy
--------------------------------------------------------------------------------
/fogpy/etc/fog_testdata2.npy:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pytroll/fogpy/4883d2198da770d2e95911b792cc764b33d15568/fogpy/etc/fog_testdata2.npy
--------------------------------------------------------------------------------
/fogpy/etc/fog_testdata_fogmask.npy:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pytroll/fogpy/4883d2198da770d2e95911b792cc764b33d15568/fogpy/etc/fog_testdata_fogmask.npy
--------------------------------------------------------------------------------
/fogpy/etc/fog_testdata_hrv.npy:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pytroll/fogpy/4883d2198da770d2e95911b792cc764b33d15568/fogpy/etc/fog_testdata_hrv.npy
--------------------------------------------------------------------------------
/fogpy/etc/fog_testdata_night.npy:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pytroll/fogpy/4883d2198da770d2e95911b792cc764b33d15568/fogpy/etc/fog_testdata_night.npy
--------------------------------------------------------------------------------
/fogpy/etc/fog_testdata_night2.npy:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pytroll/fogpy/4883d2198da770d2e95911b792cc764b33d15568/fogpy/etc/fog_testdata_night2.npy
--------------------------------------------------------------------------------
/fogpy/etc/fog_testdata_pre.npy:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pytroll/fogpy/4883d2198da770d2e95911b792cc764b33d15568/fogpy/etc/fog_testdata_pre.npy
--------------------------------------------------------------------------------
/fogpy/etc/result_20131112.bufr:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pytroll/fogpy/4883d2198da770d2e95911b792cc764b33d15568/fogpy/etc/result_20131112.bufr
--------------------------------------------------------------------------------
/fogpy/etc/result_20131112_metar.bufr:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pytroll/fogpy/4883d2198da770d2e95911b792cc764b33d15568/fogpy/etc/result_20131112_metar.bufr
--------------------------------------------------------------------------------
/fogpy/etc/result_20131112_swis.bufr:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pytroll/fogpy/4883d2198da770d2e95911b792cc764b33d15568/fogpy/etc/result_20131112_swis.bufr
--------------------------------------------------------------------------------
/fogpy/etc/result_20140827.bufr:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pytroll/fogpy/4883d2198da770d2e95911b792cc764b33d15568/fogpy/etc/result_20140827.bufr
--------------------------------------------------------------------------------
/fogpy/etc/testarea.txt:
--------------------------------------------------------------------------------
1 | Area ID: meteosatseviri[ 214528.82635592 4370087.21101246 1108648.96976938 4793144.05739266](141, 298)
2 | Name: On-the-fly area
3 | Projection ID: geos
4 | Projection: {'a': '6378169.00', 'b': '6356583.80', 'h': '35785831.00', 'lat_0': '0.00', 'lon_0': '0.00', 'proj': 'geos'}
5 | Number of columns: 298
6 | Number of rows: 141
7 | Area extent: (214528.82635591552, 4370087.2110124603, 1108648.9697693815, 4793144.0573926577)
8 |
9 |
--------------------------------------------------------------------------------
/fogpy/lowwatercloud.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | # -*- coding: utf-8 -*-
3 | # Copyright (c) 2017-2020 Fogpy developers
4 |
5 | # This file is part of the fogpy package.
6 |
7 | # This program is free software: you can redistribute it and/or modify
8 | # it under the terms of the GNU General Public License as published by
9 | # the Free Software Foundation, either version 3 of the License, or
10 | # (at your option) any later version.
11 |
12 | # This program is distributed in the hope that it will be useful,
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | # GNU General Public License for more details.
16 |
17 | # You should have received a copy of the GNU General Public License
18 | # along with this program. If not, see .
19 |
20 | """ This module implements a class for a 1D low water cloud model.
21 | The approach can be used to determine fog cloud base heights by known
22 | cloud top height and temperature and cloud liquid water path, e.g. from
23 | satellite retrievals.
24 | The implemented approch is based on a publication:
25 |
26 |
27 | The implementation is based on the following publications:
28 |
29 | * Cermak, J., & Bendix, J. (2011). Detecting ground fog from space–a
30 | microphysics-based approach. International Journal of Remote Sensing,
31 | 32(12), 3345-3371. doi:10.1016/j.atmosres.2007.11.009
32 | * Cermak, J., & Bendix, J. (2008). A novel approach to fog/low
33 | stratus detection using Meteosat 8 data. Atmospheric Research,
34 | 87(3-4), 279-292. doi:10.1016/j.atmosres.2007.11.009
35 | * Cermak, J. (2006). SOFOS-a new satellite-based operational fog
36 | observation scheme. (PhD thesis), Philipps-Universität Marburg,
37 | Marburg, Germany. doi:doi.org/10.17192/z2006.0149
38 |
39 | """
40 |
41 | import math
42 | import logging
43 | import time
44 | import matplotlib.pyplot as plt
45 | import numpy as np
46 | from scipy.optimize import basinhopping
47 | from scipy.optimize import brute
48 |
49 | # Configure logger.
50 | logger = logging.getLogger('lowwatercloud')
51 |
52 |
53 | class CloudLayer(object):
54 | """This class represent a cloud layer - 1D representation of a
55 | cloud section from its vertical profile with defined extent and homogenius
56 | cloud parameters.
57 | The layer is defined by the bottom and top height in the cloud profile"""
58 | def __init__(self, bottom, top, lowcloud, add=True):
59 | self.bottom = bottom # Bottom height of the cloud layer
60 | self.top = top # Top height of the cloud layer
61 | self.z = top - (top - bottom) / 2 # Central layer height
62 | self.debug = lowcloud.debug
63 | # Fix maximum z height to cloud top height from cloud object
64 | # Height optimasation can provoke layers above the cth
65 | if self.z > lowcloud.cth:
66 | self.z = lowcloud.cth
67 |
68 | # Get temperaure and air presure
69 | self.temp = lowcloud.get_moist_adiabatic_lapse_temp(self.z,
70 | lowcloud.cth,
71 | lowcloud.ctt,
72 | True)
73 | self.press = lowcloud.get_air_pressure(self.z)
74 |
75 | # Calculate Vapour pressure and mixing ratio
76 | self.psv = lowcloud.get_sat_vapour_pressure(self.temp,
77 | lowcloud.vapour_method)
78 | self.vmr = lowcloud.get_vapour_mixing_ratio(self.press, self.psv)
79 |
80 | # Get liquid water mixing ratio
81 | if lowcloud.cb_vmr is None:
82 | lowcloud.get_cloud_based_vapour_mixing_ratio()
83 |
84 | self.lmr = lowcloud.get_liquid_mixing_ratio(lowcloud.cb_vmr, self.vmr)
85 |
86 | # Get layer density
87 | self.rho = lowcloud.get_moist_air_density(self.press * 100,
88 | self.psv * 100,
89 | self.check_temp(self.temp,
90 | 'kelvin',
91 | self.debug))
92 |
93 | # Get layer liquid water density
94 | self.lrho = lowcloud.get_liquid_density(self.press * 100,
95 | self.check_temp(self.temp,
96 | 'celsius'))
97 | self.lrho = 1000 # TODO Fix liquid water density method
98 | # Get in cloud mixing ratio beta
99 | self.beta = lowcloud.get_incloud_mixing_ratio(self.z, lowcloud.cth,
100 | lowcloud.cbh)
101 |
102 | # Get liquid water content
103 | self.lwc = lowcloud.get_liquid_water_content(self.z, lowcloud.cth,
104 | self.rho, self.lmr,
105 | self.beta,
106 | lowcloud.upthres,
107 | lowcloud.maxlwc)
108 |
109 | # Get layer effective radius
110 | self.reff = lowcloud.get_effective_radius(self.z)
111 |
112 | # Get layer extinction coefficient
113 | self.extinct = lowcloud.get_extinct(self.lwc, self.reff,
114 | (self.lrho * 1000.))
115 |
116 | # Get visibility
117 | self.visibility = lowcloud.get_visibility(self.extinct)
118 |
119 | # Add cloud layer to low water cloud object
120 | if add:
121 | lowcloud.layers.append(self)
122 |
123 | if self.debug:
124 | logger.debug('New cloud layer: z: {} m | t: {} °C | p: {} hPa | '
125 | 'psv: {} hPa | vmr: {} g kg-1 | lmr: {} g kg-1 | '
126 | 'beta: {} | rho: {} kg m-3 | lwc: {} g m-3'
127 | .format(self.z, self.temp, round(self.press, 3),
128 | round(self.psv, 3), round(self.vmr, 3),
129 | round(self.lmr, 3), round(self.beta, 3),
130 | round(self.rho, 3), round(self.lwc, 3)))
131 |
132 | @classmethod
133 | def check_temp(self, temp, unit='celsius', debug=False):
134 | """Check for plausible range of temperature value for given unit.
135 | Convert if required"""
136 | if unit == 'celsius':
137 | if temp > 60:
138 | result = temp - 273.15
139 | if debug:
140 | logger.debug('Temperature {} is in Kelvin. Auto converting'
141 | ' to {} °C'.format(temp, result))
142 | else:
143 | result = temp
144 | elif unit == 'kelvin':
145 | if temp <= 60 or temp < 0:
146 | result = temp + 273.15
147 | if debug:
148 | logger.debug('Temperature {} is in Celsius. '
149 | 'Auto converting to {} K'
150 | .format(temp, result))
151 | else:
152 | result = temp
153 |
154 | return(result)
155 |
156 | def get_layer_info(self):
157 | print('New cloud layer: z: {} m | t: {} °C | p: {} hPa | '
158 | 'psv: {} hPa | vmr: {} g kg-1 | lmr: {} g kg-1 | '
159 | 'beta: {} | rho: {} kg m-3 | lwc: {} g m-3'
160 | .format(self.z, self.temp, round(self.press, 3),
161 | round(self.psv, 3), round(self.vmr, 3),
162 | round(self.lmr, 3), round(self.beta, 3),
163 | round(self.rho, 3), round(self.lwc, 3)))
164 |
165 |
166 | class LowWaterCloud(object):
167 | """A class to simulate the water content of a low cloud and calculate its
168 | meteorological properties.
169 |
170 | Args:
171 | | cth (:obj:`float`): Cloud top height in m.
172 | | ctt (:obj:`float`): Cloud top temperature in K.
173 | | cwp (:obj:`float`): Cloud water path in kg / m^2.
174 | | cbh (:obj:`float`): Cloud base height in m.
175 | | reff (:obj:`float`): Droplet effective radius in m.
176 | | cbt (:obj:`float`): Cloud base temperature in K.
177 | | upthres (:obj:`float`): Top layer thickness with dry air
178 | entrainment in m.
179 | | lowthres (:obj:`float`): Bottem layer thickness with ground
180 | coupling in m.
181 | | thickness (:obj:`float`): Layer thickness in m.
182 | | debug (:obj:`bool`): Boolean to activate additional debug output.
183 | | nodata (:obj:`float`): Provide a specific Nodata value.
184 | Default is: -9999.
185 |
186 | Returns:
187 | Calibrated cloud base height in m.
188 | """
189 | def __init__(self, cth=None, ctt=None, cwp=None, cbh=0, reff=None,
190 | cbt=None, upthres=50., lowthres=75., thickness=10.,
191 | debug=False, nodata=-9999):
192 | self.upthres = upthres # Top layer thickness with dry air entrainment
193 | self.lowthres = lowthres # Bottom layer thickness with coupling
194 | self.cth = cth # Cloud top height
195 | self.ctt = ctt # Cloud top temperature
196 | self.cbh = cbh # Cloud base height
197 | self.cbt = cbt # Cloud base temperature
198 | self.cwp = cwp # Cloud water path
199 | self.lwp = None # Dummy for liquid water path calculation
200 | self.reff = reff # Droplet effective radius
201 | self.layers = [] # List of cloud layers
202 | self.vapour_method = "magnus" # Method for saturated vapour pressure
203 | self.cb_vmr = None # Water vapour mixing ratio
204 | self.thickness = thickness # Layer thickness in m
205 | self.debug = debug # Boolean to activate additional output
206 | self.nodata = nodata # Specific Nodata value
207 |
208 | # Get maximal liquid water content underneath cloud top
209 | self.maxlwc = None
210 |
211 | # Raise warnings when thresholds are in conflict with top and
212 | # base cloud height
213 | if self.cth - self.upthres <= self.cbh:
214 | logger.warning("Upper threshold starting level <{}> and cloud base"
215 | " <{}> are in conflict"
216 | .format(self.cth - self.upthres, self.cbh))
217 | self.upthres = self.cth - self.cbh - 1
218 | logger.info("Reducing upper threshold <{}> to correct conflict"
219 | .format(self.upthres))
220 | if self.lowthres >= self.cth:
221 | logger.warning("Lower threshold ending level <{}> and cloud top"
222 | " <{}> are in conflict"
223 | .format(self.lowthres, self.cth))
224 |
225 | @property
226 | def cbh(self):
227 | return self.__cbh
228 |
229 | @cbh.setter
230 | def cbh(self, cbh):
231 | # Check conflicts for threshold and cloud base
232 | if cbh >= self.cth:
233 | self.__cbh = self.cth - 1
234 | self.upthres = self.cth - 1
235 | logger.info("Cloud base <{}> is higher than cloud top <{}>. "
236 | "Autmatically reduced to <{}>".format(
237 | cbh, self.cth, self.cth - 1))
238 | elif self.cth - self.upthres <= cbh:
239 | self.upthres = self.cth - cbh - 1
240 | logger.info("Reducing upper threshold <{}> to correct conflict"
241 | .format(self.upthres))
242 | self.__cbh = cbh
243 | else:
244 | self.__cbh = cbh
245 |
246 | def init_cloud_layers(self, init_cbh, thickness, overwrite=True):
247 | """Method to initialize cloud layers and corresponding parameters.
248 | the method needs a initial cloud base height and thickness in [m]."""
249 | self.cbh = init_cbh
250 | self.get_cloud_based_vapour_mixing_ratio()
251 |
252 | # Get maximal liquid water content underneath cloud top
253 | maxlwc_layer = CloudLayer(self.cth - self.upthres - thickness,
254 | self.cth - self.upthres + thickness,
255 | self, False)
256 | self.maxlwc = maxlwc_layer.lwc
257 | # Calculate layer properties
258 | # Contitional resetting cloud layers
259 | if overwrite:
260 | self.layers = []
261 | # Cloud base layer
262 | CloudLayer(init_cbh - thickness, init_cbh + thickness, self)
263 | # Loop over layers
264 | layerrange = np.arange(init_cbh, self.cth, thickness)
265 | for b in layerrange:
266 | CloudLayer(b, b + thickness, self)
267 | # Cloud top layer
268 | CloudLayer(self.cth - thickness, self.cth + thickness, self)
269 | if self.debug:
270 | logger.info("Initialize {} cloud layers with {} m thickness"
271 | " and {} m cbh"
272 | .format(len(self.layers), thickness, init_cbh))
273 |
274 | def get_cloud_base_height(self, start=0, method='basin'):
275 | """ Calculate cloud base height [m]."""
276 | # Calculate cloud base height
277 | self.cbh = self.optimize_cbh(start, method=method, debug=self.debug)
278 |
279 | return self.cbh
280 |
281 | def get_fog_base_height(self, substitude=False):
282 | """This method calculate the fog cloud base height for low clouds
283 | with visibilities below 1000 m.
284 |
285 | Args:
286 | | substitude (:obj:`bool`): Optional argument to substitude with
287 | cbh if no fbh could be found.
288 |
289 | Returns:
290 | Fog base height
291 | """
292 | fog_z = [l.z for l in self.layers
293 | if l.visibility is not None and l.visibility <= 1000]
294 | if len(fog_z) > 0:
295 | # Get lowest heights with visibility treshold
296 | self.fbh = min(fog_z)
297 | else:
298 | if substitude:
299 | logger.warning("No fog base height found: Substitude with "
300 | "cloud base height: {}".format(self.cbh))
301 | self.fbh = self.cbh
302 | else:
303 | logger.warning("No fog base height found: Set to NaN")
304 | self.fbh = np.nan
305 |
306 | return self.fbh
307 |
308 | def get_liquid_water_content(self, z, cth, hrho, lmr, beta, thres,
309 | maxlwc=None, debug=False):
310 | """Calculate liquid water content [g m-3] by air density and
311 | liquid water mixing ratio."""
312 | if z > cth - thres:
313 | if maxlwc is None:
314 | maxlwc_layer = CloudLayer(
315 | self.cth - self.upthres - self.thickness,
316 | self.cth - self.upthres + self.thickness,
317 | self, False)
318 | maxlwc = maxlwc_layer.lwc
319 | self.maxlwc = maxlwc
320 | if self.maxlwc <= 0 and debug:
321 | logger.debug(
322 | "Maximum liquid water content is zero or negative")
323 |
324 | lwc = (cth - z) / (thres) * maxlwc
325 | # Test if liquid water content is negativ
326 | # This occures while optimizing with cbh=cth
327 | if lwc < 0:
328 | logger.debug("Liquid water content <{}> is negative for "
329 | "maximum of <{}> and cbh <{}>"
330 | .format(lwc, self.maxlwc, self.cbh))
331 | lwc = 0 # Set lwc to zero
332 | else:
333 | lwc = (1 - beta) * hrho * lmr
334 |
335 | return lwc
336 |
337 | @classmethod
338 | def get_moist_air_density(self, pa, pv, temp, empiric=False, debug=False):
339 | """Calculate air density for humid air with known pressure and water
340 | vapour pressure and temperature."""
341 | Rv = 461.495 # Specific gas constant for water vapour J kg-1 K-1
342 | Rd = 287.058 # Specific gas constant for dry air J kg-1 K-1
343 | d_sea = 1.2929 # Density of dry air at sea level
344 | if temp <= 60:
345 | newtemp = temp + 273.15
346 | if debug:
347 | logger.debug('Temperature {} is in Celsius. Auto converting to'
348 | ' {} K'.format(temp, newtemp))
349 | temp = newtemp
350 | if empiric:
351 | hrho = d_sea * (273.15 / temp) * ((pa - 0.3783 * pv) / (1.013 *
352 | 10**5))
353 | else:
354 | hrho = ((pa - pv) / (Rd * temp)) + (pv / (Rv * temp))
355 |
356 | return hrho
357 |
358 | @classmethod
359 | def get_moist_adiabatic_lapse_temp(self, z, cth, ctt, convert=False):
360 | """Calculate air temperature for height z [K] following a moist
361 | adiabatic lapse rate.
362 |
363 | Requires values for cloud top height and temperature
364 | e.g. known from satellite retrievals."""
365 | malr = 0.0065 # ## MALR: Moist adiabatic lapse rate [K m-1]
366 | temp = (cth - z) * malr + ctt
367 |
368 | # Optional convertion to Celsius degrees.
369 | if convert:
370 | temp = temp - 273.15
371 |
372 | return temp
373 |
374 | @classmethod
375 | def get_sat_vapour_pressure(self, temp, mode='buck',
376 | convert=False, debug=False):
377 | """Calculate satured water vapour pressure for temperature [hPa]
378 | using different empirical approaches.
379 |
380 | Options: Buck, Magnus
381 |
382 | Convert temperatures in K to °C
383 | """
384 | if convert:
385 | newtemp = temp - 273.15
386 | if self.debug:
387 | logger.info("Converting temperature {} K to {} °C"
388 | .format(temp, newtemp))
389 | temp = newtemp
390 | elif temp > 60:
391 | newtemp = temp - 273.15
392 | if debug:
393 | logger.debug('Temperature {} is in Kelvin. Auto converting to'
394 | ' {} °C'.format(temp, newtemp))
395 | temp = newtemp
396 |
397 | if mode == 'buck':
398 | psv = 0.61121 * math.exp((18.678 - temp / 234.5) *
399 | (temp / (257.14 + temp)))
400 | elif mode == 'magnus':
401 | const1 = 6.1078
402 | if temp > 0:
403 | const2 = 17.08085
404 | const3 = 234.175
405 | else:
406 | const2 = 17.84362
407 | const3 = 245.425
408 | psv = const1 * math.exp(const2 * temp / (const3 + temp))
409 | # Convert to hPa
410 | if mode == 'buck':
411 | result = psv * 10
412 | else:
413 | result = psv
414 |
415 | return result
416 |
417 | @classmethod
418 | def get_vapour_pressure(self, z, temp):
419 | """Calculate water vapour pressure for height z [hPa]."""
420 | # TODO Finish implementation
421 | wdensity = 0 # Density of water vapour
422 | gconst = 461.51 # Gas constante of water vapour in [J kg-1 K-1]
423 | # Calculate water vapur pressure
424 | vp = wdensity * gconst * temp
425 |
426 | return vp
427 |
428 | @classmethod
429 | def get_air_pressure(self, z, elevation=0):
430 | """Calculate ambient air pressure for height z [hPa]."""
431 |
432 | pa = 100 * ((44331.514 - z) / 11880.516) ** (1 / 0.1902632)
433 |
434 | return pa / 100
435 |
436 | @classmethod
437 | def get_vapour_mixing_ratio(self, pa, pv):
438 | """Calculate water vapour mixing ratio for given ambient pressure and
439 | water vapour pressure. Also usabale under saturated conditions."""
440 | # Calculate water vapour mixing ratio
441 | vmr = 621.97 * pv / (pa - pv)
442 |
443 | return vmr
444 |
445 | @classmethod
446 | def get_liquid_mixing_ratio(self, cb_vmr, vmr, debug=False):
447 | """Calculate liquid water mixing ratio for given water vapour mixing
448 | ratio in a certain height and the maximum water vapour mixing ratio at
449 | cloud base condensation level [g/kg]."""
450 | lmr = cb_vmr - vmr
451 | if cb_vmr <= vmr and debug:
452 | logger.debug("Liquid water mixing ratio will be zero or negative"
453 | " for cbvmr: <{}> and vmr: <{}>".format(cb_vmr, vmr))
454 |
455 | return lmr
456 |
457 | def get_cloud_based_vapour_mixing_ratio(self, debug=False):
458 | # Get temperature and air pressure
459 | temp = self.get_moist_adiabatic_lapse_temp(self.cbh, self.cth,
460 | self.ctt, True)
461 | press = self.get_air_pressure(self.cbh)
462 |
463 | # Calculate Vapour pressure and mixing ratio
464 | psv = self.get_sat_vapour_pressure(temp, self.vapour_method)
465 | cb_vmr = self.get_vapour_mixing_ratio(press, psv)
466 | self.cb_vmr = cb_vmr
467 | if debug:
468 | logger.debug("Cloud based vapour mixing ratio: "
469 | "<{}> at cloud base <{}>"
470 | .format(cb_vmr, self.cbh))
471 |
472 | return cb_vmr
473 |
474 | @classmethod
475 | def get_incloud_mixing_ratio(self, z, cth, cbh, lowthres=75., upthres=50.):
476 | """Calculate in-cloud mixing ratio for given cloud height parameter."""
477 | midbeta = 0.3 * cth / 1000 # Fixed in cloud mixing ratio
478 | # Separation in three major cloud layers
479 | # Apply fixed value for middle layer
480 | if z > cbh + lowthres and z < cth - upthres:
481 | beta = midbeta
482 | # Apply zero value for upper layer
483 | elif z >= cth - upthres:
484 | beta = midbeta
485 | # Apply linear increase from zero to fixed value in the lower layer
486 | elif z <= (cbh + lowthres):
487 | beta = (z - cbh) / (lowthres) * midbeta
488 | else:
489 | beta = midbeta # Default value
490 |
491 | return beta
492 |
493 | def get_liquid_water_path(self):
494 | """Calculate liquid water path for given cloud layers [g m-2]."""
495 | z = np.array([l.top - l.bottom for l in self.layers])
496 | lwc = np.array([l.lwc for l in self.layers])
497 | # Get sum of single layer water path
498 | lwp = np.sum(z * lwc)
499 |
500 | self.lwp = lwp
501 |
502 | return lwp
503 |
504 | def optimize_cbh(self, start, method='basin', debug=False):
505 | """Find best fitting cloud base height by comparing calculated
506 | liquid water path with given satellite retrieval.
507 | Minimization with basinhopping or brute force algorithm
508 | from python scipy package."""
509 | cbhbounds = HeightBounds(self.cth - self.upthres, -1000)
510 | # Test input data
511 | if np.isnan(self.cwp) or np.isnan(self.cth):
512 | logger.warning("Input data for cwp: <{}> or cth: <{}> is not"
513 | " a number".format(self.cwp, self.cth))
514 | result = np.nan
515 | return(result)
516 | elif self.cwp == self.nodata or self.cth == self.nodata:
517 | logger.warning("Input cwp: <{}> or cth: <{}> in NoData format"
518 | .format(self.cwp, self.cth))
519 | result = np.nan
520 | return(result)
521 | # Choose method
522 | if method == 'basin':
523 | start_time = int(round(time.time() * 1000))
524 | minimizer_kwargs = {"method": "BFGS", "bounds": (0, self.cth -
525 | self.upthres)}
526 | ret = basinhopping(self.minimize_cbh,
527 | start,
528 | T=5.0,
529 | minimizer_kwargs=minimizer_kwargs,
530 | niter=30,
531 | niter_success=5,
532 | stepsize=200,
533 | accept_test=cbhbounds,
534 | seed=42)
535 | time_diff = int(round(time.time() * 1000)) - start_time
536 | result = float(ret.x[0])
537 | logger.info('Optimized lwp: start cbh: {:.2f}, cth: {:.2f}, '
538 | 'ctt: {:.2f}, observed lwp {:.2f}'
539 | ' --> result lwp: {:.2f}, calibrated cbh: {:.2f},'
540 | ' elapsed time: {:.2f} ms for {} layers with {} '
541 | 'm thickness'
542 | .format(start, float(self.cth), float(self.ctt),
543 | float(self.cwp), float(self.lwp),
544 | result, time_diff,
545 | len(self.layers), self.thickness))
546 | elif method == 'brute':
547 | ranges = slice(0, self.cth - self.upthres, 1)
548 | ret = brute(self.minimize_cbh, (ranges,), finish=None)
549 | result = ret
550 | # the minimisation routine self.minimize_cbh calls
551 | # self.init_cloud_layers, so in every call the cloud layers get reset;
552 | # we don't know if the final call corresponded to the minimum (with
553 | # basin hopping it might, with brute force it won't), which was
554 | # triggering bug issue #29, therefore re-initialise layers with the
555 | # last value
556 | self.init_cloud_layers(result, self.thickness, True)
557 | self.get_liquid_water_path() # also has side-effect...
558 | # Add optional debug output
559 | if debug:
560 | for l in self.layers:
561 | l.get_layer_info()
562 | # Set class variable for cloud base height
563 | self.cbh = result
564 |
565 | return(result)
566 |
567 | def minimize_cbh(self, x):
568 | """Minimization function for liquid water path."""
569 | x = np.reshape(x, (1,))
570 | self.init_cloud_layers(x[0], self.thickness, True)
571 | lwp = self.get_liquid_water_path()
572 | diff = abs(lwp - self.cwp)
573 |
574 | return diff
575 |
576 | def get_liquid_density(self, temp, press):
577 | """Calculate the liquid water density in [kg m-3]."""
578 | t0 = 0. # Reference temperature in [°C]
579 | rho_0 = 999.8 # Density of water for 0°C: [kg/m3]
580 | p0 = 1e5 # Air pressure at 0°C in [Pa]
581 | beta = 0.000088 # Expansion coefficient of water at 10oC: [m3/m3°C]
582 | E = 2.15e9 # Bulk modulus of water: [N/m2]
583 | rho = rho_0 / (1 + beta * (temp - t0)) / (1 - (press - p0) / E)
584 |
585 | return rho
586 |
587 | def get_visibility(self, extinct, contrast=0.02):
588 | """Calculate visibility in [m] for given cloud layer.
589 | Extinction is directly related to visibility by
590 | Koschmieder’s law.
591 | """
592 | if extinct is None:
593 | return None
594 | else:
595 | vis = (1 / extinct) * math.log(1 / contrast)
596 | # Remove negative visibilities
597 | if vis < 0:
598 | vis = 0
599 | return vis
600 |
601 | def get_extinct(self, lwc, reff, rho):
602 | """Calculate extingtion coeficient [m-1]
603 |
604 | The extinction therefore is a combination of radiation loss by
605 | (diffuse) scattering and molecular absorption.
606 | Required are the liquid water content, effective radius and
607 | liquid water density
608 | TODO: Recheck the unit of liquid water density g or kg? Should be in g
609 | """
610 | if reff is None:
611 | return None
612 | elif lwc == 0:
613 | return None
614 | else:
615 | extinct = 3 * lwc / (2 * reff * rho)
616 |
617 | return extinct
618 |
619 | def get_effective_radius(self, z):
620 | """The droplet effective radius in [um] for each level is computed on
621 | the assumptions that reff retrieved at 3.9 μm is the cloud top value,
622 | Cloud base reff is at 1 μm and the intermediate values are scaled
623 | linearly in between.
624 | """
625 | if self.reff is None:
626 | return None
627 | else:
628 | reff = 1e-6 + ((self.reff - 1e-6) / (self.cth -
629 | self.cbh)) * (z - self.cbh)
630 |
631 | return reff
632 |
633 | def plot_lowcloud(self, para, xlabel=None, save=None):
634 | """Plotting of selected low water cloud parameters."""
635 | if self.layers == []:
636 | logger.info("No layer found. Nothing to plot")
637 | heights = [getattr(l, 'z') for l in self.layers]
638 | paralist = [getattr(l, para) for l in self.layers]
639 | plt.figure()
640 | plt.plot(paralist, heights, '-o')
641 | plt.ylim((0, max(heights) + 50))
642 | plt.axvline(0, color='grey', ls='--')
643 | plt.axhline(self.cth, color='grey', ls='--')
644 | plt.axhline(self.cbh, color='grey', ls='--')
645 | plt.ylabel('Cloud height z in [m]')
646 | if xlabel is not None:
647 | plt.xlabel(xlabel)
648 | else:
649 | plt.xlabel(para)
650 | if save is not None:
651 | plt.savefig(save)
652 | else:
653 | plt.show()
654 |
655 |
656 | class HeightBounds(object):
657 | def __init__(self, xmax=2000, xmin=-1000):
658 | self.xmax = xmax
659 | self.xmin = xmin
660 |
661 | def __call__(self, **kwargs):
662 | x = kwargs["x_new"]
663 | tmax = bool(x <= self.xmax)
664 | tmin = bool(x >= self.xmin)
665 | return tmax and tmin
666 |
--------------------------------------------------------------------------------
/fogpy/test/__init__.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | # -*- coding: utf-8 -*-
3 | # Copyright (c) 2017-2020 Fogpy developers
4 |
5 | # This file is part of the fogpy package.
6 |
7 | # This program is free software: you can redistribute it and/or modify
8 | # it under the terms of the GNU General Public License as published by
9 | # the Free Software Foundation, either version 3 of the License, or
10 | # (at your option) any later version.
11 |
12 | # This program is distributed in the hope that it will be useful,
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | # GNU General Public License for more details.
16 |
17 | # You should have received a copy of the GNU General Public License
18 | # along with this program. If not, see .
19 |
20 | """The fogpy test suite.
21 | """
22 |
23 | from fogpy.test import (test_lowwatercloud,
24 | test_filters,
25 | test_algorithms
26 | )
27 |
28 | import unittest
29 |
30 |
31 | def suite():
32 | """The global test suite.
33 | """
34 |
35 | mysuite = unittest.TestSuite()
36 | mysuite.addTests(test_lowwatercloud.suite())
37 | mysuite.addTests(test_filters.suite())
38 | mysuite.addTests(test_algorithms.suite())
39 |
40 | return mysuite
41 |
--------------------------------------------------------------------------------
/fogpy/test/conftest.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | """conftest.py for fogpy."""
3 |
4 | import os
5 | import pytest
6 | import pkg_resources
7 |
8 |
9 | @pytest.fixture(scope="session", autouse=True)
10 | def setUp(tmp_path_factory):
11 | for nm in {"XDG_CACHE_HOME", "XDG_DATA_HOME"}:
12 | os.environ[nm] = str(tmp_path_factory.mktemp(nm))
13 | os.environ["SATPY_CONFIG_PATH"] = pkg_resources.resource_filename(
14 | "fogpy", "etc/")
15 |
--------------------------------------------------------------------------------
/fogpy/test/test_composites.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 |
3 | # Copyright (c) 2017-2020 Fogpy developers
4 |
5 | # This file is part of the fogpy package.
6 |
7 | # This program is free software: you can redistribute it and/or modify
8 | # it under the terms of the GNU General Public License as published by
9 | # the Free Software Foundation, either version 3 of the License, or
10 | # (at your option) any later version.
11 |
12 | # This program is distributed in the hope that it will be useful,
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | # GNU General Public License for more details.
16 |
17 | # You should have received a copy of the GNU General Public License
18 | # along with this program. If not, see .
19 |
20 | import pytest
21 | import numpy
22 | import datetime
23 | import tempfile
24 | import pathlib
25 | from numpy import array
26 | from xarray import Dataset, DataArray as xrda, open_dataset
27 | from unittest import mock
28 |
29 | import pkg_resources
30 |
31 |
32 | @pytest.fixture
33 | def fkattr():
34 | import pyresample
35 | return {
36 | 'satellite_longitude': 0.0,
37 | 'satellite_latitude': 0.0,
38 | 'satellite_altitude': 35785831.0,
39 | 'orbital_parameters': {
40 | 'projection_longitude': 0.0,
41 | 'projection_latitude': 0.0,
42 | 'projection_altitude': 35785831.0,
43 | 'satellite_nominal_longitude': 0.0,
44 | 'satellite_nominal_latitude': 0.0,
45 | 'satellite_actual_longitude': 0.0688189107392428,
46 | 'satellite_actual_latitude': 0.1640766475684642,
47 | 'satellite_actual_altitude': 35782769.05113167},
48 | 'sensor': 'seviri',
49 | 'platform_name': 'Meteosat-11',
50 | 'georef_offset_corrected': True,
51 | 'start_time': datetime.datetime(2020, 1, 6, 10, 0, 10, 604000),
52 | 'end_time': datetime.datetime(2020, 1, 6, 10, 12, 43, 608000),
53 | 'area': pyresample.AreaDefinition(
54 | "germ",
55 | "germ",
56 | None,
57 | {
58 | 'a': '6378144',
59 | 'b': '6356759',
60 | 'lat_0': '90',
61 | 'lat_ts': '50',
62 | 'lon_0': '5',
63 | 'no_defs': 'None',
64 | 'proj': 'stere',
65 | 'type': 'crs',
66 | 'units': 'm',
67 | 'x_0': '0',
68 | 'y_0': '0'},
69 | 3,
70 | 3,
71 | (-155100.4363, -4441495.3795, 868899.5637, -3417495.3795)),
72 | 'resolution': 3000.403165817,
73 | 'calibration': 'reflectance',
74 | 'polarization': None,
75 | 'level': None,
76 | 'modifiers': (),
77 | 'ancillary_variables': []}
78 |
79 |
80 | @pytest.fixture
81 | def fogpy_inputs(fkattr):
82 |
83 | D = dict(
84 | ir108=array(
85 | [
86 | [267.781, 265.75, 265.234],
87 | [266.771, 265.75, 266.432],
88 | [266.092, 266.771, 268.614],
89 | ]
90 | ),
91 | ir039=array(
92 | [
93 | [274.07, 270.986, 269.281],
94 | [273.335, 275.477, 277.236],
95 | [277.023, 279.663, 279.663],
96 | ]
97 | ),
98 | vis008=array(
99 | [
100 | [9.814, 10.652, 11.251],
101 | [11.49, 13.884, 15.799],
102 | [15.081, 16.158, 16.637],
103 | ]
104 | ),
105 | nir016=array(
106 | [
107 | [9.439, 9.559, 10.156],
108 | [11.47, 13.86, 16.011],
109 | [15.055, 16.25, 16.967],
110 | ]
111 | ),
112 | vis006=array(
113 | [
114 | [8.614, 9.215, 9.615],
115 | [9.916, 11.519, 12.921],
116 | [12.72, 13.422, 13.722],
117 | ]
118 | ),
119 | ir087=array(
120 | [
121 | [265.139, 263.453, 262.67],
122 | [264.225, 263.141, 263.608],
123 | [263.453, 264.071, 266.338],
124 | ]
125 | ),
126 | ir120=array(
127 | [
128 | [266.903, 265.208, 264.694],
129 | [265.55, 264.522, 265.379],
130 | [265.037, 265.037, 267.406],
131 | ]
132 | ),
133 | elev=array(
134 | [
135 | [319.481, 221.918, 300.449],
136 | [388.51, 501.519, 431.15],
137 | [521.734, 520.214, 505.892],
138 | ]
139 | ),
140 | cot=array([[6.15, 10.98, 11.78], [13.92, 16.04, 7.93], [7.94, 10.01, 6.12]]),
141 | reff=array(
142 | [
143 | [3.06e-06, 3.01e-06, 3.01e-06],
144 | [3.01e-06, 3.01e-06, 3.01e-06],
145 | [3.01e-06, 3.01e-06, 9.32e-06],
146 | ]
147 | ),
148 | lwp=array([[0.013, 0.022, 0.024], [0.028, 0.032, 0.016], [0.016, 0.02, 0.038]]),
149 | lat=array(
150 | [
151 | [50.669, 50.669, 50.67],
152 | [50.614, 50.615, 50.616],
153 | [50.559, 50.56, 50.561],
154 | ]
155 | ),
156 | lon=array([[6.437, 6.482, 6.528], [6.428, 6.474, 6.52], [6.42, 6.466, 6.511]]),
157 | cth=array(
158 | [
159 | [4400.0, 4200.0, 4000.0],
160 | [4200.0, 2800.0, 1200.0],
161 | [1600.0, 1000.0, 800.0],
162 | ]
163 | ),
164 | )
165 |
166 | return {k: xrda(v, dims=("x", "y"), attrs={**fkattr, "name": k})
167 | for (k, v) in D.items()}
168 |
169 |
170 | @pytest.fixture
171 | def fogpy_inputs_seviri_cmsaf(fogpy_inputs):
172 | fogpy_inputs = fogpy_inputs.copy()
173 | trans = {"ir108": "IR_108",
174 | "ir039": "IR_039",
175 | "vis008": "VIS008",
176 | "nir016": "IR_016",
177 | "vis006": "VIS006",
178 | "ir087": "IR_087",
179 | "ir120": "IR_120",
180 | "lwp": "cwp"}
181 | for (k, v) in trans.items():
182 | fogpy_inputs[v] = fogpy_inputs.pop(k)
183 | return fogpy_inputs
184 |
185 |
186 | @pytest.fixture
187 | def fogpy_inputs_abi_nwcsaf(fogpy_inputs):
188 | fogpy_inputs = fogpy_inputs.copy()
189 | trans = {"ir108": "C14",
190 | "ir039": "C07",
191 | "vis008": "C03",
192 | "nir016": "C05",
193 | "vis006": "C02",
194 | "ir087": "C11",
195 | "ir120": "C15",
196 | "lwp": "cmic_lwp",
197 | "cot": "cmic_cot",
198 | "reff": "cmic_reff"}
199 | for (k, v) in trans.items():
200 | fogpy_inputs[v] = fogpy_inputs.pop(k)
201 | return fogpy_inputs
202 |
203 |
204 | @pytest.fixture
205 | def fog_comp_base():
206 | from fogpy.composites import FogCompositor
207 | return FogCompositor(name="fls_day")
208 |
209 |
210 | @pytest.fixture
211 | def fogpy_outputs():
212 | fls = numpy.ma.masked_array(
213 | numpy.arange(9, dtype="f4").reshape((3, 3)),
214 | (numpy.arange(9) % 2).astype("?").reshape((3, 3)))
215 | mask = (numpy.arange(9, dtype="f4") % 2).astype("?").reshape((3, 3))
216 | return (fls, mask)
217 |
218 |
219 | @pytest.fixture
220 | def comp_loader():
221 | """Get a compositor loader for loading fogpy composites."""
222 | from satpy.composites.config_loader import CompositorLoader
223 | cpl = CompositorLoader()
224 | with mock.patch("requests.get") as rg, mock.patch("satpy.Scene"):
225 | rg.return_value.content = b"12345"
226 | cpl.load_compositors(["seviri", "abi"])
227 | return cpl
228 |
229 |
230 | @pytest.fixture
231 | def fog_extra():
232 | return {
233 | "vcloudmask": numpy.ma.masked_array(
234 | data=[[True, True, True], [False, False, True], [True, False, False]],
235 | mask=numpy.zeros((3, 3), dtype="?"),
236 | fill_value=True),
237 | "cbh": numpy.zeros((3, 3)),
238 | "fbh": numpy.zeros((3, 3)),
239 | "lcth": numpy.full((3, 3), numpy.nan)}
240 |
241 |
242 | @pytest.fixture
243 | def fog_comp_day():
244 | from fogpy.composites import FogCompositorDay
245 | return FogCompositorDay(name="fls_day")
246 |
247 |
248 | @pytest.fixture
249 | def fog_comp_day_extra():
250 | from fogpy.composites import FogCompositorDayExtra
251 | return FogCompositorDayExtra(name="fls_day_extra")
252 |
253 |
254 | @pytest.fixture
255 | def fog_comp_night():
256 | from fogpy.composites import FogCompositorNight
257 | return FogCompositorNight(name="fls_night")
258 |
259 |
260 | @pytest.fixture
261 | def fog_intermediate_dataset(fog_extra, fogpy_outputs, fkattr):
262 | ds = Dataset(
263 | {k: xrda(v, dims=("y", "x"), attrs=fkattr) for (k, v) in
264 | fog_extra.items()},
265 | attrs=fkattr)
266 | (fls_day, fls_mask) = fogpy_outputs
267 | ds["fls_day"] = xrda(fls_day, dims=("y", "x"), attrs=fkattr)
268 | ds["fls_mask"] = xrda(fls_mask, dims=("y", "x"), attrs=fkattr)
269 | return ds
270 |
271 |
272 | def test_convert_xr_to_ma(fogpy_inputs, fog_comp_base):
273 | fi_ma = fog_comp_base._convert_xr_to_ma(
274 | [fogpy_inputs["ir108"], fogpy_inputs["vis008"]])
275 | assert len(fi_ma) == 2
276 | assert all([isinstance(ma, numpy.ma.MaskedArray) for ma in fi_ma])
277 | assert numpy.array_equal(fi_ma[0].data, fogpy_inputs["ir108"].values)
278 | # try with some attributes missing
279 | ir108 = fogpy_inputs["ir108"].copy()
280 | del ir108.attrs["satellite_longitude"]
281 | del ir108.attrs["end_time"]
282 | fi_ma = fog_comp_base._convert_xr_to_ma([ir108])
283 |
284 |
285 | def test_convert_ma_to_xr(fogpy_inputs, fog_comp_base, fogpy_outputs):
286 | conv = fog_comp_base._convert_ma_to_xr(
287 | [fogpy_inputs["ir108"], fogpy_inputs["vis008"]],
288 | *fogpy_outputs)
289 | assert len(conv) == len(fogpy_outputs)
290 | assert all([isinstance(c, xrda) for c in conv])
291 | numpy.testing.assert_array_equal(fogpy_outputs[0].data, conv[0].values)
292 | assert conv[0].attrs["sensor"] == fogpy_inputs["ir108"].attrs["sensor"]
293 | # check without mask
294 | conv = fog_comp_base._convert_ma_to_xr(
295 | [fogpy_inputs["ir108"], fogpy_inputs["vis008"]],
296 | *(fo.data for fo in fogpy_outputs))
297 | # try with some attributes missing
298 | ir108 = fogpy_inputs["ir108"].copy()
299 | del ir108.attrs["satellite_longitude"]
300 | del ir108.attrs["end_time"]
301 | fog_comp_base._convert_ma_to_xr([ir108])
302 |
303 |
304 | def test_get_area_lat_lon(fogpy_inputs, fog_comp_base):
305 | (area, lat, lon) = fog_comp_base._get_area_lat_lon(
306 | [fogpy_inputs["ir108"], fogpy_inputs["vis008"]])
307 | assert area == fogpy_inputs["ir108"].area
308 |
309 |
310 | def test_interim(fogpy_inputs_seviri_cmsaf, fogpy_inputs_abi_nwcsaf,
311 | comp_loader, fogpy_outputs, fog_extra):
312 | fc_sev = comp_loader.get_compositor("_intermediate_fls_day", ["seviri"])
313 | fc_abi = comp_loader.get_compositor("_intermediate_fls_day", ["abi"])
314 | with mock.patch("satpy.Scene"), \
315 | mock.patch("fogpy.composites.DayFogLowStratusAlgorithm") as fcD:
316 | fcD.return_value.run.return_value = fogpy_outputs
317 | fcD.return_value.vcloudmask = fog_extra["vcloudmask"]
318 | fcD.return_value.cbh = fog_extra["cbh"]
319 | fcD.return_value.fbh = fog_extra["fbh"]
320 | fcD.return_value.lcth = fog_extra["lcth"]
321 | for (fc, fpi) in ((fc_sev, fogpy_inputs_seviri_cmsaf),
322 | (fc_abi, fogpy_inputs_abi_nwcsaf)):
323 | ds = fc(
324 | [fpi[k] for k in fc.attrs["prerequisites"]],
325 | optional_datasets=[
326 | fpi[k] for k in fc.attrs["optional_prerequisites"]
327 | if k in fpi])
328 | assert isinstance(ds, Dataset)
329 | assert ds.data_vars.keys() == {
330 | 'vmask', 'fls_mask', 'fbh', 'cbh', 'fls_day', 'lcthimg'}
331 | numpy.testing.assert_equal(ds["cbh"].values, fcD.return_value.cbh)
332 |
333 |
334 | def test_fog_comp_day(fog_comp_day, fog_intermediate_dataset):
335 | composite = fog_comp_day([fog_intermediate_dataset])
336 | assert isinstance(composite, xrda)
337 |
338 |
339 | def test_fog_comp_day_extra(fog_comp_day_extra, fog_intermediate_dataset):
340 | composite = fog_comp_day_extra([fog_intermediate_dataset])
341 | assert isinstance(composite, Dataset)
342 |
343 |
344 | def test_fog_comp_night(fog_comp_night, fogpy_inputs, fogpy_outputs):
345 | with mock.patch("fogpy.composites.NightFogLowStratusAlgorithm") as fcN:
346 | fcN.return_value.run.return_value = fogpy_outputs
347 | composite = fog_comp_night([fogpy_inputs["ir039"], fogpy_inputs["ir108"]])
348 | assert isinstance(composite, xrda)
349 |
350 |
351 | def test_save_extras(fog_intermediate_dataset):
352 | from satpy import Scene
353 | from fogpy.composites import save_extras
354 | sc = Scene()
355 | sc["fls_day_extra"] = fog_intermediate_dataset
356 | with tempfile.TemporaryDirectory() as td:
357 | fn = pathlib.Path(td) / "tofu.nc"
358 | save_extras(sc, fn)
359 | with open_dataset(fn) as ds:
360 | ds.load()
361 | assert set(ds.data_vars.keys()) >= {
362 | "vcloudmask", "fls_mask", "fbh", "cbh", "fls_day", "lcth"}
363 | numpy.testing.assert_array_equal(ds["fbh"].values, numpy.zeros((3, 3)))
364 |
--------------------------------------------------------------------------------
/fogpy/test/test_lowwatercloud.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | # -*- coding: utf-8 -*-
3 | # Copyright (c) 2017-2020 Fogpy developers
4 |
5 | # This file is part of the fogpy package.
6 |
7 | # This program is free software: you can redistribute it and/or modify
8 | # it under the terms of the GNU General Public License as published by
9 | # the Free Software Foundation, either version 3 of the License, or
10 | # (at your option) any later version.
11 |
12 | # This program is distributed in the hope that it will be useful,
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | # GNU General Public License for more details.
16 |
17 | # You should have received a copy of the GNU General Public License
18 | # along with this program. If not, see .
19 |
20 | """ This module test the low cloud water class """
21 |
22 | import unittest
23 | import numpy as np
24 | from fogpy.lowwatercloud import LowWaterCloud
25 | from fogpy.lowwatercloud import CloudLayer
26 |
27 |
28 | class Test_LowWaterCloud(unittest.TestCase):
29 |
30 | def setUp(self):
31 | self.lwc = LowWaterCloud(2000., 255., 400., 0, 10e-6)
32 | self.thinlwc = LowWaterCloud(2000., 255., 1., 0, 10e-6)
33 | self.nanlwc = LowWaterCloud(np.nan, 255., 400., 0, 10e-6)
34 | self.nodatalwc = LowWaterCloud(2000., 255., -9999, 0, 10e-6)
35 |
36 | def tearDown(self):
37 | pass
38 |
39 | def test_get_sat_vapour_pressure_buck(self):
40 | psv_m50 = self.lwc.get_sat_vapour_pressure(-50)
41 | psv_m20 = self.lwc.get_sat_vapour_pressure(-20)
42 | psv_0 = self.lwc.get_sat_vapour_pressure(0)
43 | psv_20 = self.lwc.get_sat_vapour_pressure(20)
44 | psv_50 = self.lwc.get_sat_vapour_pressure(50)
45 | self.assertAlmostEqual(psv_m50, 0.064, 3)
46 | self.assertAlmostEqual(psv_m20, 1.256, 3)
47 | self.assertAlmostEqual(psv_0, 6.112, 3)
48 | self.assertAlmostEqual(psv_20, 23.383, 3)
49 | self.assertAlmostEqual(psv_50, 123.494, 3)
50 |
51 | def test_get_sat_vapour_pressure_magnus(self):
52 | psv_m50 = self.lwc.get_sat_vapour_pressure(-50, 'magnus')
53 | psv_m20 = self.lwc.get_sat_vapour_pressure(-20, 'magnus')
54 | psv_0 = self.lwc.get_sat_vapour_pressure(0, 'magnus')
55 | psv_20 = self.lwc.get_sat_vapour_pressure(20, 'magnus')
56 | psv_50 = self.lwc.get_sat_vapour_pressure(50, 'magnus')
57 | self.assertAlmostEqual(psv_m50, 0.064, 3)
58 | self.assertAlmostEqual(psv_m20, 1.254, 3)
59 | self.assertAlmostEqual(psv_0, 6.108, 3)
60 | self.assertAlmostEqual(psv_20, 23.420, 3)
61 | self.assertAlmostEqual(psv_50, 123.335, 3)
62 |
63 | def test_get_air_pressure(self):
64 | pa_1 = self.lwc.get_air_pressure(610)
65 | pa_2 = self.lwc.get_air_pressure(0)
66 | self.assertAlmostEqual(pa_1, 942.08, 2)
67 | self.assertAlmostEqual(pa_2, 1013.25, 2)
68 |
69 | def test_get_moist_adiabatic_lapse_temp(self):
70 | temp_0 = self.lwc.get_moist_adiabatic_lapse_temp(500, 1500, 0)
71 | self.assertAlmostEqual(temp_0, 6.5, 1)
72 |
73 | def test_get_vapour_mixing_ratio(self):
74 | vmr = self.lwc.get_vapour_mixing_ratio(1007.26, 8.44)
75 | self.assertAlmostEqual(vmr, 5.26, 2)
76 |
77 | def test_get_cloud_based_vapour_mixing_ratio(self):
78 | self.lwc.cbh = 0
79 | cb_vmr = self.lwc.get_cloud_based_vapour_mixing_ratio()
80 | self.assertAlmostEqual(cb_vmr, 2.57, 2)
81 |
82 | def test_get_liquid_mixing_ratio(self):
83 | self.lwc.cbh = 0
84 | self.lwc.get_cloud_based_vapour_mixing_ratio()
85 |
86 | temp = self.lwc.get_moist_adiabatic_lapse_temp(0, self.lwc.cth,
87 | self.lwc.ctt, True)
88 | cb_press = self.lwc.get_air_pressure(self.lwc.cbh)
89 | psv = self.lwc.get_sat_vapour_pressure(temp, self.lwc.vapour_method)
90 | vmr = self.lwc.get_vapour_mixing_ratio(cb_press, psv)
91 | lmr = self.lwc.get_liquid_mixing_ratio(self.lwc.cb_vmr, vmr)
92 | self.assertAlmostEqual(self.lwc.cb_vmr, vmr)
93 | self.assertAlmostEqual(lmr, 0)
94 |
95 | def test_get_liquid_water_content(self):
96 | lwc = LowWaterCloud(2000., 255., 400., 0)
97 | lwc = self.lwc.get_liquid_water_content(1950, 2000, 1.091, 1.392, 0.0,
98 | 1.518, 50)
99 | self.assertAlmostEqual(lwc, 1.519, 3)
100 |
101 | def test_get_liquid_water_path(self):
102 | self.lwc.init_cloud_layers(421., 100)
103 | self.lwc.get_liquid_water_path()
104 | lwc = LowWaterCloud(2000., 255., 400., 0)
105 | CloudLayer(1900, 2000, lwc)
106 | lwc.get_liquid_water_path()
107 | self.assertAlmostEqual(len(lwc.layers), 1)
108 | self.assertAlmostEqual(lwc.lwp, 60.719, 3)
109 | self.assertAlmostEqual(self.lwc.lwp, 400., 1)
110 |
111 | def test_get_liquid_water_path2(self):
112 | self.lwc.init_cloud_layers(0, 50)
113 | lwc = LowWaterCloud(2000., 255., 400., 0)
114 | lwc.init_cloud_layers(0, 10)
115 | lwc.get_liquid_water_path()
116 | self.lwc.get_liquid_water_path()
117 | self.assertAlmostEqual(lwc.lwp, self.lwc.lwp, 1)
118 |
119 | def test_init_cloud_layers(self):
120 | self.lwc.init_cloud_layers(0, 100)
121 | self.lwc.plot_lowcloud('lwc', 'Liquid water content in [g m-3]',
122 | '/tmp/test_lowwatercloud_lwc.png')
123 | self.assertAlmostEqual(len(self.lwc.layers), 22)
124 | self.assertAlmostEqual(self.lwc.layers[0].z, 0)
125 | self.assertAlmostEqual(self.lwc.layers[1].z, 50)
126 | self.assertAlmostEqual(self.lwc.layers[20].press, 800, 0)
127 | self.assertAlmostEqual(self.lwc.layers[21].z, 2000)
128 |
129 | def test_cloud_layer(self):
130 | lwc = LowWaterCloud(2000., 255., 400., 0)
131 | cl = CloudLayer(0, 100, lwc)
132 | cl1 = CloudLayer(1945, 1955, lwc)
133 | cl2 = CloudLayer(1970, 1980, lwc)
134 | cl3 = CloudLayer(1950, 2050, lwc)
135 | self.assertAlmostEqual(cl.z, 50., 2)
136 | self.assertAlmostEqual(cl.temp, -5.47, 2)
137 | self.assertAlmostEqual(cl.press, 1007.26, 2)
138 | self.assertAlmostEqual(cl.psv, 4.07, 2)
139 | self.assertAlmostEqual(cl1.lwc, 0.607, 3)
140 | self.assertAlmostEqual(cl2.lwc, 0.304, 3)
141 | self.assertAlmostEqual(cl3.lwc, 0., 3)
142 |
143 | def test_cloud_layer_small(self):
144 | lwc = LowWaterCloud(1000., 235., 400., 950)
145 | cl = CloudLayer(950, 960, lwc, False)
146 | cl1 = CloudLayer(960, 970, lwc, False)
147 | cl2 = CloudLayer(970, 980, lwc, False)
148 | cl3 = CloudLayer(980, 990, lwc, False)
149 | cl4 = CloudLayer(990, 1000, lwc, False)
150 | self.assertAlmostEqual(cl.lwc, 8e-5, 5)
151 | self.assertAlmostEqual(cl1.lwc, 6e-5, 5)
152 | self.assertAlmostEqual(cl2.lwc, 4e-5, 5)
153 | self.assertAlmostEqual(cl3.lwc, 3e-5, 5)
154 | self.assertAlmostEqual(cl4.lwc, 1e-5, 5)
155 | self.assertAlmostEqual(lwc.upthres, 49)
156 | self.assertAlmostEqual(lwc.maxlwc, 8.2e-5, 5)
157 |
158 | def test_cloud_layer_small2(self):
159 | lwc = LowWaterCloud(1000., 235., 400., 950)
160 | cl1 = CloudLayer(970, 980, lwc, False)
161 | cl2 = CloudLayer(980, 990, lwc, False)
162 | cl3 = CloudLayer(990, 1000, lwc, False)
163 | self.assertAlmostEqual(cl1.lwc, 4e-5, 5)
164 | self.assertAlmostEqual(cl2.lwc, 3e-5, 5)
165 | self.assertAlmostEqual(cl3.lwc, 1e-5, 5)
166 | self.assertAlmostEqual(lwc.upthres, 49)
167 | self.assertAlmostEqual(lwc.maxlwc, 8.2e-5, 6)
168 |
169 | def test_get_moist_air_density(self):
170 | self.lwc.cbh = 0
171 | empiric_hrho_0 = self.lwc.get_moist_air_density(100000, 0, 273.15,
172 | True)
173 | empiric_hrho_20 = self.lwc.get_moist_air_density(101325, 0, 293.15,
174 | True)
175 | empiric_humid_hrho_20 = self.lwc.get_moist_air_density(101325, 2338,
176 | 293.15, True)
177 | empiric_humid_hrho_neg20 = self.lwc.get_moist_air_density(101325,
178 | 996.3,
179 | 253.15, True)
180 |
181 | ideal_hrho_15 = self.lwc.get_moist_air_density(101325, 0, 288.15)
182 | ideal_hrho_20 = self.lwc.get_moist_air_density(101325, 0, 293.15)
183 | humid_ideal_hrho_20 = self.lwc.get_moist_air_density(101325, 2338,
184 | 293.15)
185 | humid_ideal_hrho_neg20 = self.lwc.get_moist_air_density(101325, 996.3,
186 | 253.15)
187 |
188 | self.assertAlmostEqual(empiric_hrho_0, 1.276, 3)
189 | self.assertAlmostEqual(empiric_hrho_20, 1.205, 4)
190 | self.assertAlmostEqual(ideal_hrho_15, 1.2250, 4)
191 | self.assertAlmostEqual(ideal_hrho_20, 1.2041, 4)
192 | self.assertAlmostEqual(humid_ideal_hrho_20, 1.194, 3)
193 | self.assertAlmostEqual(empiric_humid_hrho_20, 1.1945, 4)
194 | self.assertAlmostEqual(humid_ideal_hrho_neg20, 1.3892, 4)
195 | self.assertAlmostEqual(empiric_humid_hrho_neg20, 1.3902, 4)
196 |
197 | def test_get_incloud_mixing_ratio(self):
198 | self.lwc.cbh = 100
199 | self.lwc.cth = 1000
200 | beta_0 = self.lwc.get_incloud_mixing_ratio(500, 1000, 100)
201 | beta_1 = self.lwc.get_incloud_mixing_ratio(100, 1000, 100)
202 | beta_2 = self.lwc.get_incloud_mixing_ratio(130, 1000, 100)
203 | beta_3 = self.lwc.get_incloud_mixing_ratio(175, 1000, 100)
204 | beta_4 = self.lwc.get_incloud_mixing_ratio(950, 1000, 100)
205 | self.assertAlmostEqual(beta_0, 0.3)
206 | self.assertAlmostEqual(beta_1, 0)
207 | self.assertAlmostEqual(beta_2, 0.12)
208 | self.assertAlmostEqual(beta_3, 0.3, 2)
209 | self.assertAlmostEqual(beta_4, 0.3)
210 |
211 | def test_get_incloud_mixing_ratio_limit(self):
212 | self.lwc.cbh = 950
213 | self.lwc.cth = 1000
214 | beta_0 = self.lwc.get_incloud_mixing_ratio(950, 1000, 950)
215 | beta_1 = self.lwc.get_incloud_mixing_ratio(960, 1000, 950)
216 | beta_2 = self.lwc.get_incloud_mixing_ratio(970, 1000, 950)
217 | beta_3 = self.lwc.get_incloud_mixing_ratio(980, 1000, 950)
218 | beta_4 = self.lwc.get_incloud_mixing_ratio(990, 1000, 950)
219 | beta_5 = self.lwc.get_incloud_mixing_ratio(1000, 1000, 950)
220 | self.assertAlmostEqual(beta_0, 0.3)
221 | self.assertAlmostEqual(beta_1, 0.3)
222 | self.assertAlmostEqual(beta_2, 0.3)
223 | self.assertAlmostEqual(beta_3, 0.3, 2)
224 | self.assertAlmostEqual(beta_4, 0.3)
225 | self.assertAlmostEqual(beta_5, 0.3)
226 |
227 | def test_optimize_cbh_brute(self):
228 | self.lwc.thickness = 100
229 | ret_brute = self.lwc.optimize_cbh(100., method='brute')
230 | self.assertAlmostEqual(ret_brute, 421., 1)
231 |
232 | def test_optimize_cbh_basin(self):
233 | self.lwc.thickness = 100
234 | np.random.seed(42)
235 | ret_basin = self.lwc.optimize_cbh(100., method='basin')
236 | self.assertIn(round(ret_basin, 0), [421, 479, 478, 477])
237 |
238 | def test_optimize_cbh_start(self):
239 | self.lwc.thickness = 100.
240 | np.random.seed(42)
241 | listresult = []
242 | listresult.append(self.lwc.optimize_cbh(1000., method='basin'))
243 | listresult.append(self.lwc.optimize_cbh(900., method='basin'))
244 | listresult.append(self.lwc.optimize_cbh(800., method='basin'))
245 | listresult.append(self.lwc.optimize_cbh(700., method='basin'))
246 | listresult.append(self.lwc.optimize_cbh(600., method='basin'))
247 | listresult.append(self.lwc.optimize_cbh(500., method='basin'))
248 | listresult.append(self.lwc.optimize_cbh(400., method='basin'))
249 | listresult.append(self.lwc.optimize_cbh(300., method='basin'))
250 | listresult.append(self.lwc.optimize_cbh(200., method='basin'))
251 | listresult.append(self.lwc.optimize_cbh(100., method='basin'))
252 | listresult.append(self.lwc.optimize_cbh(0., method='basin'))
253 | listresult.append(self.lwc.optimize_cbh(-100., method='basin'))
254 | test = [round(i, 0) == 421 for i in listresult]
255 | self.assertGreaterEqual(sum(test), 8)
256 |
257 | @unittest.expectedFailure
258 | def test_optimize_cbh_start_thin(self):
259 | self.thinlwc.thickness = 10.
260 | np.random.seed(42)
261 | listresult = []
262 | listresult.append(self.thinlwc.optimize_cbh(1000., method='basin'))
263 | listresult.append(self.thinlwc.optimize_cbh(900., method='basin'))
264 | listresult.append(self.thinlwc.optimize_cbh(800., method='basin'))
265 | listresult.append(self.thinlwc.optimize_cbh(700., method='basin'))
266 | listresult.append(self.thinlwc.optimize_cbh(600., method='basin'))
267 | listresult.append(self.thinlwc.optimize_cbh(500., method='basin'))
268 | listresult.append(self.thinlwc.optimize_cbh(400., method='basin'))
269 | listresult.append(self.thinlwc.optimize_cbh(300., method='basin'))
270 | listresult.append(self.thinlwc.optimize_cbh(200., method='basin'))
271 | listresult.append(self.thinlwc.optimize_cbh(100., method='basin'))
272 | listresult.append(self.thinlwc.optimize_cbh(0., method='basin'))
273 | listresult.append(self.thinlwc.optimize_cbh(-100., method='basin'))
274 | test = [round(i, 0) == 421 for i in listresult]
275 | self.assertGreaterEqual(sum(test), 8)
276 |
277 | def test_optimize_cbh_basin_nan(self):
278 | self.nanlwc.thickness = 100
279 | np.random.seed(42)
280 | ret_basin = self.nanlwc.optimize_cbh(100., method='basin')
281 | self.assertTrue(np.isnan(ret_basin))
282 |
283 | def test_optimize_cbh_basin_nodata(self):
284 | self.nodatalwc.thickness = 100
285 | np.random.seed(42)
286 | ret_basin = self.nodatalwc.optimize_cbh(100., method='basin')
287 | self.assertTrue(np.isnan(ret_basin))
288 |
289 | def test_get_visibility(self):
290 | LowWaterCloud(2000., 255., 400., 0, 10e-6)
291 | vis = self.lwc.get_visibility(1)
292 | vis2 = self.lwc.get_visibility(1/1000.)
293 | self.assertAlmostEqual(vis, 3.912, 3)
294 | self.assertAlmostEqual(vis2, 3912, 0)
295 |
296 | def test_get_liquid_density(self):
297 | LowWaterCloud(2000., 285., 400., 0)
298 | rho1 = self.lwc.get_liquid_density(20, 100e5)
299 | rho2 = self.lwc.get_liquid_density(4, 1e5)
300 | rho3 = self.lwc.get_liquid_density(0, 1e5)
301 | self.assertAlmostEqual(rho1, 1002.66, 3)
302 | self.assertAlmostEqual(rho2, 999.448, 3)
303 | self.assertAlmostEqual(rho3, 999.80, 3)
304 |
305 | def test_get_effective_radius(self):
306 | lwc = LowWaterCloud(1000., 255., 400., reff=10e-6, cbh=0)
307 | reff_b = lwc.get_effective_radius(0)
308 | reff_m = lwc.get_effective_radius(500)
309 | reff_t = lwc.get_effective_radius(lwc.cth)
310 | self.assertAlmostEqual(reff_b, 1e-6)
311 | self.assertAlmostEqual(reff_m, 5.5e-6)
312 | self.assertAlmostEqual(reff_t, 10e-6)
313 |
314 | def test_get_effective_radius_with_cbh(self):
315 | lwc = LowWaterCloud(1000., 255., 400., reff=10e-6, cbh=100)
316 | reff_b = lwc.get_effective_radius(100)
317 | reff_m = lwc.get_effective_radius(550)
318 | reff_t = lwc.get_effective_radius(lwc.cth)
319 | self.assertAlmostEqual(reff_b, 1e-6)
320 | self.assertAlmostEqual(reff_m, 5.5e-6)
321 | self.assertAlmostEqual(reff_t, 10e-6)
322 |
323 | def test_get_fog_cloud_height(self):
324 | lwc = LowWaterCloud(2000., 275., 400., 100, 10e-6)
325 | lwc.init_cloud_layers(100, 50)
326 | fbh = lwc.get_fog_base_height()
327 | self.assertAlmostEqual(fbh, 125, 0)
328 |
329 | def test_get_fog_cloud_height2(self):
330 | lwc = LowWaterCloud(1000., 275., 100., 100., 10e-6)
331 | lwc.init_cloud_layers(100, 10)
332 | lwc.get_liquid_water_path()
333 | np.random.seed(42)
334 | lwc.optimize_cbh(lwc.cbh, method="basin")
335 | fbh = lwc.get_fog_base_height()
336 | self.assertAlmostEqual(lwc.lwp, 100, 3)
337 | self.assertAlmostEqual(lwc.maxlwc, 0.494, 3)
338 | self.assertAlmostEqual(fbh, 612, 0)
339 |
340 | def test_reset_layers_after_minimisation(self):
341 | """Test that layers are properly reset after minimisation
342 |
343 | Test for fix for #29
344 | """
345 | lwc = LowWaterCloud(1000., 275., 100., 100., 10e-6)
346 |
347 | lwc.optimize_cbh(lwc.cbh, method="brute")
348 | brl = lwc.layers
349 | brfb = lwc.get_fog_base_height()
350 |
351 | np.random.seed(42)
352 | lwc.optimize_cbh(lwc.cbh, method="basin")
353 | bhl = lwc.layers
354 | bhfb = lwc.get_fog_base_height()
355 |
356 | np.testing.assert_almost_equal(
357 | [l.visibility for l in bhl if l.visibility is not None],
358 | [l.visibility for l in brl if l.visibility is not None],
359 | -1)
360 | self.assertAlmostEqual(brfb, bhfb, 0)
361 |
362 |
363 | def suite():
364 | """The test suite for test_lowwatercloud.
365 | """
366 | loader = unittest.TestLoader()
367 | mysuite = unittest.TestSuite()
368 | mysuite.addTest(loader.loadTestsFromTestCase(Test_LowWaterCloud))
369 |
370 | return mysuite
371 |
372 |
373 | if __name__ == "__main__":
374 | unittest.main()
375 |
--------------------------------------------------------------------------------
/fogpy/test/test_utils.py:
--------------------------------------------------------------------------------
1 | # Copyright (c) 2017-2020 Fogpy developers
2 |
3 | # This file is part of the fogpy package.
4 |
5 | # This program is free software: you can redistribute it and/or modify
6 | # it under the terms of the GNU General Public License as published by
7 | # the Free Software Foundation, either version 3 of the License, or
8 | # (at your option) any later version.
9 |
10 | # This program is distributed in the hope that it will be useful,
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | # GNU General Public License for more details.
14 |
15 | # You should have received a copy of the GNU General Public License
16 | # along with this program. If not, see .
17 | import logging
18 |
19 | import pytest
20 | import unittest.mock
21 |
22 |
23 | @unittest.mock.patch("requests.get")
24 | def test_dl_dem(rg, tmp_path, caplog):
25 | from fogpy.utils import dl_dem
26 | rg.return_value.content = b"12345"
27 |
28 | with caplog.at_level(logging.INFO):
29 | dl_dem(tmp_path / "foo")
30 | assert f"Downloading https://zenodo.org/record/3885398/files/foo to {tmp_path / 'foo'!s}" in caplog.text
31 | assert (tmp_path / "foo").exists()
32 | assert (tmp_path / "foo").open(mode="rb").read() == b"12345"
33 | with pytest.raises(FileExistsError):
34 | dl_dem(tmp_path / "foo")
35 |
--------------------------------------------------------------------------------
/fogpy/utils/__init__.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | # -*- coding: utf-8 -*-
3 | # Copyright (c) 2017-2020 Fogpy developers
4 |
5 | # This file is part of the fogpy package.
6 |
7 | # fogpy is free software: you can redistribute it and/or modify it
8 | # under the terms of the GNU General Public License as published by
9 | # the Free Software Foundation, either version 3 of the License, or
10 | # (at your option) any later version.
11 |
12 | # fogpy is distributed in the hope that it will be useful, but
13 | # WITHOUT ANY WARRANTY; without even the implied warranty of
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 | # General Public License for more details.
16 |
17 | # You should have received a copy of the GNU General Public License
18 | # along with fogpy. If not, see .
19 |
20 | """Small utilities needed by Fogpy
21 | """
22 |
23 | import logging
24 |
25 | import requests
26 |
27 | logger = logging.getLogger(__name__)
28 |
29 |
30 | def dl_dem(dem):
31 | """Download Digital Elevation Model
32 |
33 | Download a Digital Elevation Model (DEM) from Zenodo.
34 |
35 | The source URI is derived from the destination path.
36 |
37 | Args:
38 | dem (pathlib.Path): Destination
39 | """
40 | src = "https://zenodo.org/record/3885398/files/" + dem.name
41 |
42 | if dem.exists():
43 | raise FileExistsError("Already exists: {dem!s}")
44 | r = requests.get(src)
45 | logger.info(f"Downloading {src!s} to {dem!s}")
46 | dem.parent.mkdir(exist_ok=True, parents=True)
47 | with dem.open(mode="wb") as fp:
48 | fp.write(r.content)
49 |
--------------------------------------------------------------------------------
/fogpy/utils/add_synop.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | # -*- coding: utf-8 -*-
3 | # Copyright (c) 2016-2020 Fogpy developers
4 |
5 | # This file is part of the fogpy package.
6 |
7 | # This program is free software: you can redistribute it and/or modify
8 | # it under the terms of the GNU General Public License as published by
9 | # the Free Software Foundation, either version 3 of the License, or
10 | # (at your option) any later version.
11 |
12 | # This program is distributed in the hope that it will be useful,
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | # GNU General Public License for more details.
16 |
17 | # You should have received a copy of the GNU General Public License
18 | # along with this program. If not, see .
19 |
20 | """This script adds synope data for visibility to given geolocated image"""
21 |
22 | import fogpy
23 | import numpy as np
24 | import os
25 | from .import_synop import read_synop
26 | from datetime import datetime
27 | from trollimage.image import Image
28 | from trollimage.colormap import Colormap
29 |
30 |
31 | # Define custom fog colormap
32 | fogcol = Colormap((0., (250 / 255.0, 200 / 255.0, 40 / 255.0)),
33 | (1., (1.0, 1.0, 229 / 255.0)))
34 |
35 | maskcol = Colormap((1., (250 / 255.0, 200 / 255.0, 40 / 255.0)))
36 |
37 | viscol = Colormap((0., (1.0, 0.0, 0.0)),
38 | (5000, (0.7, 0.7, 0.7)))
39 | # Red - Violet - Blue - Green
40 | vis_colset = Colormap((0, (228 / 255.0, 26 / 255.0, 28 / 255.0)),
41 | (1000, (152 / 255.0, 78 / 255.0, 163 / 255.0)),
42 | (5000, (55 / 255.0, 126 / 255.0, 184 / 255.0)),
43 | (10000, (77 / 255.0, 175 / 255.0, 74 / 255.0)))
44 |
45 |
46 | def add_to_array(arr, area, time, bufr, savedir='/tmp', name=None, mode='L',
47 | resize=None, ptsize=None, save=False):
48 | """Add synoptical reports from stations to provided geolocated image array
49 | """
50 | # Create array image
51 | arrshp = arr.shape[:2]
52 | print(np.nanmin(arr), np.nanmax(arr))
53 | arr_img = Image(arr, mode=mode)
54 | # arr_img = Image(channels=[arr[:, :, 0], arr[:, :, 1], arr[:, :, 2]],
55 | # mode='RGB')
56 | arr_img.stretch('crude')
57 | arr_img.invert()
58 | arr_img.colorize(maskcol)
59 | arr_img.invert()
60 |
61 | # Import bufr
62 | stations = read_synop(bufr, 'visibility')
63 | currentstations = stations[time.strftime("%Y%m%d%H0000")]
64 | lats = [i[2] for i in currentstations]
65 | lons = [i[3] for i in currentstations]
66 | vis = [i[4] for i in currentstations]
67 |
68 | # Create array for synop parameter
69 | visarr = np.empty(arrshp)
70 | visarr.fill(np.nan)
71 |
72 | x, y = (area.get_xy_from_lonlat(lons, lats))
73 | vis_ma = np.ma.array(vis, mask=x.mask)
74 | if ptsize:
75 | xpt = np.array([])
76 | ypt = np.array([])
77 | for i, j in zip(x, y):
78 | xmesh, ymesh = np.meshgrid(np.linspace(i - ptsize, i + ptsize,
79 | ptsize * 2 + 1),
80 | np.linspace(j - ptsize, j + ptsize,
81 | ptsize * 2 + 1))
82 | xpt = np.append(xpt, xmesh.ravel())
83 | ypt = np.append(ypt, ymesh.ravel())
84 | vispt = np.ma.array([np.full(((ptsize * 2 + 1,
85 | ptsize * 2 + 1)), p) for p in vis_ma])
86 | visarr[ypt.astype(int), xpt.astype(int)] = vispt.ravel()
87 | else:
88 | visarr[y.compressed(), x.compressed()] = vis_ma.compressed()
89 | visarr_ma = np.ma.masked_invalid(visarr)
90 | station_img = Image(visarr_ma, mode='L')
91 | station_img.colorize(vis_colset)
92 | station_img.merge(arr_img)
93 | if resize is not None:
94 | station_img.resize((arrshp[0] * resize, arrshp[1] * resize))
95 | if name is None:
96 | timestr = time.strftime("%Y%m%d%H%M")
97 | name = "fog_filter_example_stations_{}.png".format(timestr)
98 | if save:
99 | savepath = os.path.join(savedir, name)
100 | station_img.save(savepath)
101 |
102 | return(station_img)
103 |
104 |
105 | def add_to_image(image, area, time, bufr, savedir='/tmp', name=None,
106 | bgimg=None, resize=None, ptsize=None, save=False):
107 | """Add synoptical visibility reports from station data to provided
108 | geolocated image array
109 | """
110 | arrshp = image.shape[:2]
111 | # Add optional background image
112 | if bgimg is not None:
113 | # Get background image
114 | bg_img = Image(bgimg.squeeze(), mode='L', fill_value=None)
115 | bg_img.stretch("crude")
116 | bg_img.convert("RGB")
117 | # bg_img.invert()
118 | image.merge(bg_img)
119 | # Import bufr
120 | stations = read_synop(bufr, 'visibility')
121 | currentstations = stations[time.strftime("%Y%m%d%H0000")]
122 | lats = [i[2] for i in currentstations]
123 | lons = [i[3] for i in currentstations]
124 | vis = [i[4] for i in currentstations]
125 |
126 | # Create array for synop parameter
127 | visarr = np.empty(arrshp)
128 | visarr.fill(np.nan)
129 | # Red - Violet - Blue - Green
130 | vis_colset = Colormap((0, (228 / 255.0, 26 / 255.0, 28 / 255.0)),
131 | (1000, (152 / 255.0, 78 / 255.0, 163 / 255.0)),
132 | (5000, (55 / 255.0, 126 / 255.0, 184 / 255.0)),
133 | (10000, (77 / 255.0, 175 / 255.0, 74 / 255.0)))
134 | x, y = (area.get_xy_from_lonlat(lons, lats))
135 | vis_ma = np.ma.array(vis, mask=x.mask)
136 | if ptsize:
137 | xpt = np.array([])
138 | ypt = np.array([])
139 | for i, j in zip(x, y):
140 | xmesh, ymesh = np.meshgrid(np.linspace(i - ptsize, i + ptsize,
141 | ptsize * 2 + 1),
142 | np.linspace(j - ptsize, j + ptsize,
143 | ptsize * 2 + 1))
144 | xpt = np.append(xpt, xmesh.ravel())
145 | ypt = np.append(ypt, ymesh.ravel())
146 | vispt = np.ma.array([np.full(((ptsize * 2 + 1,
147 | ptsize * 2 + 1)), p) for p in vis_ma])
148 | visarr[ypt.astype(int), xpt.astype(int)] = vispt.ravel()
149 | else:
150 | visarr[y.compressed(), x.compressed()] = vis_ma.compressed()
151 | visarr_ma = np.ma.masked_invalid(visarr)
152 | station_img = Image(visarr_ma, mode='L')
153 | station_img.colorize(vis_colset)
154 | image.convert("RGB")
155 | station_img.merge(image)
156 | if resize is not None:
157 | station_img.resize((arrshp[0] * resize, arrshp[1] * resize))
158 | if name is None:
159 | timestr = time.strftime("%Y%m%d%H%M")
160 | name = "fog_filter_example_stations_{}.png".format(timestr)
161 | if save:
162 | savepath = os.path.join(savedir, name)
163 | station_img.save(savepath)
164 |
165 | return(station_img)
166 |
167 |
168 | if __name__ == '__main__':
169 |
170 | from pyresample import geometry
171 | from scipy import misc
172 |
173 | # Set time stamp
174 | time = datetime(2013, 11, 12, 8, 30)
175 | # Import image
176 | # imgfile = 'LowCloudFilter_201311120830.png'
177 | imgfile = 'LowCloudFilter_201311120830.png'
178 | imgdir = '/tmp/FLS'
179 | resize = 5 # Resize factor of FLS image
180 | imgpath = os.path.join(imgdir, imgfile)
181 | arr = misc.imread(imgpath)
182 | arr = np.ma.masked_where(arr == 0, arr)
183 | print(arr.shape)
184 | print(np.min(arr))
185 | # Get bufr file
186 | base = os.path.split(fogpy.__file__)
187 | inbufr = os.path.join(base[0], '..', 'etc', 'result_{}.bufr'
188 | .format(time.strftime("%Y%m%d")))
189 | # bufr_dir = '/data/tleppelt/skydata/'
190 | # bufr_file = "result_{}".format(time.strftime("%Y%m%d"))
191 | # inbufr = os.path.join(bufr_dir, bufr_file)
192 |
193 | area_id = "geos_germ"
194 | name = "geos_germ"
195 | proj_id = "geos"
196 | proj_dict = {'a': '6378169.00', 'lon_0': '0.00', 'h': '35785831.00',
197 | 'b': '6356583.80', 'proj': 'geos', 'lat_0': '0.00'}
198 | x_size = 298 * resize
199 | y_size = 141 * resize
200 | area_extent = (214528.82635591552, 4370087.2110124603, 1108648.9697693815,
201 | 4793144.0573926577)
202 | area_def = geometry.AreaDefinition(area_id, name, proj_id, proj_dict,
203 | x_size, y_size, area_extent)
204 | print(area_def)
205 | img = Image(arr[:, :, :3], mode='RGB')
206 | add_to_image(img, area_def, time, inbufr)
207 |
--------------------------------------------------------------------------------
/fogpy/utils/export_synop.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | # -*- coding: utf-8 -*-
3 | # Copyright (c) 2017-2020 Fogpy developers
4 |
5 | # This file is part of the fogpy package.
6 |
7 | # This program is free software: you can redistribute it and/or modify
8 | # it under the terms of the GNU General Public License as published by
9 | # the Free Software Foundation, either version 3 of the License, or
10 | # (at your option) any later version.
11 |
12 | # This program is distributed in the hope that it will be useful,
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | # GNU General Public License for more details.
16 |
17 | # You should have received a copy of the GNU General Public License
18 | # along with this program. If not, see .
19 |
20 | """ This module implements export routines for synoptical station data as
21 | shapefile file"""
22 |
23 | import fogpy
24 | import os
25 | import osgeo
26 | import osgeo.ogr
27 | import osgeo.osr
28 |
29 | from fogpy.utils import import_synop
30 |
31 |
32 | class DummyException(Exception):
33 | pass
34 |
35 |
36 | def create_shpfile(data, outfile, epsg=4326, para=['vis'], nodata=-9999):
37 | """ Function to export synoptical station data as ESRI shape file"""
38 | # Init spatial reference locally
39 | spatialReference = osgeo.osr.SpatialReference()
40 | # Define this reference to be the EPSG code
41 | spatialReference.ImportFromEPSG(int(epsg))
42 | driver = osgeo.ogr.GetDriverByName('ESRI Shapefile')
43 | # Create export file
44 | shapeData = driver.CreateDataSource(outfile)
45 | # Create a corresponding layer for our data with given spatial information.
46 | layer = shapeData.CreateLayer(
47 | 'layer', spatialReference, osgeo.ogr.wkbPoint)
48 | # Gets parameters of the current shapefile
49 | layer_defn = layer.GetLayerDefn()
50 | index = 0
51 | fielddict = {'name': 0, 'altitude': 1, 'lat': 2, 'lon': 3}
52 | fields = ['name', 'altitude', 'lat', 'lon'] + para
53 | addindex = 4
54 | for ele in para:
55 | fielddict[ele] = addindex
56 | addindex += 1
57 | # Create new fields with the content of read synop data
58 | for field in fields:
59 | new_field = osgeo.ogr.FieldDefn(field, osgeo.ogr.OFTString)
60 | layer.CreateField(new_field)
61 | # Loop over stations and add them as vector points
62 | for row in data:
63 | point = osgeo.ogr.Geometry(osgeo.ogr.wkbPoint)
64 | point.AddPoint(row[3], row[2])
65 | feature = osgeo.ogr.Feature(layer_defn)
66 | feature.SetGeometry(point) # Set the coordinates
67 | feature.SetFID(index)
68 | for field in fields:
69 | i = feature.GetFieldIndex(field)
70 | if row[fielddict[field]] is None:
71 | val = nodata
72 | else:
73 | val = row[fielddict[field]]
74 | try:
75 | feature.SetField(i, val)
76 | except DummyException:
77 | Warning("Index: {} - Value {} of type: {} can't be added"
78 | .format(i, val, type(val)))
79 | feature.SetField(i, None)
80 | layer.CreateFeature(feature)
81 | index += 1
82 | shapeData.Destroy() # Close the shapefile
83 |
84 |
85 | def main():
86 | shpfile = '/tmp/FLS/stations_20131112080000.shp'
87 | base = os.path.split(fogpy.__file__)
88 | synopfile = os.path.join(base[0], '..', 'etc', 'result_20131112.bufr')
89 | metarfile = os.path.join(
90 | base[0],
91 | '..',
92 | 'etc',
93 | 'result_20131112_metar.bufr')
94 | swisfile = os.path.join(base[0], '..', 'etc', 'result_20131112_swis.bufr')
95 | synops = import_synop.read_synop(synopfile, 'visibility')
96 | metars = import_synop.read_metar(metarfile, 'visibility', latlim=(47, 56),
97 | lonlim=(4, 16))
98 | swis = import_synop.read_swis(swisfile, 'visibility')
99 | input = synops['20131112080000'] + metars['20131112083000'] + \
100 | swis['20131112083000']
101 | create_shpfile(input, shpfile)
102 |
103 |
104 | if __name__ == '__main__':
105 | main()
106 |
--------------------------------------------------------------------------------
/fogpy/utils/import_synop.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | # -*- coding: utf-8 -*-
3 | # Copyright (c) 2016-2020 Fogpy developers
4 |
5 | # This file is part of the fogpy package.
6 |
7 | # This program is free software: you can redistribute it and/or modify
8 | # it under the terms of the GNU General Public License as published by
9 | # the Free Software Foundation, either version 3 of the License, or
10 | # (at your option) any later version.
11 |
12 | # This program is distributed in the hope that it will be useful,
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | # GNU General Public License for more details.
16 |
17 | # You should have received a copy of the GNU General Public License
18 | # along with this program. If not, see .
19 |
20 | """ This module implements import routines for synoptical station data as
21 | bufr file"""
22 |
23 | import fogpy
24 | import logging
25 | import os
26 | import os.path
27 |
28 | from fogpy.lowwatercloud import CloudLayer as CL
29 | from trollbufr.bufr import Bufr
30 | from trollbufr import load_file
31 | from datetime import datetime
32 |
33 | trollbufr_logger = logging.getLogger('trollbufr')
34 | trollbufr_logger.setLevel(logging.CRITICAL)
35 |
36 |
37 | class DummyException(Exception):
38 | pass
39 |
40 |
41 | def read_synop(file, params, min=None, max=None):
42 | """ Reading bufr files for synoptical station data and provide dictionary
43 | with weather data for cloud base height and visibility.
44 | The results are subsequently filtered by cloud base height and visibility
45 |
46 | Arguments:
47 | file Bufr file with synop reports
48 | params List of parameter names that will be extracted
49 | min Threshold for minimum value of parameter
50 | max Threshold for maximum value of parameter
51 |
52 | Returns list of station dictionaries for given thresholds
53 | """
54 | result = {}
55 | bfr = Bufr("libdwd", os.getenv("BUFR_TABLES"))
56 | for blob, size, header in load_file.next_bufr(file):
57 | bfr.decode(blob)
58 | try:
59 | for subset in bfr.next_subset():
60 | stationdict = {}
61 | for (k, m, v, q) in subset.next_data():
62 | if k == 1015: # Station name
63 | stationdict['name'] = v.strip()
64 | if k == 5001: # Latitude
65 | stationdict['lat'] = v
66 | if k == 6001: # Longitude
67 | stationdict['lon'] = v
68 | if k == 7030: # Altitude
69 | stationdict['altitude'] = v
70 | elif k == 4001: # Year
71 | stationdict['year'] = v
72 | elif k == 4002: # Month
73 | stationdict['month'] = v
74 | elif k == 4003: # Day
75 | stationdict['day'] = v
76 | elif k == 4004: # Hour
77 | stationdict['hour'] = v
78 | elif k == 4005: # Hour
79 | stationdict['minute'] = v
80 | elif k == 20003: # Present weather
81 | stationdict['present weather'] = v
82 | # Values from 40 to 49 are refering to fog and ice fog
83 | # Patchy fog or fog edges value 11 or 12
84 | elif k == 20004: # Past weather
85 | stationdict['past weather'] = v
86 | # Values from 40 to 49 are refering to fog and ice fog
87 | # Patchy fog or fog edges value 11 or 12
88 | elif k == 20013: # Cloud base height
89 | if v is not None:
90 | if ('cbh' in stationdict.keys() and
91 | stationdict["cbh"] is not None):
92 | if stationdict['cbh'] > v:
93 | stationdict['cbh'] = v
94 | else:
95 | stationdict['cbh'] = v
96 | else:
97 | stationdict['cbh'] = None
98 | elif k == 2001: # Auto/manual measurement
99 | # 1 - 3 : Manual human observations. Manned stations
100 | # 0, 4 - 7 : Only automatic observations
101 | stationdict['type'] = v
102 | elif k == 20001: # Visibility
103 | stationdict['visibility'] = v
104 | elif k == 12101: # Mean air temperature in K
105 | stationdict['air temperature'] = v
106 | elif k == 12103: # Dew point temperature in K
107 | stationdict['dew point'] = v
108 | elif k == 20010: # Cloud cover in %
109 | stationdict['cloudcover'] = v
110 | elif k == 13003: # Relative humidity in %
111 | stationdict['relative humidity'] = v
112 | elif k == 11001: # Wind direction in degree
113 | stationdict['wind direction'] = v
114 | elif k == 11002: # Wind speed in m s-1
115 | stationdict['wind speed'] = v
116 | elif k == 1002: # WMO station number
117 | stationdict['wmo'] = v
118 | # Apply thresholds
119 | stationtime = datetime(stationdict['year'],
120 | stationdict['month'],
121 | stationdict['day'],
122 | stationdict['hour'],
123 | stationdict['minute'],
124 | ).strftime("%Y%m%d%H%M%S")
125 | paralist = []
126 | if not isinstance(params, list):
127 | params = [params]
128 | for param in params:
129 | if param not in stationdict:
130 | res = None
131 | elif min is not None and stationdict[param] < min:
132 | res = None
133 | elif max is not None and stationdict[param] >= max:
134 | res = None
135 | elif stationdict[param] is None:
136 | res = None
137 | else:
138 | res = stationdict[param]
139 | paralist.append(res)
140 | if all([i is None for i in paralist]):
141 | continue
142 | # Add station data to result list
143 | if stationtime in result.keys():
144 | result[stationtime].append([stationdict['name'],
145 | stationdict['altitude'],
146 | stationdict['lat'],
147 | stationdict['lon']] + paralist)
148 | else:
149 | result[stationtime] = [[stationdict['name'],
150 | stationdict['altitude'],
151 | stationdict['lat'],
152 | stationdict['lon']] + paralist]
153 | except DummyException as e:
154 | "ERROR: Unresolved station request: {}".format(e)
155 | return(result)
156 |
157 |
158 | def read_metar(file, params, min=None, max=None, latlim=None, lonlim=None):
159 | """ Reading bufr files for METAR station data and provide dictionary
160 | with weather data for cloud base height and visibility.
161 | The results are subsequently filtered by cloud base height and visibility
162 |
163 | Arguments:
164 | file Bufr file with synop reports
165 | params List of parameter names that will be extracted
166 | min Threshold for minimum value of parameter
167 | max Threshold for maximum value of parameter
168 | latlim Tuple of minimum and maximum latitude values for valid result
169 | lonlim Tuple of minimum and maximum longitude values for valid result
170 |
171 | Returns list of station dictionaries for given thresholds
172 | """
173 | result = {}
174 | bfr = Bufr("libdwd", os.getenv("BUFR_TABLES"))
175 | for blob, size, header in load_file.next_bufr(file):
176 | bfr.decode(blob)
177 | try:
178 | for subset in bfr.next_subset():
179 | stationdict = {}
180 | for (k, m, v, q) in subset.next_data():
181 | if k == 1063: # Station name
182 | stationdict['name'] = v.strip()
183 | if k == 5002: # Latitude
184 | stationdict['lat'] = v
185 | if k == 6002: # Longitude
186 | stationdict['lon'] = v
187 | if k == 7030: # Altitude
188 | stationdict['altitude'] = v
189 | elif k == 4001: # Year
190 | stationdict['year'] = v
191 | elif k == 4002: # Month
192 | stationdict['month'] = v
193 | elif k == 4003: # Day
194 | stationdict['day'] = v
195 | elif k == 4004: # Hour
196 | stationdict['hour'] = v
197 | elif k == 4005: # Hour
198 | stationdict['minute'] = v
199 | elif k == 20003: # Present weather
200 | stationdict['present weather'] = v
201 | # Values from 40 to 49 are refering to fog and ice fog
202 | # Patchy fog or fog edges value 11 or 12
203 | elif k == 20004: # Past weather
204 | stationdict['past weather'] = v
205 | # Values from 40 to 49 are refering to fog and ice fog
206 | # Patchy fog or fog edges value 11 or 12
207 | elif k == 20013: # Cloud base height
208 | if v is not None:
209 | if ('cbh' in stationdict.keys() and
210 | stationdict["cbh"] is not None):
211 | if stationdict['cbh'] > v:
212 | stationdict['cbh'] = v
213 | else:
214 | stationdict['cbh'] = v
215 | else:
216 | stationdict['cbh'] = None
217 | elif k == 2001: # Auto/manual measurement
218 | # 1 - 3 : Manual human observations. Manned stations
219 | # 0, 4 - 7 : Only automatic observations
220 | stationdict['type'] = v
221 | elif k == 20060: # Prevailing visibility
222 | stationdict['visibility'] = v
223 | elif k == 12023: # Mean air temperature in °C
224 | stationdict['air temperature'] = CL.check_temp(
225 | v, 'kelvin')
226 | elif k == 12024: # Dew point temperature in °C
227 | stationdict['dew point'] = CL.check_temp(v, 'kelvin')
228 | elif k == 20010: # Cloud cover in %
229 | stationdict['cloudcover'] = v
230 | elif k == 13003: # Relative humidity in %
231 | stationdict['relative humidity'] = v
232 | elif k == 11001: # Wind direction in degree
233 | stationdict['wind direction'] = v
234 | elif k == 11002: # Wind speed in m s-1
235 | stationdict['wind speed'] = v
236 | elif k == 1002: # WMO station number
237 | stationdict['wmo'] = v
238 | elif k == 1024: # WMO station number
239 | stationdict['coords'] = v
240 | # Apply thresholds
241 | stationtime = datetime(stationdict['year'],
242 | stationdict['month'],
243 | stationdict['day'],
244 | stationdict['hour'],
245 | stationdict['minute'],
246 | ).strftime("%Y%m%d%H%M%S")
247 | paralist = []
248 | if not isinstance(params, list):
249 | params = [params]
250 | for param in params:
251 | if param not in stationdict:
252 | res = None
253 | elif min is not None and stationdict[param] < min:
254 | res = None
255 | elif max is not None and stationdict[param] >= max:
256 | res = None
257 | elif stationdict[param] is None:
258 | res = None
259 | else:
260 | res = stationdict[param]
261 | paralist.append(res)
262 | if all([i is None for i in paralist]):
263 | continue
264 | # Test for limited coordinates
265 | if latlim is not None:
266 | if stationdict['lat'] < latlim[0]:
267 | continue
268 | elif stationdict['lat'] > latlim[1]:
269 | continue
270 | if lonlim is not None:
271 | if stationdict['lon'] < lonlim[0]:
272 | continue
273 | elif stationdict['lon'] > lonlim[1]:
274 | continue
275 | # Add station data to result list
276 | if stationtime in result.keys():
277 | result[stationtime].append([stationdict['name'],
278 | stationdict['altitude'],
279 | stationdict['lat'],
280 | stationdict['lon']] + paralist)
281 | else:
282 | result[stationtime] = [[stationdict['name'],
283 | stationdict['altitude'],
284 | stationdict['lat'],
285 | stationdict['lon']] + paralist]
286 | except DummyException as e:
287 | "ERROR: Unresolved station request: {}".format(e)
288 | return(result)
289 |
290 |
291 | def read_swis(file, params, min=None, max=None, latlim=None, lonlim=None):
292 | """ Reading bufr files for street weather information system data and
293 | provide dictionary with weather data for cloud base height and visibility.
294 | The results are subsequently filtered by cloud base height and visibility
295 |
296 | Arguments:
297 | file Bufr file with synop reports
298 | params List of parameter names that will be extracted
299 | min Threshold for minimum value of parameter
300 | max Threshold for maximum value of parameter
301 | latlim Tuple of minimum and maximum latitude values for valid result
302 | lonlim Tuple of minimum and maximum longitude values for valid result
303 |
304 | Returns list of station dictionaries for given thresholds
305 | """
306 | result = {}
307 | bfr = Bufr("libdwd", os.getenv("BUFR_TABLES"))
308 | for blob, size, header in load_file.next_bufr(file):
309 | bfr.decode(blob)
310 | try:
311 | for subset in bfr.next_subset():
312 | stationdict = {}
313 | for (k, m, v, q) in subset.next_data():
314 | if k == 1015: # Station name
315 | stationdict['name'] = v.strip()
316 | if k == 5001: # Latitude
317 | stationdict['lat'] = v
318 | if k == 6001: # Longitude
319 | stationdict['lon'] = v
320 | if k == 7030: # Altitude
321 | stationdict['altitude'] = v
322 | elif k == 4001: # Year
323 | stationdict['year'] = v
324 | elif k == 4002: # Month
325 | stationdict['month'] = v
326 | elif k == 4003: # Day
327 | stationdict['day'] = v
328 | elif k == 4004: # Hour
329 | stationdict['hour'] = v
330 | elif k == 4005: # Hour
331 | stationdict['minute'] = v
332 | elif k == 20003: # Present weather
333 | stationdict['present weather'] = v
334 | # Values from 40 to 49 are refering to fog and ice fog
335 | # Patchy fog or fog edges value 11 or 12
336 | # 28 refers to fog or ice fog from manned station
337 | # Reference: FM 94, table: 4677
338 | elif k == 20004: # Past weather
339 | stationdict['past weather'] = v
340 | # Values from 40 to 49 are refering to fog and ice fog
341 | # Patchy fog or fog edges value 11 or 12
342 | elif k == 20013: # Cloud base height
343 | if v is not None:
344 | if ('cbh' in stationdict.keys() and
345 | stationdict["cbh"] is not None):
346 | if stationdict['cbh'] > v:
347 | stationdict['cbh'] = v
348 | else:
349 | stationdict['cbh'] = v
350 | else:
351 | stationdict['cbh'] = None
352 | elif k == 2001: # Auto/manual measurement
353 | # 1 - 3 : Manual human observations. Manned stations
354 | # 0, 4 - 7 : Only automatic observations
355 | stationdict['type'] = v
356 | elif k == 20001: # Prevailing visibility
357 | if v is not None:
358 | stationdict['visibility'] = v * 10
359 | else:
360 | stationdict['visibility'] = v
361 | elif k == 12101: # Mean air temperature in K
362 | stationdict['air temperature'] = v
363 | elif k == 12103: # Dew point temperature in K
364 | stationdict['dew point'] = v
365 | elif k == 20010: # Cloud cover in %
366 | stationdict['cloudcover'] = v
367 | elif k == 13003: # Relative humidity in %
368 | stationdict['relative humidity'] = v
369 | elif k == 11001: # Wind direction in degree
370 | stationdict['wind direction'] = v
371 | elif k == 11002: # Wind speed in m s-1
372 | stationdict['wind speed'] = v
373 | elif k == 1002: # WMO station number
374 | stationdict['wmo'] = v
375 | elif k == 1024: # WMO station number
376 | stationdict['coords'] = v
377 | elif k == 33005: # WMO station number
378 | stationdict['quality'] = v
379 | # Apply thresholds
380 | stationtime = datetime(stationdict['year'],
381 | stationdict['month'],
382 | stationdict['day'],
383 | stationdict['hour'],
384 | stationdict['minute'],
385 | ).strftime("%Y%m%d%H%M%S")
386 | paralist = []
387 | if not isinstance(params, list):
388 | params = [params]
389 | for param in params:
390 | if param not in stationdict:
391 | res = None
392 | elif min is not None and stationdict[param] < min:
393 | res = None
394 | elif max is not None and stationdict[param] >= max:
395 | res = None
396 | elif stationdict[param] is None:
397 | res = None
398 | else:
399 | res = stationdict[param]
400 | paralist.append(res)
401 | if all([i is None for i in paralist]):
402 | continue
403 | # Test for limited coordinates
404 | if latlim is not None:
405 | if stationdict['lat'] < latlim[0]:
406 | continue
407 | elif stationdict['lat'] > latlim[1]:
408 | continue
409 | if lonlim is not None:
410 | if stationdict['lon'] < lonlim[0]:
411 | continue
412 | elif stationdict['lon'] > lonlim[1]:
413 | continue
414 | # Add station data to result list
415 | if stationtime in result.keys():
416 | result[stationtime].append([stationdict['name'],
417 | stationdict['altitude'],
418 | stationdict['lat'],
419 | stationdict['lon']] + paralist)
420 | else:
421 | result[stationtime] = [[stationdict['name'],
422 | stationdict['altitude'],
423 | stationdict['lat'],
424 | stationdict['lon']] + paralist]
425 | except DummyException as e:
426 | "ERROR: Unresolved station request: {}".format(e)
427 | return(result)
428 |
429 |
430 | def main():
431 | base = os.path.split(fogpy.__file__)
432 | synopfile = os.path.join(base[0], '..', 'etc', 'result_20131112.bufr')
433 | metarfile = os.path.join(
434 | base[0],
435 | '..',
436 | 'etc',
437 | 'result_20131112_metar.bufr')
438 | swisfile = os.path.join(base[0], '..', 'etc', 'result_20131112_swis.bufr')
439 | print(read_synop(synopfile, ['visibility']))
440 | print(read_metar(metarfile, 'visibility', latlim=(45, 60), lonlim=(3, 18)))
441 | print(read_swis(swisfile, ['visibility']))
442 |
443 |
444 | if __name__ == '__main__':
445 | main()
446 |
--------------------------------------------------------------------------------
/fogpy/utils/reproj_testdata.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | # -*- coding: utf-8 -*-
3 | # Copyright (c) 2017-2020 Fogpy developers
4 |
5 | # This file is part of the fogpy package.
6 |
7 | # This program is free software: you can redistribute it and/or modify
8 | # it under the terms of the GNU General Public License as published by
9 | # the Free Software Foundation, either version 3 of the License, or
10 | # (at your option) any later version.
11 |
12 | # This program is distributed in the hope that it will be useful,
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | # GNU General Public License for more details.
16 |
17 | # You should have received a copy of the GNU General Public License
18 | # along with this program. If not, see .
19 |
20 | """ This module provide utilities to reproject the test data """
21 |
22 | import os
23 | import numpy as np
24 | import fogpy
25 | from datetime import datetime
26 | from pyresample import image, geometry
27 | from pyresample import utils
28 | from satpy.scene import Scene
29 | from satpy.dataset import Dataset
30 | from trollimage.colormap import Colormap
31 | from satpy.utils import debug_on
32 |
33 | debug_on()
34 | # Define geos projection boundaries for Germany.
35 | # area_extent: (x_ll, y_ll, x_ur, y_ur)
36 | germ_areadef = utils.load_area('/home/mastho/git/satpy/satpy/etc/areas.def',
37 | 'germ')
38 | euro_areadef = utils.load_area('/home/mastho/git/satpy/satpy/etc/areas.def',
39 | 'euro4')
40 | germ_extent = germ_areadef.area_extent_ll
41 | print(dir(germ_extent))
42 | geos_areadef = utils.load_area('/home/mastho/git/satpy/satpy/etc/areas.def',
43 | 'EuropeCanary')
44 | print(germ_extent[0::2], germ_extent[1::2])
45 | print(list(germ_extent[1::2]))
46 | x, y = geos_areadef.get_xy_from_lonlat(list(germ_extent[0::2]),
47 | list(germ_extent[1::2]))
48 | print(x, y)
49 | print(y[0])
50 | xproj, yproj = geos_areadef.get_proj_coords()
51 | xll, xur = xproj[y, x]
52 | yll, yur = yproj[y, x]
53 | new_extent = (xll, yll, xur, yur)
54 | print(new_extent)
55 | area_id = 'Ger_geos'
56 | name = 'Ger_geos'
57 | proj_id = 'Ger_geos'
58 | proj4_args = ("proj=geos, lat_0=0.0, lon_0=0, a=6378144.0, "
59 | "b=6356759.0, h=35785831.0, rf=295.49")
60 | x_size = 298
61 | y_size = 141
62 | proj_dict = {'a': '6378144.0', 'b': '6356759.0', 'units': 'm', 'lon_0': '0',
63 | 'h': '35785831.0', 'lat_0': '0', 'rf': '295.49',
64 | 'proj': 'geos'}
65 | area_def = geometry.AreaDefinition(area_id, name, proj_id, proj_dict, x_size,
66 | y_size, new_extent)
67 |
68 | print(area_def)
69 |
70 | # Import test data
71 | base = os.path.split(fogpy.__file__)
72 | testfile = os.path.join(base[0], '..', 'etc', 'fog_testdata.npy')
73 | testdata = np.load(testfile)
74 |
75 | # Load test data
76 | inputs = np.dsplit(testdata, 13)
77 | ir108 = inputs[0]
78 | ir039 = inputs[1]
79 | vis008 = inputs[2]
80 | nir016 = inputs[3]
81 | vis006 = inputs[4]
82 | ir087 = inputs[5]
83 | ir120 = inputs[6]
84 | elev = inputs[7]
85 | cot = inputs[8]
86 | reff = inputs[9]
87 | cwp = inputs[10]
88 | lat = inputs[11]
89 | lon = inputs[12]
90 |
91 | msg_con_quick = image.ImageContainerQuick(ir108.squeeze(), area_def)
92 | area_con_quick = msg_con_quick.resample(euro_areadef)
93 | result_data_quick = area_con_quick.image_data
94 |
95 | # Create satpy scene
96 | testscene = Scene(platform_name="msg",
97 | sensor="seviri",
98 | start_time=datetime(2013, 11, 12, 8, 30),
99 | end_time=datetime(2013, 11, 12, 8, 45),
100 | area=area_def)
101 | array_kwargs = {'area': area_def}
102 |
103 | testscene['ir108'] = Dataset(ir108.squeeze(), **array_kwargs)
104 | print(testscene['ir108'])
105 | testscene.show(
106 | 'ir108',
107 | overlay={'coast_dir': '/home/mastho/data/', 'color': 'gray'})
108 | resampscene = testscene.resample('germ')
109 | print(resampscene.shape)
110 |
111 | # Define custom fog colormap
112 | fogcol = Colormap((0., (250 / 255.0, 200 / 255.0, 40 / 255.0)),
113 | (1., (1.0, 1.0, 229 / 255.0)))
114 | maskcol = (250 / 255.0, 200 / 255.0, 40 / 255.0)
115 |
--------------------------------------------------------------------------------
/setup.cfg:
--------------------------------------------------------------------------------
1 | [metadata]
2 | name = fogpy
3 | description = Satellite based fog and low stratus detection and nowcasting
4 | license = GNU general public license version 3
5 | license_files = LICENSE.txt
6 | classifiers =
7 | Programming Language :: Python
8 | Development Status :: 4 - Beta
9 | Natural Language :: English
10 | Environment :: Web Environment
11 | Intended Audience :: Science/Research
12 | License :: OSI Approved :: GNU General Public License v3 (GPLv3)
13 | Operating System :: OS Independent
14 | Topic :: Scientific/Engineering :: Atmospheric Science
15 | Topic :: Scientific/Engineering :: Physics
16 | url = https://github.com/pytroll/fogpy
17 | author = Thomas Leppelt, Gerrit Holl
18 | maintainer = Gerrit Holl
19 | author_email = gerrit.holl@dwd.de
20 | platforms = any
21 |
22 | [options]
23 | packages = find:
24 | include_package_data = True
25 | install_requires =
26 | numpy
27 | scipy
28 | matplotlib
29 | pyorbital
30 | trollimage
31 | satpy
32 | pyresample
33 | opencv-python
34 | opencv-contrib-python
35 | trollbufr
36 | appdirs
37 | requests
38 | python_requires = >=3.7
39 | tests_require = pytest, pytest-cov
40 |
41 | [options.package_data]
42 | fogpy =
43 | etc
44 | etc/composites/*.yaml
45 | etc/enhancements/*.yaml
46 |
47 | [flake8]
48 | max-line-length = 120
49 |
50 | [coverage:run]
51 | omit =
52 | fogpy/version.py
53 |
--------------------------------------------------------------------------------
/setup.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | # -*- coding: utf-8 -*-
3 | # Copyright (c) 2017-2021 Fogpy developers
4 |
5 | # This file is part of the fogpy package.
6 |
7 | # This program is free software: you can redistribute it and/or modify
8 | # it under the terms of the GNU General Public License as published by
9 | # the Free Software Foundation, either version 3 of the License, or
10 | # (at your option) any later version.
11 |
12 | # This program is distributed in the hope that it will be useful,
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | # GNU General Public License for more details.
16 |
17 | # You should have received a copy of the GNU General Public License
18 | # along with this program. If not, see .
19 |
20 | """Setup file for fogpy."""
21 |
22 | import setuptools
23 |
24 | if __name__ == "__main__":
25 | setuptools.setup()
26 |
--------------------------------------------------------------------------------