Skip to content

Commit

Permalink
Merge pull request #138 from sami2py/default_drifts
Browse files Browse the repository at this point in the history
Default drifts
  • Loading branch information
jklenzing committed May 17, 2021
2 parents 8249081 + 3840f73 commit 68c0a03
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## [next version] - 2021-04-05
- Added default drift fourier coefficient array accessable from run model
- Using minimum test version of numpy in accordance with NEP 29
- Removed the sami2py-1.00.namelist and version.txt files from run_name
- Bug Fix
Expand Down
29 changes: 22 additions & 7 deletions sami2py/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def run_model(tag='model_run', lat=0, lon=0, alt=300, year=2018, day=1,
no_scale=1, o2_scale=1, he_scale=1, n2_scale=1, n_scale=1,
Tinf_scale=1, Tn_scale=1., euv_scale=1,
wind_scale=1, hwm_model=14,
fejer=True, ExB_drifts=np.zeros((10, 2)), ve01=0., exb_scale=1,
fejer=True, ExB_drifts=None, ve01=0., exb_scale=1,
alt_crit=150., cqe=7.e-14,
clean=False, test=False, fmtout=True, outn=False):
"""Runs SAMI2 and archives the data in path
Expand Down Expand Up @@ -188,12 +188,16 @@ def run_model(tag='model_run', lat=0, lon=0, alt=300, year=2018, day=1,
A True value will use the Fejer-Scherliess model of ExB drifts
A False value will use a user-specified Fourier series for ExB drifts
(default = True)
ExB_drifts : (10x2 ndarray of floats)
ExB_drifts : (10x2 ndarray of floats, string, or NoneType)
Matrix of Fourier series coefficients dependent on solar local time
(SLT) in hours where
ExB_total = ExB_drifts[i,0]*cos((i+1)*pi*SLT/12)
+ ExB_drifts[i,1]*sin((i+1)*pi*SLT/12)
(default = np.zeros((10,2)))
ExB_total = ExB_drifts[i,0] * cos((i + 1) * pi * SLT / 12)
+ ExB_drifts[i,1] * sin((i + 1) * pi * SLT / 12)
Alternatively, None will produce 24 lt hrs of 0 m/s drifts everywhere.
Using the string 'default' will produce a cosine wave with a
maximum magnitude of 30 m/s at local noon and a minimum of -30 m/s
at midnight.
(default = None)
ve01 : (float)
Constant offset for Fourier ExB drifts (m/s)
(default=0)
Expand Down Expand Up @@ -282,8 +286,19 @@ def _generate_drift_info(fejer, ExB_drifts=None):
"""
drift_info = _generate_fortran_bool(fejer)
if not fejer:
if ExB_drifts.shape != (10, 2):
raise Exception('Invalid ExB drift shape! Must be 10x2 ndarray.')
if ExB_drifts is None:
ExB_drifts = np.zeros((10, 2))

if isinstance(ExB_drifts, str) and ExB_drifts == 'default':
ExB_drifts = np.zeros((10, 2))
ExB_drifts[0, 0] = -30

if isinstance(ExB_drifts, np.ndarray) and ExB_drifts.shape != (10, 2):
raise ValueError('Invalid ExB drift shape! Must be 10x2 ndarray.')

if isinstance(ExB_drifts, str) and ExB_drifts != 'default':
raise ValueError('Unrecognized drift name')

np.savetxt('exb.inp', ExB_drifts)
return drift_info

Expand Down
28 changes: 28 additions & 0 deletions sami2py/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,31 @@ def teardown(self):
if os.path.exists(self.model_path):
shutil.rmtree(self.model_path)
del self.format, self.ref_file, self.model_path, self.filelist


class TestDriftGeneration():
"""Testing of the _core function _generate_drift_info"""

def setup(self):
f = open('exb.inp', 'w')
f.close()

def teardown(self):
os.remove('exb.inp')

def test_none_drifts(self):
empty_drift = np.zeros((10, 2))
sami2py._core._generate_drift_info(False, None)
drifts = np.loadtxt('exb.inp')
assert np.array_equal(drifts, empty_drift)

def test_default_drifts(self):
default = np.zeros((10, 2))
default[0, 0] = -30
sami2py._core._generate_drift_info(False, 'default')
drifts = np.loadtxt('exb.inp')
assert np.array_equal(drifts, default)

def test_bad_string(self):
with pytest.raises(Exception):
sami2py._core._generate_drift_info(False, 'really_cool_drifts_probably')

0 comments on commit 68c0a03

Please sign in to comment.