def test_from_file_in_mag(self): fpath = op.join(self.DATA, "dummy.csv") x_unit = u.dimensionless_unscaled y_unit = u.mag lc_data = LCData.from_file(fpath, x_unit, y_unit=y_unit, reference_magnitude=1.0) assert_array_equal(lc_data.x_data, np.arange(0, 5, 1)) assert_array_equal(np.round(lc_data.y_data, 2), [2.29] * 5)
def test_from_file(self): fpath = op.join(self.DATA, "dummy.csv") x_unit = u.dimensionless_unscaled y_unit = u.dimensionless_unscaled lc_data = LCData.from_file(fpath, x_unit, y_unit=y_unit) self.assertEqual(lc_data.y_unit, u.dimensionless_unscaled) self.assertEqual(lc_data.x_unit, u.dimensionless_unscaled) assert_array_equal(lc_data.x_data, np.arange(0, 5, 1)) assert_array_equal(lc_data.y_data, [0.1] * 5)
def test_least_squares_lc_fit_community_params(self): dinit = { "system": { 'semi_major_axis': { 'value': 11.0, # 12.62 'fixed': False, 'min': 7.0, 'max': 15.0 }, 'mass_ratio': { 'value': 0.7, # 0.5 'fixed': False, 'min': 0.3, 'max': 2.0 }, 'inclination': { 'value': 90.0, 'fixed': True }, 'eccentricity': { 'value': 0.0, 'fixed': True }, 'argument_of_periastron': { 'value': 0.0, 'fixed': True }, 'period': { 'value': 3.0, 'fixed': True } }, "primary": { 't_eff': { 'value': 5000.0, 'fixed': True }, 'surface_potential': { 'value': 5.0, 'fixed': True }, 'gravity_darkening': { 'value': 1.0, 'fixed': True }, 'albedo': { 'value': 1.0, 'fixed': True } }, "secondary": { 't_eff': { 'value': 7000.0, 'fixed': True }, 'surface_potential': { 'value': 5, 'fixed': True }, 'gravity_darkening': { 'value': 1.0, 'fixed': True }, 'albedo': { 'value': 1.0, 'fixed': True } } } lc_v = LCData( x_data=self.phases['Generic.Bessell.V'], y_data=self.flux['Generic.Bessell.V'], x_unit=u.dimensionless_unscaled, y_unit=u.dimensionless_unscaled ) lc_b = LCData( x_data=self.phases['Generic.Bessell.B'], y_data=self.flux['Generic.Bessell.B'], x_unit=u.dimensionless_unscaled, y_unit=u.dimensionless_unscaled ) self.model_generator.keep_out = True with mock.patch("elisa.analytics.models.lc.synthetic_binary", self.model_generator.lc_generator): lc_initial = BinaryInitialParameters(**dinit) data = {'Generic.Bessell.V': lc_v, 'Generic.Bessell.B': lc_b} task = LCBinaryAnalyticsTask(data=data, method='least_squares', expected_morphology='detached') result = task.fit(x0=lc_initial) self.assertTrue(1.0 > result["r_squared"]['value'] > 0.9)
def test_mcmc_lc_fit_std_params_detached(self): dinit = { "primary": { "mass": { 'value': 1.8, # 2.0 'fixed': False, 'min': 1.5, 'max': 2.2 }, "t_eff": { 'value': 5000.0, 'fixed': True }, "surface_potential": { 'value': 5.0, 'fixed': True }, "gravity_darkening": { 'value': 1.0, 'fixed': True }, "albedo": { 'value': 1.0, 'fixed': True } }, "secondary": { "mass": { 'value': 1.0, 'fixed': True }, "t_eff": { 'value': 6500.0, # 7000 'fixed': False, 'min': 5000.0, 'max': 10000.0 }, "surface_potential": { 'value': 5, 'fixed': True }, "gravity_darkening": { 'value': 1.0, 'fixed': True }, "albedo": { 'value': 1.0, 'fixed': True } }, "system": { "inclination": { 'value': 90.0, 'fixed': True }, "eccentricity": { 'value': 0.0, 'fixed': True }, "argument_of_periastron": { 'value': 0.0, 'fixed': True }, "period": { 'value': 3.0, 'fixed': True } } } lc_v = LCData( x_data=self.phases['Generic.Bessell.V'], y_data=self.flux['Generic.Bessell.V'], x_unit=u.dimensionless_unscaled, y_unit=u.dimensionless_unscaled ) lc_b = LCData( x_data=self.phases['Generic.Bessell.B'], y_data=self.flux['Generic.Bessell.B'], x_unit=u.dimensionless_unscaled, y_unit=u.dimensionless_unscaled ) self.model_generator.keep_out = True with mock.patch("elisa.analytics.models.lc.synthetic_binary", self.model_generator.lc_generator): lc_initial = BinaryInitialParameters(**dinit) task = LCBinaryAnalyticsTask(data={'Generic.Bessell.V': lc_v, 'Generic.Bessell.B': lc_b}, expected_morphology="detached", method='mcmc') task.fit(x0=lc_initial, nsteps=10, discretization=5.0)
def main(): lc = get_lc() phases = {band: np.arange(-0.6, 0.62, 0.02) for band in lc} n = len(lc["Generic.Bessell.V"]) sigma = 0.004 bias = {passband: np.random.normal(0, sigma, n) for passband, curve in lc.items()} lc = {passband: curve + bias[passband] for passband, curve in lc.items()} lc_err = {passband: sigma * np.ones(curve.shape) for passband, curve in lc.items()} data = {passband: LCData(**{ "x_data": phases[passband], "y_data": lc[passband], "y_err": lc_err[passband], "x_unit": units.dimensionless_unscaled, "y_unit": units.dimensionless_unscaled, "passband": passband }) for passband in lc} lc_initial = { "system": { "semi_major_axis": { "value": 16.515, "constraint": "16.515 / sin(radians(system@inclination))" }, "inclination": { "value": 85.0, "fixed": False, "min": 80, "max": 90 }, "argument_of_periastron": { "value": 0.0, "fixed": True }, "mass_ratio": { "value": 0.5, "fixed": True }, "eccentricity": { "value": 0.0, "fixed": True }, "period": { "value": 4.5, "fixed": True, "unit": units.d } }, "primary": { "t_eff": { "value": 8307.0, "fixed": False, "min": 7800.0, "max": 8800.0, "unit": units.K }, "surface_potential": { "value": 3.0, "fixed": False, "min": 3, "max": 5 }, "gravity_darkening": { "value": 0.32, "fixed": True }, "albedo": { "value": 0.6, "fixed": True }, }, "secondary": { "t_eff": { "value": 4000.0, "fixed": False, "min": 4000.0, "max": 7000.0 }, "surface_potential": { "value": 5.0, "fixed": False, "min": 5.0, "max": 7.0 }, "gravity_darkening": { "value": 0.32, "fixed": True }, "albedo": { "value": 0.6, "fixed": True } } } lc_initial = BinaryInitialParameters(**lc_initial) task = LCBinaryAnalyticsTask(data=data, method='least_squares', expected_morphology="detached") result = task.fit(x0=lc_initial) print(json.dumps(result, indent=4))
def main(): lc = get_lc() phases = {band: np.arange(-0.6, 0.62, 0.02) for band in lc} n = len(lc["Generic.Bessell.V"]) sigma = 0.004 bias = { passband: np.random.normal(0, sigma, n) for passband, curve in lc.items() } lc = {passband: curve + bias[passband] for passband, curve in lc.items()} lc_err = { passband: sigma * np.ones(curve.shape) for passband, curve in lc.items() } data = { passband: LCData( **{ "x_data": phases[passband], "y_data": lc[passband], "y_err": lc_err[passband], "x_unit": units.dimensionless_unscaled, "y_unit": units.dimensionless_unscaled, "passband": passband }) for passband in lc } result = { "primary": { "t_eff": { "value": 8099.941757469695, "fixed": False, "unit": "K", "min": 7800.0, "max": 8800.0 }, "surface_potential": { "value": 3.9079468419211425, "fixed": False, "unit": None, "min": 3.0, "max": 5.0 }, "albedo": { "value": 0.6, "fixed": True, "unit": None }, "gravity_darkening": { "value": 0.32, "fixed": True, "unit": None } }, "secondary": { "t_eff": { "value": 5970.458040348652, "fixed": False, "unit": "K", "min": 4000.0, "max": 7000.0 }, "surface_potential": { "value": 5.9166442699971284, "fixed": False, "unit": None, "min": 5.0, "max": 7.0 }, "albedo": { "value": 0.6, "fixed": True, "unit": None }, "gravity_darkening": { "value": 0.32, "fixed": True, "unit": None } }, "system": { "inclination": { "value": 83.56583703194174, "fixed": False, "unit": "deg", "min": 80.0, "max": 90.0 }, "eccentricity": { "value": 0.0, "fixed": True, "unit": None }, "argument_of_periastron": { "value": 0.0, "fixed": True, "unit": "deg" }, "period": { "value": 4.5, "fixed": True, "unit": "d" }, "mass_ratio": { "value": 0.5, "fixed": True, "unit": None }, "semi_major_axis": { "value": 16.61968275372717, "constraint": "16.515 / sin(radians(system@inclination))", "unit": "solRad" } }, "r_squared": { "value": 0.9943566454789291, "unit": None } } task = LCBinaryAnalyticsTask(data=data, method='least_squares', expected_morphology="detached") task.set_result(result) task.plot.model()
def main(): lc = get_lc() phases = {band: np.arange(-0.6, 0.62, 0.02) for band in lc} n = len(lc["Generic.Bessell.V"]) sigma = 0.004 bias = { passband: np.random.normal(0, sigma, n) for passband, curve in lc.items() } lc = {passband: curve + bias[passband] for passband, curve in lc.items()} lc_err = { passband: sigma * np.ones(curve.shape) for passband, curve in lc.items() } data = { passband: LCData( **{ "x_data": phases[passband], "y_data": lc[passband], "y_err": lc_err[passband], "x_unit": au.dimensionless_unscaled, "y_unit": au.dimensionless_unscaled, "passband": passband }) for passband in lc } result = { "primary": { "t_eff": { "value": 8230.84100260351, "confidence_interval": { "min": 7926.453297478265, "max": 8591.643787140914 }, "fixed": False, "min": 7800.0, "max": 8800.0, "unit": "K" }, "surface_potential": { "value": 3.9337264746233775, "confidence_interval": { "min": 3.697563664749108, "max": 4.199838559400843 }, "fixed": False, "min": 3.0, "max": 5.0, "unit": None }, "albedo": { "value": 0.6, "fixed": True, "unit": None }, "gravity_darkening": { "value": 0.32, "fixed": True, "unit": None } }, "secondary": { "t_eff": { "value": 5983.733468261532, "confidence_interval": { "min": 5393.912953493938, "max": 6474.502604079509 }, "fixed": False, "min": 4000.0, "max": 7000.0, "unit": "K" }, "surface_potential": { "value": 6.112664406249967, "confidence_interval": { "min": 5.728751677639996, "max": 6.477440272860319 }, "fixed": False, "min": 5.0, "max": 7.0, "unit": None }, "albedo": { "value": 0.6, "fixed": True, "unit": None }, "gravity_darkening": { "value": 0.32, "fixed": True, "unit": None } }, "system": { "inclination": { "value": 85.33146246324937, "confidence_interval": { "min": 82.21719586922225, "max": 88.54153499552233 }, "fixed": False, "min": 80.0, "max": 90.0, "unit": "deg" }, "eccentricity": { "value": 0.0, "fixed": True, "unit": None }, "argument_of_periastron": { "value": 0.0, "fixed": True, "unit": "deg" }, "period": { "value": 4.5, "fixed": True, "unit": "d" }, "mass_ratio": { "value": 0.5, "fixed": True, "unit": None }, "semi_major_axis": { "value": 16.569975351859675, "constraint": "16.515 / sin(radians(system@inclination))", "unit": "solRad" } } } task = LCBinaryAnalyticsTask(data=data, method='mcmc') task.set_result(result) task.load_chain("mcmc_lc_fit") # task.plot.model() # task.plot.corner(truths=True) # task.plot.traces() # task.plot.autocorrelation() task.result_summary()