Demo entry 6278222

gujkhjl

   

Submitted by anonymous on Oct 16, 2016 at 20:10
Language: Python. Code size: 28.6 kB.

# -*- coding: utf-8 -*-
"""
/***************************************************************************
 sicilyflood
                                 A QGIS plugin
 Questo plug-in permette il calcolo automatico delle portate di piena per una data sezione del corso d'acqua.
                              -------------------
        begin                : 2016-09-21
        git sha              : $Format:%H$
        copyright            : (C) 2016 by Università degli studi di Palermo - Salvator Giuliano Narsete
        email                : giuliano.narsete@gmail.com
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/
"""
from PyQt4.QtCore import QSettings, QTranslator, qVersion, QCoreApplication
from PyQt4.QtGui import QAction, QIcon
# Initialize Qt resources from file resources.py
import resources
# Import the code for the dialog
from sicilyflood_dialog import sicilyfloodDialog
import os.path
import os
import sys
import webbrowser
from PyQt4.QtCore import *
from osgeo import gdal
import osr
import numpy as np 
import scipy.io as sio
import matplotlib.pyplot as plt
from PyQt4 import QtGui, QtCore #aggiunto
from qgis.utils import *
from qgis.core import *
from qgis.gui import *
from PyQt4.QtGui import *
from sfbasefuncs import sfBASEfuncs
from sfhydrofuncs import sfHYDROfuncs
sfb=sfBASEfuncs()
sfh=sfHYDROfuncs()

class sicilyflood:
    """QGIS Plugin Implementation."""

    def __init__(self, iface):
        """Constructor.

        :param iface: An interface instance that will be passed to this class
            which provides the hook by which you can manipulate the QGIS
            application at run time.
        :type iface: QgsInterface
        """
        # Save reference to the QGIS interface
        self.iface = iface
        # initialize plugin directory
        self.plugin_dir = os.path.dirname(__file__)
        # initialize locale
        locale = QSettings().value('locale/userLocale')[0:2]
        locale_path = os.path.join(
            self.plugin_dir,
            'i18n',
            'sicilyflood_{}.qm'.format(locale))

        if os.path.exists(locale_path):
            self.translator = QTranslator()
            self.translator.load(locale_path)

            if qVersion() > '4.3.3':
                QCoreApplication.installTranslator(self.translator)

        # Create the dialog (after translation) and keep reference
        self.dlg = sicilyfloodDialog()
        self.clickTool = QgsMapToolEmitPoint(iface.mapCanvas())  ### clickTool
        self.clickTool.canvasClicked.connect(self.handleMouseDown)
        # Declare instance attributes
        self.actions = []
        self.menu = self.tr(u'&SicilyFlood')
        # TODO: We are going to let the user set this up in a future iteration
        self.toolbar = self.iface.addToolBar(u'sicilyflood')
        self.toolbar.setObjectName(u'sicilyflood')

    # noinspection PyMethodMayBeStatic
    def tr(self, message):
        """Get the translation for a string using Qt translation API.

        We implement this ourselves since we do not inherit QObject.

        :param message: String for translation.
        :type message: str, QString

        :returns: Translated version of message.
        :rtype: QString
        """
        # noinspection PyTypeChecker,PyArgumentList,PyCallByClass
        return QCoreApplication.translate('sicilyflood', message)


    def add_action(self,icon_path,text,callback,enabled_flag=True,add_to_menu=True,add_to_toolbar=True,status_tip=None,whats_this=None,parent=None):
        """Add a toolbar icon to the toolbar.

        :param icon_path: Path to the icon for this action. Can be a resource
            path (e.g. ':/plugins/foo/bar.png') or a normal file system path.
        :type icon_path: str

        :param text: Text that should be shown in menu items for this action.
        :type text: str

        :param callback: Function to be called when the action is triggered.
        :type callback: function

        :param enabled_flag: A flag indicating if the action should be enabled
            by default. Defaults to True.
        :type enabled_flag: bool

        :param add_to_menu: Flag indicating whether the action should also
            be added to the menu. Defaults to True.
        :type add_to_menu: bool

        :param add_to_toolbar: Flag indicating whether the action should also
            be added to the toolbar. Defaults to True.
        :type add_to_toolbar: bool

        :param status_tip: Optional text to show in a popup when mouse pointer
            hovers over the action.
        :type status_tip: str

        :param parent: Parent widget for the new action. Defaults None.
        :type parent: QWidget

        :param whats_this: Optional text to show in the status bar when the
            mouse pointer hovers over the action.

        :returns: The action that was created. Note that the action is also
            added to self.actions list.
        :rtype: QAction
        """
        
        icon = QIcon(icon_path)
        action = QAction(icon, text, parent)
        action.triggered.connect(callback)
        action.setEnabled(enabled_flag)

        if status_tip is not None:
            action.setStatusTip(status_tip)

        if whats_this is not None:
            action.setWhatsThis(whats_this)

        if add_to_toolbar:
            self.toolbar.addAction(action)

        if add_to_menu:
            self.iface.addPluginToMenu(
                self.menu,
                action)
        self.actions.append(action)
        return action

    def initGui(self):
        """Create the menu entries and toolbar icons inside the QGIS GUI."""
        icon_path = ':/plugins/sicilyflood/icon.png'
        self.add_action(
            icon_path,
            text=self.tr(u'SicilyFlood'),
            callback=self.run,
            parent=self.iface.mainWindow())
        
        ###collegamenti ai pulsanti
        
        #caricare file e cartelle
        self.dlg.pushButtonDEM.clicked.connect(lambda: sfb.caricafile("Load a valid DEM raster",self.dlg.comboBoxDEM)) ### aggiunto
        self.dlg.pushButtonFlowdirection.clicked.connect(lambda: sfb.caricafile("Load a valid Flow Direction vector",self.dlg.comboBoxFlowdirection)) ### aggiunto
        self.dlg.pushButtonFlowAccumulation.clicked.connect(lambda: sfb.caricafile("Load a valid Flow Direction vector",self.dlg.comboBoxFlowdirection)) ### aggiunto
        self.dlg.pushButtonzoneTCEV.clicked.connect(lambda: sfb.caricafile("Load a valid zone vector",self.dlg.comboBoxzoneTCEV)) ### aggiunto
        self.dlg.pushButtonarasterTCEV.clicked.connect(lambda: sfb.caricafile("Load a valid isoa raster",self.dlg.comboBoxarasterTCEV)) ### aggiunto
        self.dlg.pushButtonnrasterTCEV.clicked.connect(lambda: sfb.caricafile("Load a valid ison raster",self.dlg.comboBoxnrasterTCEV)) ### aggiunto
        self.dlg.pushButtonCNraster.clicked.connect(lambda: sfb.caricafile("Load a valid CN raster",self.dlg.comboBoxCNraster)) ### aggiunto
        self.dlg.pushButtonOutputDirectory.clicked.connect(lambda: sfb.caricadir("Load a Output Directory",self.dlg.comboBoxOutputDirectory)) ### aggiunto
        
        #abilitazione sezione TCEV isoa
        self.dlg.radioButtonarasterTCEV.toggled.connect(lambda: sfb.abilitaDisabilita(self.dlg.radioButtonarasterTCEV.isChecked(),self.dlg.pushButtonarasterTCEV))
        self.dlg.radioButtonarasterTCEV.toggled.connect(lambda: sfb.abilitaDisabilita(self.dlg.radioButtonarasterTCEV.isChecked(),self.dlg.comboBoxarasterTCEV))
        self.dlg.radioButtonavalueTCEV.toggled.connect(lambda: sfb.abilitaDisabilita(self.dlg.radioButtonavalueTCEV.isChecked(),self.dlg.doubleSpinBoxavalueTCEV))
        
        #abilitazione sezione TCEV ison
        self.dlg.radioButtonnrasterTCEV.toggled.connect(lambda: sfb.abilitaDisabilita(self.dlg.radioButtonnrasterTCEV.isChecked(),self.dlg.comboBoxnrasterTCEV))
        self.dlg.radioButtonnrasterTCEV.toggled.connect(lambda: sfb.abilitaDisabilita(self.dlg.radioButtonnrasterTCEV.isChecked(),self.dlg.pushButtonnrasterTCEV))
        self.dlg.radioButtonnvalueTCEV.toggled.connect(lambda: sfb.abilitaDisabilita(self.dlg.radioButtonnvalueTCEV.isChecked(),self.dlg.doubleSpinBoxnvalueTCEV))
        
        #abilitazione sezione tempo di corrivazione con valore
        self.dlg.radioButtonvaluecorrivazione.toggled.connect(lambda: sfb.abilitaDisabilita(self.dlg.radioButtonvaluecorrivazione.isChecked(),self.dlg.doubleSpinBoxtcorrivazione))
        self.dlg.radioButtonvaluecorrivazione.toggled.connect(lambda: sfb.abilitaDisabilita(self.dlg.radioButtontcorrivazionemodello.isChecked(),self.dlg.label_5))

        #abilitazione sezione Tempi di ritorno
        self.dlg.checkBox50ritorno.toggled.connect(lambda: sfb.abilitaDisabilita(self.dlg.checkBox50ritorno.isChecked(),self.dlg.spinBox50ritorno))
        self.dlg.checkBox100ritorno.toggled.connect(lambda: sfb.abilitaDisabilita(self.dlg.checkBox100ritorno.isChecked(),self.dlg.spinBox100ritorno))
        self.dlg.checkBox300ritorno.toggled.connect(lambda: sfb.abilitaDisabilita(self.dlg.checkBox300ritorno.isChecked(),self.dlg.spinBox300ritorno))
        
        #abilitazione sezione CN
        self.dlg.radioButtonCNraster.toggled.connect(lambda: sfb.abilitaDisabilita(self.dlg.radioButtonCNraster.isChecked(),self.dlg.comboBoxCNraster))
        self.dlg.radioButtonCNraster.toggled.connect(lambda: sfb.abilitaDisabilita(self.dlg.radioButtonCNraster.isChecked(),self.dlg.pushButtonCNraster))
        self.dlg.radioButtonCNvalue.toggled.connect(lambda: sfb.abilitaDisabilita(self.dlg.radioButtonCNvalue.isChecked(),self.dlg.doubleSpinBoxCNvalue))
        
        #abilitare la scelta rpicco
        self.dlg.radioButtonIetoChicago.toggled.connect(lambda: sfb.abilitaDisabilita(self.dlg.radioButtonIetoChicago.isChecked(),self.dlg.doubleSpinBoxrpicco))
        self.dlg.radioButtonIetoChicago.toggled.connect(lambda: sfb.abilitaDisabilita(self.dlg.radioButtonIetoChicago.isChecked(),self.dlg.label_21))
        
        #Verifica Bacino
        self.dlg.pushButtonVerifica.clicked.connect(lambda: self.verifyWS())
        
        #Prepara Raster
        self.dlg.pushButtonPreparaRaster.clicked.connect(lambda: self.prepareRasters())
        
        #Abilitare Run Modello
        self.dlg.pushButtonPreparaRaster.clicked.connect(lambda: self.dlg.pushButtonRUN.setEnabled(True))
        
        #collegare il tasto RUN al modello
        self.dlg.pushButtonRUN.clicked.connect(lambda: self.applicaModelloSalvaReport())
        
        #Punto sulla mappa
        self.dlg.pushButtonClick.clicked.connect(self.clickPoint) 
        
        #Caricare la flow accumulation
        self.dlg.pushButtonLoadFA.clicked.connect(lambda: self.caricaFA())
        
        #Switch to results
        self.dlg.pushButtonRUN.clicked.connect(lambda: self.dlg.tabWidget.setCurrentPage(2))
        
        #si può mettere qua?
        #os.mkdir(self.dlg.comboBoxOutputDirectory.currentText()+'/raster',0755)
        
    def unload(self):
        """Removes the plugin menu item and icon from QGIS GUI."""
        for action in self.actions:
            self.iface.removePluginMenu(
                self.tr(u'&SicilyFlood'),
                action)
            self.iface.removeToolBarIcon(action)
        # remove the toolbar
        del self.toolbar
    
    def run(self):
        """Run method that performs all the real work"""
        # show the dialog
        self.dlg.show()
        # Run the dialog event loop
        result = self.dlg.exec_()
        # See if OK was pressed
        if result:
            # Do something useful here - delete the line containing pass and
            # substitute with your code.
            pass
    
    def clickPoint(self):
        self.dlg.hide()
        self.iface.mapCanvas().setMapTool(self.clickTool) 
        
    def handleMouseDown(self, point, button):  ### clickTool
        self.dlg.lineEditEstcoord.setText(str(point.x()))
        self.dlg.lineEditNordcoord.setText(str(point.y()))
        self.dlg.show()     
 
    def percorsifile(self):
        ### Percorsifile
        # File di input
        dem=self.dlg.comboBoxDEM.currentText()
        fd=self.dlg.comboBoxFlowdirection.currentText()
        zone=self.dlg.comboBoxzoneTCEV.currentText()
        isoa=self.dlg.comboBoxarasterTCEV.currentText()
        ison=self.dlg.comboBoxnrasterTCEV.currentText()
        cn=self.dlg.comboBoxCNraster.currentText()
        # File creati
        #os.mkdir(self.dlg.comboBoxOutputDirectory.currentText()+'/raster',0755)
        cartellaRaster=self.dlg.comboBoxOutputDirectory.currentText()+'//raster'
        ws=cartellaRaster+'//ws.tif'
        wsFd=cartellaRaster+'//wsFd.tif'
        fdWs=cartellaRaster+'//fdWs.tif'
        wsIsoa=cartellaRaster+'//wsIsoa.tif'
        wsIson=cartellaRaster+'//wsIson.tif'
        isoaWs=cartellaRaster+'//isoaWs.tif'
        isonWs=cartellaRaster+'//isonWs.tif'
        wsDem=cartellaRaster+'//wsDem.tif' 
        demWs=cartellaRaster+'//demWs.tif'
        wsCn=cartellaRaster+'//wsCn.tif' 
        cnWs=cartellaRaster+'//cnWs.tif'
        flWs=cartellaRaster+'//flWs.tif'
        isoieteWs=cartellaRaster+'//isoieteWs.tif'
        outletCoordsVec=cartellaRaster+'//outlet.shp'
        outletCoordsRas=cartellaRaster+'//outlet.tif'
        global dem
        global fd
        global cn
        global zone
        global isoa
        global ison
        global ws
        global wsIsoa
        global wsIson
        global isoaWs
        global isonWs
        global wsDem
        global demWs
        global flWs
        global wsCn
        global cnWs
        global isoieteWs
        global wsFd
        global fdWs
        global outletCoordsVec
        global outletCoordsRas

    def caricaFA(self):
        flowAccumulation=self.dlg.comboBoxFlowAccumulation.currentText()
        self.iface.addRasterLayer(flowAccumulation,'fa')
        
    def prepareRasters(self):
        self.dlg.labelRiassunto.setText(self.dlg.labelRiassunto.text()+'\nSetting paths\n')
        self.percorsifile()
        xcoord=self.dlg.lineEditEstcoord.text()
        ycoord=self.dlg.lineEditNordcoord.text()
        outletCoords=str(xcoord) +','+ str(ycoord)
        sfh.Bacino(fd,ws,outletCoords)
        if self.dlg.radioButtonCNraster.isChecked()==True:
            sfb.AdattaRaster(cn,ws,wsCn)
        if self.dlg.radioButtonarasterTCEV.isChecked()==True:
            sfb.AdattaRaster(isoa,ws,wsIsoa)
        if self.dlg.radioButtonnrasterTCEV.isChecked()==True:
            sfb.AdattaRaster(ison,ws,wsIson)
        sfb.AdattaRaster(dem,ws,wsDem)
        sfb.AdattaRaster(fd,ws,wsFd)
        if self.dlg.radioButtonCNraster.isChecked()==True:
            sfb.ProdottoLayers(ws,wsCn,cnWs)
        if self.dlg.radioButtonnrasterTCEV.isChecked()==True:
            sfb.ProdottoLayers(ws,wsIson,isonWs)
        if self.dlg.radioButtonarasterTCEV.isChecked()==True:
            sfb.ProdottoLayers(ws,wsIsoa,isoaWs)
        sfb.ProdottoLayers(ws,wsDem,demWs)
        sfb.ProdottoLayers(ws,wsFd,fdWs)
        sfb.outletRaster(fdWs,xcoord,ycoord,outletCoordsVec,outletCoordsRas)
        sfh.FlowLenght(fdWs,outletCoordsRas,demWs,flWs)
        msg=QMessageBox()
        msg.setWindowTitle("Information")
        msg.setIcon(QMessageBox.Information)
        msg.setText("Rasters are ready for analisys.")
        msg.exec_()
        self.dlg.labelRiassunto.setText(self.dlg.labelRiassunto.text()+'\nRasters are ready for analisys.\n')    
    
    def datidiinput(self):
        global deltat
        global AMC
        global rpicco
        global xcoord
        global ycoord
        global outletCoords
        global durata
        global tempo_ritorno1
        global tempo_ritorno2
        global tempo_ritorno3
        global tcorrivazione
        global irapporto
        global velPiena
        deltat=self.dlg.doubleSpinBoxdeltat.value()  
        xcoord=self.dlg.lineEditEstcoord.text()
        ycoord=self.dlg.lineEditNordcoord.text()
        outletCoords=str(xcoord) +','+ str(ycoord)
        durata=np.arange(1,25,0.5)
        tempo_ritorno1=sfb.tempidiritorno(self.dlg.checkBox50ritorno,self.dlg.spinBox50ritorno)
        tempo_ritorno2=sfb.tempidiritorno(self.dlg.checkBox100ritorno,self.dlg.spinBox100ritorno)
        tempo_ritorno3=sfb.tempidiritorno(self.dlg.checkBox300ritorno,self.dlg.spinBox300ritorno)
        rpicco=self.dlg.doubleSpinBoxrpicco.value()
        AMC=sfb.calcoloAMC(self.dlg.radioButtonAMC1,self.dlg.radioButtonAMC2)
        velPiena=self.dlg.doubleSpinBoxvelPiena.value()
        if self.dlg.radioButtonvaluecorrivazione.isChecked()==True:
            tcorrivazione=self.dlg.doubleSpinBoxtcorrivazione.value()
        else:
            tcorrivazione=sfh.calcolotempodicorrivazione(flWs,velPiena) 
        irapporto=tcorrivazione/deltat

    def verifyWS(self):
        xcoord=self.dlg.lineEditEstcoord.text()
        ycoord=self.dlg.lineEditNordcoord.text()
        outletCoords=str(xcoord) +','+ str(ycoord)
        self.dlg.labelRiassunto.setText(self.dlg.labelRiassunto.text()+'\nCoordinate di sezione di chiusura caricate\n')
        #os.mkdir(self.dlg.comboBoxOutputDirectory.currentText()+'//raster',0755)
        fd=self.dlg.comboBoxFlowdirection.currentText()
        #ws=self.dlg.comboBoxOutputDirectory.currentText()+'//raster//ws.tif'
        ws='E://Uni//Tesi//giuliano//input_plugin//input_plugin//output//raster//ws.tif'
        sfh.Bacino(fd,ws,outletCoords)
        wsNp=sfb.to_nparray(ws)
        areaKm2=float(np.equal(1,wsNp).sum())*40*40/1000000
        self.iface.addRasterLayer(ws,'watershed')
        msg=QMessageBox()
        msg.setWindowTitle("Area")
        msg.setIcon(QMessageBox.Information)
        msg.setText("Area = %f [kmq]" % (areaKm2))
        msg.exec_()
        self.dlg.labelRiassunto.setText(self.dlg.labelRiassunto.text()+'Il bacino e stato delimitato con successo\n Area = %f' % (areaKm2))
    
    def applicaModello(self):
        global outletCoords
        global areaKm2
        global zona
        global parametri
        global nmedio
        global amedio
        global xprimoT1
        global xprimoT2
        global xprimoT3
        global IdT1
        global IdT2
        global IdT3
        global CNmap
        global IndT1
        global IndT2
        global IndT3
        global htT1
        global htT2
        global htT3
        global Qpiena1
        global Qpiena2      
        global Qpiena3
        global diagrammah1
        global diagrammah2
        global diagrammah3
        global diagrammaQ1
        global diagrammaQ2
        global diagrammaQ3
        global cartellaRaster
        global cartellaTesto
        global cartellaImmagini
        #os.mkdir(self.dlg.comboBoxOutputDirectory.currentText()+'/raster',0755)
        cartellaRaster=self.dlg.comboBoxOutputDirectory.currentText()+'/raster'
        #os.mkdir(self.dlg.comboBoxOutputDirectory.currentText()+'/testo',0755)
        cartellaTesto=self.dlg.comboBoxOutputDirectory.currentText()+'/testo'
        #os.mkdir(self.dlg.comboBoxOutputDirectory.currentText()+'/immagini',0755)
        cartellaImmagini=self.dlg.comboBoxOutputDirectory.currentText()+'/immagini'
        
        ### Modello
        #Delimitazione Bacino 
        #sfh.Bacino(fd,ws,outletCoords)
        ws='E://Uni//Tesi//giuliano//input_plugin//input_plugin//output//raster//ws.tif'
        wsNp=sfb.to_nparray(ws)
        areaKm2=float(np.equal(1,wsNp).sum())*40*40/1000000
        
        ###Analisi pluviometrica: TCEV
        xcoord=float(self.dlg.lineEditEstcoord.text())
        ycoord=float(self.dlg.lineEditNordcoord.text())
        outletCoords=str(xcoord) +','+ str(ycoord)
        zona=sfh.sampleZones(zone,xcoord, ycoord)
        parametri=sfh.TCEVparameters(zona)
        if self.dlg.radioButtonnrasterTCEV.isChecked()==True:
            nmedio=sfb.meanRaster(isonWs)
        else:
            nmedio=self.dlg.doubleSpinBoxnvalueTCEV.value()
        if self.dlg.radioButtonarasterTCEV.isChecked()==True:
            amedio=(sfb.meanRaster(isoaWs))*(24**(-nmedio))
        else:
            amedio=self.dlg.doubleSpinBoxavalueTCEV.value()
        
        ###CPP
        xprimoT1=sfh.xprimotT(parametri[1],parametri[0],tempo_ritorno1)
        xprimoT2=sfh.xprimotT(parametri[1],parametri[0],tempo_ritorno2)
        xprimoT3=sfh.xprimotT(parametri[1],parametri[0],tempo_ritorno3)
        md=amedio*np.power(durata,nmedio)
        htT1=xprimoT1*md
        htT2=xprimoT2*md
        htT3=xprimoT3*md
        
        ###Ietogramma di piogge lorde
        IdT1=sfh.ietogrammaChicago(rpicco,deltat,tcorrivazione,irapporto,nmedio,amedio, xprimoT1)
        IdT2=sfh.ietogrammaChicago(rpicco,deltat,tcorrivazione,irapporto,nmedio,amedio, xprimoT2)
        IdT3=sfh.ietogrammaChicago(rpicco,deltat,tcorrivazione,irapporto,nmedio,amedio, xprimoT3)
        
        ###Ietogramma di piogge netta
        if self.dlg.radioButtonCNraster.isChecked()==True:
            CNmed=sfb.meanRaster(cnWs)
        else:
            CNmed=self.dlg.doubleSpinBoxCNvalue.value()
        CNmap=sfh.CalcoloCN(AMC,CNmed)
        IndT1=sfh.metodoCN(IdT1,CNmap,deltat)
        IndT2=sfh.metodoCN(IdT2,CNmap,deltat)
        IndT3=sfh.metodoCN(IdT3,CNmap,deltat)

        ###Curva Area/Tempi
        isoieteNp=sfh.isoieteMatrix(flWs,irapporto,cartellaTesto,isoieteWs)
        At=sfh.curvaAreaTempi(irapporto,isoieteNp,fdWs)
        
        ###Calcolo onda di piena
        Qpiena1=np.convolve(At,IndT1)/3600000 #con aree in mquadrati,piogge in millimetri#
        Qpiena2=np.convolve(At,IndT2)/3600000 #con aree in mquadrati,piogge in millimetri#
        Qpiena3=np.convolve(At,IndT3)/3600000 #con aree in mquadrati,piogge in millimetri#

    def salvaReport(self,path,outletCoords,zona,areaKm2,tcorrivazione,tempo_ritorno1,tempo_ritorno2,tempo_ritorno3,amedio,nmedio,parametri,xprimoT1,xprimoT2,xprimoT3,deltat,rpicco,AMC,CNmap,irapporto,IdT1,IdT2,IdT3,IndT1,IndT2,IndT3,Qpiena1,Qpiena2,Qpiena3):
        metodoietolordo=sfb.impostametodoietogrammalordo(self.dlg.radioButtonIetoRett,self.dlg.radioButtonIetoChicago) #imposta che metodo si è usato per lo ietogramma lordo
        metodoietonetto=sfb.impostametodoietogrammanetto() #imposta che metodo si è usato per lo ietogramma netto
        os.chdir(path)
        out_file = open('Report.txt',"w")
        out_file.write('***Caratteristiche Bacino***\n')
        out_file.write('Coordinate della sezione di chiusara:\t{}\n' .format(outletCoords))
        out_file.write('Sotto-zona:\t{}\n' .format(zona))
        out_file.write('Area del Bacino (A) [kmq]:\t{}\n' .format(areaKm2))
        out_file.write('Tempo di corrivazione del Bacino (tc) [ore]:\t{}\n\n' .format(tcorrivazione))
        out_file.write('***Parametri Analisi Pluviometrica***\n')
        out_file.write('Tempi di ritorno (T1,T2,T3) [anni]:\t(%s,%s,%s)\n' % (tempo_ritorno1,tempo_ritorno2,tempo_ritorno3))
        out_file.write('Pioggia oraria media bacino (amedio) [mm/ore]:\t %s \n'%(amedio))
        out_file.write('Parametro n medio bacino CPP (nmedio) [-]:\t{}\n' .format(nmedio))
        out_file.write('Parametri TCEV (a,b):\t{}\n' .format(parametri))
        out_file.write('Fattore di crescita (xprimoT1,xprimoT2,xprimoT3):\t(%s,%s,%s)\n\n' % (xprimoT1,xprimoT2,xprimoT3))
        out_file.write('\n***Parametri Ietogramma di piogge lorde sintetico***\n')
        out_file.write('Metodo usato:\t{}\n' .format(metodoietolordo))
        out_file.write('Risoluzione temporale [ore]:\t{}\n' .format(deltat))
        out_file.write('Posizione del picco [-]:\t{}\n\n' .format(rpicco))
        out_file.write('***Parametri Ietogramma di piogge nette sintetico***\n')
        out_file.write('Metodo usato:\t{}\n' .format(metodoietonetto))
        out_file.write('Risoluzione temporale [ore]:\t{}\n' .format(deltat))
        out_file.write('Condizione di umidità (AMC) [-]:\t{}\n' .format(AMC))
        out_file.write('Curve Number medio bacino (CN) [-]:\t{}\n' .format(CNmap))
        out_file.write('\n\n')
        tieto=np.arange(len(IdT1))*deltat+deltat
        out_file.write('***Ietogrammi sintetici di pioggia lorda e pioggia netta\n')
        out_file.write('t [ore]\tI1(mm/ore)\tI2(mm/ore)\tI3(mm/ore)\tIn1(mm/ore)\tIn2(mm/ore)\tIn3(mm/ore)\n')
        sfb.scriviIetogrammi(out_file,tieto,IdT1,IdT2,IdT3,IndT1,IndT2,IndT3)
        out_file.write('\n\n')
        tpiena=np.arange(len(Qpiena1))*deltat+deltat
        out_file.write('***Onde di piena***') 
        out_file.write('t [ore]\tQ1(mc/s)\tQ2(mc/s)\tQ3(mc/s)\n')
        out_file.write('0.0\t0.0\t0.0\t0.0\n')
        sfb.scriviOndedipiena(out_file,tpiena,Qpiena1,Qpiena2,Qpiena3)
        out_file.write('%s\t0.0\t0.0\t0.0\n' % ((2.0)*tcorrivazione))
        out_file.close()

    def applicaModelloSalvaReport(self):
        self.percorsifile()
        self.dlg.labelRiassunto.setText(self.dlg.labelRiassunto.text()+'File paths are set.\n')
        self.datidiinput()
        self.dlg.labelRiassunto.setText(self.dlg.labelRiassunto.text()+'The Input Data has been loaded\n')
        self.applicaModello()
        
        ###Salvataggio Report
        if self.dlg.checkBoxsalvaReport.isChecked():
            self.salvaReport(cartellaTesto,outletCoords,zona,areaKm2,tcorrivazione,tempo_ritorno1,tempo_ritorno2,tempo_ritorno3,amedio,nmedio,parametri,xprimoT1,xprimoT2,xprimoT3,deltat,rpicco,AMC,CNmap,irapporto,IdT1,IdT2,IdT3,IndT1,IndT2,IndT3,Qpiena1,Qpiena2,Qpiena3)
            self.dlg.labelRiassunto.setText(self.dlg.labelRiassunto.text()+'Report ready.\n')
            webbrowser.open('E:/Uni/Tesi/giuliano/input_plugin/input_plugin/output/testo/Report.txt')

            ###Mostrare a schermo i grafici
        if self.dlg.checkBoxfigure.isChecked():
            #grafici CPP
            sfb.diagrammi('CPP',durata,htT1,htT2,htT3,"durata [ore]", "altezza di pioggia [mm]")
            #self.dlg.labelRiassunto.setText(self.dlg.labelRiassunto.text()+'CPP1 correttamente salvata.\n')
            #ietogrammi lordi e netti
            tieto=np.arange(len(IdT1))*deltat
            #sfb.istogrammi('Ie)
            #grafici Onde di piena
            tpiena=np.arange(len(Qpiena1))*deltat+deltat
            sfb.diagrammi('Idrogramma',tpiena,Qpiena1,Qpiena2,Qpiena3,"durata [ore]", "Portate [mc/s]")
            #self.salvaFigura(diagrammaQpiena1,'Onda di piena per T=%s'%(tempo_ritorno1))
            #self.dlg.labelRiassunto.setText(self.dlg.labelRiassunto.text()+'Qpiena1 correttamente salvata.\n')
            #self.salvaFigura(diagrammaQpiena2,'Onda di piena per T=%s'%(tempo_ritorno2))
            #self.dlg.labelRiassunto.setText(self.dlg.labelRiassunto.text()+'Qpiena2 correttamente salvata.\n')
            #self.salvaFigura(diagrammaQpiena3,'Onda di piena per T=%s'%(tempo_ritorno3))
            #self.dlg.labelRiassunto.setText(self.dlg.labelRiassunto.text()+'Qpiena3 correttamente salvata.\n')
        #else:
            #self.dlg.labelRiassunto.setText(self.dlg.labelRiassunto.text()+'Figure non salvate.\n')

        ###Caricamento a schermo raster
        if self.dlg.checkBoxaggiungiRaster.isChecked():
            self.iface.addRasterLayer(demWs,'dem')
            self.dlg.labelRiassunto.setText(self.dlg.labelRiassunto.text()+'DEM added.\n')
            self.iface.addRasterLayer(cnWs,'cn')
            self.dlg.labelRiassunto.setText(self.dlg.labelRiassunto.text()+'CN added.\n')
            self.iface.addRasterLayer(ws,'watarshed')
            self.dlg.labelRiassunto.setText(self.dlg.labelRiassunto.text()+'Bacino added.\n')
            self.iface.addRasterLayer(flWs,'flow_lenght')
            self.dlg.labelRiassunto.setText(self.dlg.labelRiassunto.text()+'Flow Lenght added.\n')
            self.iface.addRasterLayer(fdWs,'flow_direction')
            self.dlg.labelRiassunto.setText(self.dlg.labelRiassunto.text()+'Flow Direction added.\n')

            
        self.dlg.labelRiassunto.setText(self.dlg.labelRiassunto.text()+'The analisys is successful.\n')  
        
                

This snippet took 0.03 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).