Example #1
0
    def from_function(cls, function: Function):
        dy = function.dy

        if dy is None:
            return function

        value = numpy.random.normal(function.eval().real, dy.eval().real)

        if function.is_complex():
            value = value + 1j * numpy.random.normal(function.eval().imag, dy.eval().imag)

        return Function.to_function(function.get_dom(), value)
Example #2
0
    def plot(self, name, f: Function, **kwargs):
        self.axs.plot(f.get_domain(), f.eval(), label=name, **self._plot_args, **kwargs)
        self.axs.set_xlabel("depth [$\AA$]")
        self.axs.set_ylabel(self._ylabel)
        self.axs.legend()

        return self
def function_to_sin(fctn: Function):
    psi = fctn.get_domain()
    theta = fctn.eval()
    sinsqrd = np.fromiter(map(lambda x: np.sin(np.deg2rad(x)) ** 2, psi), float)
    dy = fctn.dy
    if dy is not None:
        dy = Function.to_function(sinsqrd, dy.eval())

    return Function.to_function(sinsqrd, theta, dy=dy)
Example #4
0
    def plot(self, name, f: Function, f0: Function, f1: Function = None, **kwargs):
        x = f.get_domain()
        y = f.eval()

        kwargs['label'] = name
        if 'color' in kwargs:
            self._plot_args['color'] = kwargs['color']

        self._axs.fill_between(x, y, f0(x), **self._plot_args)
        if f1 is not None:
            self._axs.fill_between(x, y, f1(x), **self._plot_args)

        super(FillBetweenPlotter, self).plot(name, f, **kwargs)

        return self
Example #5
0
    def plot(self, name, f: Function, **kwargs):
        if f is None:
            return

        transform = self.transform()
        dy = f.dy
        if self.scale:
            f = f.transform(transform)
            if dy is not None:
                dy = dy.transform(transform)
            ylabel = "(100 q$)^2$ $R(q)$ [$10^{-4} \AA^{-2}$]"
        else:
            ylabel = "R(q) [1]"

        feval = f.eval()

        color = [None, None]

        if "color" in kwargs:
            if not isinstance(kwargs["color"], list) or len(kwargs["color"]) <= 1:

                color = [kwargs["color"], kwargs["color"]]
                kwargs.pop("color")
            else:
                color = kwargs.pop("color")

        if self.real:
            if name is not None:
                kwargs["label"] = "Re R(q) {}".format(name)
            self._do_plot(f.get_domain(), feval.real, color[0], dy, **kwargs)

        if self.imag:
            if name is not None:
                kwargs["label"] = "Im R(q) {}".format(name)

            self._do_plot(f.get_domain(), feval.imag, color[1], dy, imag=True, **kwargs)

        self.axs.set_xlabel("q [$\AA$]")
        self.axs.set_ylabel(ylabel)
        self.axs.legend()

        return self
Example #6
0
    def plot(self, name, f: Function, **kwargs):

        x = f.get_domain()
        y = f.eval()

        plot_function = self._axs.plot

        kwargs['label'] = name

        if f.dx is not None or f.dy is not None:
            if f.dx is not None and self.plot_dx is True:
                kwargs['xerr'] = f.dx.eval()

            if f.dy is not None and self.plot_dy is True:
                kwargs['yerr'] = f.dy.eval()

            plot_function = self._axs.errorbar

        plot_function(x, y, **self._plot_args, **kwargs)

        return self