Skip to content

Commit

Permalink
ex16: errorbar scaling
Browse files Browse the repository at this point in the history
  • Loading branch information
rpoleski committed May 5, 2024
1 parent f1da69f commit 053ac6f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 13 deletions.
2 changes: 1 addition & 1 deletion examples/example_16/ob03235_2_full.yaml
Original file line number Diff line number Diff line change
@@ -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}
Expand Down
41 changes: 29 additions & 12 deletions examples/example_16/ulens_model_fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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.
Expand Down Expand Up @@ -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:
Expand All @@ -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.
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 053ac6f

Please sign in to comment.