eppaurora.ssusi.ssusi_ioniz()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 41
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 12
nop 8
dl 0
loc 41
rs 9.8
c 0
b 0
f 0

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
# Copyright (c) 2020 Stefan Bender
2
#
3
# This file is part of pyeppaurora.
4
# pyeppaurora is free software: you can redistribute it or modify
5
# it under the terms of the GNU General Public License as published
6
# by the Free Software Foundation, version 2.
7
# See accompanying LICENSE file or http://www.gnu.org/licenses/gpl-2.0.html.
8
"""Atmospheric ionization rate parametrizations
9
10
From the SSUSI ATBD documents [#]_ [#]_ [#]_.
11
12
.. [#] https://ssusi.jhuapl.edu/data_algorithms
13
.. [#] https://ssusi.jhuapl.edu/docs/algorithms/Aurora_LID_c_Version_2.0.pdf
14
.. [#] https://ssusi.jhuapl.edu/docs/algorithms/SSUSI_DataProductAlgorithms_V1_13.doc
15
"""
16
17
import numpy as np
18
19
__all__ = ["ssusi_ioniz"]
20
21
# pre-determined analytical model coefficients of peak auroral ionization production rate height
22
# electrons
23
CHMAX_E = [2.07923, -9.41205e-2]
24
# protons
25
CHMAX_P = [2.078, -4.072e-2]
26
# pre-determined analytical model coefficients of peak auroral ionization production rate
27
# electrons
28
CPMAX_E = [0., 9.25777e-1, -5.03201e-1]
29
# protons
30
CPMAX_P = [0., 3.50766e-1, -8.84737e-2]
31
32
33
def ssusi_ioniz(z, en, flux, chmax=CHMAX_E, cpmax=CPMAX_E, eref=1., pref=2.57e3, shpc=1.427e10):
34
	"""Parametrization from Sect. 2.6.2 in [#]_
35
36
	Parameters
37
	----------
38
	z: float, array_like
39
	en: float, array_like
40
	flux: float, array_like
41
		Energy flux in [erg cm^{-2} s^{-1}], note: **not** keV.
42
	chmax: tuple, list, (2,) optional
43
		Pre-determined analytical model coefficients of peak auroral ionization production rate height.
44
	cpmax: tuple, list, (3,) optional
45
		Pre-determined analytical model coefficients of peak auroral ionization production rate
46
47
	Returns
48
	-------
49
	q: float, array_like
50
		The atmospheric ionization rate at altitude z.
51
52
	References
53
	----------
54
	.. [#] https://ssusi.jhuapl.edu/docs/algorithms/Aurora_LID_c_Version_2.0.pdf
55
	"""
56
	# pre-determined scale height proportionality factor
57
	shpf = 1e-5 / np.exp(1.)
58
	# log10 ratio of the characteristic energy (Sect. 2.6.2.2, 2.6.2.4)
59
	l10rce = np.log10(en / eref)
60
	# peak auroral ionization production rate height (Sect. 2.6.2.6)
61
	tempX = np.polyval(chmax[::-1], l10rce)
62
	pprh = 10**tempX
63
	# peak auroral ionization production rate (Sect. 2.6.2.8)
64
	tempX = np.polyval(cpmax[::-1], l10rce)
65
	ppr1 = 10**(tempX) * pref
66
	# scale height of the auroral ionization production rate (Sect. 2.6.2.10)
67
	shpr = shpf * shpc / ppr1
68
	# electron peak auroral ionization production rate (Sect. 2.6.2.12)
69
	pprq = flux * ppr1
70
	# ionization production rate altitude profile (Sect. 2.6.2.15)
71
	rhpr = (z - pprh) / shpr
72
	q = pprq * np.exp(1. - rhpr - np.exp(-rhpr))
73
	return q
74