def updateInputs(self, index): """Update inputs appearance to highlight active""" for par in self.parameters: self.__getattribute__(par).setReadOnly(True) self.__getattribute__(par).setResaltado(False) for par in PsyState.VAR_NAME[index]: self.__getattribute__(par).setReadOnly(False) self.__getattribute__(par).setResaltado(True) index = self.variables.currentIndex() kwargs = {"P": self.P.value} for par in PsyState.VAR_NAME[index]: if self.__getattribute__(par).value: kwargs[par] = self.state.__getattribute__(par) self.state = PsychroState(**kwargs)
def calculo(self): #TODO: De momento, no se implementan las cuestiones de cinetica de intercambio de calor y materia que definirían las dimensiones necesarias del equipo HR = self.kwargs.get("HR", 100) self.Heat = Power(self.kwargs["Heat"]) self.deltaP = Pressure(self.kwargs["deltaP"]) self.entradaAire = self.kwargs["entradaAire"] Pout = min(self.kwargs["entradaSolido"].P.atm, self.kwargs["entradaAire"].P.atm) - self.deltaP.atm aguaSolidoSalida = self.kwargs["HumedadResidual"] * self.kwargs[ "entradaSolido"].solido.caudal.kgh aguaSolidoEntrada = self.kwargs["entradaSolido"].caudalmasico.kgh if self.kwargs["mode"] == 0: Caudal_aguaenAireSalida = aguaSolidoEntrada - aguaSolidoSalida + self.entradaAire.caudalMasico.kgh * self.entradaAire.Xw Caudal_airesalida = self.entradaAire.caudalMasico.kgh * self.entradaAire.Xa if self.entradaAire.Hs > Caudal_aguaenAireSalida / Caudal_airesalida: H = Caudal_aguaenAireSalida / Caudal_airesalida else: H = self.entradaAire.Hs aguaSolidoSalida += Caudal_aguaenAireSalida / Caudal_airesalida - self.entradaAire.Hs self.SalidaAire = PsychroState(caudal=Caudal_aguaenAireSalida + Caudal_airesalida, tdb=self.entradaAire.Tdb, H=H) self.SalidaSolido = self.kwargs["entradaSolido"].clone( T=self.SalidaAire.Tdb, P=Pout, split=aguaSolidoSalida / aguaSolidoEntrada) else: pass
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
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:]))
def changeAltitude(self, value): """Change pressure through altitude and ICAO equation""" presion = _Pbar(value) self.P.setValue(presion) self.state = PsychroState(P=value) self.pressureChanged.emit()
def changePressure(self, value): """Change pressure to global plot and for states""" self.z.setValue(_height(value)) self.state = PsychroState(P=value) self.pressureChanged.emit()
def __init__(self, state=None, readOnly=False, parent=None): """ constructor optional state parameter to assign initial psychrometric state """ super(PsychroInput, self).__init__(parent) self.state = PsychroState(P=101325) layout = QtWidgets.QGridLayout(self) self.checkPresion = QtWidgets.QRadioButton( QtWidgets.QApplication.translate("pychemqt", "Pressure")) layout.addWidget(self.checkPresion, 1, 1, 1, 1) self.P = Entrada_con_unidades(Pressure, value=101325) self.P.valueChanged.connect(self.changePressure) layout.addWidget(self.P, 1, 2, 1, 1) self.checkAltitud = QtWidgets.QRadioButton( QtWidgets.QApplication.translate("pychemqt", "Altitude")) layout.addWidget(self.checkAltitud, 2, 1, 1, 1) self.z = Entrada_con_unidades(Length, value=0) self.checkPresion.toggled.connect(self.P.setEnabled) self.checkAltitud.toggled.connect(self.z.setEnabled) self.z.valueChanged.connect(self.changeAltitude) self.checkPresion.setChecked(True) self.z.setEnabled(False) layout.addWidget(self.z, 2, 2, 1, 1) layout.addItem(QtWidgets.QSpacerItem( 10, 10, QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed), 3, 1, 1, 2) layout.addWidget(QtWidgets.QLabel(QtWidgets.QApplication.translate( "pychemqt", "Select point")), 4, 1, 1, 2) self.variables = QtWidgets.QComboBox() for txt in PsyState.TEXT_MODE: self.variables.addItem(txt) self.variables.currentIndexChanged.connect(self.updateInputs) layout.addWidget(self.variables, 5, 1, 1, 2) layout.addWidget(QtWidgets.QLabel("Tdb:"), 6, 1, 1, 1) self.tdb = Entrada_con_unidades(Temperature) self.tdb.valueChanged.connect(partial(self.updateKwargs, "tdb")) layout.addWidget(self.tdb, 6, 2, 1, 1) layout.addWidget(QtWidgets.QLabel("Twb:"), 7, 1, 1, 1) self.twb = Entrada_con_unidades(Temperature) self.twb.valueChanged.connect(partial(self.updateKwargs, "twb")) layout.addWidget(self.twb, 7, 2, 1, 1) layout.addWidget(QtWidgets.QLabel("Tdp:"), 8, 1, 1, 1) self.tdp = Entrada_con_unidades(Temperature) self.tdp.valueChanged.connect(partial(self.updateKwargs, "tdp")) layout.addWidget(self.tdp, 8, 2, 1, 1) layout.addWidget(QtWidgets.QLabel(QtWidgets.QApplication.translate( "pychemqt", "Humidity Ratio:")), 9, 1, 1, 1) self.w = Entrada_con_unidades(float, textounidad="kgw/kgda") self.w.valueChanged.connect(partial(self.updateKwargs, "w")) layout.addWidget(self.w, 9, 2, 1, 1) layout.addWidget(QtWidgets.QLabel(QtWidgets.QApplication.translate( "pychemqt", "Relative humidity:")), 10, 1, 1, 1) self.HR = Entrada_con_unidades(float, textounidad="%") self.HR.valueChanged.connect(partial(self.updateKwargs, "HR")) layout.addWidget(self.HR, 10, 2, 1, 1) layout.addWidget(QtWidgets.QLabel(QtWidgets.QApplication.translate( "pychemqt", "Volume")), 11, 1, 1, 1) self.v = Entrada_con_unidades(SpecificVolume) self.v.valueChanged.connect(partial(self.updateKwargs, "v")) layout.addWidget(self.v, 11, 2, 1, 1) layout.addWidget(QtWidgets.QLabel(QtWidgets.QApplication.translate( "pychemqt", "Enthalpy")), 12, 1, 1, 1) self.h = Entrada_con_unidades(Enthalpy) self.h.valueChanged.connect(partial(self.updateKwargs, "h")) layout.addWidget(self.h, 12, 2, 1, 1) layout.addItem(QtWidgets.QSpacerItem( 20, 20, QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed), 13, 1, 1, 2) self.setReadOnly(readOnly) self.updateInputs(0) if state: self.setState(state)
class PsychroInput(QtWidgets.QWidget): """Widget with parameter for psychrometric state""" parameters = ["tdb", "twb", "tdp", "w", "HR", "v", "h"] stateChanged = QtCore.pyqtSignal(PsyState) pressureChanged = QtCore.pyqtSignal() def __init__(self, state=None, readOnly=False, parent=None): """ constructor optional state parameter to assign initial psychrometric state """ super(PsychroInput, self).__init__(parent) self.state = PsychroState(P=101325) layout = QtWidgets.QGridLayout(self) self.checkPresion = QtWidgets.QRadioButton( QtWidgets.QApplication.translate("pychemqt", "Pressure")) layout.addWidget(self.checkPresion, 1, 1, 1, 1) self.P = Entrada_con_unidades(Pressure, value=101325) self.P.valueChanged.connect(self.changePressure) layout.addWidget(self.P, 1, 2, 1, 1) self.checkAltitud = QtWidgets.QRadioButton( QtWidgets.QApplication.translate("pychemqt", "Altitude")) layout.addWidget(self.checkAltitud, 2, 1, 1, 1) self.z = Entrada_con_unidades(Length, value=0) self.checkPresion.toggled.connect(self.P.setEnabled) self.checkAltitud.toggled.connect(self.z.setEnabled) self.z.valueChanged.connect(self.changeAltitude) self.checkPresion.setChecked(True) self.z.setEnabled(False) layout.addWidget(self.z, 2, 2, 1, 1) layout.addItem(QtWidgets.QSpacerItem( 10, 10, QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed), 3, 1, 1, 2) layout.addWidget(QtWidgets.QLabel(QtWidgets.QApplication.translate( "pychemqt", "Select point")), 4, 1, 1, 2) self.variables = QtWidgets.QComboBox() for txt in PsyState.TEXT_MODE: self.variables.addItem(txt) self.variables.currentIndexChanged.connect(self.updateInputs) layout.addWidget(self.variables, 5, 1, 1, 2) layout.addWidget(QtWidgets.QLabel("Tdb:"), 6, 1, 1, 1) self.tdb = Entrada_con_unidades(Temperature) self.tdb.valueChanged.connect(partial(self.updateKwargs, "tdb")) layout.addWidget(self.tdb, 6, 2, 1, 1) layout.addWidget(QtWidgets.QLabel("Twb:"), 7, 1, 1, 1) self.twb = Entrada_con_unidades(Temperature) self.twb.valueChanged.connect(partial(self.updateKwargs, "twb")) layout.addWidget(self.twb, 7, 2, 1, 1) layout.addWidget(QtWidgets.QLabel("Tdp:"), 8, 1, 1, 1) self.tdp = Entrada_con_unidades(Temperature) self.tdp.valueChanged.connect(partial(self.updateKwargs, "tdp")) layout.addWidget(self.tdp, 8, 2, 1, 1) layout.addWidget(QtWidgets.QLabel(QtWidgets.QApplication.translate( "pychemqt", "Humidity Ratio:")), 9, 1, 1, 1) self.w = Entrada_con_unidades(float, textounidad="kgw/kgda") self.w.valueChanged.connect(partial(self.updateKwargs, "w")) layout.addWidget(self.w, 9, 2, 1, 1) layout.addWidget(QtWidgets.QLabel(QtWidgets.QApplication.translate( "pychemqt", "Relative humidity:")), 10, 1, 1, 1) self.HR = Entrada_con_unidades(float, textounidad="%") self.HR.valueChanged.connect(partial(self.updateKwargs, "HR")) layout.addWidget(self.HR, 10, 2, 1, 1) layout.addWidget(QtWidgets.QLabel(QtWidgets.QApplication.translate( "pychemqt", "Volume")), 11, 1, 1, 1) self.v = Entrada_con_unidades(SpecificVolume) self.v.valueChanged.connect(partial(self.updateKwargs, "v")) layout.addWidget(self.v, 11, 2, 1, 1) layout.addWidget(QtWidgets.QLabel(QtWidgets.QApplication.translate( "pychemqt", "Enthalpy")), 12, 1, 1, 1) self.h = Entrada_con_unidades(Enthalpy) self.h.valueChanged.connect(partial(self.updateKwargs, "h")) layout.addWidget(self.h, 12, 2, 1, 1) layout.addItem(QtWidgets.QSpacerItem( 20, 20, QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed), 13, 1, 1, 2) self.setReadOnly(readOnly) self.updateInputs(0) if state: self.setState(state) def updateInputs(self, index): """Update inputs appearance to highlight active""" for par in self.parameters: self.__getattribute__(par).setReadOnly(True) self.__getattribute__(par).setResaltado(False) for par in PsyState.VAR_NAME[index]: self.__getattribute__(par).setReadOnly(False) self.__getattribute__(par).setResaltado(True) index = self.variables.currentIndex() kwargs = {"P": self.P.value} for par in PsyState.VAR_NAME[index]: if self.__getattribute__(par).value: kwargs[par] = self.state.__getattribute__(par) self.state = PsychroState(**kwargs) def setReadOnly(self, readOnly): self.checkPresion.setEnabled(not readOnly) self.checkAltitud.setEnabled(not readOnly) self.P.setReadOnly(readOnly) self.z.setReadOnly(readOnly) self.variables.setEnabled(not readOnly) for par in self.parameters: self.__getattribute__(par).setReadOnly(True) self.__getattribute__(par).setResaltado(False) def updateKwargs(self, key, value): """Update kwargs of state instance, if its correctly defined show it""" kwargs = {key: value} self.state(**kwargs) if self.state.status: self.setState(self.state) self.stateChanged.emit(self.state) def setState(self, state): """Fill data input with state properties""" self.state = state if state.w < state.ws: for p in self.parameters: self.__getattribute__(p).setValue(state.__getattribute__(p)) def changePressure(self, value): """Change pressure to global plot and for states""" self.z.setValue(_height(value)) self.state = PsychroState(P=value) self.pressureChanged.emit() def changeAltitude(self, value): """Change pressure through altitude and ICAO equation""" presion = _Pbar(value) self.P.setValue(presion) self.state = PsychroState(P=value) self.pressureChanged.emit()
def plot(self): """Plot chart""" Preferences = ConfigParser() Preferences.read(config.conf_dir + "pychemqtrc") self.diagrama2D.axes2D.clear() self.diagrama2D.config() filename = config.conf_dir + "%s_%i.pkl" % ( PsychroState().__class__.__name__, self.inputs.P.value) if os.path.isfile(filename): with open(filename, "r") as archivo: data = cPickle.load(archivo) self.status.setText( QtGui.QApplication.translate("pychemqt", "Loading cached data...")) QtGui.QApplication.processEvents() else: self.progressBar.setVisible(True) self.status.setText( QtGui.QApplication.translate( "pychemqt", "Calculating data, be patient...")) QtGui.QApplication.processEvents() data = PsychroState.calculatePlot(self) cPickle.dump(data, open(filename, "w")) self.progressBar.setVisible(False) self.status.setText( QtGui.QApplication.translate("pychemqt", "Plotting...")) QtGui.QApplication.processEvents() tmax = unidades.Temperature(Preferences.getfloat( "Psychr", "isotdbEnd")) t = [unidades.Temperature(ti).config() for ti in data["t"]] Hs = data["Hs"] format = {} format["ls"] = Preferences.get("Psychr", "saturationlineStyle") format["lw"] = Preferences.getfloat("Psychr", "saturationlineWidth") format["color"] = Preferences.get("Psychr", "saturationColor") format["marker"] = Preferences.get("Psychr", "saturationmarker") format["markersize"] = 3 self.diagrama2D.plot(t, Hs, **format) format = {} format["ls"] = Preferences.get("Psychr", "isotdblineStyle") format["lw"] = Preferences.getfloat("Psychr", "isotdblineWidth") format["color"] = Preferences.get("Psychr", "isotdbColor") format["marker"] = Preferences.get("Psychr", "isotdbmarker") format["markersize"] = 3 for i, T in enumerate(t): self.diagrama2D.plot([T, T], [0, Hs[i]], **format) H = data["H"] th = data["th"] format = {} format["ls"] = Preferences.get("Psychr", "isowlineStyle") format["lw"] = Preferences.getfloat("Psychr", "isowlineWidth") format["color"] = Preferences.get("Psychr", "isowColor") format["marker"] = Preferences.get("Psychr", "isowmarker") format["markersize"] = 3 for i, H in enumerate(H): self.diagrama2D.plot([th[i], tmax.config()], [H, H], **format) format = {} format["ls"] = Preferences.get("Psychr", "isohrlineStyle") format["lw"] = Preferences.getfloat("Psychr", "isohrlineWidth") format["color"] = Preferences.get("Psychr", "isohrColor") format["marker"] = Preferences.get("Psychr", "isohrmarker") format["markersize"] = 3 for Hr, H0 in data["Hr"].iteritems(): self.diagrama2D.plot(t, H0, **format) self.drawlabel("isohr", Preferences, t, H0, Hr, "%") format = {} format["ls"] = Preferences.get("Psychr", "isotwblineStyle") format["lw"] = Preferences.getfloat("Psychr", "isotwblineWidth") format["color"] = Preferences.get("Psychr", "isotwbColor") format["marker"] = Preferences.get("Psychr", "isotwbmarker") format["markersize"] = 3 for T, (H, Tw) in data["Twb"].iteritems(): self.diagrama2D.plot(Tw, H, **format) value = unidades.Temperature(T).config() txt = unidades.Temperature.text() self.drawlabel("isotwb", Preferences, Tw, H, value, txt) format = {} format["ls"] = Preferences.get("Psychr", "isochorlineStyle") format["lw"] = Preferences.getfloat("Psychr", "isochorlineWidth") format["color"] = Preferences.get("Psychr", "isochorColor") format["marker"] = Preferences.get("Psychr", "isochormarker") format["markersize"] = 3 for v, (Td, H) in data["v"].iteritems(): self.diagrama2D.plot(Td, H, **format) value = unidades.SpecificVolume(v).config() txt = unidades.SpecificVolume.text() self.drawlabel("isochor", Preferences, Td, H, value, txt) self.diagrama2D.draw() self.status.setText( QtGui.QApplication.translate("pychemqt", "Using") + " " + PsychroState().__class__.__name__[3:])
def __init__(self, state=None, readOnly=False, parent=None): """ constructor optional state parameter to assign initial psychrometric state""" super(PsychroInput, self).__init__(parent) self.state = PsychroState(P=101325) self.setSizePolicy(QtWidgets.QSizePolicy.Maximum, QtWidgets.QSizePolicy.Preferred) layout = QtWidgets.QGridLayout(self) self.checkPresion = QtWidgets.QRadioButton( QtWidgets.QApplication.translate("pychemqt", "Pressure")) layout.addWidget(self.checkPresion, 1, 1, 1, 1) self.P = Entrada_con_unidades(unidades.Pressure, value=101325) self.P.valueChanged.connect(self.changePressure) layout.addWidget(self.P, 1, 2, 1, 1) self.checkAltitud = QtWidgets.QRadioButton( QtWidgets.QApplication.translate("pychemqt", "Altitude")) layout.addWidget(self.checkAltitud, 2, 1, 1, 1) self.z = Entrada_con_unidades(unidades.Length, value=0) self.checkPresion.toggled.connect(self.P.setEnabled) self.checkAltitud.toggled.connect(self.z.setEnabled) self.z.valueChanged.connect(self.changeAltitude) self.checkPresion.setChecked(True) self.z.setEnabled(False) layout.addWidget(self.z, 2, 2, 1, 1) layout.addItem(QtWidgets.QSpacerItem(10, 10, QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed), 3, 1, 1, 2) layout.addWidget(QtWidgets.QLabel(QtWidgets.QApplication.translate( "pychemqt", "Select point")), 4, 1, 1, 2) self.variables = QtWidgets.QComboBox() for txt in PsyState.TEXT_MODE: self.variables.addItem(txt) self.variables.currentIndexChanged.connect(self.updateInputs) layout.addWidget(self.variables, 5, 1, 1, 2) layout.addWidget(QtWidgets.QLabel("Tdb:"), 6, 1, 1, 1) self.tdb = Entrada_con_unidades(unidades.Temperature) self.tdb.valueChanged.connect(partial(self.updateKwargs, "tdb")) layout.addWidget(self.tdb, 6, 2, 1, 1) layout.addWidget(QtWidgets.QLabel("Twb:"), 7, 1, 1, 1) self.twb = Entrada_con_unidades(unidades.Temperature) self.twb.valueChanged.connect(partial(self.updateKwargs, "twb")) layout.addWidget(self.twb, 7, 2, 1, 1) layout.addWidget(QtWidgets.QLabel("Tdp:"), 8, 1, 1, 1) self.tdp = Entrada_con_unidades(unidades.Temperature) self.tdp.valueChanged.connect(partial(self.updateKwargs, "tdp")) layout.addWidget(self.tdp, 8, 2, 1, 1) layout.addWidget(QtWidgets.QLabel(QtWidgets.QApplication.translate( "pychemqt", "Humidity Ratio:")), 9, 1, 1, 1) self.w = Entrada_con_unidades(float, textounidad="kgw/kgda") self.w.valueChanged.connect(partial(self.updateKwargs, "w")) layout.addWidget(self.w, 9, 2, 1, 1) layout.addWidget(QtWidgets.QLabel(QtWidgets.QApplication.translate( "pychemqt", "Relative humidity:")), 10, 1, 1, 1) self.HR = Entrada_con_unidades(float, textounidad="%") self.HR.valueChanged.connect(partial(self.updateKwargs, "HR")) layout.addWidget(self.HR, 10, 2, 1, 1) layout.addWidget(QtWidgets.QLabel(QtWidgets.QApplication.translate( "pychemqt", "Volume")), 11, 1, 1, 1) self.v = Entrada_con_unidades(unidades.SpecificVolume) self.v.valueChanged.connect(partial(self.updateKwargs, "v")) layout.addWidget(self.v, 11, 2, 1, 1) layout.addWidget(QtWidgets.QLabel(QtWidgets.QApplication.translate( "pychemqt", "Enthalpy")), 12, 1, 1, 1) self.h = Entrada_con_unidades(unidades.Enthalpy) self.h.valueChanged.connect(partial(self.updateKwargs, "h")) layout.addWidget(self.h, 12, 2, 1, 1) layout.addItem(QtWidgets.QSpacerItem(20, 20, QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed),13,1,1,2) self.setReadOnly(readOnly) self.updateInputs(0) if state: self.setState(state)
class PsychroInput(QtWidgets.QWidget): """Widget with parameter for psychrometric state""" parameters = ["tdb", "twb", "tdp", "w", "HR", "v", "h"] stateChanged = QtCore.pyqtSignal(PsyState) pressureChanged = QtCore.pyqtSignal() def __init__(self, state=None, readOnly=False, parent=None): """ constructor optional state parameter to assign initial psychrometric state""" super(PsychroInput, self).__init__(parent) self.state = PsychroState(P=101325) self.setSizePolicy(QtWidgets.QSizePolicy.Maximum, QtWidgets.QSizePolicy.Preferred) layout = QtWidgets.QGridLayout(self) self.checkPresion = QtWidgets.QRadioButton( QtWidgets.QApplication.translate("pychemqt", "Pressure")) layout.addWidget(self.checkPresion, 1, 1, 1, 1) self.P = Entrada_con_unidades(unidades.Pressure, value=101325) self.P.valueChanged.connect(self.changePressure) layout.addWidget(self.P, 1, 2, 1, 1) self.checkAltitud = QtWidgets.QRadioButton( QtWidgets.QApplication.translate("pychemqt", "Altitude")) layout.addWidget(self.checkAltitud, 2, 1, 1, 1) self.z = Entrada_con_unidades(unidades.Length, value=0) self.checkPresion.toggled.connect(self.P.setEnabled) self.checkAltitud.toggled.connect(self.z.setEnabled) self.z.valueChanged.connect(self.changeAltitude) self.checkPresion.setChecked(True) self.z.setEnabled(False) layout.addWidget(self.z, 2, 2, 1, 1) layout.addItem(QtWidgets.QSpacerItem(10, 10, QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed), 3, 1, 1, 2) layout.addWidget(QtWidgets.QLabel(QtWidgets.QApplication.translate( "pychemqt", "Select point")), 4, 1, 1, 2) self.variables = QtWidgets.QComboBox() for txt in PsyState.TEXT_MODE: self.variables.addItem(txt) self.variables.currentIndexChanged.connect(self.updateInputs) layout.addWidget(self.variables, 5, 1, 1, 2) layout.addWidget(QtWidgets.QLabel("Tdb:"), 6, 1, 1, 1) self.tdb = Entrada_con_unidades(unidades.Temperature) self.tdb.valueChanged.connect(partial(self.updateKwargs, "tdb")) layout.addWidget(self.tdb, 6, 2, 1, 1) layout.addWidget(QtWidgets.QLabel("Twb:"), 7, 1, 1, 1) self.twb = Entrada_con_unidades(unidades.Temperature) self.twb.valueChanged.connect(partial(self.updateKwargs, "twb")) layout.addWidget(self.twb, 7, 2, 1, 1) layout.addWidget(QtWidgets.QLabel("Tdp:"), 8, 1, 1, 1) self.tdp = Entrada_con_unidades(unidades.Temperature) self.tdp.valueChanged.connect(partial(self.updateKwargs, "tdp")) layout.addWidget(self.tdp, 8, 2, 1, 1) layout.addWidget(QtWidgets.QLabel(QtWidgets.QApplication.translate( "pychemqt", "Humidity Ratio:")), 9, 1, 1, 1) self.w = Entrada_con_unidades(float, textounidad="kgw/kgda") self.w.valueChanged.connect(partial(self.updateKwargs, "w")) layout.addWidget(self.w, 9, 2, 1, 1) layout.addWidget(QtWidgets.QLabel(QtWidgets.QApplication.translate( "pychemqt", "Relative humidity:")), 10, 1, 1, 1) self.HR = Entrada_con_unidades(float, textounidad="%") self.HR.valueChanged.connect(partial(self.updateKwargs, "HR")) layout.addWidget(self.HR, 10, 2, 1, 1) layout.addWidget(QtWidgets.QLabel(QtWidgets.QApplication.translate( "pychemqt", "Volume")), 11, 1, 1, 1) self.v = Entrada_con_unidades(unidades.SpecificVolume) self.v.valueChanged.connect(partial(self.updateKwargs, "v")) layout.addWidget(self.v, 11, 2, 1, 1) layout.addWidget(QtWidgets.QLabel(QtWidgets.QApplication.translate( "pychemqt", "Enthalpy")), 12, 1, 1, 1) self.h = Entrada_con_unidades(unidades.Enthalpy) self.h.valueChanged.connect(partial(self.updateKwargs, "h")) layout.addWidget(self.h, 12, 2, 1, 1) layout.addItem(QtWidgets.QSpacerItem(20, 20, QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed),13,1,1,2) self.setReadOnly(readOnly) self.updateInputs(0) if state: self.setState(state) def updateInputs(self, index): """Update inputs appearance to highlight active""" for par in self.parameters: self.__getattribute__(par).setReadOnly(True) self.__getattribute__(par).setResaltado(False) for par in PsyState.VAR_NAME[index]: self.__getattribute__(par).setReadOnly(False) self.__getattribute__(par).setResaltado(True) index = self.variables.currentIndex() kwargs = {"P": self.P.value} for par in PsyState.VAR_NAME[index]: if self.__getattribute__(par).value: kwargs[par] = self.state.__getattribute__(par) self.state = PsychroState(**kwargs) def setReadOnly(self, readOnly): self.checkPresion.setEnabled(not readOnly) self.checkAltitud.setEnabled(not readOnly) self.P.setReadOnly(readOnly) self.z.setReadOnly(readOnly) self.variables.setEnabled(not readOnly) for par in self.parameters: self.__getattribute__(par).setReadOnly(True) self.__getattribute__(par).setResaltado(False) def updateKwargs(self, key, value): """Update kwargs of state instance, if its correctly defined show it""" kwargs = {key: value} self.state(**kwargs) if self.state.status: self.setState(self.state) self.stateChanged.emit(self.state) def setState(self, state): """Fill data input with state properties""" self.state = state if state.w < state.ws: for par in self.parameters: self.__getattribute__(par).setValue(state.__getattribute__(par)) def changePressure(self, value): """Change pressure to global plot and for states""" self.z.setValue(_height(value)) self.state = PsychroState(P=value) self.pressureChanged.emit() def changeAltitude(self, value): """Change pressure through altitude and ICAO equation""" presion = _Pbar(value) self.P.setValue(presion) self.state = PsychroState(P=value) self.pressureChanged.emit()
def plot(self): """Plot chart""" Preferences = ConfigParser() Preferences.read(config.conf_dir+"pychemqtrc") self.diagrama2D.axes2D.clear() self.diagrama2D.config() filename = config.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, be patient...")) 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() tmax = unidades.Temperature(Preferences.getfloat("Psychr", "isotdbEnd")) t = [unidades.Temperature(ti).config() for ti in data["t"]] Hs = data["Hs"] format = {} format["ls"] = Preferences.get("Psychr", "saturationlineStyle") format["lw"] = Preferences.getfloat("Psychr", "saturationlineWidth") format["color"] = Preferences.get("Psychr", "saturationColor") format["marker"] = Preferences.get("Psychr", "saturationmarker") format["markersize"] = 3 self.diagrama2D.plot(t, Hs, **format) format = {} format["ls"] = Preferences.get("Psychr", "isotdblineStyle") format["lw"] = Preferences.getfloat("Psychr", "isotdblineWidth") format["color"] = Preferences.get("Psychr", "isotdbColor") format["marker"] = Preferences.get("Psychr", "isotdbmarker") format["markersize"] = 3 for i, T in enumerate(t): self.diagrama2D.plot([T, T], [0, Hs[i]], **format) H = data["H"] th = data["th"] format = {} format["ls"] = Preferences.get("Psychr", "isowlineStyle") format["lw"] = Preferences.getfloat("Psychr", "isowlineWidth") format["color"] = Preferences.get("Psychr", "isowColor") format["marker"] = Preferences.get("Psychr", "isowmarker") format["markersize"] = 3 for i, H in enumerate(H): self.diagrama2D.plot([th[i], tmax.config()], [H, H], **format) format = {} format["ls"] = Preferences.get("Psychr", "isohrlineStyle") format["lw"] = Preferences.getfloat("Psychr", "isohrlineWidth") format["color"] = Preferences.get("Psychr", "isohrColor") format["marker"] = Preferences.get("Psychr", "isohrmarker") format["markersize"] = 3 for Hr, H0 in list(data["Hr"].items()): self.diagrama2D.plot(t, H0, **format) self.drawlabel("isohr", Preferences, t, H0, Hr, "%") format = {} format["ls"] = Preferences.get("Psychr", "isotwblineStyle") format["lw"] = Preferences.getfloat("Psychr", "isotwblineWidth") format["color"] = Preferences.get("Psychr", "isotwbColor") format["marker"] = Preferences.get("Psychr", "isotwbmarker") format["markersize"] = 3 for T, (H, Tw) in list(data["Twb"].items()): self.diagrama2D.plot(Tw, H, **format) value = unidades.Temperature(T).config() txt = unidades.Temperature.text() self.drawlabel("isotwb", Preferences, Tw, H, value, txt) format = {} format["ls"] = Preferences.get("Psychr", "isochorlineStyle") format["lw"] = Preferences.getfloat("Psychr", "isochorlineWidth") format["color"] = Preferences.get("Psychr", "isochorColor") format["marker"] = Preferences.get("Psychr", "isochormarker") format["markersize"] = 3 for v, (Td, H) in list(data["v"].items()): self.diagrama2D.plot(Td, H, **format) value = unidades.SpecificVolume(v).config() txt = unidades.SpecificVolume.text() self.drawlabel("isochor", Preferences, Td, H, value, txt) self.diagrama2D.draw() self.status.setText(QtWidgets.QApplication.translate("pychemqt", "Using") + " " + PsychroState().__class__.__name__[3:])
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:]))