You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
AttributeError Traceback (most recent call last)
File ~/AltaiPony/lib/python3.9/site-packages/astropy/units/quantity.py:1653, in Quantity._to_own_unit(self, value, check_precision, unit)
1652 try:
-> 1653 _value = value.to_value(unit)
1654 except AttributeError:
1655 # We're not a Quantity.
1656 # First remove two special cases (with a fast test):
1657 # 1) Maybe masked printing? MaskedArray with quantities does not
1658 # work very well, but no reason to break even repr and str.
1659 # 2) np.ma.masked? useful if we're a MaskedQuantity.
AttributeError: 'int' object has no attribute 'to_value'
During handling of the above exception, another exception occurred:
File ~/AltaiPony/lib/python3.9/site-packages/astropy/units/core.py:1159, in UnitBase._to(self, other)
1157 return self_decomposed.scale / other_decomposed.scale
-> 1159 raise UnitConversionError(f"'{self!r}' is not a scaled version of '{other!r}'")
UnitConversionError: 'Unit(dimensionless)' is not a scaled version of 'Unit("electron / s")'
During handling of the above exception, another exception occurred:
File ~/AltaiPony/lib/python3.9/site-packages/altaipony/altai.py:162, in find_flares(flc, minsep, sigma, **kwargs)
159 # run final flare-find on DATA - MODEL
161 if sigma is None:
--> 162 isflare = find_flares_in_cont_obs_period(flux, median, error, **kwargs)
163 else:
164 isflare = find_flares_in_cont_obs_period(flux, median, error, sigma=sigma[le:ri], **kwargs)
File ~/AltaiPony/lib/python3.9/site-packages/altaipony/altai.py:75, in find_flares_in_cont_obs_period(flux, median, error, sigma, N1, N2, N3, addtail, tailthreshdiff)
73 #array of indices where thresholds are exceeded:
74 is_pass_thresholds = np.zeros_like(flux)
---> 75 is_pass_thresholds[pass_thresholds] = 1
77 # Need to find cumulative number of points that pass_thresholds
78 # Counted in reverse!
79 # Examples reverse_counts = [0 0 0 3 2 1 0 0 1 0 4 3 2 1 0 0 0 1 0 2 1 0]
80 # isflare = [0 0 0 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 0 0 0 0]
82 reverse_counts = np.zeros_like(flux, dtype='int')
File ~/AltaiPony/lib/python3.9/site-packages/astropy/units/quantity.py:1326, in Quantity.setitem(self, i, value)
1324 if not self.isscalar and "info" in self.dict:
1325 self.info.adjust_indices(i, value, len(self))
-> 1326 self.view(np.ndarray).setitem(i, self._to_own_unit(value))
File ~/AltaiPony/lib/python3.9/site-packages/astropy/units/quantity.py:1669, in Quantity._to_own_unit(self, value, check_precision, unit)
1667 try:
1668 as_quantity = Quantity(value)
-> 1669 _value = as_quantity.to_value(unit)
1670 except UnitsError:
1671 # last chance: if this was not something with a unit
1672 # and is all 0, inf, or nan, we treat it as arbitrary unit.
1673 if not hasattr(value, "unit") and can_have_arbitrary_unit(
1674 as_quantity.value
1675 ):
File ~/AltaiPony/lib/python3.9/site-packages/astropy/units/quantity.py:985, in Quantity.to_value(self, unit, equivalencies)
982 scale = self.unit._to(unit)
983 except Exception:
984 # Short-cut failed; try default (maybe equivalencies help).
--> 985 value = self._to_value(unit, equivalencies)
986 else:
987 value = self.view(np.ndarray)
File ~/AltaiPony/lib/python3.9/site-packages/astropy/units/quantity.py:891, in Quantity._to_value(self, unit, equivalencies)
888 equivalencies = self._equivalencies
889 if not self.dtype.names or isinstance(self.unit, StructuredUnit):
890 # Standard path, let unit to do work.
--> 891 return self.unit.to(
892 unit, self.view(np.ndarray), equivalencies=equivalencies
893 )
895 else:
896 # The .to() method of a simple unit cannot convert a structured
897 # dtype, so we work around it, by recursing.
898 # TODO: deprecate this?
899 # Convert simple to Structured on initialization?
900 result = np.empty_like(self.view(np.ndarray))
File ~/AltaiPony/lib/python3.9/site-packages/astropy/units/core.py:1107, in UnitBase._get_converter(self, other, equivalencies)
1105 # if that doesn't work, maybe we can do it with equivalencies?
1106 try:
-> 1107 return self._apply_equivalencies(
1108 self, other, self._normalize_equivalencies(equivalencies)
1109 )
1110 except UnitsError as exc:
1111 # Last hope: maybe other knows how to do it?
1112 # We assume the equivalencies have the unit itself as first item.
1113 # TODO: maybe better for other to have a _back_converter method?
1114 if hasattr(other, "equivalencies"):
File ~/AltaiPony/lib/python3.9/site-packages/astropy/units/core.py:1085, in UnitBase._apply_equivalencies(self, unit, other, equivalencies)
1082 unit_str = get_err_str(unit)
1083 other_str = get_err_str(other)
-> 1085 raise UnitConversionError(f"{unit_str} and {other_str} are not convertible")
UnitConversionError: '' (dimensionless) and 'electron / s' are not convertible
is there any workaround or solution to this. Thanks.
The text was updated successfully, but these errors were encountered:
sam687
changed the title
AttributeError: 'int' object has no attribute 'to_value'
AttributeError: 'int' object has no attribute 'to_value' and UnitConversionError: '' (dimensionless) and 'electron / s' are not convertible
May 14, 2024
Hii,
I am getting this error while running the following code.
flc.detrended_flux = flc.flux
flc.detrended_flux_err = flc.flux_err
flc = flc.find_flares()
flc.flares.sort_values(by="ed_rec", ascending=False)
python==3.9.x
astropy=5.3.1
AttributeError Traceback (most recent call last)
File ~/AltaiPony/lib/python3.9/site-packages/astropy/units/quantity.py:1653, in Quantity._to_own_unit(self, value, check_precision, unit)
1652 try:
-> 1653 _value = value.to_value(unit)
1654 except AttributeError:
1655 # We're not a Quantity.
1656 # First remove two special cases (with a fast test):
1657 # 1) Maybe masked printing? MaskedArray with quantities does not
1658 # work very well, but no reason to break even repr and str.
1659 # 2) np.ma.masked? useful if we're a MaskedQuantity.
AttributeError: 'int' object has no attribute 'to_value'
During handling of the above exception, another exception occurred:
UnitConversionError Traceback (most recent call last)
File ~/AltaiPony/lib/python3.9/site-packages/astropy/units/quantity.py:982, in Quantity.to_value(self, unit, equivalencies)
981 try:
--> 982 scale = self.unit._to(unit)
983 except Exception:
984 # Short-cut failed; try default (maybe equivalencies help).
File ~/AltaiPony/lib/python3.9/site-packages/astropy/units/core.py:1159, in UnitBase._to(self, other)
1157 return self_decomposed.scale / other_decomposed.scale
-> 1159 raise UnitConversionError(f"'{self!r}' is not a scaled version of '{other!r}'")
UnitConversionError: 'Unit(dimensionless)' is not a scaled version of 'Unit("electron / s")'
During handling of the above exception, another exception occurred:
UnitConversionError Traceback (most recent call last)
Cell In[8], line 3
1 flc.detrended_flux = flc.flux
2 flc.detrended_flux_err = flc.flux_err
----> 3 flc = flc.find_flares()
4 flc.flares.sort_values(by="ed_rec", ascending=False)
File ~/AltaiPony/lib/python3.9/site-packages/altaipony/flarelc.py:453, in FlareLightCurve.find_flares(self, minsep, fake, **kwargs)
451 lc = find_iterative_median(lc)
452 #find flares
--> 453 lc = find_flares(lc, minsep=minsep, **kwargs)
455 return lc
File ~/AltaiPony/lib/python3.9/site-packages/altaipony/altai.py:162, in find_flares(flc, minsep, sigma, **kwargs)
159 # run final flare-find on DATA - MODEL
161 if sigma is None:
--> 162 isflare = find_flares_in_cont_obs_period(flux, median, error, **kwargs)
163 else:
164 isflare = find_flares_in_cont_obs_period(flux, median, error, sigma=sigma[le:ri], **kwargs)
File ~/AltaiPony/lib/python3.9/site-packages/altaipony/altai.py:75, in find_flares_in_cont_obs_period(flux, median, error, sigma, N1, N2, N3, addtail, tailthreshdiff)
73 #array of indices where thresholds are exceeded:
74 is_pass_thresholds = np.zeros_like(flux)
---> 75 is_pass_thresholds[pass_thresholds] = 1
77 # Need to find cumulative number of points that pass_thresholds
78 # Counted in reverse!
79 # Examples reverse_counts = [0 0 0 3 2 1 0 0 1 0 4 3 2 1 0 0 0 1 0 2 1 0]
80 # isflare = [0 0 0 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 0 0 0 0]
82 reverse_counts = np.zeros_like(flux, dtype='int')
File ~/AltaiPony/lib/python3.9/site-packages/astropy/units/quantity.py:1326, in Quantity.setitem(self, i, value)
1324 if not self.isscalar and "info" in self.dict:
1325 self.info.adjust_indices(i, value, len(self))
-> 1326 self.view(np.ndarray).setitem(i, self._to_own_unit(value))
File ~/AltaiPony/lib/python3.9/site-packages/astropy/units/quantity.py:1669, in Quantity._to_own_unit(self, value, check_precision, unit)
1667 try:
1668 as_quantity = Quantity(value)
-> 1669 _value = as_quantity.to_value(unit)
1670 except UnitsError:
1671 # last chance: if this was not something with a unit
1672 # and is all 0, inf, or nan, we treat it as arbitrary unit.
1673 if not hasattr(value, "unit") and can_have_arbitrary_unit(
1674 as_quantity.value
1675 ):
File ~/AltaiPony/lib/python3.9/site-packages/astropy/units/quantity.py:985, in Quantity.to_value(self, unit, equivalencies)
982 scale = self.unit._to(unit)
983 except Exception:
984 # Short-cut failed; try default (maybe equivalencies help).
--> 985 value = self._to_value(unit, equivalencies)
986 else:
987 value = self.view(np.ndarray)
File ~/AltaiPony/lib/python3.9/site-packages/astropy/units/quantity.py:891, in Quantity._to_value(self, unit, equivalencies)
888 equivalencies = self._equivalencies
889 if not self.dtype.names or isinstance(self.unit, StructuredUnit):
890 # Standard path, let unit to do work.
--> 891 return self.unit.to(
892 unit, self.view(np.ndarray), equivalencies=equivalencies
893 )
895 else:
896 # The .to() method of a simple unit cannot convert a structured
897 # dtype, so we work around it, by recursing.
898 # TODO: deprecate this?
899 # Convert simple to Structured on initialization?
900 result = np.empty_like(self.view(np.ndarray))
File ~/AltaiPony/lib/python3.9/site-packages/astropy/units/core.py:1195, in UnitBase.to(self, other, value, equivalencies)
1193 return UNITY
1194 else:
-> 1195 return self._get_converter(Unit(other), equivalencies)(value)
File ~/AltaiPony/lib/python3.9/site-packages/astropy/units/core.py:1124, in UnitBase._get_converter(self, other, equivalencies)
1121 else:
1122 return lambda v: b(converter(v))
-> 1124 raise exc
File ~/AltaiPony/lib/python3.9/site-packages/astropy/units/core.py:1107, in UnitBase._get_converter(self, other, equivalencies)
1105 # if that doesn't work, maybe we can do it with equivalencies?
1106 try:
-> 1107 return self._apply_equivalencies(
1108 self, other, self._normalize_equivalencies(equivalencies)
1109 )
1110 except UnitsError as exc:
1111 # Last hope: maybe other knows how to do it?
1112 # We assume the equivalencies have the unit itself as first item.
1113 # TODO: maybe better for other to have a
_back_converter
method?1114 if hasattr(other, "equivalencies"):
File ~/AltaiPony/lib/python3.9/site-packages/astropy/units/core.py:1085, in UnitBase._apply_equivalencies(self, unit, other, equivalencies)
1082 unit_str = get_err_str(unit)
1083 other_str = get_err_str(other)
-> 1085 raise UnitConversionError(f"{unit_str} and {other_str} are not convertible")
UnitConversionError: '' (dimensionless) and 'electron / s' are not convertible
is there any workaround or solution to this. Thanks.
The text was updated successfully, but these errors were encountered: