Exemplo n.º 1
0
    def test_export_uhs(self):
        # Tests the UHS calculation run and export end-to-end.
        # For the export, we only check the quantity, location, and names of
        # each exported file. We don't check the contents; that's covered in
        # other tests.
        uhs_cfg = helpers.demo_file('uhs/config.gem')
        export_target_dir = tempfile.mkdtemp()

        expected_export_files = [
            os.path.join(export_target_dir, 'uhs_poe:0.1.hdf5'),
            os.path.join(export_target_dir, 'uhs_poe:0.02.hdf5'),
            os.path.join(export_target_dir, 'uhs.xml'),
        ]

        # Sanity check and precondition: these files should not exist yet
        for f in expected_export_files:
            self.assertFalse(os.path.exists(f))

        try:
            ret_code = helpers.run_job(uhs_cfg)
            self.assertEqual(0, ret_code)

            job = models.OqJob.objects.latest('id')
            [output] = models.Output.objects.filter(oq_job=job.id)

            # Split into a list, 1 result for each row in the output.
            # The first row of output (the table header) is discarded.
            listed_calcs = helpers.prepare_cli_output(
                subprocess.check_output(
                    ['bin/openquake', '--list-calculations']))

            check_list_calcs(self, listed_calcs, job.id)

            listed_outputs = helpers.prepare_cli_output(
                subprocess.check_output(
                    ['bin/openquake', '--list-outputs',
                     str(job.id)]))

            check_list_outputs(self, listed_outputs, output.id, 'uh_spectra')

            listed_exports = helpers.prepare_cli_output(
                subprocess.check_output([
                    'bin/openquake', '--export',
                    str(output.id), export_target_dir
                ]))

            self.assertEqual(expected_export_files, listed_exports)

            # Check that the files actually have been created,
            # and also verify that the paths are absolute:
            for f in listed_exports:
                self.assertTrue(os.path.exists(f))
                self.assertTrue(os.path.isabs(f))
        finally:
            shutil.rmtree(export_target_dir)
    def test_export_uhs(self):
        # Tests the UHS calculation run and export end-to-end.
        # For the export, we only check the quantity, location, and names of
        # each exported file. We don't check the contents; that's covered in
        # other tests.
        uhs_cfg = helpers.demo_file('uhs/config.gem')
        export_target_dir = tempfile.mkdtemp()

        expected_export_files = [
            os.path.join(export_target_dir, 'uhs_poe:0.1.hdf5'),
            os.path.join(export_target_dir, 'uhs_poe:0.02.hdf5'),
            os.path.join(export_target_dir, 'uhs.xml'),
        ]

        # Sanity check and precondition: these files should not exist yet
        for f in expected_export_files:
            self.assertFalse(os.path.exists(f))

        try:
            ret_code = helpers.run_job(uhs_cfg)
            self.assertEqual(0, ret_code)

            job = models.OqJob.objects.latest('id')
            [output] = models.Output.objects.filter(
                oq_job=job.id)

            # Split into a list, 1 result for each row in the output.
            # The first row of output (the table header) is discarded.
            listed_calcs = helpers.prepare_cli_output(subprocess.check_output(
                ['openquake/bin/oqscript.py', '--list-calculations']))

            check_list_calcs(self, listed_calcs, job.id)

            listed_outputs = helpers.prepare_cli_output(
                subprocess.check_output(
                    ['openquake/bin/oqscript.py', '--list-outputs',
                     str(job.id)]))

            check_list_outputs(self, listed_outputs, output.id, 'uh_spectra')

            listed_exports = helpers.prepare_cli_output(
                subprocess.check_output(
                    ['openquake/bin/oqscript.py', '--export',
                     str(output.id), export_target_dir]))

            self.assertEqual(expected_export_files, listed_exports)

            # Check that the files actually have been created,
            # and also verify that the paths are absolute:
            for f in listed_exports:
                self.assertTrue(os.path.exists(f))
                self.assertTrue(os.path.isabs(f))
        finally:
            shutil.rmtree(export_target_dir)
Exemplo n.º 3
0
    def test_export_agg_loss_curve(self):
        eb_cfg = helpers.get_data_path(
            'demos/event_based_risk_small/config.gem')
        export_target_dir = tempfile.mkdtemp()

        expected_export_files = [
            os.path.join(export_target_dir, 'aggregate_loss_curve.xml'),
        ]

        try:
            ret_code = helpers.run_job(eb_cfg)
            self.assertEqual(0, ret_code)

            job = models.OqJob.objects.latest('id')
            [output
             ] = models.Output.objects.filter(oq_job=job.id,
                                              output_type='agg_loss_curve')

            listed_calcs = helpers.prepare_cli_output(
                subprocess.check_output(
                    ['bin/openquake', '--list-calculations']))

            check_list_calcs(self, listed_calcs, job.id)

            listed_outputs = helpers.prepare_cli_output(
                subprocess.check_output(
                    ['bin/openquake', '--list-outputs',
                     str(job.id)]))

            check_list_outputs(self, listed_outputs, output.id,
                               'agg_loss_curve')

            listed_exports = helpers.prepare_cli_output(
                subprocess.check_output([
                    'bin/openquake', '--export',
                    str(output.id), export_target_dir
                ]))

            self.assertEqual(expected_export_files, listed_exports)
        finally:
            shutil.rmtree(export_target_dir)
    def test_export_agg_loss_curve(self):
        eb_cfg = helpers.get_data_path(
            'demos/event_based_risk_small/config.gem')
        export_target_dir = tempfile.mkdtemp()

        expected_export_files = [
            os.path.join(export_target_dir, 'aggregate_loss_curve.xml'),
        ]

        try:
            ret_code = helpers.run_job(eb_cfg)
            self.assertEqual(0, ret_code)

            job = models.OqJob.objects.latest('id')
            [output] = models.Output.objects.filter(
                oq_job=job.id, output_type='agg_loss_curve')

            listed_calcs = helpers.prepare_cli_output(subprocess.check_output(
                ['openquake/bin/oqscript.py', '--list-calculations']))

            check_list_calcs(self, listed_calcs, job.id)

            listed_outputs = helpers.prepare_cli_output(
                subprocess.check_output(
                    ['openquake/bin/oqscript.py', '--list-outputs',
                     str(job.id)]))

            check_list_outputs(self, listed_outputs, output.id,
                               'agg_loss_curve')

            listed_exports = helpers.prepare_cli_output(
                subprocess.check_output([
                    'openquake/bin/oqscript.py', '--export', str(output.id),
                    export_target_dir]))

            self.assertEqual(expected_export_files, listed_exports)
        finally:
            shutil.rmtree(export_target_dir)
Exemplo n.º 5
0
    def test_export_dmg_distributions(self):
        cfg = helpers.demo_file("scenario_damage_risk/config.gem")
        export_target_dir = tempfile.mkdtemp()

        try:
            ret_code = helpers.run_job(cfg)
            self.assertEqual(0, ret_code)

            job = models.OqJob.objects.latest("id")

            [oasset] = models.Output.objects.filter(
                oq_job=job.id, output_type="dmg_dist_per_asset")

            [otaxon] = models.Output.objects.filter(
                oq_job=job.id, output_type="dmg_dist_per_taxonomy")

            [ototal] = models.Output.objects.filter(
                oq_job=job.id, output_type="dmg_dist_total")

            [omap] = models.Output.objects.filter(
                oq_job=job.id, output_type="collapse_map")

            calcs = helpers.prepare_cli_output(subprocess.check_output(
                ["bin/openquake", "--list-calculations"]))

            # we have the calculation...
            check_list_calcs(self, calcs, job.id)

            outputs = helpers.prepare_cli_output(
                subprocess.check_output(["bin/openquake", "--list-outputs",
                str(job.id)]))

            # the damage distributios and collapse map as output...
            check_list_outputs(self, outputs, oasset.id, "dmg_dist_per_asset")
            check_list_outputs(self, outputs, ototal.id, "dmg_dist_total")
            check_list_outputs(self, outputs, omap.id, "collapse_map")
            check_list_outputs(self, outputs, otaxon.id,
                    "dmg_dist_per_taxonomy")

            # and we exported correctly the damage distribution per asset,
            exports = helpers.prepare_cli_output(
                subprocess.check_output(["bin/openquake", "--export",
                str(oasset.id), export_target_dir]))

            expected_file = os.path.join(export_target_dir,
                    "dmg-dist-asset-%s.xml" % job.id)

            self.assertEqual([expected_file], exports)

            # and per taxonomy
            exports = helpers.prepare_cli_output(
                subprocess.check_output(["bin/openquake", "--export",
                str(otaxon.id), export_target_dir]))

            expected_file = os.path.join(export_target_dir,
                    "dmg-dist-taxonomy-%s.xml" % job.id)

            self.assertEqual([expected_file], exports)

            # and total damage distribution
            exports = helpers.prepare_cli_output(
                subprocess.check_output(["bin/openquake", "--export",
                str(ototal.id), export_target_dir]))

            expected_file = os.path.join(export_target_dir,
                    "dmg-dist-total-%s.xml" % job.id)

            self.assertEqual([expected_file], exports)

            # and collapse map
            exports = helpers.prepare_cli_output(
                subprocess.check_output(["bin/openquake", "--export",
                str(omap.id), export_target_dir]))

            expected_file = os.path.join(export_target_dir,
                    "collapse-map-%s.xml" % job.id)

            self.assertEqual([expected_file], exports)
        finally:
            shutil.rmtree(export_target_dir)
Exemplo n.º 6
0
    def test_export_dmg_distributions(self):
        cfg = helpers.demo_file("scenario_damage_risk/config.gem")
        export_target_dir = tempfile.mkdtemp()

        try:
            ret_code = helpers.run_job(cfg)
            self.assertEqual(0, ret_code)

            job = models.OqJob.objects.latest("id")

            [oasset] = models.Output.objects.filter(
                oq_job=job.id, output_type="dmg_dist_per_asset")

            [otaxon] = models.Output.objects.filter(
                oq_job=job.id, output_type="dmg_dist_per_taxonomy")

            [ototal] = models.Output.objects.filter(
                oq_job=job.id, output_type="dmg_dist_total")

            [omap] = models.Output.objects.filter(
                oq_job=job.id, output_type="collapse_map")

            calcs = helpers.prepare_cli_output(subprocess.check_output(
                ["openquake/bin/oqscript.py", "--list-calculations"]))

            # we have the calculation...
            check_list_calcs(self, calcs, job.id)

            outputs = helpers.prepare_cli_output(
                subprocess.check_output(
                    ["openquake/bin/oqscript.py", "--list-outputs",
                     str(job.id)]))

            # the damage distributios and collapse map as output...
            check_list_outputs(self, outputs, oasset.id, "dmg_dist_per_asset")
            check_list_outputs(self, outputs, ototal.id, "dmg_dist_total")
            check_list_outputs(self, outputs, omap.id, "collapse_map")
            check_list_outputs(self, outputs, otaxon.id,
                    "dmg_dist_per_taxonomy")

            # and we exported correctly the damage distribution per asset,
            exports = helpers.prepare_cli_output(
                subprocess.check_output(
                    ["openquake/bin/oqscript.py", "--export",
                    str(oasset.id), export_target_dir]))

            expected_file = os.path.join(export_target_dir,
                    "dmg-dist-asset-%s.xml" % job.id)

            self.assertEqual([expected_file], exports)

            # and per taxonomy
            exports = helpers.prepare_cli_output(
                subprocess.check_output(["openquake/bin/oqscript.py",
                    "--export", str(otaxon.id), export_target_dir]))

            expected_file = os.path.join(export_target_dir,
                    "dmg-dist-taxonomy-%s.xml" % job.id)

            self.assertEqual([expected_file], exports)

            # and total damage distribution
            exports = helpers.prepare_cli_output(
                subprocess.check_output(["openquake/bin/oqscript.py",
                    "--export", str(ototal.id), export_target_dir]))

            expected_file = os.path.join(export_target_dir,
                    "dmg-dist-total-%s.xml" % job.id)

            self.assertEqual([expected_file], exports)

            # and collapse map
            exports = helpers.prepare_cli_output(
                subprocess.check_output(["openquake/bin/oqscript.py",
                    "--export", str(omap.id), export_target_dir]))

            expected_file = os.path.join(export_target_dir,
                    "collapse-map-%s.xml" % job.id)

            self.assertEqual([expected_file], exports)
        finally:
            shutil.rmtree(export_target_dir)