diff --git a/README.md b/README.md index a60c1f83..3913e7ab 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ [**Detailed documentation: https://rpoleski.github.io/MulensModel/**](https://rpoleski.github.io/MulensModel/) -[Latest release: 2.14.0](https://github.com/rpoleski/MulensModel/releases/latest) and we're working on further developing the code. +[Latest release: 2.15.0](https://github.com/rpoleski/MulensModel/releases/latest) and we're working on further developing the code. MulensModel can generate a microlensing light curve for a given set of microlensing parameters, fit that light curve to some data, and return a chi2 value. That chi2 can then be input into an arbitrary likelihood function to find the best-fit parameters. diff --git a/documents/examples_list.md b/documents/examples_list.md index 0cc07e63..976618ae 100644 --- a/documents/examples_list.md +++ b/documents/examples_list.md @@ -31,6 +31,7 @@ Tutorials MulensModel: * [Example 21](../examples/example_21_external_mass_sheet.py) - binary lens with external mass sheet: shear and convergence as parameters, * [Example 22](../examples/example_22_pointlens_external_mass_sheet.py) - point lens with external mass sheet, i.e., Chang-Refsdal approximation, * [Example 23](../examples/example_23_logo_inspiration.py) - 2L1S and 1L2S lightcurves plotted as an inspiration for MM logo, +* [Example 24](../examples/example_24_repr.py) - print intances of different MM classes, * Three files producing plots presented in paper describing MulensModel: [plots_1.py](../examples/plots_1.py), [plots_2.py](../examples/plots_2.py), and [plots_3.py](../examples/plots_3.py). [MulensModel documentation](https://rpoleski.github.io/MulensModel/) includes description of input and output of every function. diff --git a/examples/example_24_repr.py b/examples/example_24_repr.py new file mode 100644 index 00000000..88f52809 --- /dev/null +++ b/examples/example_24_repr.py @@ -0,0 +1,68 @@ +""" +Output information about datasets, model, and event. +Created from example_05_MB08310.py + +From `Janczak et al. 2010, ApJ 711, 731 +`_. +""" +import glob +import os + +import MulensModel as mm + + +# Read in MB08310 data files (see data/MB08310) as MulensData objects. +# Grabbing all data files in the MB08310 folder +files = glob.glob(os.path.join(mm.DATA_PATH, "photometry_files", + "MB08310", "*.tbl")) + +coordinates = "17:54:14.53 −34:46:40.99" + +filters = {'Auck': 'R', 'Bron': 'R', 'Canopus': 'I', 'CTIO_H': 'H', + 'CTIO_I': 'I', 'Danish': 'I', 'MOA': 'R'} + +# Read in the data +datasets_default = [] +for file_ in sorted(files): + file_elements = os.path.basename(file_).split('_') + name = file_elements[0] + if name == 'CTIO': + name += '_' + name += file_elements[1] + + data = mm.MulensData( + file_name=file_, comments=["\\", "|"], bandpass=filters[name]) + if name == 'MOA': + data.scale_errorbars(1.6, 0.001) + + datasets_default.append(data) + + +print("Printing datasets:") +for data in datasets_default: + print(data) + +# Define basic point lens model +t_0 = 2454656.39975 +u_0 = 0.00300 +t_E = 11.14 +t_star = 0.05487 +plens_model = mm.Model({'t_0': t_0, 'u_0': u_0, 't_E': t_E, 't_star': t_star}) +method = 'finite_source_uniform_Gould94' +plens_model.set_magnification_methods([t_0-2.*t_star, method, t_0+2.*t_star]) +plens_model.set_limb_coeff_u('I', 0.547) +plens_model.set_limb_coeff_u('V', 0.714) +plens_model.set_limb_coeff_u('R', 0.633) +plens_model.set_limb_coeff_u('H', 0.368) + +print('\nPrinting model:') +print(plens_model) + +# Combine the data and model into an event +event_default = mm.Event( + datasets=datasets_default, model=plens_model, coords=coordinates) +event_default.data_ref = 6 + +print("\nPrinting event:") +print(event_default) + diff --git a/source/MulensModel/coordinates.py b/source/MulensModel/coordinates.py index 40a70526..8bd6e42a 100644 --- a/source/MulensModel/coordinates.py +++ b/source/MulensModel/coordinates.py @@ -28,6 +28,8 @@ class Coordinates(SkyCoord): unit=(u.hourangle, u.deg) where u is defined by "import astropy.units as u". + You can print an instance of this class. + .. _astropy.SkyCoord: http://docs.astropy.org/en/stable/api/astropy.coordinates.SkyCoord.html @@ -83,6 +85,9 @@ def _calculate_projected(self): north, direction) self._north_projected = np.cross(direction, self._east_projected) + def __repr__(self): + return self.to_string(style="hmsdms", sep=":", precision=2) + @property def galactic_l(self): """ diff --git a/source/MulensModel/event.py b/source/MulensModel/event.py index db8b3b0a..245bcd8e 100644 --- a/source/MulensModel/event.py +++ b/source/MulensModel/event.py @@ -62,6 +62,9 @@ class Event(object): in negative flux, then we calculate chi^2 in flux space but only for the epochs with negative model flux. + You can print an instance of this class. Information on model and datasets + will be provided. + .. _astropy.SkyCoord: http://docs.astropy.org/en/stable/api/astropy.coordinates.SkyCoord.html """ @@ -113,6 +116,28 @@ def __init__( else: self.fix_source_flux_ratio = fix_source_flux_ratio + def __repr__(self): + if self.model is None: + out = "No model" + else: + out = 'model:\n{:}'.format(self.model) + + if self.datasets is None: + out += "\nNo datasets" + else: + if isinstance(self.data_ref, (int)): + data_ref = self.datasets[self.data_ref] + else: + data_ref = self.data_ref + + out += '\ndatasets:' + for dataset in self.datasets: + out += "\n" + str(dataset) + if dataset == data_ref: + out += " *data_ref*" + + return out + def plot(self, t_range=None, residuals=True, show_errorbars=None, show_bad=None, legend=True, trajectory=None, title=None, subtract_2450000=True, subtract_2460000=False, data_ref=None): @@ -816,6 +841,12 @@ def _set_datasets(self, new_value): self._datasets = None return + if len(set(new_value)) != len(new_value): + raise ValueError( + 'Duplicated instances of MulensData are not allowed in ' + 'the Event class (though you can make 2 identical instances ' + 'and then Event will work).') + self._datasets = new_value self._fits = None # reset the fits if the data changed diff --git a/source/MulensModel/limbdarkeningcoeffs.py b/source/MulensModel/limbdarkeningcoeffs.py index b6c5a9b0..debe668a 100644 --- a/source/MulensModel/limbdarkeningcoeffs.py +++ b/source/MulensModel/limbdarkeningcoeffs.py @@ -16,11 +16,15 @@ class LimbDarkeningCoeffs(object): Note that the gamma convention has fixed total flux. + You can print an instance of this class. """ def __init__(self): self._gammas_for_band = dict() + def __repr__(self): + return self._gammas_for_band.__repr__() + def set_limb_coeff_gamma(self, bandpass, gamma): """ Remembers limb darkening gamma coefficient for given band. diff --git a/source/MulensModel/model.py b/source/MulensModel/model.py index b87970fe..e9b1d355 100644 --- a/source/MulensModel/model.py +++ b/source/MulensModel/model.py @@ -65,6 +65,9 @@ class Model(object): model = Model(parameters={'t_0': 2456789.0, ....}) print(model) + This will provide information on parameter values, coordinates, + methods used for magnification calculations, and + limb-darkening coefficients. """ def __init__( @@ -108,7 +111,20 @@ def __init__( self._bandpasses = [] def __repr__(self): - return '{0}'.format(self.parameters) + out = '{0}'.format(self.parameters) + if self.coords is not None: + out += '\ncoords: {0}'.format(self.coords) + + out += '\ndefault magnification method: {0}'.format( + self._default_magnification_method) + if self._methods is not None: + out += '\nother magnification methods: {0}'.format(self._methods) + + if len(self.bandpasses) > 0: + out += '\nlimb-darkening coeffs (gamma): {0}'.format( + self._limb_darkening_coeffs) + + return out def plot_magnification( self, times=None, t_range=None, t_start=None, t_stop=None, dt=None, diff --git a/source/MulensModel/modelparameters.py b/source/MulensModel/modelparameters.py index a5128405..3878aae6 100644 --- a/source/MulensModel/modelparameters.py +++ b/source/MulensModel/modelparameters.py @@ -364,6 +364,8 @@ def __repr__(self): if 'pi_E' in keys: keys.remove('pi_E') keys |= {'pi_E_E', 'pi_E_N'} + if 'pi_E_E' in keys or 'pi_E_N' in keys: + keys |= {'t_0_par'} # Below we define dict of dicts. Key of inner ones: 'width', # 'precision', and optional: 'unit' and 'name'. @@ -376,6 +378,7 @@ def __repr__(self): 't_star': {'width': 13, 'precision': 6, 'unit': 'd'}, 'pi_E_N': {'width': 9, 'precision': 5}, 'pi_E_E': {'width': 9, 'precision': 5}, + 't_0_par': {'width': 13, 'precision': 5, 'unit': 'HJD'}, 's': {'width': 9, 'precision': 5}, 'q': {'width': 12, 'precision': 8}, 'alpha': {'width': 11, 'precision': 5, 'unit': 'deg'}, @@ -402,18 +405,11 @@ def __repr__(self): formats[key]['unit'] = form['unit'] if 'name' in form: raise KeyError('internal issue: {:}'.format(key)) - formats_keys = [ - 't_0', 't_0_1', 't_0_2', 'u_0', 'u_0_1', 'u_0_2', 't_eff', 't_E', - 'rho', 'rho_1', 'rho_2', 't_star', 't_star_1', 't_star_2', - 'pi_E_N', 'pi_E_E', 's', 'q', 'alpha', - 'convergence_K', 'shear_G', 'ds_dt', 'dalpha_dt', - 'x_caustic_in', 'x_caustic_out', 't_caustic_in', 't_caustic_out', - ] variables = '' values = '' - for key in formats_keys: + for key in formats.keys(): if key not in keys: continue form = formats[key] @@ -429,7 +425,7 @@ def __repr__(self): value = value.value values += fmt_2.format(value) - return '{0}\n{1}\n'.format(variables, values) + return '{0}\n{1}'.format(variables, values) def _check_valid_combination_2_sources(self, keys): """ diff --git a/source/MulensModel/mulensdata.py b/source/MulensModel/mulensdata.py index 37a42889..403fae76 100644 --- a/source/MulensModel/mulensdata.py +++ b/source/MulensModel/mulensdata.py @@ -107,6 +107,11 @@ class MulensData(object): ``**kwargs``: Kwargs passed to np.loadtxt(). Works only if ``file_name`` is set. + You can print an instance of this class, which always provides label and + information on the total number of epochs and the number of bad epochs. + If applicable, additional information is provided: bandpass, + ephemerides file, color used for plotting, and errorbar scaling. + .. _instructions: https://github.com/rpoleski/MulensModel/blob/master/documents/Horizons_manual.md @@ -151,8 +156,37 @@ def __init__(self, data_list=None, file_name=None, # Set up satellite properties (if applicable) self._ephemerides_file = ephemerides_file + def __repr__(self): + if 'label' in self.plot_properties: + name = self.plot_properties['label'] + else: + name = self._file_name + + out = "{:25} n_epochs ={:>5}, n_bad ={:>5}".format( + name+":", self.n_epochs, np.sum(self.bad)) + + if self.bandpass is not None: + out += ', band = {0}'.format(self.bandpass) + + if self._ephemerides_file is not None: + out += ', eph_file = {0}'.format(self.ephemerides_file) + + if 'color' in self.plot_properties: + out += ', color = {0}'.format(self.plot_properties['color']) + + if self._errorbars_scale is not None: + out += ', Errorbar scaling:' + if self._errorbars_scale['factor'] is not None: + out += ' factor = {:}'.format(self._errorbars_scale['factor']) + + if self._errorbars_scale['minimum'] is not None: + out += ' minimum = {:}'.format( + self._errorbars_scale['minimum']) + + return out + def _import_photometry(self, data_list, **kwargs): - """import time, brightnes, and its uncertainy""" + """import time, brightness, and its uncertainty""" # Import the photometry... if data_list is not None and self._file_name is not None: raise ValueError( diff --git a/source/MulensModel/tests/test_Coords.py b/source/MulensModel/tests/test_Coords.py index bdefb883..23c1dee6 100644 --- a/source/MulensModel/tests/test_Coords.py +++ b/source/MulensModel/tests/test_Coords.py @@ -112,3 +112,10 @@ def test_v_Earth_projected(): np.testing.assert_almost_equal( [-3.60, 22.95], coords.v_Earth_projected(2455042.34,), decimal=2) + + +def test_repr(): + """Checks if coords can be printed""" + text = "17:53:50.79 -33:59:25.00" + coords = mm.Coordinates(text) + assert str(coords) == text diff --git a/source/MulensModel/tests/test_Event.py b/source/MulensModel/tests/test_Event.py index b9fead01..dc48be45 100644 --- a/source/MulensModel/tests/test_Event.py +++ b/source/MulensModel/tests/test_Event.py @@ -279,13 +279,14 @@ def test_event_get_chi2_double_source_simple(): u_0 = 0.52298 t_E = 17.94002 - data = mm.MulensData(file_name=SAMPLE_FILE_01) + data_1 = mm.MulensData(file_name=SAMPLE_FILE_01) + data_2 = mm.MulensData(file_name=SAMPLE_FILE_01) ev = mm.Event() mod = mm.Model({'t_0': t_0, 'u_0': u_0, 't_E': t_E}) ev.model = mod - ev.datasets = [data, data] + ev.datasets = [data_1, data_2] chi2 = ev.get_chi2() @@ -351,9 +352,7 @@ def test_event_chi2_binary_source_2datasets(): np.testing.assert_almost_equal(event.get_chi2_for_dataset(0), 0.) -# -------- -# Error message tests -class TestEvent(unittest.TestCase): +class TestInput(unittest.TestCase): def test_event_init_1(self): with self.assertRaises(TypeError): _ = mm.Event(model=3.14) @@ -362,6 +361,11 @@ def test_event_init_2(self): with self.assertRaises(TypeError): _ = mm.Event(datasets='some_string') + def test_event_init_3(self): + data = mm.MulensData(file_name=SAMPLE_FILE_01) + with self.assertRaises(ValueError): + mm.Event(datasets=[data, data]) + # ---------- # Chi2 Gradient Tests @@ -379,8 +383,9 @@ def __init__(self, parameters=None, grad_params=None, gradient=None): gradient={'t_0': 236.206598, 'u_0': 101940.249, 't_E': -1006.88678}) # Not used: -# f_source and f_blend cannot be gradient parameters in MulensModel, but -# this test could be moved to sfit_minimizer, which is under development by JCY. +# f_source and f_blend cannot be gradient parameters in MulensModel, +# but this test could be moved to sfit_minimizer, +# which is under development by JCY. chi2_gradient_test_2 = Chi2GradientTest( parameters={'t_0': 2456836.22, 'u_0': 0.922, 't_E': 22.87, 'pi_E_N': -0.248, 'pi_E_E': 0.234}, @@ -469,11 +474,12 @@ def test_chi2_gradient_2(): [chi2_gradient_test_1.gradient[key] for key in chi2_gradient_test_1.grad_params]) - data = mm.MulensData(file_name=SAMPLE_FILE_02) + data_1 = mm.MulensData(file_name=SAMPLE_FILE_02) + data_2 = mm.MulensData(file_name=SAMPLE_FILE_02) event = mm.Event( - datasets=[data, data], + datasets=[data_1, data_2], model=mm.Model(chi2_gradient_test_1.parameters), - fix_blend_flux={data: 0.}) + fix_blend_flux={data_1: 0., data_2: 0.}) result_0 = event.get_chi2_gradient(chi2_gradient_test_1.grad_params) result_1 = event.fits[1].chi2_gradient np.testing.assert_almost_equal(2. * reference / result_0, 1., decimal=4) @@ -588,19 +594,6 @@ def test_get_ref_fluxes_binary_source(): np.testing.assert_almost_equal(blend_flux_1, 50.) -class TestDataRef(unittest.TestCase): - def test_1(self): - """ - Try get_ref_fluxes() with an event with duplicated data - """ - (model, model_1, model_2) = generate_binary_source_models() - (data_1, data_2) = generate_binary_source_datasets(model_1, model_2) - event_1 = mm.Event([data_1, data_2, data_2], model) - with self.assertRaises(ValueError): - event_1.data_ref = data_2 - - -# -------- # Event.get_flux_for_dataset() Tests def test_get_flux_for_dataset(): """ @@ -1008,6 +1001,72 @@ def test_free_fluxes(self): fluxes[i][1] / self.expected_fluxes[i][1], 1.) np.testing.assert_almost_equal(event.get_chi2_for_dataset(i), 0.) + +def test_repr_empty(): + """ + Check printing if no input is provided. + """ + event = mm.Event() + expected = "No model\nNo datasets" + assert str(event) == expected + + +def test_repr_full(): + """ + Check printing if model and data are provided. + """ + model = mm.Model({'t_0': 0, 'u_0': .5, 't_E': 10.}, + coords="18:12:34.56 -23:45:55.55") + dataset_01 = mm.MulensData(file_name=SAMPLE_FILE_01) + dataset_02 = mm.MulensData(file_name=SAMPLE_FILE_02) + event = mm.Event(model=model, datasets=[dataset_01, dataset_02]) + expected = "model:\n{0}\ndatasets:".format(model) + for i, dataset in enumerate([dataset_01, dataset_02]): + expected += "\n{0}".format(dataset) + if i == 0: + expected += " *data_ref*" + + assert str(event) == expected + + +def get_event_to_print(): + """ + Prepare Event instance to check __repr__() + """ + kwargs = {'comments': ["\\", "|"]} + model = mm.Model({'t_0': 0, 'u_0': .5, 't_E': 10.}, + coords="18:12:34.56 -23:45:55.55") + dataset_01 = mm.MulensData(file_name=SAMPLE_FILE_310_01, **kwargs) + dataset_02 = mm.MulensData(file_name=SAMPLE_FILE_310_02, **kwargs) + dataset_03 = mm.MulensData(file_name=SAMPLE_FILE_310_03, **kwargs) + event = mm.Event( + model=model, datasets=[dataset_01, dataset_02, dataset_03]) + expected = "model:\n{0}\ndatasets:".format(model) + for i, dataset in enumerate([dataset_01, dataset_02, dataset_03]): + expected += "\n{0}".format(dataset) + if i == 1: + expected += " *data_ref*" + return (event, expected, dataset_02) + + +def test_repr_data_ref_data(): + """ + Check printing if model and data are provided. + """ + (event, expected, _) = get_event_to_print() + event.data_ref = 1 + assert str(event) == expected + + +def test_repr_data_ref_int(): + """ + Check printing if model and data are provided. + """ + (event, expected, dataset_02) = get_event_to_print() + event.data_ref = dataset_02 + assert str(event) == expected + + # Tests to add: # # properties: coords, model, datasets, data_ref, sum_function? diff --git a/source/MulensModel/tests/test_Model.py b/source/MulensModel/tests/test_Model.py index 5e13e873..6cfe1bbc 100644 --- a/source/MulensModel/tests/test_Model.py +++ b/source/MulensModel/tests/test_Model.py @@ -458,6 +458,34 @@ def test_get_lc(): almost(out, 19.668370500043526) +def test_repr(): + """Test if printing is Model instance is OK.""" + parameters = {'t_0': 2454656.4, 'u_0': 0.003, + 't_E': 11.1, 't_star': 0.055} + begin = (" t_0 (HJD) u_0 t_E (d) t_star (d) \n" + "2454656.40000 0.003000 11.1000 0.055000 \n") + end = "default magnification method: point_source" + model = mm.Model(parameters) + assert str(model) == begin + end + + coords = "17:54:32.10 -30:12:34.99" + model = mm.Model(parameters, coords=coords) + expected = "{:}coords: {:}\n{:}".format(begin, coords, end) + assert str(model) == expected + + model = mm.Model(parameters) + methods = [2454656.3, 'finite_source_uniform_Gould94', 2454656.5] + model.set_magnification_methods(methods) + expected = "{:}{:}\nother magnification methods: {:}".format( + begin, end, methods) + assert str(model) == expected + + model = mm.Model(parameters) + model.set_limb_coeff_gamma("I", 0.5) + expected = begin + end + "\nlimb-darkening coeffs (gamma): {'I': 0.5}" + assert str(model) == expected + + # Tests to Add: # # test get_trajectory: diff --git a/source/MulensModel/tests/test_ModelParameters.py b/source/MulensModel/tests/test_ModelParameters.py index 14119185..37f112a7 100644 --- a/source/MulensModel/tests/test_ModelParameters.py +++ b/source/MulensModel/tests/test_ModelParameters.py @@ -69,7 +69,44 @@ def test_repr_parameters(): params = mm.ModelParameters({'t_0': t_0, 'u_0': u_0, 't_E': t_E}) out_1 = " t_0 (HJD) u_0 t_E (d) \n" - out_2 = "2456141.59300 0.542500 62.6300 \n" + out_2 = "2456141.59300 0.542500 62.6300 " + + assert (out_1 + out_2) == str(params) + + +def test_repr_no_t_0_par(): + """ + Make sure that t_0_par is printed even if not provided directly. + """ + t_0 = 2456141. + u_0 = 0.01 + t_E = 62.63 + params = mm.ModelParameters({'t_0': t_0, 'u_0': u_0, 't_E': t_E, + 'pi_E_E': 0.1, 'pi_E_N': -0.2}) + + out_1 = (" t_0 (HJD) u_0 t_E (d) pi_E_N pi_E_E " + "t_0_par (HJD) \n") + out_2 = ("2456141.00000 0.010000 62.6300 -0.20000 0.10000 " + "2456141.00000 ") + + assert (out_1 + out_2) == str(params) + + +def test_repr_t_0_par(): + """ + Make sure that t_0_par is printed properly if provided directly. + """ + t_0 = 2456141. + u_0 = 0.01 + t_E = 62.63 + params = mm.ModelParameters({'t_0': t_0, 'u_0': u_0, 't_E': t_E, + 'pi_E_E': 0.1, 'pi_E_N': -0.2, + 't_0_par': t_0+1}) + + out_1 = (" t_0 (HJD) u_0 t_E (d) pi_E_N pi_E_E " + "t_0_par (HJD) \n") + out_2 = ("2456141.00000 0.010000 62.6300 -0.20000 0.10000 " + "2456142.00000 ") assert (out_1 + out_2) == str(params) diff --git a/source/MulensModel/tests/test_MulensData.py b/source/MulensModel/tests/test_MulensData.py index 1630cdba..f9c85e14 100644 --- a/source/MulensModel/tests/test_MulensData.py +++ b/source/MulensModel/tests/test_MulensData.py @@ -7,8 +7,11 @@ import MulensModel as mm -SAMPLE_FILE_01 = os.path.join( - mm.DATA_PATH, "photometry_files", "OB08092", "phot_ob08092_O4.dat") +dir_phot = os.path.join(mm.DATA_PATH, 'photometry_files') +SAMPLE_FILE_01 = os.path.join(dir_phot, "OB08092", "phot_ob08092_O4.dat") +SAMPLE_FILE_02 = os.path.join(dir_phot, 'OB140939', 'ob140939_Spitzer.dat') +SAMPLE_FILE_02_EPH = os.path.join(dir_phot, 'ephemeris_files', + 'Spitzer_ephemeris_01.dat') def test_file_read(): @@ -157,3 +160,86 @@ def test_scale_errorbars(): almost(data.err_mag, 0.0125) almost(data.errorbars_scale_factors, [factor, minimum]) assert data.errorbars_scaling_equation == equation_3 + + +def test_repr_1(): + """ + Check if one can print dataset nicely - n_bad>0 + """ + random_bad = 33 * [True] + 350 * [False] + np.random.shuffle(random_bad) + data = mm.MulensData(file_name=SAMPLE_FILE_01, bad=random_bad) + expected = "{0:25} n_epochs ={1:>5}, n_bad ={2:>5}".format( + "phot_ob08092_O4.dat:", 383, 33) + assert str(data) == expected + + +def test_repr_2(): + """ + Check if one can print dataset nicely - errorbar scaling factor + """ + data = mm.MulensData(file_name=SAMPLE_FILE_01) + data.scale_errorbars(factor=1.234) + expected = "{0:25} n_epochs ={1:>5}, n_bad ={2:>5},".format( + "phot_ob08092_O4.dat:", 383, 0) + expected += " Errorbar scaling: factor = 1.234" + assert str(data) == expected + + +def test_repr_3(): + """ + Check if one can print dataset nicely - bandpass and label + """ + data = mm.MulensData(file_name=SAMPLE_FILE_01, bandpass='I', + plot_properties={'label': 'OGLE'}) + expected = "{0:25} n_epochs ={1:>5}, n_bad ={2:>5}, band = I".format( + "OGLE:", 383, 0) + assert str(data) == expected + + +def test_repr_4(): + """ + Check if one can print dataset nicely - errorbar scaling minimum + """ + data = mm.MulensData(file_name=SAMPLE_FILE_01) + data.scale_errorbars(minimum=0.001) + expected = "{0:25} n_epochs ={1:>5}, n_bad ={2:>5},".format( + "phot_ob08092_O4.dat:", 383, 0) + expected += " Errorbar scaling: minimum = 0.001" + assert str(data) == expected + + +def test_repr_5(): + """ + Check if one can print dataset nicely - ephemerides file + """ + data = mm.MulensData(file_name=SAMPLE_FILE_02, + ephemerides_file=SAMPLE_FILE_02_EPH) + expected_begin = "{0:25} n_epochs ={1:>5}, n_bad ={2:>5}".format( + "ob140939_Spitzer.dat:", 31, 0) + expected_end = "photometry_files/ephemeris_files/Spitzer_ephemeris_01.dat" + assert str(data)[:len(expected_begin)] == expected_begin + assert str(data)[-len(expected_end):] == expected_end + + +def test_repr_6(): + """ + Check if one can print dataset nicely - color + """ + data = mm.MulensData(file_name=SAMPLE_FILE_01, + plot_properties={'color': 'red'}) + expected = "{0:25} n_epochs ={1:>5}, n_bad ={2:>5}, color = red".format( + "phot_ob08092_O4.dat:", 383, 0) + assert str(data) == expected + + +def test_repr_7(): + """ + Check if one can print dataset nicely - 2-parameter errorbar scaling + """ + data = mm.MulensData(file_name=SAMPLE_FILE_01) + data.scale_errorbars(factor=2.34, minimum=0.012) + expected = "{0:25} n_epochs ={1:>5}, n_bad ={2:>5},".format( + "phot_ob08092_O4.dat:", 383, 0) + expected += " Errorbar scaling: factor = 2.34 minimum = 0.012" + assert str(data) == expected diff --git a/source/MulensModel/version.py b/source/MulensModel/version.py index e199aa55..90c1ae3a 100644 --- a/source/MulensModel/version.py +++ b/source/MulensModel/version.py @@ -1 +1 @@ -__version__ = "2.14.1" +__version__ = "2.15.0"