本文整理汇总了Python中pychron.core.helpers.formatting.floatfmt函数的典型用法代码示例。如果您正苦于以下问题:Python floatfmt函数的具体用法?Python floatfmt怎么用?Python floatfmt使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了floatfmt函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _build_label_text
def _build_label_text(self, x, we, n, total_n=None, mswd_args=None, percent_error=False, sig_figs=3):
display_n = True
display_mswd = n >= 2
if display_n:
if total_n and n != total_n:
n = "n= {}/{}".format(n, total_n)
else:
n = "n= {}".format(n)
else:
n = ""
if mswd_args and display_mswd:
mswd, valid_mswd, _ = mswd_args
vd = "" if valid_mswd else "*"
mswd = "{}mswd= {:0.2f}".format(vd, mswd)
else:
mswd = ""
sx = floatfmt(x, sig_figs)
swe = floatfmt(we, sig_figs)
if self.options.index_attr in ("uF", "Ar40/Ar36"):
me = u"{} {}{}".format(sx, PLUSMINUS, swe)
else:
age_units = self._get_age_units()
pe = ""
if percent_error:
pe = "({})".format(format_percent_error(x, we, include_percent_sign=True))
me = u"{} {}{}{} {}".format(sx, PLUSMINUS, swe, pe, age_units)
return u"{} {} {}".format(me, mswd, n)
示例2: _build_label_text
def _build_label_text(self, x, we, mswd, valid_mswd, n,
percent_error=False,
sig_figs=3):
display_n = True
display_mswd = n >= 2
if display_n:
n = 'n= {}'.format(n)
else:
n = ''
if display_mswd:
vd = '' if valid_mswd else '*'
mswd = '{}mswd= {:0.2f}'.format(vd, mswd)
else:
mswd = ''
sx = floatfmt(x, sig_figs)
swe = floatfmt(we, sig_figs)
if self.options.index_attr in ('uF', 'Ar40/Ar36'):
me = '{} +/-{}'.format(sx, swe)
else:
age_units = self._get_age_units()
pe = ''
if percent_error:
pe = '({})'.format(format_percent_error(x, we, include_percent_sign=True))
me = '{} +/-{}{} {}'.format(sx, swe, pe, age_units)
return u'{} {} {}'.format(me, mswd, n)
示例3: _get_discrimination_text
def _get_discrimination_text(self):
ic = self.item.discrimination
if ic is None:
v, e = 1.0, 0
else:
v, e = nominal_value(ic), std_dev(ic)
return '{}+/-{}'.format(floatfmt(v, n=4), floatfmt(e, n=4))
示例4: _load_unknown_computed
def _load_unknown_computed(self, an, new_list):
attrs = (('Age', 'uage_w_j_err'),
# ('Age', 'age', None, None, 'age_err'),
('w/o J', 'wo_j', '', 'uage', 'age_err_wo_j'),
('K/Ca', 'kca'),
('K/Cl', 'kcl'),
('40Ar*', 'rad40_percent'),
('F', 'uF'),
('w/o Irrad', 'wo_irrad', '', 'uF', 'F_err_wo_irrad'))
if new_list:
def comp_factory(n, a, value=None, value_tag=None, error_tag=None):
if value is None:
value = getattr(an, a)
display_value = True
if value_tag:
value = getattr(an, value_tag)
display_value = False
if error_tag:
e = getattr(an, error_tag)
else:
e = std_dev(value)
return ComputedValue(name=n,
tag=a,
value=nominal_value(value) or 0,
value_tag=value_tag or '',
display_value=display_value,
error=e or 0)
cv = [comp_factory(*args)
for args in attrs]
self.computed_values = cv
else:
age = an.uage
nage, sage = nominal_value(age), std_dev(age)
try:
self.summary_str = u'Age={} {}{}({}%)'.format(floatfmt(nage), PLUSMINUS,
floatfmt(sage), format_percent_error(nage, sage))
except:
pass
for ci in self.computed_values:
attr = ci.tag
if attr == 'wo_j':
ci.error = an.age_err_wo_j or 0
ci.value = nominal_value(getattr(an, ci.value_tag))
elif attr == 'wo_irrad':
ci.error = an.F_err_wo_irrad or 0
ci.value = nominal_value(getattr(an, ci.value_tag))
else:
v = getattr(an, attr)
if v is not None:
ci.value = nominal_value(v)
ci.error = std_dev(v)
示例5: _make_flux_row
def _make_flux_row(self, ans):
mR = sum(ai.R for ai in ans) / len(ans)
j, e = calculate_flux(mR, 1, self.monitor_age)
r = Row(fontsize=8)
r.add_item(value='<b>J</b>', span=5)
r.add_item(value='<b>{}</b>'.format(floatfmt(j)))
r.add_item(value='<b>{}</b>'.format(floatfmt(e)))
return r
示例6: calculate_width
def calculate_width(self, txt):
if self.calculated_width is None:
self.calculated_width = self._calculate_label_width()
if isinstance(txt, float):
if self.nsigfigs:
txt = floatfmt(txt, self.nsigfigs, use_scientific=self.use_scientific)
else:
txt = floatfmt(txt)
self.calculated_width = max(self.calculated_width, len(str(txt))+5)
示例7: _update_ratios
def _update_ratios(self, an):
for ci in self.computed_values:
nd = ci.detectors
r = self._get_non_corrected_ratio(nd)
rr, ic = self._get_corrected_ratio(nd)
ci.trait_set(value=floatfmt(rr.nominal_value),
error=floatfmt(rr.std_dev),
noncorrected_value=r.nominal_value,
noncorrected_error=r.std_dev,
ic_factor=nominal_value(ic))
示例8: test_convert_to_scientific
def test_convert_to_scientific(self):
x = 0.001
fx = floatfmt(x, n=2)
self.assertEqual(fx, '1.00E-03')
fx = floatfmt(x, n=2, s=1)
self.assertEqual(fx, '1.0E-03')
x = 0.001
fx = floatfmt(x)
self.assertEqual(fx, '0.0010')
示例9: _permutate
def _permutate(self, ai, record_id, e, ici, prog, i, n):
if prog:
prog.change_message("Setting ic_factor to {}, {}".format(ici, e))
ai.set_ic_factor("CDD", ici, e)
ai.calculate_age(force=True)
r = PermutationRecord()
r.age = ai.uage
r.info_str = "{} (ic={},{})".format(record_id, floatfmt(ici), floatfmt(e))
r.identifier = ai.identifier
return r
示例10: comp_factory
def comp_factory(n, a, value=None, error_tag=None):
if value is None:
aa = getattr(an, a)
value = floatfmt(nominal_value(aa))
if error_tag:
e = getattr(an, error_tag)
else:
e = std_dev(aa)
return ComputedValue(name=n,
tag=a,
value=value,
error=floatfmt(e))
示例11: _get_value
def _get_value(self, attr, n=3, **kw):
v = ""
item = self.item
if hasattr(item, attr):
v = getattr(self.item, attr)
if v:
v = floatfmt(nominal_value(v), n=n, **kw)
elif hasattr(item, "isotopes"):
if attr in item.isotopes:
v = item.isotopes[attr].get_intensity()
v = floatfmt(nominal_value(v), n=n, **kw)
return v
示例12: _air_ratio
def _air_ratio(self):
a4038 = self.isotope_group.get_ratio('Ar40/Ar38', non_ic_corr=True)
a4036 = self.isotope_group.get_ratio('Ar40/Ar36', non_ic_corr=True)
# e4038 = uformat_percent_error(a4038, include_percent_sign=True)
# e4036 = uformat_percent_error(a4036, include_percent_sign=True)
lines = [self._make_header('Ratios'),
'Ar40/Ar36= {} {}'.format(floatfmt(nominal_value(a4036)), errorfmt(nominal_value(a4036),
std_dev(a4036))),
'Ar40/Ar38= {} {}'.format(floatfmt(nominal_value(a4038)), errorfmt(nominal_value(a4038),
std_dev(a4038)))]
return self._make_lines(lines)
示例13: _make_weighted_mean_row
def _make_weighted_mean_row(self, ans):
r = Row(fontsize=8)
ages, errors = zip(*[(ai.age.nominal_value, ai.age.std_dev)
for ai in ans])
wm, we = calculate_weighted_mean(ages, errors)
r.add_item(value='<b>weighted mean</b>', span=2)
r.add_blank_item(3)
r.add_item(value='<b>{}</b>'.format(floatfmt(wm)))
r.add_item(value=u'<b>\u00b1{}</b>'.format(floatfmt(we)))
return r
示例14: _update_ratios
def _update_ratios(self, an):
for ci in self.computed_values:
nd = ci.detectors
n, d = nd.split('/')
niso, diso = self._get_isotope(n), self._get_isotope(d)
noncorrected = self._get_non_corrected_ratio(niso, diso)
corrected, ic = self._get_corrected_ratio(niso, diso)
ci.trait_set(value=floatfmt(nominal_value(corrected)),
error=floatfmt(std_dev(corrected)),
noncorrected_value=nominal_value(noncorrected),
noncorrected_error=std_dev(noncorrected),
ic_factor=nominal_value(ic))
示例15: load_measurement
def load_measurement(self, an, ar):
# j = self._get_j(an)
j = ar.j
jf = 'NaN'
if j is not None:
jj = floatfmt(nominal_value(j), n=7, s=5)
pe = format_percent_error(nominal_value(j), std_dev(j), include_percent_sign=True)
jf = u'{} \u00b1{:0.2e}({})'.format(jj, std_dev(j), pe)
a39 = ar.ar39decayfactor
a37 = ar.ar37decayfactor
ms = [MeasurementValue(name='Branch',
value=an.branch),
MeasurementValue(name='DAQ Version',
value=an.collection_version),
MeasurementValue(name='UUID',
value=an.uuid),
MeasurementValue(name='RepositoryID',
value=an.repository_identifier),
MeasurementValue(name='Spectrometer',
value=an.mass_spectrometer),
MeasurementValue(name='Run Date',
value=an.rundate.strftime('%Y-%m-%d %H:%M:%S')),
MeasurementValue(name='Irradiation',
value=self._get_irradiation(an)),
MeasurementValue(name='J',
value=jf),
MeasurementValue(name='Position Error',
value=floatfmt(an.position_jerr, use_scientific=True)),
MeasurementValue(name='Lambda K',
value=nominal_value(ar.arar_constants.lambda_k),
units='1/a'),
MeasurementValue(name='Project',
value=an.project),
MeasurementValue(name='Sample',
value=an.sample),
MeasurementValue(name='Material',
value=an.material),
MeasurementValue(name='Comment',
value=an.comment),
MeasurementValue(name='Ar39Decay',
value=floatfmt(a39)),
MeasurementValue(name='Ar37Decay',
value=floatfmt(a37)),
MeasurementValue(name='Sens.',
value=floatfmt(an.sensitivity, use_scientific=True),
units=an.sensitivity_units)]
self.measurement_values = ms