Skip to content

Commit

Permalink
like previous
Browse files Browse the repository at this point in the history
  • Loading branch information
Mateusz Mroz committed May 13, 2024
1 parent 6bab7ad commit 71a02fb
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 24 deletions.
6 changes: 3 additions & 3 deletions examples/example_16/ob03235_2_full.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ starting_parameters:
s: uniform 1.09 1.11
alpha: gauss 224.0 1.0
fit_constraints:
negative_blending_flux_sigma_mag: 20.
negative_blending_flux_sigma_mag: 20.
#one can specify for which dataset soft constrain on blending flux should be applied: sigma dataset_number(s)
#negative_blending_flux_sigma_mag: 20. 1 3
#negative_blending_flux_sigma_mag: 20. "OGLE I-band" 1
# Alternative sharp constraint:
# no_negative_blending_flux: True
#color constrains, where color=flux_S_dataset_k/flux_S_dataset_m: gauss mu sigma k m
color : gauss 25. 5. "OGLE I-band" "OB03235_MOA.txt"
color : gauss 25. 5. "OGLE I-band" 1
#Alternative for binary source models:
#color source 1 : gauss 25. 5. "OGLE I-band" "OB03235_MOA.txt"
#and/or
Expand Down
54 changes: 33 additions & 21 deletions examples/example_16/ulens_model_fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -1483,12 +1483,15 @@ def _parse_fit_constraints_soft_blending(self, key, value):
"""
Check if soft fit constraint on blending flux are correctly defined.
"""
if isinstance(value, (float, int)):
if isinstance(value, float):
sigma = float(value)
sets = list(range(1, len(self._datasets) + 1))
sets = list(range(len(self._datasets)))

else:

sigma = float(value.split()[0])
sets = list(map(int, value.split()[1:]))
sets = list(map(self._get_no_of_dataset,
shlex.split(value, posix=False)[1:]))
if len(sets) > len(self._datasets):
raise ValueError(
'dataset number specified in negative_blending_flux_sigma_mag do not match with provided datasets')
Expand All @@ -1515,20 +1518,17 @@ def _parse_fit_constraints_color(self, key, value):
words[2] + " " + words[3] + " " + words[4])
if settings[2] < 0.:
raise ValueError('sigma cannot be negative: ' + words[2])

settings[3] = self._get_no_of_dataset(settings[3])
settings[4] = self._get_no_of_dataset(settings[4])

if settings[3] == settings[4]:
raise ValueError(
"in " + key + " fluxes have to be from different datasets")

if isinstance(settings[3], str) and isinstance(settings[4], str):
settings[3] = settings[3].strip('"')
settings[4] = settings[4].strip('"')
settings[3] = self._get_no_of_dataset_by_lable(settings[3])
settings[4] = self._get_no_of_dataset_by_lable(settings[4])

if isinstance(settings[3], int) and isinstance(settings[4], int):
if (0 >= settings[3] >= len(self._datasets)-1) or (0 >= settings[4] >= len(self._datasets)-1):
raise ValueError(
'dataset specified in color prior do not match with provided datasets')
if (0 >= settings[3] >= len(self._datasets)-1) or (0 >= settings[4] >= len(self._datasets)-1):
raise ValueError(
'dataset specified in color prior do not match with provided datasets')

self._fit_constraints[key] = settings

Expand Down Expand Up @@ -1569,24 +1569,36 @@ def _parse_fit_constraints_prior(self):
if len(priors) > 0:
self._priors = priors

def _get_no_of_dataset_by_lable(self, label):
def _get_no_of_dataset(self, label):
"""
Returns the index of a dataset with a specific label.
Parameters
----------
label : str
Label of the dataset defined by MulensData.plot_properties['label'].
Label of the dataset defined by MulensData.plot_properties['label']
or sequential index of the dataset
Returns
-------
int
Sequential index of the dataset [1,2,...,n_datasets]
Sequential index of the dataset from [0,1,...,n_datasets-1]
"""
for (i, dataset) in enumerate(self._datasets):
if dataset.plot_properties['label'] == label:
return i
return -99
if '"' in label:
label = label.strip('"')

try:
ind = int(label)
if 0 <= ind <= len(self._datasets)-1:
return ind
except:
for (i, dataset) in enumerate(self._datasets):

if dataset.plot_properties['label'] == label:
return i
raise KeyError(
"Unrecognized dataset lable in fit_constraints/prior: " + label)

def _read_prior_t_E_data(self):
"""
Expand Down Expand Up @@ -2244,7 +2256,7 @@ def _run_flux_checks_ln_prior(self, fluxes):
if key in self._fit_constraints:

for (i, dataset) in enumerate(self._datasets):
if i+1 in self._fit_constraints[key][1]:
if i in self._fit_constraints[key][1]:
blend_index = ((i+1)*self._n_fluxes_per_dataset) - 1
if fluxes[blend_index] < 0.:
sigma = self._fit_constraints[key][0]
Expand Down

0 comments on commit 71a02fb

Please sign in to comment.