示例#1
0
    def test_get_site_model_too_many_site_models(self):
        haz_calc = self._create_haz_calc()

        site_model_inp1 = models.Input(
            owner=haz_calc.owner, digest='fake', path='fake',
            input_type='site_model', size=0
        )
        site_model_inp1.save()
        site_model_inp2 = models.Input(
            owner=haz_calc.owner, digest='fake', path='fake',
            input_type='site_model', size=0
        )
        site_model_inp2.save()

        # link both site models to the calculation:
        models.Input2hcalc(
            input=site_model_inp1, hazard_calculation=haz_calc).save()
        models.Input2hcalc(
            input=site_model_inp2, hazard_calculation=haz_calc).save()

        with self.assertRaises(RuntimeError) as assert_raises:
            models.get_site_model(haz_calc.id)

        self.assertEqual('Only 1 site model per job is allowed, found 2.',
                         assert_raises.exception.message)
示例#2
0
    def initialize_site_model(self):
        """
        If a site model is specified in the calculation configuration, parse
        it and load it into the `hzrdi.site_model` table. This includes a
        validation step to ensure that the area covered by the site model
        completely envelops the calculation geometry. (If this requirement is
        not satisfied, an exception will be raised. See
        :func:`openquake.engine.calculators.hazard.general.validate_site_model`.)
        """
        logs.LOG.progress("initializing site model")
        site_model_inp = models.get_site_model(self.hc.id)
        if site_model_inp:
            # explicit cast to `str` because the XML parser doesn't like
            # unicode. (More specifically, lxml doesn't like unicode.)
            site_model_content = site_model_inp.model_content.\
                raw_content_ascii

            # Store `site_model` records:
            store_site_model(
                site_model_inp, StringIO.StringIO(site_model_content))

            # Get the site model records we stored:
            site_model_data = models.SiteModel.objects.filter(
                input=site_model_inp)

            validate_site_model(site_model_data, self.hc.points_to_compute(save_sites=True))
        else:
            self.hc.points_to_compute(save_sites=True)
示例#3
0
    def test_get_site_model(self):
        haz_calc = self._create_haz_calc()

        site_model_inp = models.Input(
            owner=haz_calc.owner, digest='fake', path='fake',
            input_type='site_model', size=0
        )
        site_model_inp.save()

        # The link has not yet been made in the input2haz_calc table.
        self.assertIsNone(models.get_site_model(haz_calc.id))

        # Complete the link:
        models.Input2hcalc(
            input=site_model_inp, hazard_calculation=haz_calc).save()

        actual_site_model = models.get_site_model(haz_calc.id)
        self.assertEqual(site_model_inp, actual_site_model)