Skip to content

Commit

Permalink
no units test
Browse files Browse the repository at this point in the history
  • Loading branch information
jrob93 committed Jun 6, 2024
1 parent c1b1c88 commit 2de2e32
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/adler/science/PhaseCurve.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ def FitModel(self, phase_angle, reduced_mag, mag_err=None, fitter=None):
fitter : object
Select a fitting function from astropy.modeling.fitting, defaults to astropy.modeling.fitting.LevMarLSQFitter.
N.B. that LevMarLSQFitter cannot handle inequality constraints for the HG1G2 model.
N.B. that LevMarLSQFitter cannot handle inequality constraints for the HG1G2 model, use something like SLSQPLSQFitter from astropy.modeling.fitting (does not return covariance matrix!).
Returns
----------
Expand Down Expand Up @@ -297,5 +297,6 @@ def FitModel(self, phase_angle, reduced_mag, mag_err=None, fitter=None):

### if overwrite_model: # add an overwrite option?
# redo __init__ with the new fitted parameters
# this would then return an adler PhaseCurve object rather than an sbpy object

return model_fit
22 changes: 22 additions & 0 deletions tests/adler/science/test_PhaseCurve.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,28 @@ def test_PhaseCurve_FitModel_HG():
assert pc2.phase_parameter_1_err is not None # the fitted model has some uncertainties


def test_PhaseCurve_FitModel_HG_no_units():
"""Test fitting a HG model to generated data, but without units.
If units are not provided, the phase angles must be in radians!"""

# generate some model data
pc1 = PhaseCurve(H=18.0, phase_parameter_1=0.15, model_name="HG")
alpha = np.radians(np.linspace(0, 30))
red_mag = pc1.ReducedMag(alpha)

# fit the same phase curve model to the data
pc_fit = pc1.FitModel(alpha, red_mag)
# convert from sbpy to adler PhaseCurve object
pc2 = pc1.InitModelSbpy(pc_fit)

# the new fitted model should have the same parameters as the input model
assert pc2.H == pc1.H
assert pc2.phase_parameter_1 == pc1.phase_parameter_1
assert pc2.phase_parameter_2 is None
assert pc1.phase_parameter_1_err is None # the first model had no uncertainties
assert pc2.phase_parameter_1_err is not None # the fitted model has some uncertainties


def test_PhaseCurve_FitModel_HG_fixed():
"""Test fitting a just H whilst keeping G fixed."""

Expand Down

0 comments on commit 2de2e32

Please sign in to comment.