Beispiel #1
0
 def change_exp(self, evt):
     dat = self.data
     alt_i = dat.get("alt I")
     exp = dat["data"].get("Exp. data")
     if exp is None or alt_i is None:
         return
     rv = v_input(dat["window"], _("Believe factor"),
                  (_("The visible part only"), False),
                  (_("Believe factor:"), dat["eic_bf"]))
     if rv is None:
         return
     ov, bf = rv
     dat["eic_bf"] = bf
     if ov:
         if dat["plot"].get_cur_key() != PN_AIC:
             return
         beg, end = dat["plot"].axes1.get_xbound()
         ib, ie = sqc.get_from_to(exp.x_data, beg, end)
         chy = exp.y_data[ib:ie]
         sqc.change_curve(chy, alt_i[ib:ie], bf)
         exp.y_data[ib:ie] = chy
     else:
         sqc.change_curve(exp.y_data, alt_i, bf)
     from v_plot import plot_exp_data
     plot_exp_data(dat["plot"], exp, dat["menu"])
     dat.pop("alt I")
     dat["menu"].action_catch("exp I changed")
Beispiel #2
0
 def rft_calc(self, evt):
     "changes experimental intensity"
     dat = self.data
     rdf = dat.get("RDFd")
     if rdf is None:
         return
     strt = _("Start:"), dat["rft_start"]
     end = _("End:"), rdf.get("tail_s", dat["rft_end"])
     rang = _("Steps:"), dat["rft_steps"], 100, 100000
     refur = v_input(dat["window"], _("RFT params"), strt, end, rang)
     if refur is None:
         return
     q = rdf["q"]
     strt, end, rang = refur
     dat["rft_start"], dat["rft_end"], dat["rft_steps"] = strt, end, rang
     rarr = np.linspace(strt, end, rang)
     gr = sqc.calc_gr_arr(rarr, **rdf)
     q2 = np.linspace(q[0], q[-1], len(q) * 10)
     sq2 = sqc.calc_rft_arr(q2, rarr, gr, **rdf)
     dat["data"]["RFT sq"] = sqc.calc_rft_arr(q, rarr, gr, **rdf)
     pld = dat["plot"].set_data(
         PN_RFT, [(q, rdf["sq"], 1, None, "o"), (q2, sq2, 1)],
         r"$q,\,\AA^{-1}$", "s(q)", "A^{-1}")
     pld.discards.update(("liq samp", "sq found", "sq changed"))
     pld.journal.set_parent(dat["plot"].get_data(PN_RDF).journal)
     pld.journal.log("Reverse Fourier Transform")
     dat["menu"].action_catch("RFT made")
     dat["plot"].plot_dataset(PN_RFT)
Beispiel #3
0
 def sq_tail(self, evt):
     dat = self.data
     if "SSF" not in dat["data"]:
         return
     q, sq, sqd = dat["data"]["SSF"][:3]
     if "SQ point" in dat:
         tail = len(q) - dat["SQ point"]
     else:
         tail = sqd.get("tail", {"points": 4})["points"]
     if tail < 4:
         tail = 4
     a, b, c, d = sqd.get("tail", {"coefs": [1., 2., 1., .1]})["coefs"]
     if d < .1:
         d = .1
     tail = _("Points:"), tail, 4, len(q)
     a = "a:", float(a)
     b = "b:", float(b)
     c = "c:", float(c)
     d = "d:", float(d)
     rv = v_input(dat["window"], _("Tail init params"), tail, a, b, c, d)
     if rv is None:
         return
     tail, a, b, c, d = rv
     lmn = sqd["Elements"]
     prevc = a, b, c, d
     coefs = sqc.sq_tail(q[-tail:], sq[-tail:], lmn, prevc)
     sqd["tail"] = {"coefs": coefs, "points": tail}
     plot_sq(dat, q, sq, sqd)
     dat["menu"].action_catch("SF tail found")
Beispiel #4
0
 def rft_calc(self, evt):
     "changes experimental intensity"
     dat = self.data
     rdf = dat.get("RDFd")
     if rdf is None:
         return
     strt = _("Start:"), dat["rft_start"]
     end = _("End:"), rdf.get("tail_s", dat["rft_end"])
     rang = _("Steps:"), dat["rft_steps"], 100, 100000
     refur = v_input(dat["window"], _("RFT params"), strt, end, rang)
     if refur is None:
         return
     q = rdf["q"]
     strt, end, rang = refur
     dat["rft_start"], dat["rft_end"], dat["rft_steps"] = strt, end, rang
     rarr = np.linspace(strt, end, rang)
     gr = sqc.calc_gr_arr(rarr, **rdf)
     q2 = np.linspace(q[0], q[-1], len(q) * 10)
     sq2 = sqc.calc_rft_arr(q2, rarr, gr, **rdf)
     dat["data"]["RFT sq"] = sqc.calc_rft_arr(q, rarr, gr, **rdf)
     pld = dat["plot"].set_data(PN_RFT, [(q, rdf["sq"], 1, None, "o"),
                                         (q2, sq2, 1)], r"$q,\,\AA^{-1}$",
                                "s(q)", "A^{-1}")
     pld.discards.update(("liq samp", "sq found", "sq changed"))
     pld.journal.set_parent(dat["plot"].get_data(PN_RDF).journal)
     pld.journal.log("Reverse Fourier Transform")
     dat["menu"].action_catch("RFT made")
     dat["plot"].plot_dataset(PN_RFT)
Beispiel #5
0
 def change_exp(self, evt):
     dat = self.data
     alt_i = dat.get("alt I")
     exp = dat["data"].get("Exp. data")
     if exp is None or alt_i is None:
         return
     rv = v_input(dat["window"], _("Believe factor"),
                  (_("The visible part only"), False),
                  (_("Believe factor:"), dat["eic_bf"]))
     if rv is None:
         return
     ov, bf = rv
     dat["eic_bf"] = bf
     if ov:
         if dat["plot"].get_cur_key() != PN_AIC:
             return
         beg, end = dat["plot"].axes1.get_xbound()
         ib, ie = sqc.get_from_to(exp.x_data, beg, end)
         chy = exp.y_data[ib:ie]
         sqc.change_curve(chy, alt_i[ib:ie], bf)
         exp.y_data[ib:ie] = chy
     else:
         sqc.change_curve(exp.y_data, alt_i, bf)
     from v_plot import plot_exp_data
     plot_exp_data(dat["plot"], exp, dat["menu"])
     dat.pop("alt I")
     dat["menu"].action_catch("exp I changed")
Beispiel #6
0
 def sq_head(self, evt):
     dat = self.data
     if "SSF" not in dat["data"]:
         return
     q, sq, sqd = dat["data"]["SSF"][:3]
     if "SQ point" not in dat:
         head = int(sq.argmax() + 1)
     else:
         head = dat["SQ point"] + 1
     diam = 2.
     dens = float(dat["data"]["Exp. data"].rho0)
     rv = v_input(dat["window"], _("Head init. params"),
                  (_("Points:"), head, 3, len(q)), (_("Diam:"), diam),
                  (_("Dens:"), dens))
     if rv is None:
         return
     head, diam, dens = rv
     diam, dens = sqc.calc_hs_head(diam, dens, q[:head], sq[:head])
     sqd["head"] = {
         "diam": diam,
         "dens": dens,
         "points": head,
         "S(0)": sqc.calc_hs_s0(diam, dens)
     }
     plot_sq(dat, q, sq, sqd)
     dat["menu"].action_catch("SF head found")
Beispiel #7
0
 def sq_tail(self, evt):
     dat = self.data
     if "SSF" not in dat["data"]:
         return
     q, sq, sqd = dat["data"]["SSF"][:3]
     if "SQ point" in dat:
         tail = len(q) - dat["SQ point"]
     else:
         tail = sqd.get("tail", {"points": 4})["points"]
     if tail < 4:
         tail = 4
     a, b, c, d = sqd.get("tail", {"coefs": [1., 2., 1., .1]})["coefs"]
     if d < .1:
         d = .1
     tail = _("Points:"), tail, 4, len(q)
     a = "a:", float(a)
     b = "b:", float(b)
     c = "c:", float(c)
     d = "d:", float(d)
     rv = v_input(dat["window"], _("Tail init params"), tail, a, b, c, d)
     if rv is None:
         return
     tail, a, b, c, d = rv
     lmn = sqd["Elements"]
     prevc = a, b, c, d
     coefs = sqc.sq_tail(q[-tail:], sq[-tail:], lmn, prevc)
     sqd["tail"] = {"coefs": coefs, "points": tail}
     plot_sq(dat, q, sq, sqd)
     dat["menu"].action_catch("SF tail found")
Beispiel #8
0
 def calc_s0(self, evt):
     if not self.Validate():
         return
     internal = self.internal
     diam = internal.get("diam", 2.)
     rv = v_input(self, _("Diameter"), (_("Diam:"), diam))
     if rv is None:
         return
     diam = rv[0]
     dens = self.get_rho0()
     s0 = sqc.calc_hs_s0(diam, dens, *internal['data']["SSF"][:2])
     self.s_0.SetValue(loc.format(u"%g", s0))
Beispiel #9
0
 def calc_s0(self, evt):
     if not self.Validate():
         return
     internal = self.internal
     diam = internal.get("diam", 2.)
     rv = v_input(self, _("Diameter"), (_("Diam:"), diam))
     if rv is None:
         return
     diam = rv[0]
     dens = self.get_rho0()
     s0 = sqc.calc_hs_s0(diam, dens, *internal['data']["SSF"][:2])
     self.s_0.SetValue(loc.format(u"%g", s0))
Beispiel #10
0
 def shift_data(self, evt):
     dat = self.data
     tfn = _("Intensity curve")
     plot = dat['plot']
     if plot.get_cur_key() != tfn:
         plot.plot_dataset(tfn)
         return
     x_sh = _("Shift X by:"), 0.
     y_sh = _("Shift Y by:"), 0.
     rv = v_input(dat["window"], _("Shift data"), x_sh, y_sh)
     if rv is None:
         return
     x_sh, y_sh = rv
     edat = dat['data'].get("Exp. data")
     if edat is None:
         return
     if x_sh != 0.:
         edat.x_data += x_sh
     if y_sh != 0.:
         edat.y_data += y_sh
     plot_exp_data(plot, edat, dat['menu'])
Beispiel #11
0
 def shift_data(self, evt):
     dat = self.data
     tfn = _("Intensity curve")
     plot = dat['plot']
     if plot.get_cur_key() != tfn:
         plot.plot_dataset(tfn)
         return
     x_sh = _("Shift X by:"), 0.
     y_sh = _("Shift Y by:"), 0.
     rv = v_input(dat["window"], _("Shift data"), x_sh, y_sh)
     if rv is None:
         return
     x_sh, y_sh = rv
     edat = dat['data'].get("Exp. data")
     if edat is None:
         return
     if x_sh != 0.:
         edat.x_data += x_sh
     if y_sh != 0.:
         edat.y_data += y_sh
     plot_exp_data(plot, edat, dat['menu'])
Beispiel #12
0
 def sq_head(self, evt):
     dat = self.data
     if "SSF" not in dat["data"]:
         return
     q, sq, sqd = dat["data"]["SSF"][:3]
     if "SQ point" not in dat:
         head = int(sq.argmax() + 1)
     else:
         head = dat["SQ point"] + 1
     diam = 2.
     dens = float(dat["data"]["Exp. data"].rho0)
     rv = v_input(dat["window"], _("Head init. params"),
                  (_("Points:"), head, 3, len(q)),
                  (_("Diam:"), diam), (_("Dens:"), dens))
     if rv is None:
         return
     head, diam, dens = rv
     diam, dens = sqc.calc_hs_head(diam, dens, q[:head], sq[:head])
     sqd["head"] = {"diam": diam, "dens": dens, "points": head,
                    "S(0)": sqc.calc_hs_s0(diam, dens)}
     plot_sq(dat, q, sq, sqd)
     dat["menu"].action_catch("SF head found")
Beispiel #13
0
 def tail_gr(self, evt):
     dat = self.data
     plot = dat["plot"]
     rdf = dat.get("RDFd")
     if rdf is None:
         return
     beg, end = plot.axes1.get_xbound()
     pts = _("Points:"), dat["gr_tail_pts"], 10, 10000
     beg = _("Start:"), float(beg)
     end = _("End:"), float(end)
     a = "a:", 1.
     b = "b:", 2.
     c = "c:", .1
     d = "d:", .1
     rv = v_input(dat["window"], _("RDF tail"), pts, beg, end, a, b, c, d)
     if rv is None:
         return
     pts, beg, end, a, b, c, d = rv
     dat["gr_tail_pts"] = pts
     rarr = np.linspace(beg, end, pts)
     grarr = sqc.calc_gr_arr(rarr, **rdf)
     coefs = sqc.gr_tail(rarr, grarr, (a, b, c, d))
     x, y = sqc.tail_xy(coefs, beg, end, pts)
     y += 1
     rdf["tail"] = coefs
     rdf["tail_s"] = beg
     pdt = plot.set_data(PN_RDFT, [(rarr, grarr, 1), (x, y, 1)],
                         r"$r,\,\AA$", "g(r)", "A")
     pdt.discards.update(("liq samp", "sq found", "sq changed", "gr found"))
     pdt.journal.log("find RDF's tail")
     info = ["\n\n",
             "''g(r) = 1 + a * cos(b * r - c) * exp(-d * r) / r''",
             "\n\n----\n\n{|\n! %s\n! %s\n"] +\
         ["|-\n| %s\n| %%s\n" % (i,) for i in "a b c d".split()] + ["|}"]
     info = u"".join(info) % ((_("parameter"), _("value")) +
                              tuple([loc.format("%g", i) for i in coefs]))
     pdt.set_info(info)
     plot.plot_dataset(PN_RDFT)
Beispiel #14
0
 def tail_gr(self, evt):
     dat = self.data
     plot = dat["plot"]
     rdf = dat.get("RDFd")
     if rdf is None:
         return
     beg, end = plot.axes1.get_xbound()
     pts = _("Points:"), dat["gr_tail_pts"], 10, 10000
     beg = _("Start:"), float(beg)
     end = _("End:"), float(end)
     a = "a:", 1.
     b = "b:", 2.
     c = "c:", .1
     d = "d:", .1
     rv = v_input(dat["window"], _("RDF tail"), pts, beg, end, a, b, c, d)
     if rv is None:
         return
     pts, beg, end, a, b, c, d = rv
     dat["gr_tail_pts"] = pts
     rarr = np.linspace(beg, end, pts)
     grarr = sqc.calc_gr_arr(rarr, **rdf)
     coefs = sqc.gr_tail(rarr, grarr, (a, b, c, d))
     x, y = sqc.tail_xy(coefs, beg, end, pts)
     y += 1
     rdf["tail"] = coefs
     rdf["tail_s"] = beg
     pdt = plot.set_data(PN_RDFT, [(rarr, grarr, 1), (x, y, 1)],
                         r"$r,\,\AA$", "g(r)", "A")
     pdt.discards.update(("liq samp", "sq found", "sq changed", "gr found"))
     pdt.journal.log("find RDF's tail")
     info = ["\n\n",
             "''g(r) = 1 + a * cos(b * r - c) * exp(-d * r) / r''",
             "\n\n----\n\n{|\n! %s\n! %s\n"] +\
         ["|-\n| %s\n| %%s\n" % (i,) for i in "a b c d".split()] + ["|}"]
     info = u"".join(info) % ((_("parameter"), _("value")) +
                              tuple([loc.format("%g", i) for i in coefs]))
     pdt.set_info(info)
     plot.plot_dataset(PN_RDFT)
Beispiel #15
0
def calculate_reflexes(idata):
    "Search reflexes shapes"
    parent = idata["window"]
    exd = idata["data"]["Exp. data"]
    x, y, bg, sig2 = idata["data"]["Background"][:4]
    if exd.lambda2:
        l21 = exd.lambda2 / exd.lambda1
    else:
        l21 = None
    dreflexes = {}
    dreflexes["lambda"] = exd.lambda1
    I2 = exd.I2
    sigmin = _(u"Min. \u03c3:"), idata["refl_sigmin"]
    consig = _(u"Const. \u03c3"), idata["refl_consig"]
    mbells = _("Max. bells:"), idata["refl_mbells"]
    bell_t = _("Shape function:"), _BELL_NAMES, idata["refl_bt"]
    pts_mi = _("Ignore points:"), idata["refl_ptm"], 4
    bf = _("Believe factor:"), idata["refl_bf"]
    if idata["data"]["User refl"]:
        alg = 1
    else:
        alg = 0
    algorithm = _("Algorithm:"), [_("alg 1"), _("alg 2")], alg
    rv = v_input(parent, _("Shapes of reflexes"), sigmin, consig, mbells,
                 bell_t, bf, pts_mi, algorithm)
    if rv is None:
        return
    sigmin, consig, mbells, bell_t, bf, pts_mi, algorithm = rv
    idata["refl_sigmin"] = sigmin
    idata["refl_consig"] = consig
    idata["refl_mbells"] = mbells
    idata["refl_bt"] = bell_t
    idata["refl_ptm"] = pts_mi
    idata["refl_bf"] = bf
    sects = refl_sects(x, y, bg, sig2, bf)
    sects = [i for i in sects if len(i) > pts_mi]
    lsec = len(sects)
    titl = _("Calculate shapes")
    msg = _("Calculating shapes of the reflexes...")
    if lsec:
        dlgp = DlgProgressCallb(parent, titl, msg, lsec, can_abort=True)
    done = 0
    totreflexes = []
    totsigmas = []
    plts = []
    plts.append((x, y - bg, 1, 'black', '.'))
    if algorithm == 1:
        apposs = [(i[0], i[3]) for i in idata["data"]["User refl"].get()]
    for sect in sects:
        rfd = ReflexDedect(sect, l21, I2)
        if algorithm == 0:
            reflexes, stdev = rfd.find_bells(sigmin, not consig,
                                             mbells, _BELL_TYPES[bell_t])
        else:
            mi = sect[0][0]
            ma = sect[-1][0]
            pposs = [i for i in apposs if mi <= i[0] <= ma]
            posfxs = [i for i in range(len(pposs)) if pposs[i][1]]
            pposs = [i[0] for i in pposs]
            reflexes, stdev = rfd.find_bells_pp(_BELL_TYPES[bell_t],
                                                pposs, posfxs)
        totreflexes += reflexes
        totsigmas += [stdev] * len(reflexes)
        plts.append((rfd.x_ar, rfd.y_ar - rfd.calc_shape(), 1,
                     'magenta', '-'))
        rfd.x_ar = np.linspace(rfd.x_ar[0], rfd.x_ar[-1], len(rfd.x_ar) * 10)
        plts.append((rfd.x_ar, rfd.calc_shape(), 1, 'green', '-'))
        rfd.lambda21 = None
        for peak in reflexes:
            pv = np.array(peak)[:3]
            plts.append((rfd.x_ar, rfd.calc_shape(pv), 1, 'b', '-'))
        done += 1
        if not dlgp(done):
            break
    dreflexes["shape"] = _BELL_TYPES[bell_t]
    dreflexes["items"] = [i + (j,) for i, j in zip(totreflexes, totsigmas)]
    return dreflexes, plts