Skip to content

Commit

Permalink
Added Warning for previously set rescale_parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
JasperMartins committed Jan 21, 2025
1 parent 60d7be1 commit 6c1bd66
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions bilby/core/prior/joint.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,18 +332,18 @@ def rescale(self, value, **kwargs):
"""
if value is None:
samp = np.array(list(self._current_unit_cube_parameter_values.values())).T
if len(samp.shape) == 1:
samp = samp.reshape(1, self.num_vars)
else:
for key, val in zip(self.names, value):
self.set_rescale(key, val)
samp = np.asarray(value)

if len(samp.shape) == 1:
samp = samp.reshape(1, self.num_vars)

if len(samp.shape) != 2:
raise ValueError("Array is the wrong shape")
elif samp.shape[1] != self.num_vars:
raise ValueError("Array is the wrong shape")
if len(samp.shape) == 1:
samp = samp.reshape(1, self.num_vars)
if len(samp.shape) != 2:
raise ValueError("Array is the wrong shape")
elif samp.shape[1] != self.num_vars:
raise ValueError("Array is the wrong shape")
for key, val in zip(self.names, samp.T):
self.set_rescale(key, val)

samp = self._rescale(samp, **kwargs)
for i, key in enumerate(self.names):
Expand Down Expand Up @@ -821,6 +821,18 @@ def rescale(self, val, **kwargs):
the rescaled value once all parameters have been requested
"""

if self.dist.get_rescaled(self.name) is not None:
import warnings
warnings.warn(
f"Rescale values for {self.name} in {self.dist} have already been set, "
"indicating that another rescale-operation is in progress.\n"
"Call dist.reset_rescale() on the joint prior distribution associated "
"with this prior after using dist.rescale() and make sure all parameters "
"necessary for rescaling have been requested in PriorDict.rescale().\n"
"Resetting now.",
RuntimeWarning
)
self.dist.reset_rescale()
self.dist.set_rescale(self.name, val)

if self.dist.filled_rescale():
Expand Down

0 comments on commit 6c1bd66

Please sign in to comment.