From 053ac6fafc5513f68b89e26aa80c78c8af514daf Mon Sep 17 00:00:00 2001 From: radek_poleski Date: Sun, 5 May 2024 11:29:16 +0200 Subject: [PATCH] ex16: errorbar scaling --- examples/example_16/ob03235_2_full.yaml | 2 +- examples/example_16/ulens_model_fit.py | 41 +++++++++++++++++-------- 2 files changed, 30 insertions(+), 13 deletions(-) diff --git a/examples/example_16/ob03235_2_full.yaml b/examples/example_16/ob03235_2_full.yaml index 04b247b5..59512d05 100644 --- a/examples/example_16/ob03235_2_full.yaml +++ b/examples/example_16/ob03235_2_full.yaml @@ -1,5 +1,5 @@ photometry_files: - - {file_name: data/OB03235/OB03235_OGLE.txt, bandpass: I, plot_properties: {zorder: 10., color: red, label: "OGLE I-band"}} + - {file_name: data/OB03235/OB03235_OGLE.txt, bandpass: I, plot_properties: {zorder: 10., color: red, label: "OGLE I-band"}, scale_errorbars: {factor: 1.5, minimum: 0.001}} - {file_name: data/OB03235/OB03235_MOA.txt, phot_fmt: flux} # To add satellite ephemeris: # - {file_name: some_K2_data.txt, phot_fmt: flux, bandpass: 'Kp', ephemerides_file: K2_ephemeris_01.dat} diff --git a/examples/example_16/ulens_model_fit.py b/examples/example_16/ulens_model_fit.py index abdc367b..e6ab7e3b 100644 --- a/examples/example_16/ulens_model_fit.py +++ b/examples/example_16/ulens_model_fit.py @@ -38,7 +38,7 @@ except Exception: raise ImportError('\nYou have to install MulensModel first!\n') -__version__ = '0.35.1' +__version__ = '0.36.0' class UlensModelFit(object): @@ -63,6 +63,10 @@ class UlensModelFit(object): [{'file_name': 'data_1.dat'}, 'data_2.dat'] Currently, keyword ``'add_2450000'`` is turned on by default. + Except standard parameters of MulensData, one can additionally + pass + ``'scale_errorbars': {'factor': kappa, 'minimum': epsilon}`` + to scale uncertainties. starting_parameters: *dict* Starting values of the parameters. @@ -1016,16 +1020,7 @@ def _get_datasets(self): for f in self._photometry_files] self._datasets = [] for file_ in files: - try: - dataset = mm.MulensData(**{**kwargs, **file_}) - except FileNotFoundError: - raise FileNotFoundError( - 'Provided file path does not exist: ' + - str(file_['file_name'])) - except Exception: - print('Something went wrong while reading file ' + - str(file_['file_name']), file=sys.stderr) - raise + dataset = self._get_1_dataset(file_, kwargs) self._datasets.append(dataset) if self._residuals_output: @@ -1035,6 +1030,27 @@ def _get_datasets(self): raise ValueError('The number of datasets and files for ' 'residuals ouptut do not match: ' + out) + def _get_1_dataset(self, file_, kwargs): + """ + Construct a single dataset and possibly rescale uncertainties in it. + """ + scaling = file_.pop("scale_errorbars", None) + try: + dataset = mm.MulensData(**{**kwargs, **file_}) + except FileNotFoundError: + raise FileNotFoundError( + 'Provided file path does not exist: ' + + str(file_['file_name'])) + except Exception: + print('Something went wrong while reading file ' + + str(file_['file_name']), file=sys.stderr) + raise + + if scaling is not None: + dataset.scale_errorbars(**scaling) + + return dataset + def _check_ulens_model_parameters(self): """ Check if there aren't too many parameters. @@ -1604,7 +1620,8 @@ def _check_fixed_parameters(self): fixed = set(self._fixed_parameters.keys()) - allowed = set(self._all_MM_parameters + self._fixed_only_MM_parameters + + allowed = set(self._all_MM_parameters + + self._fixed_only_MM_parameters + self._other_parameters) unknown = fixed - allowed if len(unknown) > 0: