Passed
Push — master ( 861427...2a29b5 )
by Stefan
01:38
created

eppaurora.ssusi.ssusi_ioniz()   A

Complexity

Conditions 1

Size

Total Lines 42
Code Lines 12

Duplication

Lines 42
Ratio 100 %

Importance

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

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
# pre-determined analytical model coefficients of peak auroral ionization production rate height
20
# electrons
21
CHMAX_E = [2.07923, -9.41205e-2]
22
# protons
23
CHMAX_P = [2.078, -4.072e-2]
24
# pre-determined analytical model coefficients of peak auroral ionization production rate
25
# electrons
26
CPMAX_E = [0., 9.25777e-1, -5.03201e-1]
27
# protons
28
CPMAX_P = [0., 3.50766e-1, -8.84737e-2]
29
30
31 View Code Duplication
def ssusi_ioniz(z, en, flux, chmax=CHMAX_E, cpmax=CPMAX_E, eref=1., pref=2.57e3, shpc=1.427e10):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
32
	"""Parametrization from Sect. 2.6.2 in [#]_
33
34
	Parameters
35
	----------
36
	z: float, array_like
37
	en: float, array_like
38
	flux: float, array_like
39
		Energy flux in [erg cm^{-2} s^{-2}], note: **not** keV.
40
	chmax: tuple, list, (2,) optional
41
		Pre-determined analytical model coefficients of peak auroral ionization production rate height.
42
	cpmax: tuple, list, (3,) optional
43
		Pre-determined analytical model coefficients of peak auroral ionization production rate
44
		
45
	Returns
46
	-------
47
	q: float, array_like
48
		The atmospheric ionization rate at altitude z.
49
50
	References
51
	----------
52
	
53
	.. [#] https://ssusi.jhuapl.edu/docs/algorithms/Aurora_LID_c_Version_2.0.pdf
54
	"""
55
	# pre-determined scale height proportionality factor
56
	shpf = 1e-5 / np.exp(1.)
57
	# log10 ratio of the characteristic energy (Sect. 2.6.2.2, 2.6.2.4)
58
	l10rce = np.log10(en / eref)
59
	# peak auroral ionization production rate height (Sect. 2.6.2.6)
60
	tempX = np.polyval(chmax[::-1], l10rce)
61
	pprh = 10**tempX
62
	# peak auroral ionization production rate (Sect. 2.6.2.8)
63
	tempX = np.polyval(cpmax[::-1], l10rce)
64
	ppr1 = 10**(tempX) * pref
65
	# scale height of the auroral ionization production rate (Sect. 2.6.2.10)
66
	shpr = shpf * shpc / ppr1
67
	# electron peak auroral ionization production rate (Sect. 2.6.2.12)
68
	pprq = flux * ppr1
69
	# ionization production rate altitude profile (Sect. 2.6.2.15)
70
	rhpr = (z - pprh) / shpr
71
	q = pprq * np.exp(1. - rhpr - np.exp(-rhpr))
72
	return q
73