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

eppaurora.ssusi   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 73
Duplicated Lines 57.53 %

Importance

Changes 0
Metric Value
wmc 1
eloc 18
dl 42
loc 73
rs 10
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A ssusi_ioniz() 42 42 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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