-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
7 changed files
with
93 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,6 +36,9 @@ | |
/results.txt | ||
/env | ||
|
||
# python | ||
__pycache__ | ||
|
||
# directories | ||
/build | ||
/doc | ||
|
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# | ||
# Python interface to the `radbelt_fortran` shared library. | ||
# | ||
|
||
from . import radbelt_fortran | ||
|
||
class RadbeltClass: | ||
""" | ||
Class for using the radbelt model. | ||
""" | ||
|
||
def __init__(self) -> None: | ||
"""constructor for the fortran class""" | ||
|
||
#`ip` is an integer that represents a c pointer | ||
# to a `radbelt_type` in the Fortran library. | ||
self.ip = radbelt_fortran.radbelt_c_module.initialize_c() | ||
|
||
#TODO should allow for passing in the data directories here | ||
|
||
def __del__(self) -> None: | ||
"""destructor for the fortran class""" | ||
|
||
radbelt_fortran.radbelt_c_module.destroy_c(self.ip) | ||
|
||
def set_data_files_paths(self, aep8_dir : str, igrf_dir : str) -> None: | ||
"""Set the file paths""" | ||
|
||
#TODO split these up so they can be called separately | ||
|
||
radbelt_fortran.radbelt_c_module.set_data_files_paths_c(self.ip, aep8_dir, igrf_dir, | ||
len(aep8_dir), len(igrf_dir)) | ||
|
||
def get_flux(self, lon : float, lat : float , height : float, year : float, | ||
e : float, particle : str, solar : str) -> float: | ||
""" | ||
Compute the flux. | ||
Parameters | ||
---------- | ||
lon : float | ||
Longitude (deg) | ||
lat : float | ||
Latitude (deg) | ||
height : float | ||
Altitude (deg) | ||
year : float | ||
Decimal year (needed to account for drift of the Earth's magnetic field). | ||
energy : float | ||
Minimum energy. | ||
particle : {'e', 'p'} | ||
Particle species: 'e' for electrons, 'p' for protons. | ||
solar : {'min', 'max'} | ||
Solar activity: solar minimum or solar maximum. | ||
Returns | ||
------- | ||
flux : float | ||
The flux of particles above the given energy, (cm^-2 s^-1). | ||
""" | ||
|
||
model = _model_index(particle, solar) | ||
return radbelt_fortran.radbelt_c_module.get_flux_g_c(self.ip,lon,lat,height,year,e,model) | ||
|
||
def _model_index(particle : str, solar : str) -> int: | ||
"""convert the particle and solar options to model number for the low-level routine""" | ||
|
||
p = particle.lower() | ||
s = solar.lower() | ||
if p not in ('e', 'p'): raise ValueError('particle must be "e" or "p"') | ||
if s not in ('min', 'max'): raise ValueError('solar must be "min" or "max"') | ||
return { ('e', 'min'): 1, | ||
('e', 'max'): 2, | ||
('p', 'min'): 3, | ||
('p', 'max'): 4 }[(p, s)] |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters