From 2de2e322c8a052323c53e1cd936681d53fd4ef53 Mon Sep 17 00:00:00 2001 From: jrob93 Date: Thu, 6 Jun 2024 15:41:55 +0100 Subject: [PATCH] no units test --- src/adler/science/PhaseCurve.py | 3 ++- tests/adler/science/test_PhaseCurve.py | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/adler/science/PhaseCurve.py b/src/adler/science/PhaseCurve.py index 99fc16d..a40d1cb 100644 --- a/src/adler/science/PhaseCurve.py +++ b/src/adler/science/PhaseCurve.py @@ -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 ---------- @@ -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 diff --git a/tests/adler/science/test_PhaseCurve.py b/tests/adler/science/test_PhaseCurve.py index 4cbf76b..77e0385 100644 --- a/tests/adler/science/test_PhaseCurve.py +++ b/tests/adler/science/test_PhaseCurve.py @@ -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."""