How to use the uncertainties.ufloat function in uncertainties

To help you get started, we’ve selected a few uncertainties examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github xraypy / xraylarch / lib / fitting / uncertainties / test_uncertainties.py View on Github external
def test_copy():
    "Standard copy module integration"
    import gc

    x = ufloat((3, 0.1))
    assert x == x

    y = copy.copy(x)
    assert x != y
    assert not(x == y)
    assert y in y.derivatives.keys()  # y must not copy the dependence on x

    z = copy.deepcopy(x)
    assert x != z

    # Copy tests on expressions:
    t = x + 2*z
    # t depends on x:
    assert x in t.derivatives

    # The relationship between the copy of an expression and the
github NMGRL / pychron / test / experiment / peak_hop.py View on Github external
def setUpClass(cls):
        aspec = AutomatedRunSpec()
        aspec.mass_spectrometer = 'jan'
        aspec.labnumber = '17005'
        aspec.aliquot = 95

        a = AutomatedRun()
        a.script_info.measurement_script_name = 'unknown_peak_hop'
        s = ArgusSpectrometerManager()
        ion = IonOpticsManager(spectrometer=s.spectrometer)

        s.load(db_mol_weights=False)
        a.spectrometer_manager = s
        a.ion_optics_manager = ion
        a.arar_age = ArArAge()
        a.arar_age.j=ufloat(0.001, 1e-6)

        a._alive = True
        a.uuid = '12345-ABCDE'

        a.spec = aspec
        a._measured = True
        a._save_enabled = True

        cls.arun = a
github NMGRL / pychron / pychron / processing / arar_age.py View on Github external
k = self.get_computed_value('k39')
        cl = self.get_non_ar_isotope('cl38')

        prs = self.production_ratios
        k_cl_pr = 1
        if prs:
            clk = prs.get('Cl_K', 1)
            if not clk:
                clk = 1.0

            k_cl_pr = 1 / clk
        try:
            self.kcl = k / cl * k_cl_pr
            self.clk = 1 / self.kcl
        except ZeroDivisionError:
            self.kcl = ufloat(0, 0)
            if not self._kcl_warning:
                self._kcl_warning = True
                self.warning("cl38 is zero. can't calculated k/cl")
github NMGRL / pychron / standalone_age_calculator.py View on Github external
try:
        R = ar40rad / k39
        # dont include error in decay constant
        age = age_equation(j, R, include_decay_error=include_decay_error, constants=constants)
        #        age = age_equation(j, R)
        age_with_jerr = deepcopy(age)

        # dont include error in decay constant
        j.set_std_dev(0)
        age = age_equation(j, R, include_decay_error=include_decay_error, constants=constants)
        #        age = age_equation(j, R)
        age_wo_jerr = deepcopy(age)

    except (ZeroDivisionError, ValueError), e:
        print e
        age = ufloat(0, 0)
        age_wo_jerr = ufloat(0, 0)

    #    print s40 / s36
    result = dict(
        age=age_with_jerr,
        age_err_wo_j=age_wo_jerr.std_dev,
        rad40=ar40rad,

        k39=k39,
        ca37=ca37,
        atm36=atm36,
        cl36=cl36,

        s40=s40,
        s39=s39,
        s38=s38,
github NMGRL / pychron / standalone_age_calculator.py View on Github external
#    if isinstance(blanks[0], tuple):
    s40bl, s39bl, s38bl, s37bl, s36bl = map(to_ufloat, blanks)

    #    if isinstance(backgrounds[0], tuple):
    s40bk, s39bk, s38bk, s37bk, s36bk = map(to_ufloat, backgrounds)

    k4039, k3839, k3739, ca3937, ca3837, ca3637, cl3638, chronology_segments, decay_time = irradinfo

    ca3637 = ufloat(ca3637)
    ca3937 = ufloat(ca3937)
    ca3837 = ufloat(ca3837)
    k4039 = ufloat(k4039)
    k3839 = ufloat(k3839)
    cl3638 = ufloat(cl3638)
    k3739 = ufloat(k3739)
    ic = ufloat(ic)
    j = ufloat(j)
    #    temp_ic = ufloat(ic)

    #===============================================================================
    #
    #===============================================================================

    # subtract blanks and baselines (and backgrounds)
    s40 -= (s40bl + s40bs + s40bk)
    s39 -= (s39bl + s39bs + s39bk)
    s38 -= (s38bl + s38bs + s38bk)
    s37 -= (s37bl + s37bs + s37bk)
    s36 -= (s36bl + s36bs + s36bk)

    # apply intercalibration factor to corrected 36
    s36 *= ic
github NMGRL / pychron / standalone_age_calculator.py View on Github external
cl38 = s38 - ar38atm - k38 - ca38
        cl36 = cl38 * m
        atm36 = s36 - ca36 - cl36

        # calculate rodiogenic
        # dont include error in 40/36

    #    pc = sc.node('pychron').node('experiment')
    #    print pc
    #    print pc.get('constants')
    #    print pc.node_names()
    atm40 = atm36 * constants.atm4036.nominal_value
    k40 = k39 * k4039
    ar40rad = s40 - atm40 - k40

    age_with_jerr = ufloat(0, 0)
    age_wo_jerr = ufloat(0, 0)
    try:
        R = ar40rad / k39
        # dont include error in decay constant
        age = age_equation(j, R, include_decay_error=include_decay_error, constants=constants)
        #        age = age_equation(j, R)
        age_with_jerr = deepcopy(age)

        # dont include error in decay constant
        j.set_std_dev(0)
        age = age_equation(j, R, include_decay_error=include_decay_error, constants=constants)
        #        age = age_equation(j, R)
        age_wo_jerr = deepcopy(age)

    except (ZeroDivisionError, ValueError), e:
        print e
github NMGRL / pychron / pychron / processing / xml / primitives.py View on Github external
def _make_ufloat(self, meas_elem, key):
        return ufloat(meas_elem.get(key), meas_elem.get('{}Sigma'.format(key)))
github NMGRL / pychron / pychron / pipeline / tables / xlsx_table_writer.py View on Github external
pmsigma = PLUSMINUS_NSIGMA.format(nsigma)
            pv = group.get_preferred_obj('kca')

            kind = pv.kind
            if 'integrated' in kind.lower():
                label = 'Integrated'
            else:
                label = kind.capitalize()

            sh.write_string(self._current_row, start_col,
                            u'{} {} {}'.format(label, kcalabel, pmsigma),
                            fmt)

            v, e = pv.value, pv.error
            if self._options.invert_kca_kcl:
                u = 1 / ufloat(v, e)
                v, e = nominal_value(u), std_dev(u)

            sh.write_number(self._current_row, idx, v, nfmt)
            sh.write_number(self._current_row, idx + 1, e * nsigma, nfmt)
            sh.write_string(self._current_row, idx + 2, pv.error_kind, fmt)
            self._current_row += 1

        nfmt = self._get_number_format('summary_age')
        nfmt.set_bold(True)

        idx = next((i for i, c in enumerate(cols) if c.label == 'Age'))

        k2o_idx, k2o_col = next((c for c in enumerate(cols) if c[1].attr == 'display_k2o'))
        nsigma = self._options.asummary_age_nsigma
        pmsigma = PLUSMINUS_NSIGMA.format(nsigma)
github joferkington / oost_paper_code / shortening_calculations.py View on Github external
def plate_motion():
    """
    Plate motion rate (forearc relative to oceanic plate) _parallel_ _to_
    _section_ (Not full plate vector!) based on elastic block modeling 
    (Loveless&Meade, 2010).

    Returns:
    --------
        rate : A ufloat in mm/yr with a 2 sigma error
    """
    # See /data/MyCode/VariousJunk/loveless_meade_block_model_slip_vector.py
    # for details of derivation... Uses block segment nearest study area instead
    # of derived euler pole.
    # I'm assuming that Loveless's reported errors are 2 sigma...
    section_parallel_rate = ufloat(42.9, 2.1)
    return section_parallel_rate
github captain-exoplanet / misttborn / misttbornplotter.py View on Github external
f.write('Measured Parameters \\\ \n')

    for i in range (0,ndim):
        if str(k+1) in inposindex[i] and not 'gamma' in inposindex[i] and not 'q' in inposindex[i] and not 'jitter' in inposindex[i] and not 'dilution' in inposindex[i]:
            v=np.nanpercentile(samples[:,i], [16, 50, 84], axis=0)
            temp=[v[1], v[2]-v[1], v[1]-v[0]]
            if not args.bestprob:
                inpos[i]=temp[0]
            else:
                inpos[i]=samples[best,i]
            f.write(symdex(inposindex[i],args,exstruc)+' & '+schar1+parstring(temp)+schar2+' \\\ \n')

            if args.relpars:
                if 'rprs' in inposindex[i]: rprsp, rprsm = ufloat(temp[0],temp[1]), ufloat(temp[0],temp[2])
                if 'semiamp' in inposindex[i]: Kp, Km = ufloat(temp[0],temp[1]), ufloat(temp[0],temp[2])
                if 'aors' in inposindex[i]: aorsp, aorsm = ufloat(temp[0],temp[1]), ufloat(temp[0],temp[2])
                if 'Per' in inposindex[i]: Pdp, Pdm = ufloat(temp[0],temp[1]), ufloat(temp[0],temp[2])
        elif 'gamma' in inposindex[i] or (('g' in inposindex[i] or 'q' in inposindex[i]) and ('p' in inposindex[i] or 't' in inposindex[i])) or 'rvtrend' in inposindex[i] or 'jitter' in inposindex[i] or 'fluxrat' in inposindex[i] or 'dilution' in inposindex[i] or 'vsini' in inposindex[i] or 'intwidth' in inposindex[i]:
            v=np.nanpercentile(samples[:,i], [16, 50, 84], axis=0)
            temp=[v[1], v[2]-v[1], v[1]-v[0]]
            inpos[i]=temp[0]
            f.write(symdex(inposindex[i],args,exstruc)+' & '+schar1+parstring(temp)+schar2+' \\\ \n')
        
            
            

    f.write('\hline \n')
    f.write('Derived Parameters \\\ \n')


    bstr='bpar'+str(k+1)
    rstr='rprs'+str(k+1)