Skip to content

Commit 69aaaeb

Browse files
committed
Add fixes suggested by ruff
1 parent a3bd981 commit 69aaaeb

5 files changed

Lines changed: 459 additions & 442 deletions

File tree

doc/conf.py

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919

2020
# -- Project information -----------------------------------------------------
2121

22-
project = 'ibei'
23-
copyright = '2022, Joshua Ryan Smith'
24-
author = 'Joshua Ryan Smith'
22+
project = "ibei"
23+
copyright = "2022, Joshua Ryan Smith"
24+
author = "Joshua Ryan Smith"
2525
version = ibei.__version__
2626

2727

@@ -30,22 +30,17 @@
3030
# Add any Sphinx extension module names here, as strings. They can be
3131
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
3232
# ones.
33-
extensions = [
34-
'sphinx.ext.autodoc',
35-
'sphinx.ext.mathjax',
36-
'sphinx.ext.napoleon',
37-
'sphinxcontrib.bibtex'
38-
]
33+
extensions = ["sphinx.ext.autodoc", "sphinx.ext.mathjax", "sphinx.ext.napoleon", "sphinxcontrib.bibtex"]
3934

4035
# Configuration for `autodoc`.
4136
autodoc_member_order = "bysource"
4237

4338

4439
# Configuration for `sphinxcontrib-bibtex`.
45-
bibtex_bibfiles = ['bib.bib']
40+
bibtex_bibfiles = ["bib.bib"]
4641

4742
# Add any paths that contain templates here, relative to this directory.
48-
templates_path = ['_templates']
43+
templates_path = ["_templates"]
4944

5045
# List of patterns, relative to source directory, that match files and
5146
# directories to ignore when looking for source files.
@@ -58,10 +53,10 @@
5853
# The theme to use for HTML and HTML Help pages. See the documentation for
5954
# a list of builtin themes.
6055

61-
html_theme = 'sphinx_rtd_theme'
56+
html_theme = "sphinx_rtd_theme"
6257

6358

6459
# Add any paths that contain custom static files (such as style sheets) here,
6560
# relative to this directory. They are copied after the builtin static files,
6661
# so a file named "default.css" will overwrite the builtin "default.css".
67-
html_static_path = ['_static']
62+
html_static_path = ["_static"]

src/ibei/models.py

Lines changed: 67 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def _int_converter(value):
2727
try:
2828
int(value)
2929
except ValueError as ex:
30-
raise TypeError("Argument must be coercible to type int.") from ex #noqa: TRY003, EM101
30+
raise TypeError("Argument must be coercible to type int.") from ex # noqa: TRY003, EM101
3131

3232
elif int(value) != value:
3333
# I have to do some validation in this converter because if I were
@@ -39,14 +39,14 @@ def _int_converter(value):
3939
#
4040
# I'd not be able to catch this case because the attribute
4141
# would be assigned to the possibly truncated value.
42-
raise TypeError("Argument must be coercible to type int without truncation.") #noqa: TRY003, EM101
42+
raise TypeError("Argument must be coercible to type int without truncation.") # noqa: TRY003, EM101
4343

4444
return int(value)
4545

4646

47-
def _validate_is_scalar(instance, attribute, value): #noqa: ARG001
47+
def _validate_is_scalar(instance, attribute, value): # noqa: ARG001
4848
if not value.isscalar:
49-
raise TypeError("Attributes must be scalar") #noqa: TRY003, EM101
49+
raise TypeError("Attributes must be scalar") # noqa: TRY003, EM101
5050

5151

5252
@attrs.frozen
@@ -114,40 +114,39 @@ class BEI:
114114
----------
115115
.. [1] https://ibei.readthedocs.io/
116116
"""
117+
117118
order: int = attrs.field(
118-
converter=_int_converter,
119-
)
119+
converter=_int_converter,
120+
)
120121
energy_bound: float | astropy.units.Quantity[astropy.units.eV] = attrs.field(
121-
converter=functools.partial(astropy.units.Quantity, unit=astropy.units.eV),
122-
validator=[
123-
_validate_is_scalar,
124-
attrs.validators.ge(0),
125-
]
126-
)
122+
converter=functools.partial(astropy.units.Quantity, unit=astropy.units.eV),
123+
validator=[
124+
_validate_is_scalar,
125+
attrs.validators.ge(0),
126+
],
127+
)
127128
temperature: float | astropy.units.Quantity[astropy.units.K] = attrs.field(
128-
converter=_temperature_converter,
129-
validator=[
130-
_validate_is_scalar,
131-
attrs.validators.gt(0),
132-
]
133-
)
129+
converter=_temperature_converter,
130+
validator=[
131+
_validate_is_scalar,
132+
attrs.validators.gt(0),
133+
],
134+
)
134135
chemical_potential: float | astropy.units.Quantity[astropy.units.eV] = attrs.field(
135-
default=0.,
136-
converter=functools.partial(astropy.units.Quantity, unit=astropy.units.eV),
137-
validator=[
138-
_validate_is_scalar,
139-
attrs.validators.ge(0),
140-
]
141-
)
142-
136+
default=0.0,
137+
converter=functools.partial(astropy.units.Quantity, unit=astropy.units.eV),
138+
validator=[
139+
_validate_is_scalar,
140+
attrs.validators.ge(0),
141+
],
142+
)
143143

144144
def lower(self) -> astropy.units.Quantity:
145145
"""
146146
Lower-incomplete Bose-Einstein integral.
147147
"""
148148
return self.full() - self.upper()
149149

150-
151150
def upper(self) -> astropy.units.Quantity:
152151
"""
153152
Upper-incomplete Bose-Einstein integral.
@@ -181,7 +180,6 @@ def upper(self) -> astropy.units.Quantity:
181180

182181
return bei
183182

184-
185183
def full(self) -> astropy.units.Quantity:
186184
"""
187185
Full Bose-Einstein integral.
@@ -197,7 +195,6 @@ def full(self) -> astropy.units.Quantity:
197195

198196
return bei
199197

200-
201198
def photon_flux(self) -> astropy.units.Quantity[astropy.units.Unit("1/(m2 s)")]:
202199
"""
203200
Number of photons radiated per unit time per unit area.
@@ -207,12 +204,10 @@ def photon_flux(self) -> astropy.units.Quantity[astropy.units.Unit("1/(m2 s)")]:
207204
This convenience method is a special case of :meth:`BEI.full`. This
208205
method assumes the value of :attr:`order` is 2.
209206
"""
210-
flux = (4 * np.pi * float(mpmath.zeta(3)) * self.kT**3) / \
211-
(astropy.constants.h**3 * astropy.constants.c**2)
207+
flux = (4 * np.pi * float(mpmath.zeta(3)) * self.kT**3) / (astropy.constants.h**3 * astropy.constants.c**2)
212208

213209
return flux.to("1/(m2 s)")
214210

215-
216211
def radiant_power_flux(self) -> astropy.units.Quantity[astropy.units.Unit("J/(m2 s)")]:
217212
"""
218213
Energy radiated per unit time per unit area.
@@ -227,9 +222,8 @@ def radiant_power_flux(self) -> astropy.units.Quantity[astropy.units.Unit("J/(m2
227222

228223
return power_flux.to("J/(m2 s)")
229224

230-
231225
@property
232-
def kT(self) -> astropy.units.Quantity[astropy.units.dimensionless_unscaled]: #noqa: N802
226+
def kT(self) -> astropy.units.Quantity[astropy.units.dimensionless_unscaled]: # noqa: N802
233227
"""
234228
Product of Boltzmann's constant and :attr:`temperature`.
235229
"""
@@ -259,8 +253,7 @@ def prefactor(self) -> astropy.units.Quantity:
259253
For :attr:`order` equal to `3`, this factor is NOT equal to the
260254
Stefan-Boltzmann constant because is missing the Riemann-Zeta term.
261255
"""
262-
return (2 * np.pi * self.kT**(self.order + 1)) / \
263-
(astropy.constants.h**3 * astropy.constants.c**2)
256+
return (2 * np.pi * self.kT ** (self.order + 1)) / (astropy.constants.h**3 * astropy.constants.c**2)
264257

265258

266259
@attrs.frozen
@@ -297,29 +290,28 @@ class SQSolarcell:
297290
ValueError
298291
If ``solar_temperature`` <= 0
299292
"""
293+
300294
bei = attrs.field(init=False)
301295
bandgap: float | astropy.units.Quantity[astropy.units.eV] = attrs.field(
302-
converter=functools.partial(astropy.units.Quantity, unit=astropy.units.eV),
303-
validator=[
304-
_validate_is_scalar,
305-
attrs.validators.ge(0),
306-
]
307-
)
296+
converter=functools.partial(astropy.units.Quantity, unit=astropy.units.eV),
297+
validator=[
298+
_validate_is_scalar,
299+
attrs.validators.ge(0),
300+
],
301+
)
308302
solar_temperature: float | astropy.units.Quantity[astropy.units.K] = attrs.field(
309-
default=5772.,
310-
converter=_temperature_converter,
311-
validator=[
312-
_validate_is_scalar,
313-
attrs.validators.gt(0),
314-
]
315-
)
316-
303+
default=5772.0,
304+
converter=_temperature_converter,
305+
validator=[
306+
_validate_is_scalar,
307+
attrs.validators.gt(0),
308+
],
309+
)
317310

318311
def __attrs_post_init__(self):
319-
bei = BEI(order=2, energy_bound=self.bandgap, temperature=self.solar_temperature, chemical_potential=0.)
312+
bei = BEI(order=2, energy_bound=self.bandgap, temperature=self.solar_temperature, chemical_potential=0.0)
320313
object.__setattr__(self, "bei", bei)
321314

322-
323315
def power_density(self) -> astropy.units.Quantity[astropy.units.Unit("W/m2")]:
324316
"""
325317
Solar cell power density
@@ -328,13 +320,12 @@ def power_density(self) -> astropy.units.Quantity[astropy.units.Unit("W/m2")]:
328320
modification of Shockley & Queisser's :cite:`10.1063/1.1736034` Eq.
329321
2.4.
330322
"""
331-
solar_flux = astropy.units.Quantity(0., "1/(m2 s)") if self.bandgap == 0 else self.bei.upper()
323+
solar_flux = astropy.units.Quantity(0.0, "1/(m2 s)") if self.bandgap == 0 else self.bei.upper()
332324

333325
power_density = self.bandgap * solar_flux
334326

335327
return power_density.to("W/m2")
336328

337-
338329
def efficiency(self) -> astropy.units.Quantity[astropy.units.dimensionless_unscaled]:
339330
"""
340331
Solar cell efficiency
@@ -344,7 +335,7 @@ def efficiency(self) -> astropy.units.Quantity[astropy.units.dimensionless_unsca
344335
"""
345336
power_density = self.power_density()
346337
solar_power_density = self.bei.radiant_power_flux()
347-
efficiency = power_density/solar_power_density
338+
efficiency = power_density / solar_power_density
348339

349340
return efficiency.decompose()
350341

@@ -392,22 +383,22 @@ class DeVosSolarcell(SQSolarcell):
392383
ValueError
393384
If ``planetary_temperature`` <= 0
394385
"""
386+
395387
planetary_temperature: float | astropy.units.Quantity[astropy.units.K] = attrs.field(
396-
default=300.,
397-
converter=_temperature_converter,
398-
validator=[
399-
_validate_is_scalar,
400-
attrs.validators.gt(0),
401-
]
402-
)
388+
default=300.0,
389+
converter=_temperature_converter,
390+
validator=[
391+
_validate_is_scalar,
392+
attrs.validators.gt(0),
393+
],
394+
)
403395
voltage: float | astropy.units.Quantity[astropy.units.V] = attrs.field(
404-
default=0.,
405-
converter=functools.partial(astropy.units.Quantity, unit=astropy.units.V),
406-
validator=[
407-
_validate_is_scalar,
408-
]
409-
)
410-
396+
default=0.0,
397+
converter=functools.partial(astropy.units.Quantity, unit=astropy.units.V),
398+
validator=[
399+
_validate_is_scalar,
400+
],
401+
)
411402

412403
def power_density(self) -> astropy.units.Quantity[astropy.units.Unit("W/m2")]:
413404
"""
@@ -421,15 +412,15 @@ def power_density(self) -> astropy.units.Quantity[astropy.units.Unit("W/m2")]:
421412
electron_energy = astropy.constants.e.si * self.voltage
422413

423414
if self.bandgap == 0:
424-
solar_flux = astropy.units.Quantity(0., "1/(m2 s)")
425-
solar_cell_flux = astropy.units.Quantity(0., "1/(m2 s)")
415+
solar_flux = astropy.units.Quantity(0.0, "1/(m2 s)")
416+
solar_cell_flux = astropy.units.Quantity(0.0, "1/(m2 s)")
426417
else:
427418
bei = BEI(
428-
order=2,
429-
energy_bound=self.bandgap,
430-
temperature=self.planetary_temperature,
431-
chemical_potential=electron_energy
432-
)
419+
order=2,
420+
energy_bound=self.bandgap,
421+
temperature=self.planetary_temperature,
422+
chemical_potential=electron_energy,
423+
)
433424
solar_flux = self.bei.upper()
434425
solar_cell_flux = bei.upper()
435426

0 commit comments

Comments
 (0)