Skip to content

Commit

Permalink
Merge pull request #23 from FormingWorlds/testing
Browse files Browse the repository at this point in the history
Testing
  • Loading branch information
lsoucasse authored Sep 30, 2024
2 parents 0196097 + a817a59 commit 0db696d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 28 deletions.
15 changes: 5 additions & 10 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,44 +12,39 @@ on:
jobs:
test:

runs-on: ubuntu-latest
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
python-version: ['3.10', '3.11', '3.12']

steps:
- uses: actions/checkout@v4

- name: Setup system
run: |
sudo apt-get update
sudo apt-get install libnetcdff-dev netcdf-bin
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- uses: actions/cache@v3
- uses: actions/cache@v4
id: cache-virtualenv
with:
path: ${{ env.pythonLocation }}
key: ${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}

- name: Build MORS
if: steps.cache-virtualenv.outputs.cache-hit != 'true'
run: |
python -m pip install -e .[develop]
- uses: actions/cache@v3
id: cache-fwl-data
with:
path: /home/runner/work/fwl_data
path: $HOME/work/fwl_data
key: fwl-data-1

- name: Test with pytest
run: |
export FWL_DATA="/home/runner/work/fwl_data"
export FWL_DATA="$HOME/work/fwl_data"
coverage run -m pytest
- name: Report coverage
Expand Down
2 changes: 1 addition & 1 deletion src/mors/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def SetDefaultParameters(paramsDefault):
"""Sets up the default parameters."""

# Time integration solver parameters
paramsDefault['TimeIntegrationMethod'] = 'Rosenbrock' # options are 'ForwardEuler', 'RungeKutta4', 'RungeKuttaFehlberg', 'Rosenbrock'
paramsDefault['TimeIntegrationMethod'] = 'ForwardEuler' # options are 'ForwardEuler', 'RungeKutta4', 'RungeKuttaFehlberg', 'Rosenbrock'
paramsDefault['nStepMax'] = 10**6 # maximum number of timesteps to allow before error
paramsDefault['DeltaDesired'] = 1.0e-5 # desired Delta value to use in numerical solvers such as Runge-Kutta-Fehlberg and Rosenbrock
paramsDefault['AgeMinDefault'] = 1.0 # Myr - default age to start evolutionary tracks
Expand Down
22 changes: 7 additions & 15 deletions src/mors/stellarevo.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ def _ReadEvolutionTrack(starEvoDir,evoModels,Mstar,MstarFilenameMiddle):
dRcoredt[:] = _CalculateGradient( Age , Rcore )

# Round mass and ages to nDecValue decimal places as specified at top of file
Mstar = round( Mstar , nDecValue )
Mstar = np.round( Mstar , decimals=nDecValue )
Age = np.round( Age , decimals=nDecValue )

# Add all quantities to the dictionary
Expand Down Expand Up @@ -496,7 +496,7 @@ def _LoadTrack(Mstar,ModelData):
"""Takes stellar mass and model data dictionary, returns dictionary with track for this mass."""

# Round mass to nDecValue decimal places specified at top of this file
Mstar = round( Mstar , nDecValue )
Mstar = np.round( Mstar , decimals=nDecValue )

# Make sure within mass limit
_CheckMassLimit( ModelData['MstarAll'] , Mstar )
Expand Down Expand Up @@ -728,7 +728,7 @@ def _CheckAgeLimit(AgeArray,Age):
"""Takes age track and an age, outputs error and stops code if age is not within limits."""

# Round the age to decimal places determined by nDecValue at top of file
Age = round( Age , nDecValue )
Age = np.round( Age , decimals=nDecValue )

# Do check
if not ( AgeArray[0] <= Age <= AgeArray[-1] ):
Expand All @@ -747,17 +747,13 @@ def _CheckMassLimit(MstarArray,Mstar):
def _Interpolate2D(Z1,Z2,Z,Xarray1,Xarray2,X,Yarray1,Yarray2):
"""Takes two sets of 1D arrays for corresponding X and Y values, returns interpolated Y value corresponding to input X."""

# Round the input values to decimal places determined by nDecValue at top of file
Z = round( Z , nDecValue )

# Do interpolations to get Y at X for both tracks
Y1 = _Interpolate1D( Xarray1 , Yarray1 , X )
Y2 = _Interpolate1D( Xarray2 , Yarray2 , X )

# Do linear interpolation between Y1 and Y2 in Z direction
mInterp = ( Y2 - Y1 ) / ( Z2 - Z1 )
cInterp = Y1 - mInterp * Z1
Y = mInterp * Z + cInterp
delta = (Z-Z1)/(Z2-Z1)
Y = Y2*delta + Y1*(1-delta)

return Y

Expand All @@ -766,9 +762,6 @@ def _Interpolate1D(Xarray,Yarray,X):

# Note that it is assumed here that Xarray is in ascending order and this won't work if it is not

# Round the input values to decimal places determined by nDecValue at top of file
X = round( X , nDecValue )

# Make sure X is in limits
if not ( Xarray[0] <= X <= Xarray[-1] ):
raise Exception("input value "+str(X)+" is not within limits of "+str(Xarray[0])+" to "+str(Xarray[-1]))
Expand All @@ -785,9 +778,8 @@ def _Interpolate1D(Xarray,Yarray,X):
else:

# Do linear interpolation
mInterp = ( Yarray[iMax] - Yarray[iMin] ) / ( Xarray[iMax] - Xarray[iMin] )
cInterp = Yarray[iMin] - mInterp * Xarray[iMin]
Y = mInterp * X + cInterp
delta = (X-Xarray[iMin])/(Xarray[iMax]-Xarray[iMin])
Y = Yarray[iMax]*delta + Yarray[iMin]*(1-delta)

return Y

Expand Down
6 changes: 4 additions & 2 deletions tests/test_spada.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
from numpy.testing import assert_allclose

TEST_DATA = (
((0.128, 45.2, 8.5e1),(0.21263373, 1.68612613e+31, 1.74497354e+28)),
((1.113, 17.7, 3.2e3),(1.16581856, 6.81769993e+33, 7.95296357e+28)),
((0.128, 45.2, 8.5e1),(0.21263373, 1.68612614e+31, 1.73275380e+28)),
((1.113, 17.7, 3.2e3),(1.16581827, 6.81769926e+33, 7.94292986e+28)),
((0.995, 1.005, 1.0e4),(1.48904952e+00, 7.80667546e+33, 3.22933432e+28)),
((1.000, 1.00, 1.0e4),(1.52583342e+00, 8.13191736e+33, 3.38245392e+28)),
)

@pytest.mark.parametrize("inp,expected", TEST_DATA)
Expand Down

0 comments on commit 0db696d

Please sign in to comment.