Example #1
0
 def convert_from_nrml(self, fname):
     """
     Populate the underlying archive with CSV files extracted from the
     given XML file.
     """
     assert fname.endswith('.xml'), fname
     prefix = os.path.basename(fname)[:-4]
     return self.convert_from_node(node_from_nrml(fname)[0], prefix)
Example #2
0
 def convert_from_nrml(self, fname):
     """
     Populate the underlying archive with CSV files extracted from the
     given XML file.
     """
     assert fname.endswith('.xml'), fname
     prefix = os.path.basename(fname)[:-4]
     return self.convert_from_node(node_from_nrml(fname)[0], prefix)
Example #3
0
 def open_file(self):
     fname = unicode(QtGui.QFileDialog.getOpenFileName(
         self, 'Choose file',
         self.inputdir,  # QtCore.QDir.homePath(),
         "Model file (*.xml);;Config files (*.ini)"))
     self.fileNameLbl.setText(fname)
     root = node_from_nrml(fname)
     tab = self.tabwidget.findChild(QtGui.QWidget, root.tag)
     tab.root = root
     self.tabwidget.setCurrentWidget(tab)
     self.populate_table_widgets()
Example #4
0
def main(argv):
    if not argv[1:]:
        sys.exit('Please give the input NRML file')

    app = QtGui.QApplication(argv, True)
    app.setStyleSheet('''
QTableWidget::item:selected
{ background-color: palette(highlight)}
''')
    node = node_from_nrml(sys.argv[1])[0]
    tbl = Converter.node_to_tables(node)
    mw = Dialog(tbl['DiscreteVulnerability'])
    mw.show()
    sys.exit(app.exec_())
Example #5
0
def convert_nrml_to_flat(fname, outname):
    """
    Convert a NRML file into .csv and .mdata files. Returns the path names
    of the generated files.

    :param fname: path to a NRML file of kind <path>.xml
    :param outfname: output path without extension
    """
    # extract the first node inside the <nrml> tag
    assert fname.endswith('.xml'), fname
    node = node_from_nrml(fname)[0]
    tables = list(converter(node).build_tables())
    suffixes = set(t.suffix for t in tables)
    if len(suffixes) < len(tables):
        raise ValueError('Duplicates in %s' % suffixes)
    tozip = []
    for table in tables:
        tozip.extend(table.save(outname))
    return tozip
Example #6
0
    def __init__(self, inputdir):
        QtGui.QMainWindow.__init__(self)
        self.inputdir = inputdir
        self.setupUi(self)
        self.tabwidget.currentWidget().root = None

        # table widgets
        self.vSetsTbl.itemSelectionChanged.connect(self.populate_vFnTbl)
        self.vFnTbl.itemSelectionChanged.connect(self.populate_imlsTbl)
        self.vSetsTbl.cellChanged.connect(self.update_vSets)
        self.vFnTbl.cellChanged.connect(self.update_vFn)
        self.imlsTbl.cellChanged.connect(self.update_imls)

        # add/del buttons
        self.vSetsAddBtn.clicked.connect(lambda: self.rowAdd(self.vSetsTbl))
        self.vSetsDelBtn.clicked.connect(lambda: self.rowDel(self.vSetsTbl))
        self.vFnAddBtn.clicked.connect(lambda: self.rowAdd(self.vFnTbl))
        self.vFnDelBtn.clicked.connect(lambda: self.rowDel(self.vFnTbl))
        self.imlsAddBtn.clicked.connect(lambda: self.rowAdd(self.imlsTbl))
        self.imlsDelBtn.clicked.connect(lambda: self.rowDel(self.imlsTbl))

        self.actionCopy.triggered.connect(self.copy)
        self.actionPaste.triggered.connect(self.paste)

        # menu actions
        self.actionOpen.triggered.connect(self.open_file)
        self.actionSave.triggered.connect(self.save_file)

        ## HARD-CODED FOR THE MOMENT
        root = node_from_nrml(
            os.path.join(inputdir, 'vulnerability-model-discrete.xml'))[0]
        self.fileNameLbl.setText('vulnerability-model-discrete.xml')
        tab = self.tabwidget.findChild(QtGui.QWidget, root.tag)
        tab.root = root
        self.tabwidget.setCurrentWidget(tab)
        self.populate_table_widgets()
Example #7
0
    def test_nrml(self):
        # can read and write a NRML file converted into a Node object
        xmlfile = cStringIO.StringIO("""\
<?xml version='1.0' encoding='utf-8'?>
<nrml xmlns="http://openquake.org/xmlns/nrml/0.4"
      xmlns:gml="http://www.opengis.net/gml">
  <exposureModel
      id="my_exposure_model_for_population"
      category="population"
      taxonomySource="fake population datasource">

    <description>
      Sample population
    </description>

    <assets>
      <asset id="asset_01" number="7" taxonomy="IT-PV">
          <location lon="9.15000" lat="45.16667" />
      </asset>

      <asset id="asset_02" number="7" taxonomy="IT-CE">
          <location lon="9.15333" lat="45.12200" />
      </asset>
    </assets>
  </exposureModel>
</nrml>
""")
        root = n.node_from_nrml(xmlfile)
        outfile = cStringIO.StringIO()
        n.node_to_xml(root, outfile)
        self.assertEqual(outfile.getvalue(), """\
<?xml version="1.0" encoding="utf-8"?>
<nrml
xmlns="http://openquake.org/xmlns/nrml/0.4"
xmlns:gml="http://www.opengis.net/gml"
>
    <exposureModel
    category="population"
    id="my_exposure_model_for_population"
    taxonomySource="fake population datasource"
    >
        <description>
            Sample population
        </description>
        <assets>
            <asset
            id="asset_01"
            number="7"
            taxonomy="IT-PV"
            >
                <location lat="45.16667" lon="9.15000"/>
            </asset>
            <asset
            id="asset_02"
            number="7"
            taxonomy="IT-CE"
            >
                <location lat="45.12200" lon="9.15333"/>
            </asset>
        </assets>
    </exposureModel>
</nrml>
""")
Example #8
0
    def test_nrml(self):
        # can read and write a NRML file converted into a Node object
        xmlfile = cStringIO.StringIO("""\
<?xml version='1.0' encoding='utf-8'?>
<nrml xmlns="http://openquake.org/xmlns/nrml/0.4"
      xmlns:gml="http://www.opengis.net/gml">
  <exposureModel
      id="my_exposure_model_for_population"
      category="population"
      taxonomySource="fake population datasource">

    <description>
      Sample population
    </description>

    <assets>
      <asset id="asset_01" number="7" taxonomy="IT-PV">
          <location lon="9.15000" lat="45.16667" />
      </asset>

      <asset id="asset_02" number="7" taxonomy="IT-CE">
          <location lon="9.15333" lat="45.12200" />
      </asset>
    </assets>
  </exposureModel>
</nrml>
""")
        root = n.node_from_nrml(xmlfile)
        outfile = cStringIO.StringIO()
        n.node_to_xml(root, outfile)
        self.assertEqual(
            outfile.getvalue(), """\
<?xml version="1.0" encoding="utf-8"?>
<nrml
xmlns="http://openquake.org/xmlns/nrml/0.4"
xmlns:gml="http://www.opengis.net/gml"
>
    <exposureModel
    category="population"
    id="my_exposure_model_for_population"
    taxonomySource="fake population datasource"
    >
        <description>
            Sample population
        </description>
        <assets>
            <asset
            id="asset_01"
            number="7"
            taxonomy="IT-PV"
            >
                <location lat="45.16667" lon="9.15000"/>
            </asset>
            <asset
            id="asset_02"
            number="7"
            taxonomy="IT-CE"
            >
                <location lat="45.12200" lon="9.15333"/>
            </asset>
        </assets>
    </exposureModel>
</nrml>
""")