exchange value by factor and scale in Parameter
@@ -23,10 +23,12 @@ class Parameter(object):
----------
name : str
Name
- value : float or `~astropy.units.Quantity`
- Value
+ factor : float or `~astropy.units.Quantity`
+ Factor
unit : str, optional
Unit
+ scale : float, optional
+ Scale
min : float, optional
Minimum (sometimes used in fitting)
max : float, optional
@@ -34,16 +36,18 @@ class Parameter(object):
frozen : bool, optional
Frozen? (used in fitting)
"""
- __slots__ = ['_name', '_value', '_unit', '_min', '_max', '_frozen']
+ __slots__ = ['_name', '_factor', '_unit', '_scale', '_min', '_max', '_frozen']
- def __init__(self, name, value, unit='', min=np.nan, max=np.nan, frozen=False):
+ def __init__(self, name, factor, unit='', scale=1, min=np.nan, max=np.nan,
+ frozen=False):
self.name = name
- if isinstance(value, u.Quantity) or isinstance(value, six.string_types):
+ if isinstance(factor, u.Quantity) or isinstance(factor, six.string_types):
self.quantity = value
else:
- self.value = value
+ self.factor = factor
self.unit = unit
+ self.scale = scale
self.min = min
self.max = max
@@ -58,12 +62,12 @@ class Parameter(object):
self._name = str(val)
@property
- def value(self):
- return self._value
+ def factor(self):
+ return self._factor
- @value.setter
- def value(self, val):
- self._value = float(val)
+ @factor.setter
+ def factor(self, val):
+ self._factor = float(val)
@property
def unit(self):
@@ -73,6 +77,14 @@ class Parameter(object):
def unit(self, val):
self._unit = str(val)
+ @property
+ def scale(self):
+ return self._scale
+
+ @scale.setter
+ def scale(self, val):
+ self._scale = float(val)
+
@property
def min(self):
return self._min
@@ -97,6 +109,15 @@ class Parameter(object):
def frozen(self, val):
self._frozen = bool(val)
+ @property
+ def value(self):
+ return self._factor * self._scale
+
+ @value.setter
+ def value(self, val):
+ self._factor = float(val)
+ self._scale = 1
+
@property
def quantity(self):
return self.value * u.Unit(self.unit)
@@ -104,7 +125,8 @@ class Parameter(object):
@quantity.setter
def quantity(self, par):
par = u.Quantity(par)
- self.value = par.value
+ self.factor = par.value
+ self.scale = 1
self.unit = str(par.unit)
def __repr__(self):
