├── .gitattributes
├── .github
└── workflows
│ ├── ci.yaml
│ └── publish.yml
├── .gitignore
├── .gitmodules
├── .pre-commit-config.yaml
├── CITATION.cff
├── LICENSE
├── MANIFEST.in
├── README.md
├── ci
└── environment.yml
├── setup.cfg
├── setup.py
├── source
├── aerobulk
│ ├── __init__.py
│ └── flux.py
└── fortran
│ ├── .f2py_f2cmap
│ ├── mod_aerobulk_wrap_noskin.f90
│ ├── mod_aerobulk_wrap_noskin.pyf
│ ├── mod_aerobulk_wrap_skin.f90
│ └── mod_aerobulk_wrap_skin.pyf
└── tests
├── create_test_data.py
├── test_flux_np.py
├── test_flux_xr.py
└── test_fortran.py
/.gitattributes:
--------------------------------------------------------------------------------
1 | source/aerobulk/_version.py export-subst
2 |
--------------------------------------------------------------------------------
/.github/workflows/ci.yaml:
--------------------------------------------------------------------------------
1 | name: CI
2 | on:
3 | push:
4 | branches:
5 | - "main"
6 | pull_request:
7 | branches:
8 | - "*"
9 | schedule:
10 | - cron: "0 13 * * 1"
11 | workflow_dispatch:
12 |
13 | concurrency:
14 | group: ${{ github.workflow }}-${{ github.ref }}
15 | cancel-in-progress: true
16 |
17 | jobs:
18 | build:
19 | name: Build (${{ matrix.python-version }} | ${{ matrix.os }})
20 | if: github.repository == 'xgcm/aerobulk-python'
21 | runs-on: ${{ matrix.os }}
22 | timeout-minutes: 30
23 | defaults:
24 | run:
25 | shell: bash -l {0}
26 | strategy:
27 | fail-fast: false
28 | matrix:
29 | os: ["ubuntu-latest"]
30 | python-version: ["3.8", "3.9", "3.10", "3.11"]
31 | steps:
32 | - uses: actions/checkout@v3
33 | with:
34 | submodules: recursive
35 | - name: Create conda environment
36 | uses: mamba-org/provision-with-micromamba@main
37 | with:
38 | cache-downloads: true
39 | micromamba-version: 'latest'
40 | environment-file: ci/environment.yml
41 | extra-specs: |
42 | python=${{ matrix.python-version }}
43 | - name: Install aerobulk-python
44 | run: |
45 | python -m pip install -e . --no-deps
46 | conda list
47 | - name: Run Tests
48 | run: |
49 | pytest -vv --cov=./ --cov-report=xml
50 | - name: Upload code coverage to Codecov
51 | uses: codecov/codecov-action@v3.1.1
52 | with:
53 | file: ./coverage.xml
54 | flags: unittests
55 | env_vars: OS,PYTHON
56 | name: codecov-umbrella
57 | fail_ci_if_error: false
58 |
--------------------------------------------------------------------------------
/.github/workflows/publish.yml:
--------------------------------------------------------------------------------
1 | name: Upload Python Package
2 |
3 | on:
4 | release:
5 | types: [created]
6 |
7 | jobs:
8 | deploy:
9 | if: github.repository == 'xgcm/aerobulk-python'
10 | runs-on: ubuntu-latest
11 | steps:
12 | - uses: actions/checkout@v3
13 | with:
14 | submodules: recursive
15 | - name: Set up Python
16 | uses: actions/setup-python@v3
17 | with:
18 | python-version: '3.11'
19 | - name: Install dependencies
20 | run: |
21 | python -m pip install --upgrade pip
22 | pip install numpy setuptools setuptools-scm wheel twine
23 | - name: Build tarball
24 | run: python setup.py sdist
25 | - name: Check dist
26 | run: ls -la dist
27 | - name: Check version
28 | run: python setup.py --version
29 | - name: Check built artifacts
30 | run: |
31 | python -m twine check dist/*
32 | pwd
33 | if [ -f dist/aerobulk-python-0.0.0.tar.gz ]; then
34 | echo "❌ INVALID VERSION NUMBER"
35 | exit 1
36 | else
37 | echo "✅ Looks good"
38 | fi
39 | - name: Publish a Package to PyPI
40 | uses: pypa/gh-action-pypi-publish@v1.5.0
41 | with:
42 | user: __token__
43 | password: ${{ secrets.PYPI_API_TOKEN }}
44 | verbose: true
45 | verify_metadata: true
46 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .ipynb_checkpoints
2 | # might have to remove this later, if we want to add nbs
3 | *.ipynb
4 |
5 | _version.py
6 | *.egg-info
7 | .eggs/
8 | build/
9 | __pycache__
10 | dist/
11 |
12 | # files built by f2py
13 | source/fortran/*f2pywrappers*
14 | source/fortran/*.c
15 | source/aerobulk/aerobulk/
16 | mod_*.so
17 |
18 | # should we ignore submodules
19 | .DS_Store
20 | .vscode/
21 |
--------------------------------------------------------------------------------
/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule "source/fortran/aerobulk"]
2 | path = source/fortran/aerobulk
3 | url = git@github.com:jbusecke/aerobulk.git
4 |
--------------------------------------------------------------------------------
/.pre-commit-config.yaml:
--------------------------------------------------------------------------------
1 | autoupdate_schedule: quarterly
2 | default_language_version:
3 | python: python3
4 | repos:
5 | - repo: https://github.com/pre-commit/pre-commit-hooks
6 | rev: v5.0.0
7 | hooks:
8 | - id: trailing-whitespace
9 | - id: end-of-file-fixer
10 | - id: check-yaml
11 | - repo: https://github.com/PyCQA/isort
12 | rev: 5.13.2
13 | hooks:
14 | - id: isort
15 | - repo: https://github.com/psf/black
16 | rev: 24.10.0
17 | hooks:
18 | - id: black
19 | - repo: https://github.com/PyCQA/flake8
20 | rev: 7.1.1
21 | hooks:
22 | - id: flake8
23 |
--------------------------------------------------------------------------------
/CITATION.cff:
--------------------------------------------------------------------------------
1 | cff-version: 1.2.0
2 | message: "If you use this software, please cite it as below."
3 | authors:
4 | - family-names: "Busecke"
5 | given-names: "Julius J. M."
6 | orcid: "https://orcid.org/0000-0001-8571-865X"
7 | - family-names: "Martin"
8 | given-names: "Paige E."
9 | - family-names: "Abernathey"
10 | given-names: "Ryan P."
11 | orcid: "https://orcid.org/0000-0001-5999-4917"
12 | title: "aerobulk-python"
13 | url: "https://github.com/xgcm/aerobulk-python"
14 | # version and doi are completed by Zenodo automatically, do not provide here.
15 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
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 README.md
2 | include LICENSE
3 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | [](https://results.pre-commit.ci/latest/github/xgcm/aerobulk-python/main)
2 | [](https://zenodo.org/doi/10.5281/zenodo.11205090)
3 |
4 |
5 | # aerobulk-python
6 | A python wrapper for aerobulk (https://github.com/brodeau/aerobulk)
7 |
8 | ## Installation
9 | Due to the heavy dependencies in this package we recommend installing the package from conda-forge with mamba/conda
10 |
11 | ```
12 | mamba install -c conda-forge aerobulk-python
13 | ```
14 | or
15 | ```
16 | conda install -c conda-forge aerobulk-python
17 | ```
18 |
19 | ## aerobulk-python developer guide
20 |
21 | These are the steps to install and develop the package locally
22 |
23 | 1. Set up a development environment.
24 | ```
25 | mamba create -n aerobulk-python-dev python=3.9 dask numpy gfortran xarray pytest ipython
26 | conda activate aerobulk-python-dev
27 | ```
28 |
29 | 2. Clone the repository
30 |
31 | Make sure to clone the repo with `--recursive` to also pull the git submodule!
32 |
33 | ```
34 | git clone --recursive git@github.com:xgcm/aerobulk-python.git
35 | ```
36 |
37 | 3. Compile/Install aerobulk-python (this has to be rerun after every change to the fortran code/wrapper/signature file)
38 | Run these commands from within the `aerobulk-python` folder.
39 |
40 | a. Use pip to install aerobulk locally (this will install the python package and compile).
41 | ```
42 | pip install -e .
43 | ```
44 | b. Manual version (you will have to install the python module separately)
45 | ```
46 | python -m numpy.f2py --verbose -c --f90flags="-fdefault-real-8 -ffree-line-length-200 --std=gnu" ./source/fortran/aerobulk/src/mod_const.f90 ./source/fortran/aerobulk/src/mod_phymbl.f90 ./source/fortran/aerobulk/src/mod_skin_coare.f90 ./source/fortran/aerobulk/src/mod_skin_ecmwf.f90 ./source/fortran/aerobulk/src/mod_blk_andreas.f90 ./source/fortran/aerobulk/src/mod_common_coare.f90 ./source/fortran/aerobulk/src/mod_blk_coare3p0.f90 ./source/fortran/aerobulk/src/mod_blk_coare3p6.f90 ./source/fortran/aerobulk/src/mod_blk_ecmwf.f90 ./source/fortran/aerobulk/src/mod_blk_ncar.f90 ./source/fortran/aerobulk/src/mod_blk_neutral_10m.f90 ./source/fortran/aerobulk/src/mod_aerobulk_compute.f90 ./source/fortran/aerobulk/src/mod_aerobulk.f90 ./source/fortran/mod_aerobulk_wrap_skin.f90 ./source/fortran/mod_aerobulk_wrap_skin.pyf
47 | ```
48 | and
49 |
50 | ```
51 | python -m numpy.f2py --verbose -c --f90flags="-fdefault-real-8 -ffree-line-length-200 --std=gnu" ./source/fortran/aerobulk/src/mod_const.f90 ./source/fortran/aerobulk/src/mod_phymbl.f90 ./source/fortran/aerobulk/src/mod_skin_coare.f90 ./source/fortran/aerobulk/src/mod_skin_ecmwf.f90 ./source/fortran/aerobulk/src/mod_blk_andreas.f90 ./source/fortran/aerobulk/src/mod_common_coare.f90 ./source/fortran/aerobulk/src/mod_blk_coare3p0.f90 ./source/fortran/aerobulk/src/mod_blk_coare3p6.f90 ./source/fortran/aerobulk/src/mod_blk_ecmwf.f90 ./source/fortran/aerobulk/src/mod_blk_ncar.f90 ./source/fortran/aerobulk/src/mod_blk_neutral_10m.f90 ./source/fortran/aerobulk/src/mod_aerobulk_compute.f90 ./source/fortran/aerobulk/src/mod_aerobulk.f90 ./source/fortran/mod_aerobulk_wrap_noskin.f90 ./source/fortran/mod_aerobulk_wrap_noskin.pyf
52 | ```
53 | 4. Make sure things work
54 | ```
55 | pytest tests/test_fortran.py
56 | ```
57 | 🎉
58 |
59 | ## Local Aerobulk compilation guide
60 | Assumes that you have an environment with a gfortran compiler set up, have aerobulk cloned and that you are in the root aerobulk (not aerobulk-python) directory.
61 |
62 | 1. Build the aerobulk source
63 |
64 | First copy the appropriate macro file to the source directory:
65 | ```
66 | cp arch/make.macro_GnuLinux make.macro
67 | ```
68 |
69 | those of us on mac needed to edit `make.macro` make this change
70 | ```diff
71 | # These are needed for the C/C++ interface
72 | - FF += -std=gnu -lstdc++
73 | + FF += -std=gnu
74 | ```
75 |
76 | Then you should be able to run `make`
77 |
78 | This will build:
79 | - Object files `src/*.o`
80 | - Mode files `mod/*.mod`
81 | - Library file `lib/libaerobulk.a`
82 | - Binary executables `bin/*x`
83 |
84 | I was able to run one of the binaries with `bin/example_call_aerobulk.x`
85 |
86 |
87 | Output
88 | ```
89 | *********** COARE 3.0 *****************
90 |
91 | ===================================================================
92 | ----- AeroBulk_init -----
93 |
94 | *** Bulk parameterization to be used => "coare3p0"
95 | ==> will use the Cool-skin & Warm-ayer scheme of `coare3p0` !
96 | *** Computational domain shape: Ni x Nj = 00002 x 00001
97 | *** Number of time records that will be treated: 1
98 | *** Number of iterations in bulk algos: nb_iter = 10
99 | *** Filling the `mask` array...
100 | ==> no points need to be masked! :)
101 | *** Type of prescribed air humidity `specific humidity [kg/kg]`
102 | ===================================================================
103 | ===================================================================
104 | ----- AeroBulk_bye -----
105 | ===================================================================
106 |
107 |
108 | ---------------------------------------------------------------------
109 | Parameter | Unstable ASL | Stable ASL | units
110 | ---------------------------------------------------------------------
111 | Wind speed at zu = 5.00000000 5.00000000 m/s
112 | SST = 22.0000000 22.0000000 deg.C
113 | Abs. temperature at zt = 20.0000000 25.0000000 deg.C
114 | Pot. temperature at zt = 20.0134144 25.0150242 deg.C
115 |
116 | Sensible heat flux: QH = -15.1545086 17.8423691 W/m**2
117 | Latent heat flux: QL = -81.3846741 -50.8408585 W/m**2
118 | Evaporation: Evap = -2.87061906 -1.79333246 mm/day
119 | Skin temperature: SSST = 21.7219677 21.7576351 deg.C
120 | Tau_x = 3.57834995E-02 1.73626728E-02 N/m**2
121 | Tau_y = 0.00000000 0.00000000 N/m**2
122 | Tau = 3.57834995E-02 1.73626728E-02 N/m**2
123 |
124 |
125 |
126 | *********** COARE 3.6 *****************
127 |
128 | ===================================================================
129 | ----- AeroBulk_init -----
130 |
131 | *** Bulk parameterization to be used => "coare3p6"
132 | ==> will use the Cool-skin & Warm-ayer scheme of `coare3p6` !
133 | *** Computational domain shape: Ni x Nj = 00002 x 00001
134 | *** Number of time records that will be treated: 1
135 | *** Number of iterations in bulk algos: nb_iter = 10
136 | *** Filling the `mask` array...
137 | ==> no points need to be masked! :)
138 | *** Type of prescribed air humidity `specific humidity [kg/kg]`
139 | ===================================================================
140 | ===================================================================
141 | ----- AeroBulk_bye -----
142 | ===================================================================
143 |
144 |
145 | ---------------------------------------------------------------------
146 | Parameter | Unstable ASL | Stable ASL | units
147 | ---------------------------------------------------------------------
148 | Wind speed at zu = 5.00000000 5.00000000 m/s
149 | SST = 22.0000000 22.0000000 deg.C
150 | Abs. temperature at zt = 20.0000000 25.0000000 deg.C
151 | Pot. temperature at zt = 20.0134144 25.0150242 deg.C
152 |
153 | Sensible heat flux: QH = -15.3865499 17.0818920 W/m**2
154 | Latent heat flux: QL = -83.0788422 -48.4459152 W/m**2
155 | Evaporation: Evap = -2.93033028 -1.70883954 mm/day
156 | Skin temperature: SSST = 21.7057972 21.7485600 deg.C
157 | Tau_x = 3.21817845E-02 1.51577257E-02 N/m**2
158 | Tau_y = 0.00000000 0.00000000 N/m**2
159 | Tau = 3.21817845E-02 1.51577257E-02 N/m**2
160 |
161 |
162 |
163 | *********** ECMWF *****************
164 |
165 | ===================================================================
166 | ----- AeroBulk_init -----
167 |
168 | *** Bulk parameterization to be used => "ecmwf"
169 | ==> will use the Cool-skin & Warm-ayer scheme of `ecmwf` !
170 | *** Computational domain shape: Ni x Nj = 00002 x 00001
171 | *** Number of time records that will be treated: 1
172 | *** Number of iterations in bulk algos: nb_iter = 10
173 | *** Filling the `mask` array...
174 | ==> no points need to be masked! :)
175 | *** Type of prescribed air humidity `specific humidity [kg/kg]`
176 | ===================================================================
177 | ===================================================================
178 | ----- AeroBulk_bye -----
179 | ===================================================================
180 |
181 |
182 | ---------------------------------------------------------------------
183 | Parameter | Unstable ASL | Stable ASL | units
184 | ---------------------------------------------------------------------
185 | Wind speed at zu = 5.00000000 5.00000000 m/s
186 | SST = 22.0000000 22.0000000 deg.C
187 | Abs. temperature at zt = 20.0000000 25.0000000 deg.C
188 | Pot. temperature at zt = 20.0134144 25.0150242 deg.C
189 |
190 | Sensible heat flux: QH = -14.3822346 17.6531811 W/m**2
191 | Latent heat flux: QL = -80.2958984 -52.4623947 W/m**2
192 | Evaporation: Evap = -2.83224440 -1.85053933 mm/day
193 | Skin temperature: SSST = 21.7325401 21.7630310 deg.C
194 | Tau_x = 3.84389125E-02 1.93256922E-02 N/m**2
195 | Tau_y = 0.00000000 0.00000000 N/m**2
196 | Tau = 3.84389125E-02 1.93256922E-02 N/m**2
197 |
198 |
199 |
200 | *********** NCAR *****************
201 |
202 | ===================================================================
203 | ----- AeroBulk_init -----
204 |
205 | *** Bulk parameterization to be used => "ncar"
206 | *** Cool-skin & Warm-layer schemes will NOT be used!
207 | *** Computational domain shape: Ni x Nj = 00002 x 00001
208 | *** Number of time records that will be treated: 1
209 | *** Number of iterations in bulk algos: nb_iter = 10
210 | *** Filling the `mask` array...
211 | ==> no points need to be masked! :)
212 | *** Type of prescribed air humidity `specific humidity [kg/kg]`
213 | ===================================================================
214 | ===================================================================
215 | ----- AeroBulk_bye -----
216 | ===================================================================
217 |
218 |
219 | ---------------------------------------------------------------------
220 | Parameter | Unstable ASL | Stable ASL | units
221 | ---------------------------------------------------------------------
222 | Wind speed at zu = 5.00000000 5.00000000 m/s
223 | SST = 22.0000000 22.0000000 deg.C
224 | Abs. temperature at zt = 20.0000000 25.0000000 deg.C
225 | Pot. temperature at zt = 20.0134144 25.0150242 deg.C
226 |
227 | Sensible heat flux: QH = -16.6969528 10.7261686 W/m**2
228 | Latent heat flux: QL = -88.4781876 -71.9012222 W/m**2
229 | Evaporation: Evap = -3.12166286 -2.53679895 mm/day
230 | Tau_x = 3.58519591E-02 2.77329944E-02 N/m**2
231 | Tau_y = 0.00000000 0.00000000 N/m**2
232 | Tau = 3.58519591E-02 2.77329944E-02 N/m**2
233 |
234 |
235 |
236 | *********** ANDREAS *****************
237 |
238 | ===================================================================
239 | ----- AeroBulk_init -----
240 |
241 | *** Bulk parameterization to be used => "andreas"
242 | *** Cool-skin & Warm-layer schemes will NOT be used!
243 | *** Computational domain shape: Ni x Nj = 00002 x 00001
244 | *** Number of time records that will be treated: 1
245 | *** Number of iterations in bulk algos: nb_iter = 10
246 | *** Filling the `mask` array...
247 | ==> no points need to be masked! :)
248 | *** Type of prescribed air humidity `specific humidity [kg/kg]`
249 | ===================================================================
250 | ===================================================================
251 | ----- AeroBulk_bye -----
252 | ===================================================================
253 |
254 |
255 | ---------------------------------------------------------------------
256 | Parameter | Unstable ASL | Stable ASL | units
257 | ---------------------------------------------------------------------
258 | Wind speed at zu = 5.00000000 5.00000000 m/s
259 | SST = 22.0000000 22.0000000 deg.C
260 | Abs. temperature at zt = 20.0000000 25.0000000 deg.C
261 | Pot. temperature at zt = 20.0134144 25.0150242 deg.C
262 |
263 | Sensible heat flux: QH = -14.4129944 15.1970539 W/m**2
264 | Latent heat flux: QL = -74.4637756 -51.7018318 W/m**2
265 | Evaporation: Evap = -2.62721038 -1.82412970 mm/day
266 | Tau_x = 3.02770734E-02 1.79436151E-02 N/m**2
267 | Tau_y = 0.00000000 0.00000000 N/m**2
268 | Tau = 3.02770734E-02 1.79436151E-02 N/m**2
269 | ```
270 |
271 |
--------------------------------------------------------------------------------
/ci/environment.yml:
--------------------------------------------------------------------------------
1 | name: test_env_aerobulk_python
2 | channels:
3 | - conda-forge
4 | dependencies:
5 | - codecov
6 | - dask
7 | - gfortran
8 | - numpy
9 | - pytest
10 | - pytest-cov
11 | - python
12 | - xarray
13 |
--------------------------------------------------------------------------------
/setup.cfg:
--------------------------------------------------------------------------------
1 | [flake8]
2 | exclude = __init__.py,.eggs,doc
3 | ignore =
4 | # whitespace before ':' - doesn't work well with black
5 | E203
6 | E402
7 | # line too long - let black worry about that
8 | E501
9 | # do not assign a lambda expression, use a def
10 | E731
11 | # line break before binary operator
12 | W503
13 | E265
14 | F811
15 | [tool:pytest]
16 | testpaths = tests
17 |
--------------------------------------------------------------------------------
/setup.py:
--------------------------------------------------------------------------------
1 | import os
2 |
3 | # We need to import setuptools here in order for it to persist in sys.modules.
4 | # Its presence/absence is used in subclassing setup in numpy/distutils/core.py.
5 | # However, we need to run the distutils version of sdist, so import that first
6 | # so that it is in sys.modules
7 | import numpy.distutils.command.sdist # noqa
8 | import setuptools # noqa
9 | from numpy.distutils.core import Extension, setup
10 | from numpy.distutils.fcompiler import get_default_fcompiler
11 |
12 | # Trying this from the numpy setup.py
13 |
14 |
15 | here = os.path.dirname(__file__)
16 | with open(os.path.join(here, "README.md"), encoding="utf-8") as f:
17 | long_description = f.read()
18 |
19 | install_requires = [
20 | "numpy",
21 | ]
22 |
23 | # figure out which compiler we're going to use
24 | compiler = get_default_fcompiler()
25 | # set some fortran compiler-dependent flags
26 | f90flags = []
27 | if compiler == "gnu95":
28 | # f90flags.append('-fno-range-check')
29 | # f90flags.append('-ffree-form')
30 | # These are the flags I used in the manual version (might have some more here)
31 | f90flags.append("-fdefault-real-8")
32 | f90flags.append("-ffree-line-length-200")
33 | elif compiler == "intel" or compiler == "intelem":
34 | f90flags.append("-132")
35 | # Set aggressive optimization level
36 | f90flags.append("-O3")
37 | # Suppress all compiler warnings (avoid huge CI log files)
38 | f90flags.append("-w")
39 |
40 | # for this API we will only expose a single extension?
41 | ext_modules = [
42 | Extension(
43 | name="mod_aerobulk_wrap_noskin",
44 | sources=[
45 | "./source/fortran/aerobulk/src/mod_const.f90",
46 | "./source/fortran/aerobulk/src/mod_phymbl.f90",
47 | "./source/fortran/aerobulk/src/mod_skin_coare.f90",
48 | "./source/fortran/aerobulk/src/mod_skin_ecmwf.f90",
49 | "./source/fortran/aerobulk/src/mod_blk_andreas.f90",
50 | "./source/fortran/aerobulk/src/mod_common_coare.f90",
51 | "./source/fortran/aerobulk/src/mod_blk_coare3p0.f90",
52 | "./source/fortran/aerobulk/src/mod_blk_coare3p6.f90",
53 | "./source/fortran/aerobulk/src/mod_blk_ecmwf.f90",
54 | "./source/fortran/aerobulk/src/mod_blk_ncar.f90",
55 | "./source/fortran/aerobulk/src/mod_blk_neutral_10m.f90",
56 | "./source/fortran/aerobulk/src/mod_aerobulk_compute.f90",
57 | "./source/fortran/aerobulk/src/mod_aerobulk.f90",
58 | "./source/fortran/mod_aerobulk_wrap_noskin.f90",
59 | "./source/fortran/mod_aerobulk_wrap_noskin.pyf",
60 | ],
61 | extra_f90_compile_args=f90flags,
62 | # f2py_options=['--quiet'],
63 | ),
64 | Extension(
65 | name="mod_aerobulk_wrap_skin",
66 | sources=[
67 | "./source/fortran/aerobulk/src/mod_const.f90",
68 | "./source/fortran/aerobulk/src/mod_phymbl.f90",
69 | "./source/fortran/aerobulk/src/mod_skin_coare.f90",
70 | "./source/fortran/aerobulk/src/mod_skin_ecmwf.f90",
71 | "./source/fortran/aerobulk/src/mod_blk_andreas.f90",
72 | "./source/fortran/aerobulk/src/mod_common_coare.f90",
73 | "./source/fortran/aerobulk/src/mod_blk_coare3p0.f90",
74 | "./source/fortran/aerobulk/src/mod_blk_coare3p6.f90",
75 | "./source/fortran/aerobulk/src/mod_blk_ecmwf.f90",
76 | "./source/fortran/aerobulk/src/mod_blk_ncar.f90",
77 | "./source/fortran/aerobulk/src/mod_blk_neutral_10m.f90",
78 | "./source/fortran/aerobulk/src/mod_aerobulk_compute.f90",
79 | "./source/fortran/aerobulk/src/mod_aerobulk.f90",
80 | "./source/fortran/mod_aerobulk_wrap_skin.f90",
81 | "./source/fortran/mod_aerobulk_wrap_skin.pyf",
82 | ],
83 | extra_f90_compile_args=f90flags,
84 | f2py_options=["--quiet"],
85 | ),
86 | ]
87 |
88 | setup(
89 | name="aerobulk-python",
90 | description="General Circulation Model Postprocessing with xarray",
91 | url="https://github.com/xgcm/aerobulk-python",
92 | author="aerobulk-python Developers",
93 | author_email="julius@ldeo.columbia.edu",
94 | license="GPLv3",
95 | classifiers=[
96 | "Development Status :: 2 - Pre-Alpha",
97 | "Intended Audience :: Science/Research",
98 | "Topic :: Scientific/Engineering",
99 | "License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
100 | "Operating System :: OS Independent",
101 | "Programming Language :: Python :: 3.8",
102 | "Programming Language :: Python :: 3.9",
103 | "Programming Language :: Python :: 3.10",
104 | "Programming Language :: Python :: 3.11",
105 | ],
106 | install_requires=install_requires,
107 | python_requires=">=3.8, <3.12",
108 | # long_description=long_description,
109 | # long_description_content_type="text/x-rst",
110 | setup_requires="setuptools_scm",
111 | use_scm_version={
112 | "write_to": "source/aerobulk/_version.py",
113 | "write_to_template": '__version__ = "{version}"',
114 | "tag_regex": r"^(?Pv)?(?P[^\+]+)(?P.*)?$",
115 | },
116 | package_dir={"": "source"},
117 | packages=["aerobulk"],
118 | ext_package="aerobulk.aerobulk",
119 | ext_modules=ext_modules,
120 | )
121 |
--------------------------------------------------------------------------------
/source/aerobulk/__init__.py:
--------------------------------------------------------------------------------
1 | from importlib.metadata import PackageNotFoundError, version
2 |
3 | try:
4 | __version__ = version("aerobulk-python")
5 | except PackageNotFoundError:
6 | __version__ = "unknown"
7 | pass
8 |
9 | from .flux import noskin, skin
10 |
--------------------------------------------------------------------------------
/source/aerobulk/flux.py:
--------------------------------------------------------------------------------
1 | import warnings
2 |
3 | import aerobulk.aerobulk.mod_aerobulk_wrap_noskin as aeronoskin
4 | import aerobulk.aerobulk.mod_aerobulk_wrap_skin as aeroskin
5 | import numpy as np
6 | import xarray as xr
7 |
8 | VALID_ALGOS = ["coare3p0", "coare3p6", "ecmwf", "ncar", "andreas"]
9 | VALID_ALGOS_SKIN = ["coare3p0", "coare3p6", "ecmwf"]
10 | VALID_VALUE_RANGES = {
11 | "sst": [270, 320],
12 | "t_zt": [180, 330],
13 | "hum_zt": [0, 0.08],
14 | "u_zu": [-50, 50],
15 | "v_zu": [-50, 50],
16 | "slp": [80000, 110000],
17 | "rad_sw": [0, 1500],
18 | "rad_lw": [0, 750],
19 | }
20 |
21 |
22 | def _check_algo(algo, valids):
23 | if algo not in valids:
24 | raise ValueError(f"Algorithm {algo} not valid. Choose from {valids}.")
25 |
26 |
27 | def _check_value_range(*args):
28 | """Checks the input ranges for input fields"""
29 | # parse inputs to names
30 | args_dict = {
31 | k: v
32 | for k, v in zip(
33 | ["sst", "t_zt", "hum_zt", "u_zu", "v_zu", "slp", "rad_sw", "rad_lw"], args
34 | )
35 | }
36 | for var, data in args_dict.items():
37 | # check for misaligned nans
38 | if var != "sst":
39 | if np.isnan(data).any():
40 | raise ValueError(
41 | f"Found nans in {var} that do not align with nans in `sst`. Check that nans in all fields are matched."
42 | )
43 |
44 | # check for valid range
45 | range = VALID_VALUE_RANGES[var]
46 |
47 | # check that values are in range
48 | out_of_range = ~np.logical_and(data >= range[0], data <= range[1])
49 | if out_of_range.any():
50 | raise ValueError(
51 | f"Found values in {var} that are out of the valid range ({range[0]}-{range[1]})."
52 | )
53 |
54 |
55 | # Unshrink the data (i.e. put land NaN values back in their correct locations)
56 | def unshrink_arr(shrunk_array, shape, ocean_index):
57 | unshrunk_array = np.full(shape, np.nan)
58 | unshrunk_array[ocean_index] = np.squeeze(shrunk_array)
59 | return unshrunk_array
60 |
61 |
62 | def noskin_np(
63 | sst, t_zt, hum_zt, u_zu, v_zu, slp, algo, zt, zu, niter, input_range_check
64 | ):
65 | """Python wrapper for aerobulk without skin correction.
66 | !ATTENTION If input not provided in correct units, will crash.
67 | !ATTENTION Missing values taken from NaN values in sst field. No input variables may have NaN values that are not reflected in the sst.
68 |
69 | Parameters
70 | ----------
71 | sst : numpy.array
72 | Bulk sea surface temperature [K]
73 | t_zt : numpy.array
74 | Absolute air temperature at height zt [K]
75 | hum_zt : numpy.array
76 | air humidity at zt, given as specific humidity [kg/kg]
77 | u_zu : numpy.array
78 | zonal wind speed at zu [m/s]
79 | v_zu : numpy.array
80 | meridional wind speed at zu [m/s]
81 | slp : numpy.array, optional
82 | mean sea-level pressure [Pa] ~101000 Pa,
83 | by default 101000.0
84 | algo : str
85 | Algorithm, can be one of: "coare3p0", "coare3p6", "ecmwf", "ncar", "andreas",
86 | zt : int
87 | height for temperature and spec. hum. of air [m],
88 | zu : int
89 | height for wind (10m = traditional anemometric height [m],
90 | niter : int
91 | Number of iteration steps used in the algorithm,
92 |
93 | Returns
94 | -------
95 | ql : numpy.array
96 | Latent heat flux [W/m^2]
97 | qh : numpy.array
98 | Sensible heat flux [W/m^2]
99 | taux : numpy.array
100 | zonal wind stress [N/m^2]
101 | tauy : numpy.array
102 | meridional wind stress [N/m^2]
103 | evap : numpy.array
104 | evaporation [mm/s] aka [kg/m^2/s] (usually <0, as ocean loses water!)
105 | """
106 |
107 | # Define the land mask from the native SST land mask
108 | ocean_index = np.where(~np.isnan(sst))
109 |
110 | # Shrink the input data (i.e. remove all land points)
111 | args_shrunk = tuple(
112 | np.atleast_3d(a[ocean_index]) for a in (sst, t_zt, hum_zt, u_zu, v_zu, slp)
113 | )
114 |
115 | if input_range_check:
116 | _check_value_range(*args_shrunk)
117 |
118 | out_data = aeronoskin.mod_aerobulk_wrapper_noskin.aerobulk_model_noskin(
119 | algo, zt, zu, *args_shrunk, niter
120 | )
121 |
122 | return tuple(unshrink_arr(o, sst.shape, ocean_index) for o in out_data)
123 |
124 |
125 | def skin_np(
126 | sst,
127 | t_zt,
128 | hum_zt,
129 | u_zu,
130 | v_zu,
131 | slp,
132 | rad_sw,
133 | rad_lw,
134 | algo,
135 | zt,
136 | zu,
137 | niter,
138 | input_range_check,
139 | ):
140 | """Python wrapper for aerobulk with skin correction.
141 | !ATTENTION If input not provided in correct units, will crash.
142 | !ATTENTION Missing values taken from NaN values in sst field. No input variables may have NaN values that are not reflected in the sst.
143 |
144 | Parameters
145 | ----------
146 | sst : numpy.array
147 | Bulk sea surface temperature [K]
148 | t_zt : numpy.array
149 | Absolute air temperature at height zt [K]
150 | hum_zt : numpy.array
151 | air humidity at zt, given as specific humidity [kg/kg]
152 | u_zu : numpy.array
153 | zonal wind speed at zu [m/s]
154 | v_zu : numpy.array
155 | meridional wind speed at zu [m/s]
156 | rad_sw : numpy.array
157 | downwelling shortwave radiation at the surface (>0) [W/m^2]
158 | rad_lw : numpy.array
159 | rad_lw : downwelling longwave radiation at the surface (>0) [W/m^2]
160 | slp : numpy.array, optional
161 | mean sea-level pressure [Pa] ~101000 Pa,
162 | by default 101000.0
163 | algo : str
164 | Algorithm, can be one of: "coare3p0", "coare3p6", "ecmwf",
165 | zt : int
166 | height for temperature and spec. hum. of air [m],
167 | zu : int
168 | height for wind (10m = traditional anemometric height [m],
169 | niter : int
170 | Number of iteration steps used in the algorithm,
171 |
172 | Returns
173 | -------
174 | ql : numpy.array
175 | Latent heat flux [W/m^2]
176 | qh : numpy.array
177 | Sensible heat flux [W/m^2]
178 | taux : numpy.array
179 | zonal wind stress [N/m^2]
180 | tauy : numpy.array
181 | meridional wind stress [N/m^2]
182 | t_s : numpy.array
183 | skin temperature [K] (only when l_use_skin_schemes=TRUE)
184 | evap : numpy.array
185 | evaporation [mm/s] aka [kg/m^2/s] (usually <0, as ocean loses water!)
186 | """
187 | # Define the land mask from the native SST land mask
188 | ocean_index = np.where(~np.isnan(sst))
189 |
190 | # Shrink the input data (i.e. remove all land points)
191 | args_shrunk = tuple(
192 | np.atleast_3d(a[ocean_index])
193 | for a in (sst, t_zt, hum_zt, u_zu, v_zu, slp, rad_sw, rad_lw)
194 | )
195 |
196 | if input_range_check:
197 | _check_value_range(*args_shrunk)
198 |
199 | out_data = aeroskin.mod_aerobulk_wrapper_skin.aerobulk_model_skin(
200 | algo, zt, zu, *args_shrunk, niter
201 | )
202 |
203 | return tuple(unshrink_arr(o, sst.shape, ocean_index) for o in out_data)
204 |
205 |
206 | def noskin(
207 | sst,
208 | t_zt,
209 | hum_zt,
210 | u_zu,
211 | v_zu,
212 | slp=101000.0,
213 | algo="coare3p0",
214 | zt=2,
215 | zu=10,
216 | niter=6,
217 | input_range_check=True,
218 | ):
219 | """xarray wrapper for aerobulk without skin correction.
220 |
221 | Warnings
222 | --------
223 | !ATTENTION If input not provided in the units shown in [] below the code will crash.
224 | !ATTENTION Missing values taken from NaN values in sst field. No input variables may have NaN values that are not reflected in the sst.
225 |
226 | Parameters
227 | ----------
228 | sst : xarray.DataArray
229 | Bulk sea surface temperature [K]
230 | t_zt : xarray.DataArray
231 | Absolute air temperature at height zt [K]
232 | hum_zt : xarray.DataArray
233 | air humidity at zt, given as specific humidity [kg/kg]
234 | u_zu : xarray.DataArray
235 | zonal wind speed at zu [m/s]
236 | v_zu : xarray.DataArray
237 | meridional wind speed at zu [m/s]
238 | slp : xarray.DataArray, optional
239 | mean sea-level pressure [Pa] ~101000 Pa,
240 | by default 101000.0
241 | algo : str, optional
242 | Algorithm, can be one of: "coare3p0", "coare3p6", "ecmwf", "ncar", "andreas",
243 | by default "coare3p0"
244 | zt : int, optional
245 | height for temperature and spec. hum. of air [m],
246 | by default 2
247 | zu : int, optional
248 | height for wind (10m = traditional anemometric height [m],
249 | by default 10
250 | niter : int, optional
251 | Number of iteration steps used in the algorithm,
252 | by default 6
253 | input_range_check: bool, optional
254 | Turn on/off explicit checking of input variables for valid ranges.
255 | On by default, but for best performance should be turned off
256 |
257 | Returns
258 | -------
259 | ql : xarray.DataArray
260 | Latent heat flux [W/m^2]
261 | qh : xarray.DataArray
262 | Sensible heat flux [W/m^2]
263 | taux : xarray.DataArray
264 | zonal wind stress [N/m^2]
265 | tauy : xarray.DataArray
266 | meridional wind stress [N/m^2]
267 | evap : xarray.DataArray
268 | evaporation [mm/s] aka [kg/m^2/s] (usually <0, as ocean loses water!)
269 | """
270 | _check_algo(algo, VALID_ALGOS)
271 |
272 | sst, t_zt, hum_zt, u_zu, v_zu, slp = xr.broadcast(
273 | sst, t_zt, hum_zt, u_zu, v_zu, slp
274 | )
275 | if input_range_check:
276 | performance_msg = (
277 | "Checking for misaligned nans and values outside of the valid range is performed by default, but reduces performance. \n"
278 | "If you are sure your data is valid you can deactivate these checks by setting `input_range_check=False`"
279 | )
280 | warnings.warn(performance_msg)
281 |
282 | out_vars = xr.apply_ufunc(
283 | noskin_np,
284 | sst,
285 | t_zt,
286 | hum_zt,
287 | u_zu,
288 | v_zu,
289 | slp,
290 | input_core_dims=[()] * 6,
291 | output_core_dims=[()] * 5,
292 | dask="parallelized",
293 | kwargs=dict(
294 | algo=algo, zt=zt, zu=zu, niter=niter, input_range_check=input_range_check
295 | ),
296 | output_dtypes=[sst.dtype]
297 | * 5, # deactivates the 1 element check which aerobulk does not like
298 | )
299 |
300 | if not isinstance(out_vars, tuple) or len(out_vars) != 5:
301 | raise TypeError("F2Py returned unexpected types")
302 |
303 | return out_vars
304 |
305 |
306 | def skin(
307 | sst,
308 | t_zt,
309 | hum_zt,
310 | u_zu,
311 | v_zu,
312 | rad_sw,
313 | rad_lw,
314 | slp=101000.0,
315 | algo="coare3p0",
316 | zt=2,
317 | zu=10,
318 | niter=6,
319 | input_range_check=True,
320 | ):
321 | """xarray wrapper for aerobulk with skin correction.
322 |
323 | Warnings
324 | --------
325 | !ATTENTION If input not provided in the units shown in [] below the code will crash.
326 | !ATTENTION Missing values taken from NaN values in sst field. No input variables may have NaN values that are not reflected in the sst.
327 |
328 | Parameters
329 | ----------
330 | sst : xr.DataArray
331 | Bulk sea surface temperature [K]
332 | t_zt : xr.DataArray
333 | Absolute air temperature at height zt [K]
334 | hum_zt : xr.DataArray
335 | air humidity at zt, given as specific humidity [kg/kg]
336 | u_zu : xr.DataArray
337 | zonal wind speed at zu [m/s]
338 | v_zu : xr.DataArray
339 | meridional wind speed at zu [m/s]
340 | rad_sw : xr.DataArray
341 | downwelling shortwave radiation at the surface (>0) [W/m^2]
342 | rad_lw : xr.DataArray
343 | rad_lw : downwelling longwave radiation at the surface (>0) [W/m^2]
344 | slp : xr.DataArray, optional
345 | mean sea-level pressure [Pa] ~101000 Pa,
346 | by default 101000.0
347 | algo : str, optional
348 | Algorithm, can be one of: "coare3p0", "coare3p6", "ecmwf",
349 | by default "coare3p0"
350 | zt : int, optional
351 | height for temperature and spec. hum. of air [m],
352 | by default 2
353 | zu : int, optional
354 | height for wind (10m = traditional anemometric height [m],
355 | by default 10
356 | niter : int, optional
357 | Number of iteration steps used in the algorithm,
358 | by default 6
359 | input_range_check: bool, optional
360 | Turn on/off explicit checking of input variables for valid ranges.
361 | On by default, but for best performance should be turned off
362 |
363 | Returns
364 | -------
365 | ql : xr.DataArray
366 | Latent heat flux [W/m^2]
367 | qh : xr.DataArray
368 | Sensible heat flux [W/m^2]
369 | taux : xr.DataArray
370 | zonal wind stress [N/m^2]
371 | tauy : xr.DataArray
372 | meridional wind stress [N/m^2]
373 | t_s : xr.DataArray
374 | skin temperature [K] (only when l_use_skin_schemes=TRUE)
375 | evap : xr.DataArray
376 | evaporation [mm/s] aka [kg/m^2/s] (usually <0, as ocean loses water!)
377 | """
378 |
379 | _check_algo(algo, VALID_ALGOS_SKIN)
380 |
381 | sst, t_zt, hum_zt, u_zu, v_zu, rad_sw, rad_lw, slp = xr.broadcast(
382 | sst, t_zt, hum_zt, u_zu, v_zu, rad_sw, rad_lw, slp
383 | )
384 |
385 | if input_range_check:
386 | performance_msg = (
387 | "Checking for misaligned nans and values outside of the valid range is performed by default, but reduces performance. \n"
388 | "If you are sure your data is valid you can deactivate these checks by setting `input_range_check=False`"
389 | )
390 | warnings.warn(performance_msg)
391 |
392 | out_vars = xr.apply_ufunc(
393 | skin_np,
394 | sst,
395 | t_zt,
396 | hum_zt,
397 | u_zu,
398 | v_zu,
399 | rad_sw,
400 | rad_lw,
401 | slp,
402 | input_core_dims=[()] * 8,
403 | output_core_dims=[()] * 6,
404 | dask="parallelized",
405 | kwargs=dict(
406 | algo=algo, zt=zt, zu=zu, niter=niter, input_range_check=input_range_check
407 | ),
408 | output_dtypes=[sst.dtype]
409 | * 6, # deactivates the 1 element check which aerobulk does not like
410 | )
411 |
412 | if not isinstance(out_vars, tuple) or len(out_vars) != 6:
413 | raise TypeError("F2Py returned unexpected types")
414 |
415 | return out_vars
416 |
--------------------------------------------------------------------------------
/source/fortran/.f2py_f2cmap:
--------------------------------------------------------------------------------
1 | {"real": {"wp": "double", "dp": "double", "sp": "float"}}
2 |
--------------------------------------------------------------------------------
/source/fortran/mod_aerobulk_wrap_noskin.f90:
--------------------------------------------------------------------------------
1 | MODULE mod_aerobulk_wrapper_noskin
2 |
3 | USE mod_const
4 | USE mod_aerobulk, ONLY: AEROBULK_INIT, AEROBULK_BYE
5 | USE mod_aerobulk_compute
6 |
7 | IMPLICIT NONE
8 |
9 | PRIVATE
10 |
11 | PUBLIC :: AEROBULK_MODEL_NOSKIN
12 |
13 | CONTAINS
14 |
15 | SUBROUTINE AEROBULK_MODEL_NOSKIN( Ni, Nj, Nt, &
16 | & calgo, zt, zu, sst, t_zt, &
17 | & hum_zt, U_zu, V_zu, slp, &
18 | & Niter, &
19 | & QL, QH, Tau_x, Tau_y, Evap)
20 |
21 | INTEGER, INTENT(in) :: Ni, Nj, Nt
22 | CHARACTER(len=*), INTENT(in) :: calgo
23 | REAL(8), INTENT(in) :: zt, zu
24 | REAL(8), DIMENSION(Ni,Nj,Nt), INTENT(in) :: sst, t_zt, hum_zt, U_zu, V_zu, slp
25 | INTEGER, INTENT(in) :: Niter
26 | REAL(8), DIMENSION(Ni,Nj,Nt), INTENT(out) :: QL, QH, Tau_x, Tau_y, Evap
27 |
28 | nb_iter = Niter
29 | !! All the variables that are set in INIT
30 | ctype_humidity = 'sh'
31 | l_use_skin_schemes = .FALSE.
32 |
33 | CALL AEROBULK_COMPUTE(1, calgo, zt, zu, sst(:, :, 1), t_zt(:, :, 1), &
34 | & hum_zt(:, :, 1), U_zu(:, :, 1), V_zu(:, :, 1), slp(:, :, 1), &
35 | & QL(:, :, 1), QH(:, :, 1), Tau_x(:, :, 1), Tau_y(:, :, 1), &
36 | & Evp=Evap(:, :, 1))
37 |
38 | END SUBROUTINE AEROBULK_MODEL_NOSKIN
39 |
40 | END MODULE mod_aerobulk_wrapper_noskin
41 |
--------------------------------------------------------------------------------
/source/fortran/mod_aerobulk_wrap_noskin.pyf:
--------------------------------------------------------------------------------
1 | ! -*- f90 -*-
2 | ! Note: the context of this file is case sensitive.
3 |
4 | python module mod_aerobulk_wrap_noskin ! in
5 | interface ! in :mod_aerobulk_wrap_noskin
6 | module mod_aerobulk_wrapper_noskin ! in :mod_aerobulk_wrap_noskin:mod_aerobulk_wrap_noskin.f90
7 | use mod_const
8 | use mod_aerobulk, only: aerobulk_init,aerobulk_bye
9 | use mod_aerobulk_compute
10 | subroutine aerobulk_model_noskin(ni,nj,nt,calgo,zt,zu,sst,t_zt,hum_zt,u_zu,v_zu,slp,niter,ql,qh,tau_x,tau_y,evap) ! in :mod_aerobulk_wrap_noskin:mod_aerobulk_wrap_noskin.f90:mod_aerobulk_wrapper_noskin
11 | threadsafe
12 | integer, optional,intent(in),check(shape(sst, 0) == ni),depend(sst) :: ni=shape(sst, 0)
13 | integer, optional,intent(in),check(shape(sst, 1) == nj),depend(sst) :: nj=shape(sst, 1)
14 | integer, optional,intent(in),check(shape(sst, 2) == nt),depend(sst) :: nt=shape(sst, 2)
15 | character*(*) intent(in) :: calgo
16 | real(kind=8) intent(in) :: zt
17 | real(kind=8) intent(in) :: zu
18 | real(kind=8) dimension(ni,nj,nt),intent(in) :: sst
19 | real(kind=8) dimension(ni,nj,nt),intent(in),depend(nj,ni,nt) :: t_zt
20 | real(kind=8) dimension(ni,nj,nt),intent(in),depend(nj,ni,nt) :: hum_zt
21 | real(kind=8) dimension(ni,nj,nt),intent(in),depend(nj,ni,nt) :: u_zu
22 | real(kind=8) dimension(ni,nj,nt),intent(in),depend(nj,ni,nt) :: v_zu
23 | real(kind=8) dimension(ni,nj,nt),intent(in),depend(nj,ni,nt) :: slp
24 | integer intent(in) :: niter
25 | real(kind=8) dimension(ni,nj,nt),intent(out),depend(nj,ni,nt) :: ql
26 | real(kind=8) dimension(ni,nj,nt),intent(out),depend(nj,ni,nt) :: qh
27 | real(kind=8) dimension(ni,nj,nt),intent(out),depend(nj,ni,nt) :: tau_x
28 | real(kind=8) dimension(ni,nj,nt),intent(out),depend(nj,ni,nt) :: tau_y
29 | real(kind=8) dimension(ni,nj,nt),intent(out),depend(nj,ni,nt) :: evap
30 | end subroutine aerobulk_model_noskin
31 | end module mod_aerobulk_wrapper_noskin
32 | end interface
33 | end python module mod_aerobulk_wrap_noskin
34 |
35 | ! This file was auto-generated with f2py (version:1.22.3).
36 | ! See:
37 | ! https://web.archive.org/web/20140822061353/http://cens.ioc.ee/projects/f2py2e
38 |
--------------------------------------------------------------------------------
/source/fortran/mod_aerobulk_wrap_skin.f90:
--------------------------------------------------------------------------------
1 | MODULE mod_aerobulk_wrapper_skin
2 |
3 | USE mod_const
4 | USE mod_aerobulk, ONLY: AEROBULK_INIT, AEROBULK_BYE
5 | USE mod_aerobulk_compute
6 |
7 | IMPLICIT NONE
8 |
9 | PRIVATE
10 |
11 | PUBLIC :: AEROBULK_MODEL_SKIN
12 |
13 | CONTAINS
14 | SUBROUTINE AEROBULK_MODEL_SKIN( Ni, Nj, Nt, &
15 | & calgo, zt, zu, sst, t_zt, &
16 | & hum_zt, U_zu, V_zu, slp, &
17 | & rad_sw, rad_lw, &
18 | & Niter, &
19 | & QL, QH, Tau_x, Tau_y, T_s, Evap)
20 |
21 | INTEGER, INTENT(in) :: Ni, Nj, Nt
22 | CHARACTER(len=*), INTENT(in) :: calgo
23 | REAL(8), INTENT(in) :: zt, zu
24 | REAL(8), DIMENSION(Ni,Nj,Nt), INTENT(in) :: sst, t_zt, hum_zt, U_zu, V_zu, slp, rad_sw, rad_lw
25 | INTEGER, INTENT(in) :: Niter
26 | REAL(8), DIMENSION(Ni,Nj,Nt), INTENT(out) :: QL, QH, Tau_x, Tau_y, T_s, Evap
27 |
28 | nb_iter = Niter
29 | !! All the variables that are set in INIT
30 | ctype_humidity = 'sh'
31 | l_use_skin_schemes = .TRUE.
32 |
33 | CALL AEROBULK_COMPUTE(1, calgo, zt, zu, sst(:, :, 1), t_zt(:, :, 1), &
34 | & hum_zt(:, :, 1), U_zu(:, :, 1), V_zu(:, :, 1), slp(:, :, 1), &
35 | & QL(:, :, 1), QH(:, :, 1), Tau_x(:, :, 1), Tau_y(:, :, 1), &
36 | & rad_sw=rad_sw(:, :, 1), rad_lw=rad_lw(:, :, 1), T_s=T_s(:, :, 1), Evp=Evap(:, :, 1))
37 |
38 | END SUBROUTINE AEROBULK_MODEL_SKIN
39 |
40 | END MODULE mod_aerobulk_wrapper_skin
41 |
--------------------------------------------------------------------------------
/source/fortran/mod_aerobulk_wrap_skin.pyf:
--------------------------------------------------------------------------------
1 | ! -*- f90 -*-
2 | ! Note: the context of this file is case sensitive.
3 |
4 | python module mod_aerobulk_wrap_skin ! in
5 | interface ! in :mod_aerobulk_wrap_skin
6 | module mod_aerobulk_wrapper_skin ! in :mod_aerobulk_wrap_skin:mod_aerobulk_wrap_skin.f90
7 | use mod_const
8 | use mod_aerobulk, only: aerobulk_init,aerobulk_bye
9 | use mod_aerobulk_compute
10 | subroutine aerobulk_model_skin(ni,nj,nt,calgo,zt,zu,sst,t_zt,hum_zt,u_zu,v_zu,slp,rad_sw,rad_lw,niter,ql,qh,tau_x,tau_y,t_s,evap) ! in :mod_aerobulk_wrap_skin:mod_aerobulk_wrap_skin.f90:mod_aerobulk_wrapper_skin
11 |
12 | integer, optional,intent(in),check(shape(sst, 0) == ni),depend(sst) :: ni=shape(sst, 0)
13 | integer, optional,intent(in),check(shape(sst, 1) == nj),depend(sst) :: nj=shape(sst, 1)
14 | integer, optional,intent(in),check(shape(sst, 2) == nt),depend(sst) :: nt=shape(sst, 2)
15 | character*(*) intent(in) :: calgo
16 | real(kind=8) intent(in) :: zt
17 | real(kind=8) intent(in) :: zu
18 | real(kind=8) dimension(ni,nj,nt),intent(in) :: sst
19 | real(kind=8) dimension(ni,nj,nt),intent(in),depend(nj,ni,nt) :: t_zt
20 | real(kind=8) dimension(ni,nj,nt),intent(in),depend(nj,ni,nt) :: hum_zt
21 | real(kind=8) dimension(ni,nj,nt),intent(in),depend(nj,ni,nt) :: u_zu
22 | real(kind=8) dimension(ni,nj,nt),intent(in),depend(nj,ni,nt) :: v_zu
23 | real(kind=8) dimension(ni,nj,nt),intent(in),depend(nj,ni,nt) :: slp
24 | real(kind=8) dimension(ni,nj,nt),intent(in),depend(nj,ni,nt) :: rad_sw
25 | real(kind=8) dimension(ni,nj,nt),intent(in),depend(nj,ni,nt) :: rad_lw
26 | integer intent(in) :: niter
27 | real(kind=8) dimension(ni,nj,nt),intent(out),depend(nj,ni,nt) :: ql
28 | real(kind=8) dimension(ni,nj,nt),intent(out),depend(nj,ni,nt) :: qh
29 | real(kind=8) dimension(ni,nj,nt),intent(out),depend(nj,ni,nt) :: tau_x
30 | real(kind=8) dimension(ni,nj,nt),intent(out),depend(nj,ni,nt) :: tau_y
31 | real(kind=8) dimension(ni,nj,nt),intent(out),depend(nj,ni,nt) :: t_s
32 | real(kind=8) dimension(ni,nj,nt),intent(out),depend(nj,ni,nt) :: evap
33 | end subroutine aerobulk_model_skin
34 | end module mod_aerobulk_wrapper_skin
35 | end interface
36 | end python module mod_aerobulk_wrap_skin
37 |
38 | ! This file was auto-generated with f2py (version:1.22.3).
39 | ! See:
40 | ! https://web.archive.org/web/20140822061353/http://cens.ioc.ee/projects/f2py2e
41 |
--------------------------------------------------------------------------------
/tests/create_test_data.py:
--------------------------------------------------------------------------------
1 | from typing import Dict, Tuple
2 |
3 | import numpy as np
4 | import xarray as xr
5 | from numpy.random import default_rng
6 |
7 |
8 | def create_data(
9 | shape: Tuple[int, ...],
10 | chunks: Dict[str, int] = {},
11 | skin_correction: bool = False,
12 | order: str = "F",
13 | use_xr=True,
14 | land_mask=False,
15 | sst=290.0,
16 | t_zt=280.0,
17 | hum_zt=0.001,
18 | u_zu=1.0,
19 | v_zu=-1.0,
20 | slp=101000.0,
21 | rad_sw=0.000001,
22 | rad_lw=350.0,
23 | ):
24 | size = shape[0] * shape[1]
25 | shape2d = (shape[0], shape[1])
26 | rng = default_rng()
27 | indices = rng.choice(size, size=int(size * 0.3), replace=False)
28 | multi_indices = np.unravel_index(indices, shape2d)
29 |
30 | def _arr(value, chunks, order):
31 | arr = np.full(shape, value, order=order)
32 | # adds random noise scaled by a percentage of the value
33 | randomize_factor = 0.001
34 | randomize_range = value * randomize_factor
35 | noise = np.random.rand(*shape) * randomize_range
36 | arr = arr + noise
37 |
38 | if land_mask:
39 | arr[multi_indices[0], multi_indices[1], :] = (
40 | np.nan
41 | ) # add NaNs to mimic land mask
42 | if use_xr:
43 | arr = xr.DataArray(arr)
44 | if chunks:
45 | arr = arr.chunk(chunks)
46 | return arr
47 |
48 | if skin_correction:
49 | return tuple(
50 | _arr(a, chunks, order)
51 | for a in (
52 | sst,
53 | t_zt,
54 | hum_zt,
55 | u_zu,
56 | v_zu,
57 | slp,
58 | rad_sw,
59 | rad_lw,
60 | )
61 | )
62 | else:
63 | return tuple(
64 | _arr(a, chunks, order) for a in (sst, t_zt, hum_zt, u_zu, v_zu, slp)
65 | )
66 |
--------------------------------------------------------------------------------
/tests/test_flux_np.py:
--------------------------------------------------------------------------------
1 | import numpy as np
2 | import pytest
3 | from aerobulk.flux import noskin_np, skin_np
4 | from create_test_data import create_data
5 |
6 | """Tests for the numpy land_mask wrapper"""
7 |
8 |
9 | @pytest.mark.parametrize(
10 | "algo, skin_correction",
11 | [
12 | ("ecmwf", True),
13 | ("ecmwf", False),
14 | ("coare3p0", True),
15 | ("coare3p0", False),
16 | ("coare3p6", True),
17 | ("coare3p6", False),
18 | ("andreas", False),
19 | ("ncar", False),
20 | ],
21 | )
22 | def test_land_mask(skin_correction, algo):
23 | shape = (2, 3, 4)
24 | size = shape[0] * shape[1] * shape[2]
25 |
26 | if skin_correction:
27 | func = skin_np
28 | else:
29 | func = noskin_np
30 |
31 | args = create_data(
32 | shape,
33 | chunks=False,
34 | skin_correction=skin_correction,
35 | use_xr=False,
36 | land_mask=True,
37 | )
38 | out_data = func(*args, algo, 2, 10, 6, input_range_check=True)
39 |
40 | # Check the location of all NaNs is correct
41 | for o in out_data:
42 | np.testing.assert_allclose(np.isnan(args[0]), np.isnan(o))
43 |
44 | # Check that values of the unshrunk array are correct
45 | for i in range(size):
46 | index = np.unravel_index(i, shape)
47 | if not np.isnan(out_data[0][index]):
48 | single_inputs = tuple(np.atleast_3d(i[index]) for i in args)
49 |
50 | single_outputs = func(
51 | *single_inputs, algo, 2, 10, 6, input_range_check=True
52 | )
53 | for so, o in zip(single_outputs, out_data):
54 | assert so == o[index]
55 |
56 |
57 | @pytest.mark.parametrize(
58 | "varname",
59 | [
60 | "t_zt",
61 | "hum_zt",
62 | "u_zu",
63 | "v_zu",
64 | "slp",
65 | "rad_sw",
66 | "rad_lw",
67 | ],
68 | )
69 | class Test_Range_Check:
70 | def test_range_check_nan(self, varname):
71 | shape = (1, 1)
72 | args_noskin = create_data(shape, skin_correction=False, **{varname: np.nan})
73 | args_skin = create_data(shape, skin_correction=True, **{varname: np.nan})
74 | msg = f"Found nans in {varname} that do not align with nans in `sst`. Check that nans in all fields are matched."
75 |
76 | if varname not in ["rad_sw", "rad_lw"]: # Test these only for skin
77 | with pytest.raises(ValueError, match=msg):
78 | noskin_np(*args_noskin, "ecmwf", 2, 10, 6, input_range_check=True)
79 |
80 | with pytest.raises(ValueError, match=msg):
81 | skin_np(*args_skin, "ecmwf", 2, 10, 6, input_range_check=True)
82 |
83 | def test_range_check_invalid(self, varname):
84 | invalid_values = {
85 | "sst": 200.0,
86 | "t_zt": 100,
87 | "hum_zt": 0.1,
88 | "u_zu": 60,
89 | "v_zu": 60,
90 | "slp": 2000,
91 | "rad_sw": -20,
92 | "rad_lw": 4000,
93 | }
94 | shape = (1, 1)
95 | args_noskin = create_data(
96 | shape, skin_correction=False, **{varname: invalid_values[varname]}
97 | )
98 | args_skin = create_data(
99 | shape, skin_correction=True, **{varname: invalid_values[varname]}
100 | )
101 | # I hate regex sooo much. If someone has a nice way to just test that the varname is in here and the error message contains 'range'
102 | # that would be amazing. This is the best I could do...
103 | msg = r"\b(?:out of the valid range)\b"
104 | if varname not in ["rad_sw", "rad_lw"]:
105 | with pytest.raises(ValueError, match=str(msg)):
106 | noskin_np(*args_noskin, "ecmwf", 2, 10, 6, input_range_check=True)
107 |
108 | with pytest.raises(ValueError, match=str(msg)):
109 | skin_np(*args_skin, "ecmwf", 2, 10, 6, input_range_check=True)
110 |
--------------------------------------------------------------------------------
/tests/test_flux_xr.py:
--------------------------------------------------------------------------------
1 | import pytest
2 | import xarray as xr
3 | from aerobulk import noskin, skin
4 | from create_test_data import create_data
5 |
6 | """Tests for the xarray wrapper"""
7 |
8 |
9 | @pytest.mark.parametrize("algo", ["wrong"])
10 | def test_algo_error_noskin(algo):
11 | shape = (1, 1, 1)
12 | args = create_data(shape, chunks=False, skin_correction=False)
13 | with pytest.raises(ValueError):
14 | noskin(*args, algo=algo)
15 |
16 |
17 | @pytest.mark.parametrize("algo", ["wrong", "ncar"])
18 | def test_algo_error_skin(algo):
19 | shape = (1, 1, 1)
20 | args = create_data(shape, chunks=False, skin_correction=True)
21 | with pytest.raises(ValueError):
22 | skin(*args, algo=algo)
23 |
24 |
25 | @pytest.mark.parametrize(
26 | "chunks", [{"dim_2": -1}, {"dim_0": 10}, {"dim_0": 1}, {"dim_2": 8}, {"dim_2": 1}]
27 | )
28 | @pytest.mark.parametrize("skin_correction", [False, True])
29 | class Test_xarray:
30 | def test_chunked(self, chunks, skin_correction):
31 | shape = (10, 13, 12)
32 | args = create_data(shape, chunks=chunks, skin_correction=skin_correction)
33 | if skin_correction:
34 | func = skin
35 | else:
36 | func = noskin
37 | out_vars_chunked = func(*args)
38 | out_vars_nochunks = func(*(a.load() for a in args))
39 |
40 | for out_chunk, out_nochunk in zip(out_vars_chunked, out_vars_nochunks):
41 | assert out_chunk.shape == shape
42 | xr.testing.assert_allclose(out_chunk, out_nochunk)
43 |
44 | @pytest.mark.parametrize("order", ["F", "C"])
45 | def test_transpose_invariance_noskin(self, chunks, skin_correction, order):
46 | shape = (10, 13, 12)
47 | chunks = {"dim_0": 10}
48 | args = create_data(
49 | shape, chunks=chunks, skin_correction=skin_correction, order=order
50 | )
51 | if skin_correction:
52 | func = skin
53 | else:
54 | func = noskin
55 |
56 | out_vars_012 = func(*(a.transpose("dim_0", "dim_1", "dim_2") for a in args))
57 | out_vars_210 = func(*(a.transpose("dim_2", "dim_1", "dim_0") for a in args))
58 | out_vars_120 = func(*(a.transpose("dim_1", "dim_2", "dim_0") for a in args))
59 |
60 | for i, ii, iii in zip(out_vars_012, out_vars_120, out_vars_210):
61 | xr.testing.assert_allclose(
62 | i.transpose("dim_0", "dim_1", "dim_2"),
63 | ii.transpose("dim_0", "dim_1", "dim_2"),
64 | )
65 | xr.testing.assert_allclose(
66 | ii.transpose("dim_0", "dim_1", "dim_2"),
67 | iii.transpose("dim_0", "dim_1", "dim_2"),
68 | )
69 |
70 |
71 | @pytest.mark.parametrize("skin_correction", [True, False])
72 | def test_all_input_array_sizes_valid(skin_correction):
73 | shapes = (
74 | (3, 4),
75 | (2, 3, 4),
76 | (2, 3, 4, 5),
77 | ) # create_data() only allows for inputs of 2 or more dimensions
78 | data = (create_data(s, skin_correction=skin_correction) for s in shapes)
79 | if skin_correction:
80 | func = skin
81 | else:
82 | func = noskin
83 | tuple(func(*d, "coare3p0", 2, 10, 6) for d in data)
84 | assert (
85 | 1 == 1
86 | ) # This line is always true, but verifies that the above line doesn't crash the Fortran code
87 |
--------------------------------------------------------------------------------
/tests/test_fortran.py:
--------------------------------------------------------------------------------
1 | import numpy as np
2 | import pytest
3 | from aerobulk.flux import noskin_np, skin_np
4 |
5 |
6 | @pytest.mark.parametrize(
7 | "algo, expected",
8 | [
9 | (
10 | "andreas",
11 | {
12 | "ql": -74.4637756,
13 | "qh": -14.4129944,
14 | "evap": -2.62721038,
15 | "taux": 3.02770734e-02,
16 | "tauy": 0.0,
17 | },
18 | ),
19 | (
20 | "ncar",
21 | {
22 | "ql": -88.4781876,
23 | "qh": -16.6969528,
24 | "evap": -3.12166286,
25 | "taux": 3.58519591e-02,
26 | "tauy": 0.0,
27 | },
28 | ),
29 | ],
30 | )
31 | def test_fortran_noskin(algo, expected):
32 | # Compare python wrapper output with fortran results from (...)
33 |
34 | # inputs are the same for all test cases in the fortran example
35 | rt0 = np.atleast_3d(273.15) # conversion to Kelvin
36 | sst = np.atleast_3d(rt0 + 22) # in Kelvin
37 | t_zt = np.atleast_3d(rt0 + 20)
38 | hum_zt = np.atleast_3d(0.012) # kg/kg
39 | u_zu = np.atleast_3d(5) # m/s
40 | v_zu = np.atleast_3d(0)
41 | slp = np.atleast_3d(101000.0) # Pa
42 | ql, qh, taux, tauy, evap = noskin_np(
43 | sst,
44 | t_zt,
45 | hum_zt,
46 | u_zu,
47 | v_zu,
48 | slp,
49 | algo=algo,
50 | zt=2,
51 | zu=10,
52 | niter=10,
53 | input_range_check=True,
54 | )
55 | evap = evap * 3600 * 24 # convert to mm/day
56 |
57 | np.testing.assert_allclose(ql, expected["ql"])
58 | np.testing.assert_allclose(qh, expected["qh"])
59 | np.testing.assert_allclose(evap, expected["evap"])
60 | np.testing.assert_allclose(taux, expected["taux"])
61 | np.testing.assert_allclose(tauy, expected["tauy"])
62 |
63 |
64 | @pytest.mark.parametrize(
65 | "algo, expected",
66 | [
67 | (
68 | "coare3p0",
69 | {
70 | "ql": -81.3846741,
71 | "qh": -15.1545086,
72 | "evap": -2.87061906,
73 | "taux": 3.57834995e-02,
74 | "tauy": 0.0,
75 | "t_s": 21.7219677,
76 | },
77 | ),
78 | (
79 | "coare3p6",
80 | {
81 | "ql": -83.0788422,
82 | "qh": -15.3865499,
83 | "evap": -2.93033028,
84 | "taux": 3.21817845e-02,
85 | "tauy": 0.0,
86 | "t_s": 21.7057972,
87 | },
88 | ),
89 | (
90 | "ecmwf",
91 | {
92 | "ql": -80.2958984,
93 | "qh": -14.3822346,
94 | "evap": -2.83224440,
95 | "taux": 3.84389125e-02,
96 | "tauy": 0.0,
97 | "t_s": 21.7325401,
98 | },
99 | ),
100 | ],
101 | )
102 | def test_fortran_skin(algo, expected):
103 | # Compare python wrapper output with fortran results from (...)
104 |
105 | # inputs are the same for all test cases in the fortran example
106 | rt0 = np.atleast_3d(273.15) # conversion to Kelvin
107 | sst = np.atleast_3d(rt0 + 22) # in Kelvin
108 | t_zt = np.atleast_3d(rt0 + 20)
109 | hum_zt = np.atleast_3d(0.012) # kg/kg
110 | u_zu = np.atleast_3d(5) # m/s
111 | v_zu = np.atleast_3d(0)
112 | slp = np.atleast_3d(101000.0) # Pa
113 | rad_sw = np.atleast_3d(0)
114 | rad_lw = np.atleast_3d(350)
115 | ql, qh, taux, tauy, t_s, evap = skin_np(
116 | sst,
117 | t_zt,
118 | hum_zt,
119 | u_zu,
120 | v_zu,
121 | slp,
122 | rad_sw,
123 | rad_lw,
124 | algo=algo,
125 | zt=2,
126 | zu=10,
127 | niter=10,
128 | input_range_check=True,
129 | )
130 | evap = evap * 3600 * 24 # convert to mm/day
131 | t_s = t_s - rt0
132 |
133 | np.testing.assert_allclose(ql, expected["ql"])
134 | np.testing.assert_allclose(qh, expected["qh"])
135 | np.testing.assert_allclose(evap, expected["evap"])
136 | np.testing.assert_allclose(taux, expected["taux"])
137 | np.testing.assert_allclose(tauy, expected["tauy"])
138 | np.testing.assert_allclose(t_s, expected["t_s"])
139 |
--------------------------------------------------------------------------------