Example #1
0
    def setUp(self):
        super(HazardCurveDataManagerTestCase, self).setUp()
        self.manager = models.HazardCurveData.objects

        # Setup some data
        # Requires a working version of Django models
        output = models.Output.objects.create_output(
            self.job, "fake output", "hazard_curve")

        curves_per_location = (
            self.job.hazard_calculation.individual_curves_per_location())

        self.a_location = (
            helpers.random_location_generator(max_x=50, max_y=50))
        self.a_bigger_location = helpers.random_location_generator(
                min_x=50,
                min_y=50)

        for curve_nr in range(0, curves_per_location):
            realization = models.LtRealization.objects.all()[curve_nr]
            curve = models.HazardCurve.objects.create(
                output=output,
                lt_realization=realization,
                investigation_time=10,
                imt="PGA", imls=[1, 2, 3])

            models.HazardCurveData.objects.create(
                hazard_curve=curve,
                location=self.a_location.wkt,
                poes=[random.random()])

            models.HazardCurveData.objects.create(
                hazard_curve=curve,
                location=self.a_bigger_location.wkt,
                poes=[random.random()])
Example #2
0
 def setUp(self):
     """
     Setup a curve database with presets data
     """
     self.location_nr = 2
     self.curves_per_location = 3
     self.level_nr = 3
     self.location_db = [random_location_generator().wkb,
                         random_location_generator().wkb]
     self.curve_db = [
         dict(wkb=self.location_db[0],
              weight=0.5,
              poes=numpy.array([9.9996e-01, 9.9962e-01, 9.9674e-01])),
         dict(wkb=self.location_db[0],
              weight=0.3,
              poes=numpy.array([6.9909e-01, 6.0859e-01, 5.0328e-01])),
         dict(wkb=self.location_db[0],
              weight=0.2,
              poes=numpy.array([1.0000e+00, 9.9996e-01, 9.9947e-01])),
         dict(wkb=self.location_db[1],
              weight=0.5,
              poes=numpy.array([9.1873e-01, 8.6697e-01, 7.8992e-01])),
         dict(wkb=self.location_db[1],
              weight=0.3,
              poes=numpy.array([8.9556e-01, 8.3045e-01, 7.3646e-01])),
         dict(wkb=self.location_db[1],
              weight=0.2,
              poes=numpy.array([9.2439e-01, 8.6700e-01, 7.7785e-01]))]
     self.curve_writer = SimpleCurveWriter()
Example #3
0
    def setUp(self):
        super(HazardCurveDataManagerTestCase, self).setUp()
        self.manager = models.HazardCurveData.objects
        self.manager.current_job = self.job

        # Setup some data
        # Requires a working version of Django models
        output = models.Output.objects.create_output(
            self.job, "fake output", "hazard_curve")
        realization = models.LtRealization.objects.all()[0]
        curve = models.HazardCurve.objects.create(
            output=output,
            lt_realization=realization,
            investigation_time=10,
            imt="PGA", imls=[1, 2, 3])

        self.a_location = helpers.random_location_generator(max_x=50, max_y=50)
        models.HazardCurveData.objects.create(
            hazard_curve=curve,
            location=self.a_location.wkt,
            poes=[random.random()])

        self.a_bigger_location = helpers.random_location_generator(
            min_x=50,
            min_y=50)
        models.HazardCurveData.objects.create(
            hazard_curve=curve,
            location=self.a_bigger_location.wkt,
            poes=[random.random()])
Example #4
0
def _curve_db(location_nr, level_nr, curves_per_location, sigma):
    """
    Create a random db of curves stored in a list of dictionaries
    """
    curve_db = []
    location_db = []

    weights = [1.0 for _ in range(0, curves_per_location)]
    weights = [w / sum(weights) for w in weights]

    for i in range(0, location_nr):
        location = random_location_generator()
        # individual curve poes set with a gauss distribution with
        # mean set to [1 / (1 + i + j) for j in level_indexes].
        # So we can easily calculate mean and 0.5 quantile
        location_db.append(location.wkb)
        for j in range(0, curves_per_location):
            poes = []
            for k in range(0, level_nr):
                poe = random.gauss(1.0 / (1 + i + k), sigma)
                poes.append(min(1, poe))
            curve_db.append(
                dict(wkb=location.wkb,
                     weight=weights[j],
                     poes=numpy.array(poes)))
    return curve_db, location_db