Skip to content

Commit e84a1e6

Browse files
committed
black and isort cleanups
1 parent 77e278b commit e84a1e6

19 files changed

+369
-287
lines changed

PyPartMC/__init__.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# pylint: disable=invalid-name,wrong-import-position
22
import os
3+
from collections import namedtuple
34
from contextlib import contextmanager
45
from pathlib import Path
5-
from collections import namedtuple
6+
67

78
# https://github.com/diegoferigo/cmake-build-extension/blob/master/src/cmake_build_extension/__init__.py
89
@contextmanager
@@ -11,8 +12,8 @@ def __build_extension_env():
1112
# https://docs.python.org/3/whatsnew/3.8.html#bpo-36085-whatsnew
1213
if hasattr(os, "add_dll_directory"):
1314
basepath = os.path.dirname(os.path.abspath(__file__))
14-
dllspath = os.path.join(basepath, '..')
15-
os.environ['PATH'] = dllspath + os.pathsep + os.environ['PATH']
15+
dllspath = os.path.join(basepath, "..")
16+
os.environ["PATH"] = dllspath + os.pathsep + os.environ["PATH"]
1617
for path in os.environ.get("PATH", "").split(os.pathsep):
1718
if path and Path(path).is_absolute() and Path(path).is_dir():
1819
cookies.append(os.add_dll_directory(path))
@@ -22,25 +23,24 @@ def __build_extension_env():
2223
for cookie in cookies:
2324
cookie.close()
2425

26+
2527
# TODO #113: 2 x loop over prefixes and units
26-
si = namedtuple("SI", (
27-
"m", "cm", "um", "nm",
28-
"kg", "g",
29-
"s",
30-
"K",
31-
"Pa", "hPa",
32-
"mol"
33-
))(
34-
m=1., cm=.01, um=1e-6, nm=1e-9,
35-
kg=1., g=1e-3,
36-
s=1.,
37-
K=1.,
38-
Pa=1., hPa=100.,
39-
mol=1.
28+
si = namedtuple("SI", ("m", "cm", "um", "nm", "kg", "g", "s", "K", "Pa", "hPa", "mol"))(
29+
m=1.0,
30+
cm=0.01,
31+
um=1e-6,
32+
nm=1e-9,
33+
kg=1.0,
34+
g=1e-3,
35+
s=1.0,
36+
K=1.0,
37+
Pa=1.0,
38+
hPa=100.0,
39+
mol=1.0,
4040
)
4141
""" TODO #113 """
4242

4343
with __build_extension_env():
44+
import _PyPartMC
4445
from _PyPartMC import *
4546
from _PyPartMC import __all__, __version__
46-
import _PyPartMC

setup.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
import subprocess
1010
import sys
1111
from pathlib import Path
12-
from setuptools import Extension, setup, find_packages
12+
13+
from setuptools import Extension, find_packages, setup
1314
from setuptools.command.build_ext import build_ext
1415

1516
# Convert distutils Windows platform specifiers to CMake -A arguments
@@ -140,11 +141,11 @@ def build_extension(self, ext): # pylint: disable=too-many-branches
140141
zip_safe=False,
141142
python_requires=">=3.7",
142143
setup_requires=["setuptools_scm"],
143-
install_requires=['numpy'],
144+
install_requires=["numpy"],
144145
license="GPL-3.0",
145146
project_urls={
146147
"Tracker": "https://github.com/open-atmos/PyPartMC/issues",
147148
"Documentation": "https://open-atmos.github.io/PyPartMC",
148149
"Source": "https://github.com/open-atmos/PyPartMC/",
149-
}
150+
},
150151
)

src/pypartmc.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,18 @@ PYBIND11_MODULE(_PyPartMC, m) {
4848
py::class_<AeroData>(m, "AeroData",
4949
R"pbdoc(
5050
Aerosol material properties and associated data.
51-
51+
5252
The data in this structure is constant, as it represents physical
5353
quantities that cannot change over time.
54-
54+
5555
Each aerosol species is identified by an index <tt>i =
5656
1,...,aero_data_n_spec(aero_data)</tt>. Then \c name(i) is the name of
5757
that species, \c density(i) is its density, etc. The ordering of the
5858
species is arbitrary and should not be relied upon (currently it is the
5959
order in the species data file). The only exception is that it is
6060
possible to find out which species is water from the \c i_water
6161
variable.
62-
62+
6363
The names of the aerosol species are not important to PartMC, as
6464
only the material properties are used. The names are used for
6565
input and output, and also for communication with MOSAIC. For the
@@ -86,7 +86,7 @@ PYBIND11_MODULE(_PyPartMC, m) {
8686
py::class_<AeroParticle>(m, "AeroParticle",
8787
R"pbdoc(
8888
Single aerosol particle data structure.
89-
89+
9090
The \c vol array stores the total volumes of the different
9191
species that make up the particle. This array must have length
9292
equal to aero_data%%n_spec, so that \c vol(i) is the volume (in
@@ -122,12 +122,12 @@ PYBIND11_MODULE(_PyPartMC, m) {
122122
py::class_<AeroState>(m, "AeroState",
123123
R"pbdoc(
124124
The current collection of aerosol particles.
125-
125+
126126
The particles in \c aero_state_t are stored in a single flat
127127
array (the \c apa data member), with a sorting into size bins and
128128
weight groups/classes possibly stored in the \c aero_sorted data
129129
member (if \c valid_sort is true).
130-
130+
131131
Every time we remove particles we keep track of the particle ID
132132
and the action performed in the aero_info_array_t structure. This
133133
is typically cleared each time we output data to disk.
@@ -160,7 +160,7 @@ PYBIND11_MODULE(_PyPartMC, m) {
160160
py::class_<GasData>(m, "GasData",
161161
R"pbdoc(
162162
Constant gas data.
163-
163+
164164
Each gas species is identified by an integer \c i between 1 and
165165
\c gas_data_n_spec(gas_data). Species \c i has name \c gas_data%%name(i).
166166
The variable gas data describing the current mixing ratios is stored
@@ -178,7 +178,7 @@ PYBIND11_MODULE(_PyPartMC, m) {
178178
"EnvState",
179179
R"pbdoc(
180180
Current environment state.
181-
181+
182182
All quantities are instantaneous, describing the state at a
183183
particular instant of time. Constant data and other data not
184184
associated with the current environment state is stored in
@@ -218,7 +218,7 @@ PYBIND11_MODULE(_PyPartMC, m) {
218218
"Scenario",
219219
R"pbdoc(
220220
This is everything needed to drive the scenario being simulated.
221-
221+
222222
The temperature, pressure, emissions and background states are profiles
223223
prescribed as functions of time by giving a number of times and
224224
the corresponding data. Simple data such as temperature and pressure is
@@ -244,11 +244,11 @@ PYBIND11_MODULE(_PyPartMC, m) {
244244
"GasState",
245245
R"pbdoc(
246246
Current state of the gas mixing ratios in the system.
247-
247+
248248
The gas species are defined by the gas_data_t structure, so that
249249
\c gas_state%%mix_rat(i) is the current mixing ratio of the gas
250250
with name \c gas_data%%name(i), etc.
251-
251+
252252
By convention, if gas_state_is_allocated() return \c .false.,
253253
then the gas_state is treated as zero for all operations on
254254
it. This will be the case for new \c gas_state_t structures.
@@ -265,7 +265,7 @@ PYBIND11_MODULE(_PyPartMC, m) {
265265
"returns a string with JSON representation of the object")
266266
;
267267

268-
py::class_<RunPartOpt>(m,
268+
py::class_<RunPartOpt>(m,
269269
"RunPartOpt",
270270
"Options controlling the execution of run_part()."
271271
)

tests/test_aero_data.py

Lines changed: 81 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import numpy as np
88
import pytest
9+
910
import PyPartMC as ppmc
1011
from PyPartMC import si
1112

@@ -105,26 +106,36 @@ def test_rad2vol_sphere():
105106
value = sut.rad2vol(radius)
106107

107108
# assert
108-
np.testing.assert_almost_equal(value,(4/3)*np.pi*(radius)**3)
109+
np.testing.assert_almost_equal(value, (4 / 3) * np.pi * (radius) ** 3)
109110

110111
@staticmethod
111-
@pytest.mark.parametrize("aero_data_params", (
112-
{"frac_dim": 2.4, "vol_fill_factor": 1.2, 'prime_radius': 1e-7},
113-
{"frac_dim": 2.5, "vol_fill_factor": 1.1, "prime_radius": 1e-8},
114-
{"frac_dim": 2.2, "vol_fill_factor": 1.3, 'prime_radius': 1e-6}))
115-
def test_rad2vol_fractal(aero_data_params:dict):
112+
@pytest.mark.parametrize(
113+
"aero_data_params",
114+
(
115+
{"frac_dim": 2.4, "vol_fill_factor": 1.2, "prime_radius": 1e-7},
116+
{"frac_dim": 2.5, "vol_fill_factor": 1.1, "prime_radius": 1e-8},
117+
{"frac_dim": 2.2, "vol_fill_factor": 1.3, "prime_radius": 1e-6},
118+
),
119+
)
120+
def test_rad2vol_fractal(aero_data_params: dict):
116121
# arrange
117122
sut = ppmc.AeroData(AERO_DATA_CTOR_ARG_MINIMAL)
118123
radius = 1e-6
119-
for key,value in aero_data_params.items():
124+
for key, value in aero_data_params.items():
120125
setattr(sut, key, value)
121126

122127
# act
123128
value = sut.rad2vol(radius)
124129

125130
# assert
126-
np.testing.assert_almost_equal(value, (4/3)*np.pi*(sut.prime_radius)**3 *
127-
(radius/sut.prime_radius)**sut.frac_dim / sut.vol_fill_factor)
131+
np.testing.assert_almost_equal(
132+
value,
133+
(4 / 3)
134+
* np.pi
135+
* (sut.prime_radius) ** 3
136+
* (radius / sut.prime_radius) ** sut.frac_dim
137+
/ sut.vol_fill_factor,
138+
)
128139

129140
@staticmethod
130141
def test_vol2rad_sphere():
@@ -133,30 +144,40 @@ def test_vol2rad_sphere():
133144
vol = 4.19e-18
134145

135146
# act
136-
value = sut.vol2rad(vol)
147+
value = sut.vol2rad(vol)
137148

138149
# assert
139150
np.testing.assert_almost_equal(value, 1e-6)
140151

141152
@staticmethod
142-
@pytest.mark.parametrize("aero_data_params", (
143-
{"frac_dim": 2.4, "vol_fill_factor": 1.2, 'prime_radius': 1e-7},
144-
{"frac_dim": 2.5, "vol_fill_factor": 1.1, "prime_radius": 1e-8},
145-
{"frac_dim": 2.2, "vol_fill_factor": 1.3, 'prime_radius': 1e-6}))
146-
def test_vol2rad_fractal(aero_data_params:dict):
153+
@pytest.mark.parametrize(
154+
"aero_data_params",
155+
(
156+
{"frac_dim": 2.4, "vol_fill_factor": 1.2, "prime_radius": 1e-7},
157+
{"frac_dim": 2.5, "vol_fill_factor": 1.1, "prime_radius": 1e-8},
158+
{"frac_dim": 2.2, "vol_fill_factor": 1.3, "prime_radius": 1e-6},
159+
),
160+
)
161+
def test_vol2rad_fractal(aero_data_params: dict):
147162
# arrange
148163
sut = ppmc.AeroData(AERO_DATA_CTOR_ARG_MINIMAL)
149164
vol = 4.19e-18
150-
for key,value in aero_data_params.items():
165+
for key, value in aero_data_params.items():
151166
setattr(sut, key, value)
152167

153168
# act
154169
value = sut.vol2rad(vol)
155170

156171
# assert
157-
np.testing.assert_almost_equal(value, sut.prime_radius *
158-
(((3*vol/4/np.pi)**(1/3)/sut.prime_radius)**3 * sut.vol_fill_factor)**
159-
(1/sut.frac_dim))
172+
np.testing.assert_almost_equal(
173+
value,
174+
sut.prime_radius
175+
* (
176+
((3 * vol / 4 / np.pi) ** (1 / 3) / sut.prime_radius) ** 3
177+
* sut.vol_fill_factor
178+
)
179+
** (1 / sut.frac_dim),
180+
)
160181

161182
@staticmethod
162183
def test_diam2vol_sphere():
@@ -168,26 +189,36 @@ def test_diam2vol_sphere():
168189
vol = sut.diam2vol(diam)
169190

170191
# assert
171-
np.testing.assert_almost_equal(vol, (np.pi/6)*diam**3)
192+
np.testing.assert_almost_equal(vol, (np.pi / 6) * diam**3)
172193

173194
@staticmethod
174-
@pytest.mark.parametrize("aero_data_params", (
175-
{"frac_dim": 2.4, "vol_fill_factor": 1.2, 'prime_radius': 1e-7},
176-
{"frac_dim": 2.5, "vol_fill_factor": 1.1, "prime_radius": 1e-8},
177-
{"frac_dim": 2.2, "vol_fill_factor": 1.3, 'prime_radius': 1e-6}))
178-
def test_diam2vol_fractal(aero_data_params:dict):
195+
@pytest.mark.parametrize(
196+
"aero_data_params",
197+
(
198+
{"frac_dim": 2.4, "vol_fill_factor": 1.2, "prime_radius": 1e-7},
199+
{"frac_dim": 2.5, "vol_fill_factor": 1.1, "prime_radius": 1e-8},
200+
{"frac_dim": 2.2, "vol_fill_factor": 1.3, "prime_radius": 1e-6},
201+
),
202+
)
203+
def test_diam2vol_fractal(aero_data_params: dict):
179204
# arrange
180205
sut = ppmc.AeroData(AERO_DATA_CTOR_ARG_MINIMAL)
181206
diam = 2e-6
182-
for key,value in aero_data_params.items():
207+
for key, value in aero_data_params.items():
183208
setattr(sut, key, value)
184209

185210
# act
186211
value = sut.diam2vol(diam)
187212

188213
# assert
189-
np.testing.assert_almost_equal(value, (4/3)*np.pi*(sut.prime_radius)**3 *
190-
(1e-6/sut.prime_radius)**sut.frac_dim / sut.vol_fill_factor)
214+
np.testing.assert_almost_equal(
215+
value,
216+
(4 / 3)
217+
* np.pi
218+
* (sut.prime_radius) ** 3
219+
* (1e-6 / sut.prime_radius) ** sut.frac_dim
220+
/ sut.vol_fill_factor,
221+
)
191222

192223
@staticmethod
193224
def test_vol2diam_sphere():
@@ -202,21 +233,34 @@ def test_vol2diam_sphere():
202233
np.testing.assert_almost_equal(value, 2e-6)
203234

204235
@staticmethod
205-
@pytest.mark.parametrize("aero_data_params", (
206-
{"frac_dim": 2.4, "vol_fill_factor": 1.2, 'prime_radius': 1e-7},
207-
{"frac_dim": 2.5, "vol_fill_factor": 1.1, "prime_radius": 1e-8},
208-
{"frac_dim": 2.2, "vol_fill_factor": 1.3, 'prime_radius': 1e-6}))
209-
def test_vol2diam_fractal(aero_data_params:dict):
236+
@pytest.mark.parametrize(
237+
"aero_data_params",
238+
(
239+
{"frac_dim": 2.4, "vol_fill_factor": 1.2, "prime_radius": 1e-7},
240+
{"frac_dim": 2.5, "vol_fill_factor": 1.1, "prime_radius": 1e-8},
241+
{"frac_dim": 2.2, "vol_fill_factor": 1.3, "prime_radius": 1e-6},
242+
),
243+
)
244+
def test_vol2diam_fractal(aero_data_params: dict):
210245
# arrange
211246
sut = ppmc.AeroData(AERO_DATA_CTOR_ARG_MINIMAL)
212247
vol = 4.19e-18
213-
for key,value in aero_data_params.items():
248+
for key, value in aero_data_params.items():
214249
setattr(sut, key, value)
215250

216251
# act
217252
value = sut.vol2diam(vol)
218253

219254
# assert
220-
np.testing.assert_almost_equal(value, 2*(sut.prime_radius *
221-
(((3*vol/4/np.pi)**(1/3)/sut.prime_radius)**3 * sut.vol_fill_factor)**
222-
(1/sut.frac_dim)))
255+
np.testing.assert_almost_equal(
256+
value,
257+
2
258+
* (
259+
sut.prime_radius
260+
* (
261+
((3 * vol / 4 / np.pi) ** (1 / 3) / sut.prime_radius) ** 3
262+
* sut.vol_fill_factor
263+
)
264+
** (1 / sut.frac_dim)
265+
),
266+
)

0 commit comments

Comments
 (0)