Exemplo n.º 1
0
 def test_plot_area(self):
     """
     Test the get_available_width() and get_available_height() functions.
     They should return the material width and height minus the padding
     around the outside.
     """
     plot = Plot(90*12,90*12*4)
     plot.set_padding(35,0,35,0) # should be default but to make sure
     assert plot.get_available_width() == 90*12
     assert plot.get_available_height() == 90*12*4-70
Exemplo n.º 2
0
 def test_align_center_x(self):
     """ Makes sure the graphic is centered correctly in the x direction"""
     plot = Plot(90*12,90*12*4)
     plot.set_padding(35,0,35,0)
     plot.set_graphic(etree.tostring(etree.parse("arrow.svg")))
     plot.set_align_center_x(True)
     f = open("out/plot_%s.svg"%sys._getframe().f_code.co_name,"w")
     f.write(plot.get_preview_xml())
     f.close()
     log.debug("Checking position...")
     assert round(plot.get_position()[0],10) == round((90*12-plot.graphic.get_width())/2,10), "%s != %s" % (round(plot.get_position()[0],10),round((90*12-plot.graphic.get_width())/2,10))
     assert round(plot.get_position()[1],10) == 0, "%s != %s" % (round(plot.get_position()[1],10),0)
Exemplo n.º 3
0
 def temp_get_devices_2(self):
     """ Test set_copies() and set_rotation(90) should stack along x axis."""
     plot = Plot(90 * 12, 90 * 12 * 4)
     plot.set_graphic(etree.tostring(etree.parse("arrow.svg")))
     plot.set_copies(4)
     plot.set_rotation(90)
     f = open("out/plot_%s.svg" % sys._getframe().f_code.co_name, "w")
     f.write(plot.get_preview_xml())
     f.close()
Exemplo n.º 4
0
 def test_material_size_limited(self):
     """Test that the material is sized correctly when limited=True"""
     plot = Plot(90 * 12, 90 * 12 * 4)
     plot.set_graphic(etree.parse("arrow.svg"))
     plot.set_padding(35, 0, 35, 0)
     h = 170.563
     log.debug(" %s should = %s" %
               (round(plot.get_material_height(limited=True), 3), h + 70))
     assert round(plot.get_material_height(limited=True), 3) == h + 70
     w = 333.469
     log.debug(" %s should = %s" %
               (round(plot.get_material_width(limited=True), 3), w))
     assert round(plot.get_material_width(limited=True), 3) == w
Exemplo n.º 5
0
 def test_material_size_limited(self):
     """Test that the material is sized correctly when limited=True"""
     plot = Plot(90*12,90*12*4)
     plot.set_graphic(etree.parse("arrow.svg"))
     plot.set_padding(35,0,35,0)
     h = 170.563
     log.debug(" %s should = %s" %(round(plot.get_material_height(limited=True),3),h+70))
     assert round(plot.get_material_height(limited=True),3) == h+70
     w = 333.469
     log.debug(" %s should = %s" %(round(plot.get_material_width(limited=True),3),w))
     assert round(plot.get_material_width(limited=True),3) == w
Exemplo n.º 6
0
 def temp_get_devices_2(self):
     """ Test set_copies() and set_rotation(90) should stack along x axis."""
     plot = Plot(90*12,90*12*4)
     plot.set_graphic(etree.tostring(etree.parse("arrow.svg")))
     plot.set_copies(4)
     plot.set_rotation(90)
     f = open("out/plot_%s.svg"%sys._getframe().f_code.co_name,"w")
     f.write(plot.get_preview_xml())
     f.close()
Exemplo n.º 7
0
 def test_set_copies(self):
     """ Test set_copies(7) with no rotation should stack along y axis."""
     plot = Plot(90 * 12 * 16, 90 * 12 * 4)
     plot.set_graphic(etree.tostring(etree.parse("fat-giraffes.svg")))
     plot.set_copies(40)  # two horizontal stacks and one extra
     f = open("out/plot_%s.svg" % sys._getframe().f_code.co_name, "w")
     f.write(plot.get_preview_xml())
Exemplo n.º 8
0
 def test_graphic_rotation(self):
     """ Test that the graphic is rotated and plot automatically updated. """
     plot = Plot(90 * 12, 90 * 12 * 4)
     plot.set_graphic(etree.parse("arrow.svg"))
     h = plot.graphic.get_height()
     w = plot.graphic.get_width()
     plot.graphic.set_rotation(90)
     f = open("out/plot_%s.svg" % sys._getframe().f_code.co_name, "w")
     f.write(plot.get_preview_xml())
     f.close()
     spacing = plot.get_spacing()
     assert round(plot.get_width(),
                  10) == round(h, 10), "they should be rotated"
     assert round(plot.get_height(), 10) == round(w, 10)
Exemplo n.º 9
0
 def test_set_copies(self):
     """ Test set_copies(7) with no rotation should stack along y axis."""
     plot = Plot(90*12*16,90*12*4)
     plot.set_graphic(etree.tostring(etree.parse("fat-giraffes.svg")))
     plot.set_copies(40) # two horizontal stacks and one extra
     f = open("out/plot_%s.svg"%sys._getframe().f_code.co_name,"w")
     f.write(plot.get_preview_xml())
Exemplo n.º 10
0
    def set_shorter(self, trial):
        self.shorter_trial.setText(trial.name)
        self.shorter_trial_data = trial

        self.shorter = TimingData()
        self.shorter.parse_csv(self.shorter_trial_data.result)
        self.shorter_plot = Plot(self.shorter)
        self.shorter_plot.color = 'blue'
        self.shorter_plot.label = trial.name
        self.plotter.add_plot(self.shorter_plot)

        self.shorter_trial_edit.setEnabled(True)
        self.update_plot_settings_view()
Exemplo n.º 11
0
 def test_set_graphic(self):
     """ Test set_graphic() and get_preview_xml() """
     plot = Plot(90 * 12, 90 * 12 * 4)
     plot.set_graphic(etree.tostring(etree.parse("arrow.svg")))
     f = open("out/plot_%s.svg" % sys._getframe().f_code.co_name, "w")
     f.write(plot.get_preview_xml())
     f.close()
     assert plot.get_width() == plot.graphic.get_width()
     assert round(plot.get_height(),
                  10) == round(plot.graphic.get_height(),
                               10)  # why does it need rounding???
Exemplo n.º 12
0
 def test_set_graphic(self):
     """ Test set_graphic() and get_preview_xml() """
     plot = Plot(90*12,90*12*4)
     plot.set_graphic(etree.tostring(etree.parse("arrow.svg")))
     f = open("out/plot_%s.svg"%sys._getframe().f_code.co_name,"w")
     f.write(plot.get_preview_xml())
     f.close()
     assert plot.get_width() == plot.graphic.get_width()
     assert round(plot.get_height(),10) == round(plot.graphic.get_height(),10) # why does it need rounding???
Exemplo n.º 13
0
 def test_graphic_rotation(self):
     """ Test that the graphic is rotated and plot automatically updated. """
     plot = Plot(90*12,90*12*4)
     plot.set_graphic(etree.parse("arrow.svg"))
     h = plot.graphic.get_height()
     w = plot.graphic.get_width()
     plot.graphic.set_rotation(90)
     f = open("out/plot_%s.svg"%sys._getframe().f_code.co_name,"w")
     f.write(plot.get_preview_xml())
     f.close()
     spacing = plot.get_spacing()
     assert round(plot.get_width(),10) == round(h,10), "they should be rotated"
     assert round(plot.get_height(),10) == round(w,10)
Exemplo n.º 14
0
 def test_plot_area(self):
     """
     Test the get_available_width() and get_available_height() functions.
     They should return the material width and height minus the padding
     around the outside.
     """
     plot = Plot(90 * 12, 90 * 12 * 4)
     plot.set_padding(35, 0, 35, 0)  # should be default but to make sure
     assert plot.get_available_width() == 90 * 12
     assert plot.get_available_height() == 90 * 12 * 4 - 70
Exemplo n.º 15
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()
Exemplo n.º 16
0
 def test_weedline_padding(self):
     """
     Test that a weedline graphic is added to the plot and that 35 padding
     only changes the width and height of the bbox by +=2*padding.
     """
     plot = Plot(90*12,90*12*4)
     plot.set_graphic(etree.tostring(etree.parse("arrow.svg")))
     plot.set_rotation(90)
     plot.set_copies(6)
     bbox = plot.get_bounding_box()
     plot.set_weedline(True)
     pad = 35
     plot.set_weedline_padding(pad)
     f = open("out/plot_%s.svg"%sys._getframe().f_code.co_name,"w")
     f.write(plot.get_preview_xml())
     f.close()
     assert len(plot._data) == 7, "len(plot._data) = %s, expect 7" %(len(plot._data))
     assert map(lambda x: round(x,10),plot.get_bounding_box()) == [0,bbox[1]+2*pad,35,bbox[3]+2*pad], "bbox before %s != bbox after weedline %s" % ([0,bbox[1]+35,35,bbox[3]+35],map(lambda x: round(x,10),plot.get_bounding_box()))
Exemplo n.º 17
0
 def test_weedline(self):
     """
     Test that a weedline graphic is added to the plot and that 0 padding
     doesn't change the bbox.
     """
     plot = Plot(90*12,90*12*4)
     plot.set_graphic(etree.tostring(etree.parse("arrow.svg")))
     plot.set_rotation(90)
     plot.set_copies(7)
     bbox = plot.get_bounding_box()
     plot.set_weedline(True)
     f = open("out/plot_%s.svg"%sys._getframe().f_code.co_name,"w")
     f.write(plot.get_preview_xml())
     f.close()
     assert len(plot._data) == 8, "len(plot._data) = %s, expect 8" %(len(plot._data))
     assert map(lambda x: round(x,10),plot.get_bounding_box()) == map(lambda x: round(x,10),bbox), "bbox before %s != bbox after weedline %s" % (bbox,plot.get_bounding_box())
Exemplo n.º 18
0
 def test_align_center_y_2(self):
     """ Makes sure the graphic is centered correctly in the y direction"""
     plot = Plot(90 * 12, 90 * 12 * 4)
     plot.set_rotation(90)
     plot.set_padding(35, 0, 35, 0)
     plot.set_copies(7)
     plot.set_graphic(etree.tostring(etree.parse("arrow.svg")))
     h = plot.graphic.get_height() * 5 + 4 * plot.get_spacing()[1]
     plot.set_align_center_y(True)
     f = open("out/plot_%s.svg" % sys._getframe().f_code.co_name, "w")
     f.write(plot.get_preview_xml())
     f.close()
     log.debug("Checking position...")
     assert round(
         plot.get_position()[0],
         10) == 0, "%s != %s" % (round(plot.get_position()[0], 10), 0)
     assert round(plot.get_position()[1], 10) == round(
         (90 * 12 - 70 - h) / 2, 10), "%s != %s" % (round(
             plot.get_position()[1], 10), round((90 * 12 - 70 - h) / 2, 10))
Exemplo n.º 19
0
 def test_set_graphic_2(self):
     """ Test set_graphic() and setting a new graphic after one has already been set. """
     plot = Plot(90 * 12, 90 * 12 * 4)
     plot.set_graphic(etree.tostring(etree.parse("arrow.svg")))
     f = open("out/plot_%s_1.svg" % sys._getframe().f_code.co_name, "w")
     f.write(plot.get_preview_xml())
     f.close()
     assert plot.get_width() == plot.graphic.get_width()
     assert round(plot.get_height(),
                  10) == round(plot.graphic.get_height(),
                               10)  # why does it need rounding???
     plot.set_graphic(etree.tostring(etree.parse("fat-giraffes.svg")))
     f = open("out/plot_%s_2.svg" % sys._getframe().f_code.co_name, "w")
     f.write(plot.get_preview_xml())
     f.close()
     assert round(plot.get_width(), 10) == round(plot.graphic.get_width(),
                                                 10)
     assert round(plot.get_height(),
                  10) == round(plot.graphic.get_height(),
                               10)  # why does it need rounding???
Exemplo n.º 20
0
 def test_set_copies_3(self):
     """ Test set_copies() and get_preview_xml() should stack 7 along  the x axis. """
     plot = Plot(90*12,90*12*4)
     plot.set_graphic(etree.tostring(etree.parse("arrow.svg")))
     plot.set_copies(7)
     plot.set_rotation(90)
     f = open("out/plot_%s.svg"%sys._getframe().f_code.co_name,"w")
     f.write(plot.get_preview_xml())
     f.close()
     spacing = plot.get_spacing()
     assert len(plot._data) == 7
     assert plot.get_stack_size_y() == 5, "Stack size: %s" % plot.get_stack_size_y()
     assert round(plot.get_width(),10) == round(plot.graphic.get_width()*2 + spacing[0],10)
     assert round(plot.get_height(),10) == round(plot.graphic.get_height()*5+spacing[1]*4,10)
Exemplo n.º 21
0
 def test_set_copies_2(self):
     """ Test set_copies(7) with no rotation should stack along y axis."""
     plot = Plot(90*12,90*12*4)
     plot.set_graphic(etree.tostring(etree.parse("arrow.svg")))
     plot.set_copies(7) # two horizontal stacks and one extra
     f = open("out/plot_%s.svg"%sys._getframe().f_code.co_name,"w")
     f.write(plot.get_preview_xml())
     f.close()
     spacing = plot.get_spacing()
     assert len(plot._data) == 7
     assert plot.get_stack_size_x() == 3, "Stack size: %s" % plot.get_stack_size_x()
     assert round(plot.get_width(),10) == round(plot.graphic.get_width()*3 + spacing[0]*2,10)
     assert round(plot.get_height(),10) == round(plot.graphic.get_height()*3+spacing[1]*2,10)
Exemplo n.º 22
0
 def test_weedline_padding(self):
     """
     Test that a weedline graphic is added to the plot and that 35 padding
     only changes the width and height of the bbox by +=2*padding.
     """
     plot = Plot(90 * 12, 90 * 12 * 4)
     plot.set_graphic(etree.tostring(etree.parse("arrow.svg")))
     plot.set_rotation(90)
     plot.set_copies(6)
     bbox = plot.get_bounding_box()
     plot.set_weedline(True)
     pad = 35
     plot.set_weedline_padding(pad)
     f = open("out/plot_%s.svg" % sys._getframe().f_code.co_name, "w")
     f.write(plot.get_preview_xml())
     f.close()
     assert len(plot._data) == 7, "len(plot._data) = %s, expect 7" % (len(
         plot._data))
     assert map(lambda x: round(x, 10), plot.get_bounding_box()) == [
         0, bbox[1] + 2 * pad, 35, bbox[3] + 2 * pad
     ], "bbox before %s != bbox after weedline %s" % ([
         0, bbox[1] + 35, 35, bbox[3] + 35
     ], map(lambda x: round(x, 10), plot.get_bounding_box()))
Exemplo n.º 23
0
 def test_set_padding(self):
     """ Test the set_padding() """
     plot = Plot(90 * 12, 90 * 12 * 4)
     plot.set_padding(35, 0, 35, 0)
     assert plot.get_available_width() == 90 * 12
     assert plot.get_available_height() == 90 * 12 * 4 - 70
     plot.set_padding(top=30)
     assert plot.get_available_width() == 90 * 12
     assert plot.get_available_height() == 90 * 12 * 4 - 65
     plot.set_padding(right=30)
     assert plot.get_available_width() == 90 * 12 - 30
     assert plot.get_available_height() == 90 * 12 * 4 - 65
     plot.set_padding(left=17.3)
     assert plot.get_available_width() == 90 * 12 - 30 - 17.3
     assert plot.get_available_height() == 90 * 12 * 4 - 65
     plot.set_padding(bottom=0)
     assert plot.get_available_width() == 90 * 12 - 30 - 17.3
     assert plot.get_available_height() == 90 * 12 * 4 - 30
     plot.set_padding(top=35, right=0, bottom=35, left=0)
     assert plot.get_available_width() == 90 * 12
     assert plot.get_available_height() == 90 * 12 * 4 - 70
     plot.set_padding(top=0, right=0, bottom=0, left=0)
     assert plot.get_available_width() == 90 * 12
     assert plot.get_available_height() == 90 * 12 * 4
Exemplo n.º 24
0
 def test_set_copies_3(self):
     """ Test set_copies() and get_preview_xml() should stack 7 along  the x axis. """
     plot = Plot(90 * 12, 90 * 12 * 4)
     plot.set_graphic(etree.tostring(etree.parse("arrow.svg")))
     plot.set_copies(7)
     plot.set_rotation(90)
     f = open("out/plot_%s.svg" % sys._getframe().f_code.co_name, "w")
     f.write(plot.get_preview_xml())
     f.close()
     spacing = plot.get_spacing()
     assert len(plot._data) == 7
     assert plot.get_stack_size_y(
     ) == 5, "Stack size: %s" % plot.get_stack_size_y()
     assert round(plot.get_width(),
                  10) == round(plot.graphic.get_width() * 2 + spacing[0],
                               10)
     assert round(plot.get_height(), 10) == round(
         plot.graphic.get_height() * 5 + spacing[1] * 4, 10)
Exemplo n.º 25
0
 def test_set_copies_2(self):
     """ Test set_copies(7) with no rotation should stack along y axis."""
     plot = Plot(90 * 12, 90 * 12 * 4)
     plot.set_graphic(etree.tostring(etree.parse("arrow.svg")))
     plot.set_copies(7)  # two horizontal stacks and one extra
     f = open("out/plot_%s.svg" % sys._getframe().f_code.co_name, "w")
     f.write(plot.get_preview_xml())
     f.close()
     spacing = plot.get_spacing()
     assert len(plot._data) == 7
     assert plot.get_stack_size_x(
     ) == 3, "Stack size: %s" % plot.get_stack_size_x()
     assert round(plot.get_width(), 10) == round(
         plot.graphic.get_width() * 3 + spacing[0] * 2, 10)
     assert round(plot.get_height(), 10) == round(
         plot.graphic.get_height() * 3 + spacing[1] * 2, 10)
Exemplo n.º 26
0
import sys
import os
import logging
dirname = os.path.dirname
sys.path.append(os.path.join(os.path.abspath(dirname(dirname(__file__)))))
from lxml import etree
from lib.plot import Plot
logging.basicConfig()
log = logging.getLogger(__name__)


plot = Plot(90*12*16,90*12*4)
plot.set_graphic(etree.tostring(etree.parse("tests/fat-giraffes.svg")))
plot.set_copies(40) # two horizontal stacks and one extra
#f = open("out/plot_%s.svg"%sys._getframe().f_code.co_name,"w")
#f.write(plot.get_preview_xml())
Exemplo n.º 27
0
    def McCabe(self, LK=0, HK=1):
        A = self.kwargs["entrada"].componente[LK].nombre
        B = self.kwargs["entrada"].componente[HK].nombre
        P = self.kwargs["entrada"].P
        Psat = dict()
        Psat[A] = self.kwargs["entrada"].componente[LK].Pv
        Psat[B] = self.kwargs["entrada"].componente[HK].Pv
        Tsat = dict()
        for i, s in enumerate(Psat.keys()):
            Tsat[s] = lambda P, s=s: fsolve(lambda T: Psat[s](T)-P,self.kwargs["entrada"].componente[i].Tb)[0]

        T = linspace(Tsat[A](P),Tsat[B](P))

        x = lambda T: (P-Psat[B](T))/(Psat[A](T)-Psat[B](T))
        y = lambda T: x(T)*Psat[A](T)/P

        xB = 1-self.kwargs["HKsplit"]
        xF = self.kwargs["entrada"].fraccion[LK]
        xD = self.kwargs["LKsplit"]
        Tbub = fsolve(lambda T:x(T) - xF,T[25])
        yF = y(Tbub)

        if self.kwargs["R"]:
            R=self.kwargs["R"]
        else:
            Eslope = (xD-yF)/(xD-xF)
            Rmin = Eslope/(1-Eslope)
            R=self.kwargs["R_Rmin"]*Rmin

        zF = xD-R*(xD-xF)/(R+1)
        Sslope = (zF-xB)/(xF-xB)
        S = 1/(Sslope-1)
        xP = xD
        yP = xD

        dialog=Plot()
        dialog.plot.ax.grid(True)
        dialog.plot.ax.set_title(QApplication.translate("pychemqt", "x-y Diagram for") + "{:s}/{:s} P={:s}".format(A,B,P.str), size="x-large")
        dialog.plot.ax.set_xlabel(QApplication.translate("pychemqt", "Liquid Mole Fraction")+" {:s}".format(A), size="x-large")
        dialog.plot.ax.set_ylabel(QApplication.translate("pychemqt", "Vapor Mole Fraction")+" {:s}".format(B), size="x-large")
        dialog.plot.ax.set_xticks(linspace(0,1.0,21))
        dialog.plot.ax.set_yticks(linspace(0.05,1.0,20))
        dialog.addData([0,1],[0,1],'b--')
        dialog.addData(map(x,T),map(y,T))
        dialog.addData([xB,xB],[0,xB],'r--')
        dialog.addData(xB,xB,'ro',ms=5)
        dialog.addText(xB+0.005,0.02,'xB = {:0.3f}'.format(float(xB)))
        dialog.addData([xF,xF,xF],[0,xF,yF],'r--')
        dialog.addData([xF,xF],[xF,yF],'ro',ms=5)
        dialog.addText(xF+0.005,0.02,'xF = {:0.3f}'.format(float(xF)))
        dialog.addData([xD,xD],[0,xD],'r--')
        dialog.addData(xD,xD,'ro',ms=5)
        dialog.addText(xD-0.005,0.02,'xD = {:0.3f}'.format(float(xD)), ha="right")

        dialog.addData([xD,xF],[xD,yF],'r--')
        dialog.addData([xD,xF],[xD,zF],'r-')
        dialog.addData([xB,xF],[xB,xB + (S+1)*(xF-xB)/S],'r-')

        nTray = 0
        while xP > xB:
            nTray += 1
            Tdew = fsolve(lambda T:y(T) - yP, T[25])
            xQ = xP
            xP = x(Tdew)
            dialog.addData([xQ,xP],[yP,yP],'r')
            dialog.addData(xP,yP,'ro',ms=5)
            dialog.addText(xP-0.03,yP,nTray)

            yQ = yP
            yP = min([xD - (R/(R+1))*(xD-xP),xB + ((S+1)/S)*(xP-xB)])
            dialog.addData([xP,xP],[yQ,yP],'r')

        nTray -= 1

        dialog.addText(0.1,0.90,'Rmin = {:0.2f}'.format(float(Rmin)), size="large")
        dialog.addText(0.1,0.85,'R = {:0.2f}'.format(float(R)), size="large")
        dialog.addText(0.1,0.80,'S = {:0.2f}'.format(float(S)), size="large")
        dialog.addText(0.1,0.75,'nTrays = {:d}'.format(int(nTray)), size="large")


        dialog.exec_()
Exemplo n.º 28
0
 def event_file_selected(self, file_name):
     new_data = TimingData()
     new_data.load_from_csv(file_name)
     new_plot = Plot(new_data)
     self.data_source_model.add_data(new_plot)
     self.data_source_table.resizeColumnsToContents()
Exemplo n.º 29
0
    def McCabe(self, LK=0, HK=1):
        A = self.kwargs["entrada"].componente[LK].nombre
        B = self.kwargs["entrada"].componente[HK].nombre
        P = self.kwargs["entrada"].P
        Psat = dict()
        Psat[A] = self.kwargs["entrada"].componente[LK].Pv
        Psat[B] = self.kwargs["entrada"].componente[HK].Pv
        Tsat = dict()
        for i, s in enumerate(Psat.keys()):
            Tsat[s] = lambda P, s=s: fsolve(
                lambda T: Psat[s]
                (T) - P, self.kwargs["entrada"].componente[i].Tb)[0]

        T = linspace(Tsat[A](P), Tsat[B](P))

        x = lambda T: (P - Psat[B](T)) / (Psat[A](T) - Psat[B](T))
        y = lambda T: x(T) * Psat[A](T) / P

        xB = 1 - self.kwargs["HKsplit"]
        xF = self.kwargs["entrada"].fraccion[LK]
        xD = self.kwargs["LKsplit"]
        Tbub = fsolve(lambda T: x(T) - xF, T[25])
        yF = y(Tbub)

        if self.kwargs["R"]:
            R = self.kwargs["R"]
        else:
            Eslope = (xD - yF) / (xD - xF)
            Rmin = Eslope / (1 - Eslope)
            R = self.kwargs["R_Rmin"] * Rmin

        zF = xD - R * (xD - xF) / (R + 1)
        Sslope = (zF - xB) / (xF - xB)
        S = 1 / (Sslope - 1)
        xP = xD
        yP = xD

        dialog = Plot()
        dialog.plot.ax.grid(True)
        dialog.plot.ax.set_title(
            QApplication.translate("pychemqt", "x-y Diagram for") +
            "{:s}/{:s} P={:s}".format(A, B, P.str),
            size="x-large")
        dialog.plot.ax.set_xlabel(
            QApplication.translate("pychemqt", "Liquid Mole Fraction") +
            " {:s}".format(A),
            size="x-large")
        dialog.plot.ax.set_ylabel(
            QApplication.translate("pychemqt", "Vapor Mole Fraction") +
            " {:s}".format(B),
            size="x-large")
        dialog.plot.ax.set_xticks(linspace(0, 1.0, 21))
        dialog.plot.ax.set_yticks(linspace(0.05, 1.0, 20))
        dialog.addData([0, 1], [0, 1], 'b--')
        dialog.addData(list(map(x, T)), list(map(y, T)))
        dialog.addData([xB, xB], [0, xB], 'r--')
        dialog.addData(xB, xB, 'ro', ms=5)
        dialog.addText(xB + 0.005, 0.02, 'xB = {:0.3f}'.format(float(xB)))
        dialog.addData([xF, xF, xF], [0, xF, yF], 'r--')
        dialog.addData([xF, xF], [xF, yF], 'ro', ms=5)
        dialog.addText(xF + 0.005, 0.02, 'xF = {:0.3f}'.format(float(xF)))
        dialog.addData([xD, xD], [0, xD], 'r--')
        dialog.addData(xD, xD, 'ro', ms=5)
        dialog.addText(xD - 0.005,
                       0.02,
                       'xD = {:0.3f}'.format(float(xD)),
                       ha="right")

        dialog.addData([xD, xF], [xD, yF], 'r--')
        dialog.addData([xD, xF], [xD, zF], 'r-')
        dialog.addData([xB, xF], [xB, xB + (S + 1) * (xF - xB) / S], 'r-')

        nTray = 0
        while xP > xB:
            nTray += 1
            Tdew = fsolve(lambda T: y(T) - yP, T[25])
            xQ = xP
            xP = x(Tdew)
            dialog.addData([xQ, xP], [yP, yP], 'r')
            dialog.addData(xP, yP, 'ro', ms=5)
            dialog.addText(xP - 0.03, yP, nTray)

            yQ = yP
            yP = min([
                xD - (R / (R + 1)) * (xD - xP), xB + ((S + 1) / S) * (xP - xB)
            ])
            dialog.addData([xP, xP], [yQ, yP], 'r')

        nTray -= 1

        dialog.addText(0.1,
                       0.90,
                       'Rmin = {:0.2f}'.format(float(Rmin)),
                       size="large")
        dialog.addText(0.1, 0.85, 'R = {:0.2f}'.format(float(R)), size="large")
        dialog.addText(0.1, 0.80, 'S = {:0.2f}'.format(float(S)), size="large")
        dialog.addText(0.1,
                       0.75,
                       'nTrays = {:d}'.format(int(nTray)),
                       size="large")

        dialog.exec_()
Exemplo n.º 30
0
 def test_set_padding(self):
     """ Test the set_padding() """
     plot = Plot(90*12,90*12*4)
     plot.set_padding(35,0,35,0)
     assert plot.get_available_width() == 90*12
     assert plot.get_available_height() == 90*12*4-70
     plot.set_padding(top=30)
     assert plot.get_available_width() == 90*12
     assert plot.get_available_height() == 90*12*4-65
     plot.set_padding(right=30)
     assert plot.get_available_width() == 90*12-30
     assert plot.get_available_height() == 90*12*4-65
     plot.set_padding(left=17.3)
     assert plot.get_available_width() == 90*12-30-17.3
     assert plot.get_available_height() == 90*12*4-65
     plot.set_padding(bottom=0)
     assert plot.get_available_width() == 90*12-30-17.3
     assert plot.get_available_height() == 90*12*4-30
     plot.set_padding(top=35,right=0,bottom=35,left=0)
     assert plot.get_available_width() == 90*12
     assert plot.get_available_height() == 90*12*4-70
     plot.set_padding(top=0,right=0,bottom=0,left=0)
     assert plot.get_available_width() == 90*12
     assert plot.get_available_height() == 90*12*4
Exemplo n.º 31
0
 def test_set_copies(self):
     """ Test set_copies() and set_rotation(90) should stack along x axis."""
     plot = Plot(90 * 12, 90 * 12 * 4)
     plot.set_graphic(etree.tostring(etree.parse("arrow.svg")))
     plot.set_copies(4)
     plot.set_rotation(90)
     f = open("out/plot_%s.svg" % sys._getframe().f_code.co_name, "w")
     f.write(plot.get_preview_xml())
     f.close()
     spacing = plot.get_spacing()
     assert len(plot._data) == 4
     assert plot.get_width() == plot.graphic.get_width()
     assert round(plot.get_height(), 10) == round(
         plot.graphic.get_height() * 4 + spacing[1] * 3, 10)
Exemplo n.º 32
0
 def test_set_graphic_2(self):
     """ Test set_graphic() and setting a new graphic after one has already been set. """
     plot = Plot(90*12,90*12*4)
     plot.set_graphic(etree.tostring(etree.parse("arrow.svg")))
     f = open("out/plot_%s_1.svg"%sys._getframe().f_code.co_name,"w")
     f.write(plot.get_preview_xml())
     f.close()
     assert plot.get_width() == plot.graphic.get_width()
     assert round(plot.get_height(),10) == round(plot.graphic.get_height(),10) # why does it need rounding???
     plot.set_graphic(etree.tostring(etree.parse("fat-giraffes.svg")))
     f = open("out/plot_%s_2.svg"%sys._getframe().f_code.co_name,"w")
     f.write(plot.get_preview_xml())
     f.close()
     assert round(plot.get_width(),10) == round(plot.graphic.get_width(),10)
     assert round(plot.get_height(),10) == round(plot.graphic.get_height(),10) # why does it need rounding???
Exemplo n.º 33
0
 def test_set_position(self):
     """ Test set_position()"""
     plot = Plot(90*12,90*12*4)
     plot.set_graphic(etree.tostring(etree.parse("arrow.svg")))
     log.info("Checking position 0,0...")
     assert map(lambda x:round(x,10),plot.get_position()) == [0,0], "Got %s" % map(lambda x:round(x,10),plot.get_position())
     log.info("OK")
     log.info("Checking position 50,0...")
     plot.set_position(50,0)
     assert map(lambda x:round(x,10),plot.get_position()) == [50,0], "Got %s" % map(lambda x:round(x,10),plot.get_position())
     log.info("OK")
     log.info("Checking position 13.2,459...")
     plot.set_position(13.2,459)
     assert map(lambda x:round(x,10),plot.get_position()) == [13.2,459], "Got %s" % map(lambda x:round(x,10),plot.get_position())
     log.info("OK")
     f = open("out/plot_%s_1.svg"%sys._getframe().f_code.co_name,"w")
     f.write(plot.get_preview_xml())
     f.close()
Exemplo n.º 34
0
 def test_set_copies(self):
     """ Test set_copies() and set_rotation(90) should stack along x axis."""
     plot = Plot(90*12,90*12*4)
     plot.set_graphic(etree.tostring(etree.parse("arrow.svg")))
     plot.set_copies(4)
     plot.set_rotation(90)
     f = open("out/plot_%s.svg"%sys._getframe().f_code.co_name,"w")
     f.write(plot.get_preview_xml())
     f.close()
     spacing = plot.get_spacing()
     assert len(plot._data) == 4
     assert plot.get_width() == plot.graphic.get_width()
     assert round(plot.get_height(),10) == round(plot.graphic.get_height()*4+spacing[1]*3,10)
Exemplo n.º 35
0
 def test_weedline(self):
     """
     Test that a weedline graphic is added to the plot and that 0 padding
     doesn't change the bbox.
     """
     plot = Plot(90 * 12, 90 * 12 * 4)
     plot.set_graphic(etree.tostring(etree.parse("arrow.svg")))
     plot.set_rotation(90)
     plot.set_copies(7)
     bbox = plot.get_bounding_box()
     plot.set_weedline(True)
     f = open("out/plot_%s.svg" % sys._getframe().f_code.co_name, "w")
     f.write(plot.get_preview_xml())
     f.close()
     assert len(plot._data) == 8, "len(plot._data) = %s, expect 8" % (len(
         plot._data))
     assert map(lambda x: round(x, 10), plot.get_bounding_box()) == map(
         lambda x: round(x, 10),
         bbox), "bbox before %s != bbox after weedline %s" % (
             bbox, plot.get_bounding_box())
Exemplo n.º 36
0
import sys
import os
import logging
dirname = os.path.dirname
sys.path.append(os.path.join(os.path.abspath(dirname(dirname(__file__)))))
from lxml import etree
from lib.plot import Plot
logging.basicConfig()
log = logging.getLogger(__name__)

plot = Plot(90 * 12 * 16, 90 * 12 * 4)
plot.set_graphic(etree.tostring(etree.parse("tests/fat-giraffes.svg")))
plot.set_copies(40)  # two horizontal stacks and one extra
#f = open("out/plot_%s.svg"%sys._getframe().f_code.co_name,"w")
#f.write(plot.get_preview_xml())
Exemplo n.º 37
0
 def test_set_position(self):
     """ Test set_position()"""
     plot = Plot(90 * 12, 90 * 12 * 4)
     plot.set_graphic(etree.tostring(etree.parse("arrow.svg")))
     log.info("Checking position 0,0...")
     assert map(lambda x: round(x, 10), plot.get_position()) == [
         0, 0
     ], "Got %s" % map(lambda x: round(x, 10), plot.get_position())
     log.info("OK")
     log.info("Checking position 50,0...")
     plot.set_position(50, 0)
     assert map(lambda x: round(x, 10), plot.get_position()) == [
         50, 0
     ], "Got %s" % map(lambda x: round(x, 10), plot.get_position())
     log.info("OK")
     log.info("Checking position 13.2,459...")
     plot.set_position(13.2, 459)
     assert map(lambda x: round(x, 10), plot.get_position()) == [
         13.2, 459
     ], "Got %s" % map(lambda x: round(x, 10), plot.get_position())
     log.info("OK")
     f = open("out/plot_%s_1.svg" % sys._getframe().f_code.co_name, "w")
     f.write(plot.get_preview_xml())
     f.close()