Пример #1
0
    def config(self, config):
        self.ax.set_autoscale_on(False)
        chart = config.getboolean("Psychr", "chart")
        xlabel = "Tdb, " + Temperature.text()
        ylabel = "%s, %s/%s" % (
            QtWidgets.QApplication.translate("pychemqt", "Absolute humidity"),
            Mass.text(), Mass.text())

        tmin = Temperature(config.getfloat("Psychr", "isotdbStart")).config()
        tmax = Temperature(config.getfloat("Psychr", "isotdbEnd")).config()
        wmin = config.getfloat("Psychr", "isowStart")
        wmax = config.getfloat("Psychr", "isowEnd")

        if chart:
            self.ax.set_xlabel(xlabel, size="large")
            self.ax.set_ylabel(ylabel, size="large")
            self.ax.set_xlim(tmin, tmax)
            self.ax.set_ylim(wmin, wmax)
            self.ax.yaxis.set_ticks_position("right")
            self.ax.yaxis.set_label_position("right")
            self.ax.figure.subplots_adjust(left=0.05, top=0.95)
        else:
            self.ax.set_xlabel(ylabel, size="large")
            self.ax.set_ylabel(xlabel, size="large")
            self.ax.set_xlim(wmin, wmax)
            self.ax.set_ylim(tmin, tmax)
            self.ax.xaxis.set_ticks_position("top")
            self.ax.xaxis.set_label_position("top")
            self.ax.figure.subplots_adjust(right=0.95, bottom=0.05)

        kw = formatLine(config, "Psychr", "crux")
        self.lx = self.ax.axhline(**kw)  # the horiz line
        self.ly = self.ax.axvline(**kw)  # the vert line
Пример #2
0
 def curveIndexChanged(self, index):
     """Show the composition unit appropiated to the new curve selected"""
     if index == 3:
         header = ["wt.%", "Tb, " + Temperature.text()]
     else:
         header = ["Vol.%", "Tb, " + Temperature.text()]
     self.curvaDestilacion.tabla.setHorizontalHeaderLabels(header)
Пример #3
0
    def config(self, config):
        self.ax.set_autoscale_on(False)
        chart = config.getboolean("Psychr", "chart")
        xlabel = "Tdb, " + Temperature.text()
        ylabel = "%s, %s/%s" % (
            QtWidgets.QApplication.translate("pychemqt", "Absolute humidity"),
            Mass.text(), Mass.text())

        tmin = Temperature(config.getfloat("Psychr", "isotdbStart")).config()
        tmax = Temperature(config.getfloat("Psychr", "isotdbEnd")).config()
        wmin = Temperature(config.getfloat("Psychr", "isowStart")).config()
        wmax = Temperature(config.getfloat("Psychr", "isowEnd")).config()

        if chart:
            self.ax.set_xlabel(xlabel, size="large")
            self.ax.set_ylabel(ylabel, size="large")
            self.ax.set_xlim(tmin, tmax)
            self.ax.set_ylim(wmin, wmax)
            self.ax.yaxis.set_ticks_position("right")
            self.ax.yaxis.set_label_position("right")
            self.ax.figure.subplots_adjust(left=0.05, top=0.95)
        else:
            self.ax.set_xlabel(ylabel, size="large")
            self.ax.set_ylabel(xlabel, size="large")
            self.ax.set_xlim(wmin, wmax)
            self.ax.set_ylim(tmin, tmax)
            self.ax.xaxis.set_ticks_position("top")
            self.ax.xaxis.set_label_position("top")
            self.ax.figure.subplots_adjust(right=0.95, bottom=0.05)

        kw = formatLine(config, "Psychr", "crux")
        self.lx = self.ax.axhline(**kw)  # the horiz line
        self.ly = self.ax.axvline(**kw)  # the vert line
Пример #4
0
    def calculo(self):
        self.entrada = self.kwargs["entrada"]
        metodo = self.kwargs["metodo"]
        self.Pout = Pressure(self.kwargs["Pout"])
        razon = self.kwargs["razon"]
        self.rendimientoCalculado = Dimensionless(self.kwargs["rendimiento"])
        if self.kwargs["etapas"]:
            self.etapas = self.kwargs["etapas"]
        else:
            self.etapas = 1.
        self.power = Power(self.kwargs["trabajo"])

        def f(Pout, rendimiento):
            W_ideal = self.__Wideal(Pout)
            power = W_ideal * self.entrada.caudalmasico.gs / rendimiento
            return power

        if metodo in [0, 3] or (metodo == 5 and self.Pout):
            if self.etapas == 1:
                razon = self.Pout.atm / self.entrada.P.atm
            else:
                razon = (self.Pout.atm / self.entrada.P.atm)**(1. /
                                                               self.etapas)
        elif metodo in [1, 4] or (metodo == 5 and razon):
            if self.etapas == 1:
                self.Pout = Pressure(self.entrada.P * razon)
            else:
                self.Pout = Pressure(razon**self.etapas * self.entrada.P)

        if metodo in [0, 1]:
            Wideal = self.__Wideal(self.Pout.atm)
            power = Wideal * self.entrada.caudalmasico.gs / self.rendimientoCalculado
            self.power = Power(power * self.etapas)
        elif metodo == 2:
            funcion = lambda P: f(P, self.rendimientoCalculado) - self.power
            self.Pout = Pressure(fsolve(funcion, self.entrada.P + 1))
            if self.etapas == 1:
                razon = self.Pout / self.entrada.P
            else:
                razon = (self.Pout / self.entrada.P)**(1. / self.etapas)
        elif metodo in [3, 4]:
            funcion = lambda rendimiento: f(self.Pout.atm, rendimiento
                                            ) - self.power
            self.rendimientoCalculado = Dimensionless(fsolve(funcion, 0.5))
        elif metodo == 5:
            Wideal = self.__Wideal(self.Pout.atm)
            caudalmasico = MassFlow(
                self.power * self.rendimientoCalculado / Wideal, "gs")
            self.Tout = self.__Tout(Wideal)
            self.entrada = self.entrada.clone(caudalMasico=caudalmasico)

        Wideal = self.__Wideal(self.Pout.atm)
        self.Tout = Temperature(self.__Tout(Wideal))
        self.salida = [self.entrada.clone(T=self.Tout, P=self.Pout)]
        self.razonCalculada = Dimensionless(self.Pout / self.entrada.P)
        self.deltaT = DeltaT(self.salida[0].T - self.entrada.T)
        self.deltaP = DeltaP(self.salida[0].P - self.entrada.P)
        self.cp_cv = self.entrada.Gas.cp_cv
        self.Pin = self.entrada.P
        self.Tin = self.entrada.T
Пример #5
0
def _Tbar(Z):
    """
    Standard temperature as a function of altitude as explain in [1]_
    pag 1.1 Eq 4

    Parameters
    ------------
    Z : float
        Altitude, [m]

    Returns
    -------
    T : float
        Temperature, [K]

    Examples
    --------
    Selected point from Table 1 in [1]_

    >>> "%0.1f" % _Tbar(-500).C
    '18.2'
    >>> "%0.1f" % _Tbar(8000).C
    '-37.0'
    """
    t = 15-0.0065*Z
    return Temperature(t, "C")
Пример #6
0
 def RhoS(self, T):
     densidad = 0
     for i in range(len(self.ids)):
         densidad += self.caudalUnitario[i]/self.caudal * \
             self.componente[i].RhoS(T)
     self.rho = Density(densidad)
     self.T = Temperature(T)
Пример #7
0
 def calculo(self):
     tdp, tdb, twb, P, Pvs, Pv, ws, w, HR, v, h = self._lib()
     self.tdp = Temperature(tdp)
     self.tdb = Temperature(tdb)
     self.twb = Temperature(twb)
     self.P = Pressure(P)
     self.Pvs = Pressure(Pvs)
     self.Pv = Pressure(Pv)
     self.ws = Dimensionless(ws, txt="kgw/kgda")
     self.w = Dimensionless(w, txt="kgw/kgda")
     self.HR = Dimensionless(HR, txt="%")
     self.mu = Dimensionless(w/ws*100)
     self.v = SpecificVolume(v)
     self.rho = Density(1/v)
     self.h = Enthalpy(h, "kJkg")
     self.Xa = 1/(1+self.w/0.62198)
     self.Xw = 1-self.Xa
Пример #8
0
    def drawlabel(self, name, t, W, label, unit):
        """
        Draw annotation for isolines
            name: name of isoline
            t: x array of line
            W: y array of line
            label: text value to draw
            unit: text units to draw
        """
        if self.Preferences.getboolean("Psychr", name + "label"):
            TMIN = self.Preferences.getfloat("Psychr", "isotdbStart")
            TMAX = self.Preferences.getfloat("Psychr", "isotdbEnd")
            tmin = Temperature(TMIN).config()
            tmax = Temperature(TMAX).config()
            wmin = self.Preferences.getfloat("Psychr", "isowStart")
            wmax = self.Preferences.getfloat("Psychr", "isowEnd")
            if self.Preferences.getboolean("Psychr", "chart"):
                x = tmax - tmin
                y = wmax - wmin
                i = 0
                for ti, wi in zip(t, W):
                    if tmin <= ti <= tmax and wmin <= wi <= wmax:
                        i += 1
            else:
                x = wmax - wmin
                y = tmax - tmin
                i = 0
                for ti, wi in zip(t, W):
                    if tmin <= wi <= tmax and wmin <= ti <= wmax:
                        i += 1

            if isinstance(label, float):
                label = "%4g" % label

            if self.Preferences.getboolean("Psychr", name + "units"):
                label += unit
            pos = self.Preferences.getfloat("Psychr", name + "position")
            p = int(i * pos / 100 - 1)
            rot = arctan(
                (W[p] - W[p - 1]) / y / (t[p] - t[p - 1]) * x) * 360 / 2 / pi
            self.plt.ax.annotate(label, (t[p], W[p]),
                                 rotation=rot,
                                 size="small",
                                 ha="center",
                                 va="center")
Пример #9
0
 def readStatefromJSON(self, state):
     """Load instance parameter from saved file"""
     self.Pout = Pressure(state["Pout"])
     self.Tout = Temperature(state["Tout"])
     self.rendimientoCalculado = Dimensionless(state["rendimientoCalculado"])  # noqa
     self.power = Power(state["power"])
     self.razonCalculada = Dimensionless(state["razonCalculada"])
     self.razon = Dimensionless(state["razon"])
     self.deltaT = DeltaT(state["deltaT"])
     self.deltaP = DeltaP(state["deltaP"])
     self.cp_cv = Dimensionless(state["cp_cv"])
     self.Pin = Pressure(state["Pin"])
     self.Tin = Temperature(state["Tin"])
     self.cp_cv = Dimensionless(state["cp_cv"])
     self.statusCoste = state["statusCoste"]
     if self.statusCoste:
         self.C_adq = Currency(state["C_adq"])
         self.C_inst = Currency(state["C_inst"])
     self.salida = [None]
Пример #10
0
    def calculo(self):
        self.entrada = self.kwargs["entrada"]
        self.Pout = Pressure(self.kwargs["Pout"])
        self.razon = Dimensionless(self.kwargs["razon"])
        self.rendimientoCalculado = Dimensionless(self.kwargs["rendimiento"])
        self.power = Power(-abs(self.kwargs["trabajo"]))

        def f(Pout, rendimiento):
            W_ideal = self.__Wideal(Pout)
            power = W_ideal * self.entrada.caudalmasico.gs * rendimiento
            return power

        self.cp_cv = self.entrada.Gas.cp_cv

        if self.kwargs["metodo"] in [0, 3] or \
                (self.kwargs["metodo"] == 5 and self.Pout):
            self.razon = Dimensionless(self.Pout / self.entrada.P)
        elif self.kwargs["metodo"] in [1, 4] or \
                (self.kwargs["metodo"] == 5 and self.razon):
            self.Pout = Pressure(self.entrada.P * self.razon)

        if self.kwargs["metodo"] in [0, 1]:
            Wideal = self.__Wideal(self.Pout)
            G = self.entrada.caudalmasico.gs
            self.power = Power(Wideal * G * self.rendimientoCalculado)
        elif self.kwargs["metodo"] == 2:

            def function(P):
                return f(P, self.rendimientoCalculado) - self.power

            self.Pout = Pressure(fsolve(function, self.entrada.P.atm + 1),
                                 "atm")
            self.razon = Dimensionless(self.Pout / self.entrada.P)
        elif self.kwargs["metodo"] in [3, 4]:

            def function(rendimiento):
                return f(self.Pout.atm, rendimiento) - self.power

            self.rendimientoCalculado = Dimensionless(fsolve(function, 0.5))
        elif self.kwargs["metodo"] == 5:
            Wideal = self.__Wideal(self.Pout)
            G = MassFlow(self.power / self.rendimientoCalculado / Wideal, "gs")
            self.Tout = self.__Tout(Wideal)
            self.entrada = self.entrada.clone(caudalMasico=G)

        Wideal = self.__Wideal(self.Pout)
        self.Tout = Temperature(self.__Tout(Wideal))
        self.razonCalculada = Dimensionless(self.Pout / self.entrada.P)
        self.salida = [self.entrada.clone(T=self.Tout, P=self.Pout)]
        self.deltaT = DeltaT(self.salida[0].T - self.entrada.T)
        self.deltaP = DeltaP(self.salida[0].P - self.entrada.P)
        self.Pin = self.entrada.P
        self.Tin = self.entrada.T
Пример #11
0
 def readStatefromJSON(self, solid):
     if solid:
         self._bool = True
         self.status = solid["status"]
         self.ids = solid["ids"]
         self.componente = [Componente(int(i)) for i in self.ids]
         self.caudalUnitario = [MassFlow(q) for q in solid["unitFlow"]]
         self.caudal = MassFlow(solid["caudal"])
         self.diametros = [Length(d, "m", "ParticleDiameter") for d in solid["diametros"]]
         self.fracciones = solid["fracciones"]
         self.fracciones_acumuladas = solid["fracciones_acumuladas"]
         self.diametro_medio = Length(solid["diametro_medio"])
         self.rho = Density(solid["rho"])
         self.T = Temperature(solid["T"])
     else:
         self._bool = False
         self.status = False
Пример #12
0
    def regresionCurve(self):
        dlg = Plot(accept=True)
        x = self.curvaDestilacion.column(0)
        T = self.curvaDestilacion.column(1, Temperature)
        dlg.addData(x, T, color="black", ls="None", marker="s", mfc="red")
        parameters, r2 = curve_Predicted(x, T)
        xi = arange(0, 1, 0.01)
        Ti = [_Tb_Predicted(parameters, x_i) for x_i in xi]
        dlg.addData(xi, Ti, color="black", lw=0.5)

        # Add equation formula to plot
        txt = r"$\frac{T-T_{o}}{T_{o}}=\left[\frac{A}{B}\ln\left(\frac{1}{1-x}"
        txt += r"\right)\right]^{1/B}$"
        To = Temperature(parameters[0])
        txt2 = "\n\n\n$T_o=%s$" % To.str
        txt2 += "\n$A=%0.4f$" % parameters[1]
        txt2 += "\n$B=%0.4f$" % parameters[2]
        txt2 += "\n$r^2=%0.6f$" % r2
        dlg.plot.ax.text(0, T[-1], txt, size="14", va="top", ha="left")
        dlg.plot.ax.text(0, T[-1], txt2, size="10", va="top", ha="left")
        if dlg.exec_():
            self.curveParameters = parameters
            self.checkStatusCurve()
Пример #13
0
 def createState(self, x, y):
     """Create psychrometric state from click or mouse position"""
     tdb = Temperature(x, "conf")
     punto = PsychroState(P=self.inputs.P.value, tdb=tdb, w=y)
     return punto
Пример #14
0
    def plot(self):
        """Plot chart"""
        self.plt.clearPointData()
        self.plt.ax.clear()
        chart = self.Preferences.getboolean("Psychr", "chart")
        self.plt.config(self.Preferences)
        filename = conf_dir+"%s_%i.json" % (
            PsychroState().__class__.__name__, self.inputs.P.value)
        if os.path.isfile(filename):
            with open(filename, "r") as archivo:
                data = json.load(archivo)
                self.status.setText(QtWidgets.QApplication.translate(
                    "pychemqt", "Loading cached data..."))
                QtWidgets.QApplication.processEvents()
        else:
            self.progressBar.setVisible(True)
            self.status.setText(QtWidgets.QApplication.translate(
                "pychemqt", "Calculating data..."))
            QtWidgets.QApplication.processEvents()
            data = PsychroState.calculatePlot(self)
            with open(filename, "w") as file:
                json.dump(data, file, indent=4)

            self.progressBar.setVisible(False)
        self.status.setText(
            QtWidgets.QApplication.translate("pychemqt", "Plotting..."))
        QtWidgets.QApplication.processEvents()

        # Saturation line
        t = [Temperature(ti).config() for ti in data["t"]]
        Hs = data["Hs"]
        format = formatLine(self.Preferences, "Psychr", "saturation")
        if chart:
            self.plt.plot(t, Hs, **format)
        else:
            self.plt.plot(Hs, t, **format)

        # Iso dew bulb temperaure lines, vertial lines in normal h-Tdb plot,
        # vertical in mollier diagram
        format = formatLine(self.Preferences, "Psychr", "isotdb")
        for i, T in enumerate(t):
            if chart:
                self.plt.plot([T, T], [0, Hs[i]], **format)
            else:
                self.plt.plot([0, Hs[i]], [T, T], **format)

        # Iso humidity lines, horizontal lines in normal h-Tdb plot, vertical
        # in mollier diagram
        H = data["H"]
        th = data["th"]
        tm = Temperature(self.Preferences.getfloat("Psychr", "isotdbEnd"))
        format = formatLine(self.Preferences, "Psychr", "isow")
        for i, H in enumerate(H):
            ts = Temperature(th[i]).config()
            if chart:
                self.plt.plot([ts, tm.config()], [H, H], **format)
            else:
                self.plt.plot([H, H], [ts, tm.config()], **format)

        # Iso relative humidity lines
        format = formatLine(self.Preferences, "Psychr", "isohr")
        for Hr, H0 in list(data["Hr"].items()):
            if chart:
                self.plt.plot(t, H0, **format)
                self.drawlabel("isohr", t, H0, Hr, "%")
            else:
                self.plt.plot(H0, t, **format)
                self.drawlabel("isohr", H0, t, Hr, "%")

        # Iso wet bulb temperature lines
        format = formatLine(self.Preferences, "Psychr", "isotwb")
        for T, (H, Tw) in list(data["Twb"].items()):
            value = Temperature(T).config()
            Tw_conf = [Temperature(Twi).config() for Twi in Tw]
            txt = Temperature.text()
            if chart:
                self.plt.plot(Tw_conf, H, **format)
                self.drawlabel("isotwb", Tw_conf, H, value, txt)
            else:
                self.plt.plot(H, Tw_conf, **format)
                self.drawlabel("isotwb", H, Tw_conf, value, txt)

        # Isochor lines
        format = formatLine(self.Preferences, "Psychr", "isochor")
        for v, (Td, H) in list(data["v"].items()):
            value = SpecificVolume(v).config()
            Td_conf = [Temperature(Tdi).config() for Tdi in Td]
            txt = SpecificVolume.text()
            if chart:
                self.plt.plot(Td_conf, H, **format)
                self.drawlabel("isochor", Td_conf, H, value, txt)
            else:
                self.plt.plot(H, Td_conf, **format)
                self.drawlabel("isochor", H, Td_conf, value, txt)

        if self.plt.state:
            self.plt.createCrux(self.plt.state, chart)
        self.plt.draw()
        self.status.setText("%s %s" % (
            QtWidgets.QApplication.translate("pychemqt", "Using"),
            PsychroState().__class__.__name__[3:]))
Пример #15
0
    def calculatePlot(cls, parent):
        """Funtion to calculate point in chart"""
        Preferences = ConfigParser()
        Preferences.read(conf_dir+"pychemqtrc")
        parent.setProgressValue(0)

        data = {}
        P = parent.inputs.P.value
        P_kPa = P/1000
        t = cls.LineList("isotdb", Preferences)

        # Saturation line
        Hs = []
        for tdb in t:
            Hs.append(HAProps("W", "P", P_kPa, "Tdb", tdb, "RH", 1))
            parent.setProgressValue(5*len(Hs)/len(t))
        data["t"] = t
        data["Hs"] = Hs

        # left limit of isow lines
        H = cls.LineList("isow", Preferences)
        th = []
        for w in H:
            if w:
                tdp = HAProps("Tdp", "P", 101.325, "W", w, "RH", 1)
                th.append(Temperature(tdp).config())
            else:
                tmin = Preferences.getfloat("Psychr", "isotdbStart")
                th.append(Temperature(tmin).config())
        data["H"] = H
        data["th"] = th

        # Humidity ratio lines
        hr = cls.LineList("isohr", Preferences)
        Hr = {}
        cont = 0
        for i in hr:
            Hr[i] = []
            for tdb in t:
                Hr[i].append(HAProps("W", "P", P_kPa, "Tdb", tdb, "RH", i/100))
                cont += 1
                parent.progressBar.setValue(5+10*cont/len(hr)/len(Hs))
        data["Hr"] = Hr

        # Twb
        lines = cls.LineList("isotwb", Preferences)
        Twb = {}
        cont = 0
        for T in lines:
            ws = HAProps("W", "P", P_kPa, "RH", 1, "Tdb", T)
            H = [ws, 0]
            _td = HAProps("Tdb", "P", P_kPa, "Twb", T, "RH", 0)
            Tw = [Temperature(T).config(), Temperature(_td).config()]
            cont += 1
            parent.progressBar.setValue(15+75*cont/len(lines))
            Twb[T] = (H, Tw)
        data["Twb"] = Twb

        # v
        lines = cls.LineList("isochor", Preferences)
        V = {}
        # rh = arange(1, -0.05, -0.05)
        rh = arange(0.00, 1.05, 0.05)
        for cont, v in enumerate(lines):
            w = []
            Td = []
            for r in rh:
                try:
                    w.append(HAProps("W", "P", P_kPa, "RH", r, "V", v))
                    _td = HAProps("Tdb", "P", P_kPa, "RH", r, "V", v)
                    Td.append(Temperature(_td).config())
                except ValueError:
                    pass
            parent.progressBar.setValue(90+10*cont/len(lines))
            V[v] = (Td, w)
        data["v"] = V

        return data
Пример #16
0
    def calculatePlot(cls, parent):
        """Funtion to calculate point in chart"""
        Preferences = ConfigParser()
        Preferences.read(conf_dir+"pychemqtrc")
        parent.setProgressValue(0)

        data = {}
        P = parent.inputs.P.value
        t = cls.LineList("isotdb", Preferences)

        # Saturation line
        Hs = []
        Pvs = []
        for ti in t:
            Pv = _Psat(ti)
            Pvs.append(Pv)
            Hs.append(0.62198*Pv/(P-Pv))
            parent.setProgressValue(5*len(Hs)/len(t))
        data["t"] = t
        data["Hs"] = Hs

        # left limit of isow lines
        H = cls.LineList("isow", Preferences)
        th = []
        for w in H:
            if w:
                Pv = w*P/(0.62198+w)
                th.append(Temperature(_tdp(Pv)).config())
            else:
                tmin = Preferences.getfloat("Psychr", "isotdbStart")
                th.append(Temperature(tmin).config())
        data["H"] = H
        data["th"] = th

        # Humidity ratio lines
        hr = cls.LineList("isohr", Preferences)
        Hr = {}
        cont = 0
        for i in hr:
            Hr[i] = []
            for pvs in Pvs:
                pv = pvs*i/100
                Hr[i].append(0.62198*pv/(P-pv))
                cont += 1
                parent.setProgressValue(5+10*cont/len(hr)/len(Hs))
        data["Hr"] = Hr

        # Twb
        lines = cls.LineList("isotwb", Preferences)
        Twb = {}
        cont = 0
        for T in lines:
            H = concatenate((arange(_W(P, T), 0, -0.001), [0.]))
            Tw = []
            for h in H:
                Tw.append(Temperature(_Tdb(T, h, P)).config())
            cont += 1
            parent.setProgressValue(15+75*cont/len(lines))
            Twb[T] = (H, Tw)
        data["Twb"] = Twb

        # v
        lines = cls.LineList("isochor", Preferences)
        V = {}
        for cont, v in enumerate(lines):
            ts = _Tdb_V(v, P)
            T = linspace(ts, v*P/287.055, 50)
            Td = [Temperature(ti).config() for ti in T]
            _W_V
            H = [_W_V(ti, P, v) for ti in T]
            parent.setProgressValue(90+10*cont/len(lines))
            V[v] = (Td, H)
        data["v"] = V

        return data
Пример #17
0
    def plot(self):
        """Plot chart"""
        self.plt.clearPointData()
        self.plt.ax.clear()
        chart = self.Preferences.getboolean("Psychr", "chart")
        self.plt.config(self.Preferences)
        filename = conf_dir+"%s_%i.pkl" % (
            PsychroState().__class__.__name__, self.inputs.P.value)
        if os.path.isfile(filename):
            with open(filename, "rb") as archivo:
                data = pickle.load(archivo)
                self.status.setText(QtWidgets.QApplication.translate(
                    "pychemqt", "Loading cached data..."))
                QtWidgets.QApplication.processEvents()
        else:
            self.progressBar.setVisible(True)
            self.status.setText(QtWidgets.QApplication.translate(
                "pychemqt", "Calculating data..."))
            QtWidgets.QApplication.processEvents()
            data = PsychroState.calculatePlot(self)
            pickle.dump(data, open(filename, "wb"))
            self.progressBar.setVisible(False)
        self.status.setText(
            QtWidgets.QApplication.translate("pychemqt", "Plotting..."))
        QtWidgets.QApplication.processEvents()

        # Saturation line
        t = [Temperature(ti).config() for ti in data["t"]]
        Hs = data["Hs"]
        format = formatLine(self.Preferences, "Psychr", "saturation")
        if chart:
            self.plt.plot(t, Hs, **format)
        else:
            self.plt.plot(Hs, t, **format)

        # Iso dew bulb temperaure lines, vertial lines in normal h-Tdb plot,
        # vertical in mollier diagram
        format = formatLine(self.Preferences, "Psychr", "isotdb")
        for i, T in enumerate(t):
            if chart:
                self.plt.plot([T, T], [0, Hs[i]], **format)
            else:
                self.plt.plot([0, Hs[i]], [T, T], **format)

        # Iso humidity lines, horizontal lines in normal h-Tdb plot, vertical
        # in mollier diagram
        H = data["H"]
        th = data["th"]
        tm = Temperature(self.Preferences.getfloat("Psychr", "isotdbEnd"))
        format = formatLine(self.Preferences, "Psychr", "isow")
        for i, H in enumerate(H):
            if chart:
                self.plt.plot([th[i], tm.config()], [H, H], **format)
            else:
                self.plt.plot([H, H], [th[i], tm.config()], **format)

        # Iso relative humidity lines
        format = formatLine(self.Preferences, "Psychr", "isohr")
        for Hr, H0 in list(data["Hr"].items()):
            if chart:
                self.plt.plot(t, H0, **format)
                self.drawlabel("isohr", t, H0, Hr, "%")
            else:
                self.plt.plot(H0, t, **format)
                self.drawlabel("isohr", H0, t, Hr, "%")

        # Iso wet bulb temperature lines
        format = formatLine(self.Preferences, "Psychr", "isotwb")
        for T, (H, Tw) in list(data["Twb"].items()):
            value = Temperature(T).config()
            txt = Temperature.text()
            if chart:
                self.plt.plot(Tw, H, **format)
                self.drawlabel("isotwb", Tw, H, value, txt)
            else:
                self.plt.plot(H, Tw, **format)
                self.drawlabel("isotwb", H, Tw, value, txt)

        # Isochor lines
        format = formatLine(self.Preferences, "Psychr", "isochor")
        for v, (Td, H) in list(data["v"].items()):
            value = SpecificVolume(v).config()
            txt = SpecificVolume.text()
            if chart:
                self.plt.plot(Td, H, **format)
                self.drawlabel("isochor", Td, H, value, txt)
            else:
                self.plt.plot(H, Td, **format)
                self.drawlabel("isochor", H, Td, value, txt)

        if self.plt.state:
            self.plt.createCrux(self.plt.state, chart)
        self.plt.draw()
        self.status.setText("%s %s" % (
            QtWidgets.QApplication.translate("pychemqt", "Using"),
            PsychroState().__class__.__name__[3:]))
Пример #18
0
    def __init__(self, parent=None):
        super(Definicion_Petro, self).__init__(parent)
        self.setWindowTitle(QtGui.QApplication.translate(
            "pychemqt", "Petrol component definition"))
        layout = QtGui.QGridLayout(self)
        layout.addWidget(QtGui.QLabel(QtGui.QApplication.translate(
            "pychemqt", "Name")), 1, 1)
        self.nombre = QtGui.QLineEdit()
        self.nombre.textChanged.connect(partial(self.changeParams, "name"))
        layout.addWidget(self.nombre, 1, 2, 1, 4)
        layout.addItem(QtGui.QSpacerItem(10, 10, QtGui.QSizePolicy.Fixed,
                                         QtGui.QSizePolicy.Fixed), 2, 1, 1, 2)
        layout.addWidget(QtGui.QLabel(QtGui.QApplication.translate(
            "pychemqt", "Boiling point")), 3, 1)
        self.Tb = Entrada_con_unidades(Temperature)
        self.Tb.valueChanged.connect(partial(self.changeParams, "Tb"))
        layout.addWidget(self.Tb, 3, 2)
        layout.addWidget(QtGui.QLabel(QtGui.QApplication.translate(
            "pychemqt", "Molecular Weight")), 4, 1)
        self.M = Entrada_con_unidades(float, textounidad="g/mol")
        self.M.valueChanged.connect(partial(self.changeParams, "M"))
        layout.addWidget(self.M, 4, 2)
        layout.addWidget(QtGui.QLabel(QtGui.QApplication.translate(
            "pychemqt", "Specific Gravity")), 5, 1)
        self.SG = Entrada_con_unidades(float)
        self.SG.valueChanged.connect(partial(self.changeParams, "SG"))
        layout.addWidget(self.SG, 5, 2)
        layout.addWidget(QtGui.QLabel(QtGui.QApplication.translate(
            "pychemqt", "API gravity")), 6, 1)
        self.API = Entrada_con_unidades(float)
        self.API.valueChanged.connect(partial(self.changeParams, "API"))
        layout.addWidget(self.API, 6, 2)
        layout.addWidget(QtGui.QLabel("K watson:"), 7, 1)
        self.Kw = Entrada_con_unidades(float)
        self.Kw.valueChanged.connect(partial(self.changeParams, "Kw"))
        layout.addWidget(self.Kw, 7, 2)
        layout.addWidget(QtGui.QLabel("C/H:"), 8, 1)
        self.CH = Entrada_con_unidades(float)
        self.CH.valueChanged.connect(partial(self.changeParams, "CH"))
        layout.addWidget(self.CH, 8, 2)
        layout.addWidget(QtGui.QLabel(u"ν<sub>100F</sub>:"), 9, 1)
        self.v100 = Entrada_con_unidades(Diffusivity)
        self.v100.valueChanged.connect(partial(self.changeParams, "v100"))
        layout.addWidget(self.v100, 9, 2)
        layout.addWidget(QtGui.QLabel(u"ν<sub>210F</sub>:"), 10, 1)
        self.v210 = Entrada_con_unidades(Diffusivity)
        self.v210.valueChanged.connect(partial(self.changeParams, "v210"))
        layout.addWidget(self.v210, 10, 2)
        layout.addWidget(QtGui.QLabel(QtGui.QApplication.translate(
            "pychemqt", "Refraction index")), 11, 1)
        self.n = Entrada_con_unidades(float)
        self.n.valueChanged.connect(partial(self.changeParams, "n"))
        layout.addWidget(self.n, 11, 2)
        layout.addWidget(QtGui.QLabel(QtGui.QApplication.translate(
            "pychemqt", "Huang parameter")), 12, 1)
        self.I = Entrada_con_unidades(float)
        self.I.valueChanged.connect(partial(self.changeParams, "I"))
        layout.addWidget(self.I, 12, 2)
        layout.addWidget(QtGui.QLabel("%S"), 13, 1)
        self.S = Entrada_con_unidades(float, spinbox=True, step=1.0, max=100)
        self.S.valueChanged.connect(partial(self.changeParams, "S"))
        layout.addWidget(self.S, 13, 2)
        layout.addWidget(QtGui.QLabel("%H"), 14, 1)
        self.H = Entrada_con_unidades(float, spinbox=True, step=1.0, max=100)
        self.H.valueChanged.connect(partial(self.changeParams, "H"))
        layout.addWidget(self.H, 14, 2)
        layout.addWidget(QtGui.QLabel("%N"), 15, 1)
        self.N = Entrada_con_unidades(float, spinbox=True, step=1.0, max=100)
        self.N.valueChanged.connect(partial(self.changeParams, "N"))
        layout.addWidget(self.N, 15, 2)

        layout.addWidget(QtGui.QLabel(QtGui.QApplication.translate(
            "pychemqt", "Carbons number")), 19, 1)
        self.carbonos = Entrada_con_unidades(int, width=50, spinbox=True,
                                             step=1, start=7, min=5, max=100)
        self.N.valueChanged.connect(partial(self.changeParams, "Nc"))
        layout.addWidget(self.carbonos, 19, 2)

        layout.addItem(QtGui.QSpacerItem(10, 10, QtGui.QSizePolicy.Expanding,
                                         QtGui.QSizePolicy.Expanding), 3, 3, 15, 1)
        self.checkCurva = QtGui.QCheckBox(QtGui.QApplication.translate(
            "pychemqt", "Define destillation curve"))
        layout.addWidget(self.checkCurva, 3, 4, 1, 2)
        self.tipoCurva = QtGui.QComboBox()
        self.tipoCurva.addItem("ASTM D86")
        self.tipoCurva.addItem("TBP")
        self.tipoCurva.addItem("EFV")
        self.tipoCurva.addItem("ASTM D1186")
        self.tipoCurva.addItem("ASTM D2887 (SD)")
        self.tipoCurva.setEnabled(False)
        layout.addWidget(self.tipoCurva, 4, 4, 1, 2)
        self.textoPresion = QtGui.QLabel(
            QtGui.QApplication.translate("pychemqt", "Pressure"))
        self.textoPresion.setEnabled(False)
        layout.addWidget(self.textoPresion, 5, 4)
        self.presion = Entrada_con_unidades(Pressure, value=101325.)
        self.presion.setEnabled(False)
        self.presion.valueChanged.connect(partial(self.changeParams, "P_dist"))
        layout.addWidget(self.presion, 5, 5)
        self.curvaDestilacion = Tabla(
            2, filas=1, horizontalHeader=["%dist", "Tb, "+Temperature.text()],
            verticalHeader=False, dinamica=True)
        self.curvaDestilacion.setEnabled(False)
        self.curvaDestilacion.editingFinished.connect(self.changeCurva)
        layout.addWidget(self.curvaDestilacion, 6, 4, 13, 2)
        self.checkBlend = QtGui.QCheckBox(QtGui.QApplication.translate(
            "pychemqt", "Blend if its necessary"))
        layout.addWidget(self.checkBlend, 19, 4, 1, 2)

        self.checkCurva.toggled.connect(self.tipoCurva.setEnabled)
        self.checkCurva.toggled.connect(self.presion.setEnabled)
        self.checkCurva.toggled.connect(self.textoPresion.setEnabled)
        self.checkCurva.toggled.connect(self.curvaDestilacion.setEnabled)

        layout.addItem(QtGui.QSpacerItem(20, 20, QtGui.QSizePolicy.Fixed,
                                         QtGui.QSizePolicy.Fixed), 20, 1, 1, 2)
        self.checkCrudo = QtGui.QCheckBox(QtGui.QApplication.translate(
            "pychemqt", "Use petrol fraction from list"))
        self.checkCrudo.toggled.connect(self.changeUnknown)
        layout.addWidget(self.checkCrudo, 21, 1, 1, 2)
        self.crudo = QtGui.QComboBox()
        self.crudo.setEnabled(False)
        self.crudo.addItem("")
        for i in crudo[1:]:
            self.crudo.addItem("%s (%s)  API: %s %S: %s" % (i[0], i[1], i[3], i[4]))
            # i[0]+" ("+i[1]+")"+"   API: "+str(i[3])+"  %S: "+str(i[4]))
        self.crudo.currentIndexChanged.connect(partial(
            self.changeParams, "indice"))
        layout.addWidget(self.crudo, 23, 1, 1, 5)
        layout.addWidget(QtGui.QLabel("Pseudo C+"), 24, 1)
        self.Cplus = Entrada_con_unidades(int, width=50, spinbox=True, step=1,
                                          min=6)
        self.Cplus.valueChanged.connect(partial(self.changeParams, "Cplus"))
        layout.addWidget(self.Cplus, 24, 2)
        self.checkCrudo.toggled.connect(self.crudo.setEnabled)
        self.checkCrudo.toggled.connect(self.Cplus.setEnabled)
        layout.addItem(QtGui.QSpacerItem(5, 5, QtGui.QSizePolicy.Expanding,
                                         QtGui.QSizePolicy.Expanding), 29, 1, 1, 2)

        newComponent.loadUI(self)

        self.Petroleo = Petroleo()
        self.Crudo = Crudo()
Пример #19
0
    def __init__(self, parent=None):
        super(Definicion_Petro, self).__init__(parent)
        self.setWindowTitle(
            QtGui.QApplication.translate("pychemqt",
                                         "Petrol component definition"))
        layout = QtGui.QGridLayout(self)
        layout.addWidget(
            QtGui.QLabel(QtGui.QApplication.translate("pychemqt", "Name")), 1,
            1)
        self.nombre = QtGui.QLineEdit()
        self.nombre.textChanged.connect(partial(self.changeParams, "name"))
        layout.addWidget(self.nombre, 1, 2, 1, 4)
        layout.addItem(
            QtGui.QSpacerItem(10, 10, QtGui.QSizePolicy.Fixed,
                              QtGui.QSizePolicy.Fixed), 2, 1, 1, 2)
        layout.addWidget(
            QtGui.QLabel(
                QtGui.QApplication.translate("pychemqt", "Boiling point")), 3,
            1)
        self.Tb = Entrada_con_unidades(Temperature)
        self.Tb.valueChanged.connect(partial(self.changeParams, "Tb"))
        layout.addWidget(self.Tb, 3, 2)
        layout.addWidget(
            QtGui.QLabel(
                QtGui.QApplication.translate("pychemqt", "Molecular Weight")),
            4, 1)
        self.M = Entrada_con_unidades(float, textounidad="g/mol")
        self.M.valueChanged.connect(partial(self.changeParams, "M"))
        layout.addWidget(self.M, 4, 2)
        layout.addWidget(
            QtGui.QLabel(
                QtGui.QApplication.translate("pychemqt", "Specific Gravity")),
            5, 1)
        self.SG = Entrada_con_unidades(float)
        self.SG.valueChanged.connect(partial(self.changeParams, "SG"))
        layout.addWidget(self.SG, 5, 2)
        layout.addWidget(
            QtGui.QLabel(
                QtGui.QApplication.translate("pychemqt", "API gravity")), 6, 1)
        self.API = Entrada_con_unidades(float)
        self.API.valueChanged.connect(partial(self.changeParams, "API"))
        layout.addWidget(self.API, 6, 2)
        layout.addWidget(QtGui.QLabel("K watson:"), 7, 1)
        self.Kw = Entrada_con_unidades(float)
        self.Kw.valueChanged.connect(partial(self.changeParams, "Kw"))
        layout.addWidget(self.Kw, 7, 2)
        layout.addWidget(QtGui.QLabel("C/H:"), 8, 1)
        self.CH = Entrada_con_unidades(float)
        self.CH.valueChanged.connect(partial(self.changeParams, "CH"))
        layout.addWidget(self.CH, 8, 2)
        layout.addWidget(QtGui.QLabel(u"ν<sub>100F</sub>:"), 9, 1)
        self.v100 = Entrada_con_unidades(Diffusivity)
        self.v100.valueChanged.connect(partial(self.changeParams, "v100"))
        layout.addWidget(self.v100, 9, 2)
        layout.addWidget(QtGui.QLabel(u"ν<sub>210F</sub>:"), 10, 1)
        self.v210 = Entrada_con_unidades(Diffusivity)
        self.v210.valueChanged.connect(partial(self.changeParams, "v210"))
        layout.addWidget(self.v210, 10, 2)
        layout.addWidget(
            QtGui.QLabel(
                QtGui.QApplication.translate("pychemqt", "Refraction index")),
            11, 1)
        self.n = Entrada_con_unidades(float)
        self.n.valueChanged.connect(partial(self.changeParams, "n"))
        layout.addWidget(self.n, 11, 2)
        layout.addWidget(
            QtGui.QLabel(
                QtGui.QApplication.translate("pychemqt", "Huang parameter")),
            12, 1)
        self.I = Entrada_con_unidades(float)
        self.I.valueChanged.connect(partial(self.changeParams, "I"))
        layout.addWidget(self.I, 12, 2)
        layout.addWidget(QtGui.QLabel("%S"), 13, 1)
        self.S = Entrada_con_unidades(float, spinbox=True, step=1.0, max=100)
        self.S.valueChanged.connect(partial(self.changeParams, "S"))
        layout.addWidget(self.S, 13, 2)
        layout.addWidget(QtGui.QLabel("%H"), 14, 1)
        self.H = Entrada_con_unidades(float, spinbox=True, step=1.0, max=100)
        self.H.valueChanged.connect(partial(self.changeParams, "H"))
        layout.addWidget(self.H, 14, 2)
        layout.addWidget(QtGui.QLabel("%N"), 15, 1)
        self.N = Entrada_con_unidades(float, spinbox=True, step=1.0, max=100)
        self.N.valueChanged.connect(partial(self.changeParams, "N"))
        layout.addWidget(self.N, 15, 2)

        layout.addWidget(
            QtGui.QLabel(
                QtGui.QApplication.translate("pychemqt", "Carbons number")),
            19, 1)
        self.carbonos = Entrada_con_unidades(int,
                                             width=50,
                                             spinbox=True,
                                             step=1,
                                             start=7,
                                             min=5,
                                             max=100)
        self.N.valueChanged.connect(partial(self.changeParams, "Nc"))
        layout.addWidget(self.carbonos, 19, 2)

        layout.addItem(
            QtGui.QSpacerItem(10, 10, QtGui.QSizePolicy.Expanding,
                              QtGui.QSizePolicy.Expanding), 3, 3, 15, 1)
        self.checkCurva = QtGui.QCheckBox(
            QtGui.QApplication.translate("pychemqt",
                                         "Define destillation curve"))
        layout.addWidget(self.checkCurva, 3, 4, 1, 2)
        self.tipoCurva = QtGui.QComboBox()
        self.tipoCurva.addItem("ASTM D86")
        self.tipoCurva.addItem("TBP")
        self.tipoCurva.addItem("EFV")
        self.tipoCurva.addItem("ASTM D1186")
        self.tipoCurva.addItem("ASTM D2887 (SD)")
        self.tipoCurva.setEnabled(False)
        layout.addWidget(self.tipoCurva, 4, 4, 1, 2)
        self.textoPresion = QtGui.QLabel(
            QtGui.QApplication.translate("pychemqt", "Pressure"))
        self.textoPresion.setEnabled(False)
        layout.addWidget(self.textoPresion, 5, 4)
        self.presion = Entrada_con_unidades(Pressure, value=101325.)
        self.presion.setEnabled(False)
        self.presion.valueChanged.connect(partial(self.changeParams, "P_dist"))
        layout.addWidget(self.presion, 5, 5)
        self.curvaDestilacion = Tabla(
            2,
            filas=1,
            horizontalHeader=["%dist", "Tb, " + Temperature.text()],
            verticalHeader=False,
            dinamica=True)
        self.curvaDestilacion.setEnabled(False)
        self.curvaDestilacion.editingFinished.connect(self.changeCurva)
        layout.addWidget(self.curvaDestilacion, 6, 4, 13, 2)
        self.checkBlend = QtGui.QCheckBox(
            QtGui.QApplication.translate("pychemqt", "Blend if its necessary"))
        layout.addWidget(self.checkBlend, 19, 4, 1, 2)

        self.checkCurva.toggled.connect(self.tipoCurva.setEnabled)
        self.checkCurva.toggled.connect(self.presion.setEnabled)
        self.checkCurva.toggled.connect(self.textoPresion.setEnabled)
        self.checkCurva.toggled.connect(self.curvaDestilacion.setEnabled)

        layout.addItem(
            QtGui.QSpacerItem(20, 20, QtGui.QSizePolicy.Fixed,
                              QtGui.QSizePolicy.Fixed), 20, 1, 1, 2)
        self.checkCrudo = QtGui.QCheckBox(
            QtGui.QApplication.translate("pychemqt",
                                         "Use petrol fraction from list"))
        self.checkCrudo.toggled.connect(self.changeUnknown)
        layout.addWidget(self.checkCrudo, 21, 1, 1, 2)
        self.crudo = QtGui.QComboBox()
        self.crudo.setEnabled(False)
        self.crudo.addItem("")
        for i in crudo[1:]:
            self.crudo.addItem("%s (%s)  API: %s %S: %s" %
                               (i[0], i[1], i[3], i[4]))
            # i[0]+" ("+i[1]+")"+"   API: "+str(i[3])+"  %S: "+str(i[4]))
        self.crudo.currentIndexChanged.connect(
            partial(self.changeParams, "indice"))
        layout.addWidget(self.crudo, 23, 1, 1, 5)
        layout.addWidget(QtGui.QLabel("Pseudo C+"), 24, 1)
        self.Cplus = Entrada_con_unidades(int,
                                          width=50,
                                          spinbox=True,
                                          step=1,
                                          min=6)
        self.Cplus.valueChanged.connect(partial(self.changeParams, "Cplus"))
        layout.addWidget(self.Cplus, 24, 2)
        self.checkCrudo.toggled.connect(self.crudo.setEnabled)
        self.checkCrudo.toggled.connect(self.Cplus.setEnabled)
        layout.addItem(
            QtGui.QSpacerItem(5, 5, QtGui.QSizePolicy.Expanding,
                              QtGui.QSizePolicy.Expanding), 29, 1, 1, 2)

        newComponent.loadUI(self)

        self.Petroleo = Petroleo()
        self.Crudo = Crudo()