예제 #1
0
파일: test.py 프로젝트: dynaryu/oq-engine
    def check_loss_map_stats(self, job):
        mean_maps = models.LossMap.objects.filter(
            output__oq_job=job, statistics='mean',
            loss_type='structural').order_by('poe')
        data = numpy.zeros((3, 4, 4))
        # 3 clp x (3 quantiles + 1 mean) x 4 assets
        for j, mm in enumerate(mean_maps):
            dataset = mm.lossmapdata_set.order_by('asset_ref')
            data[j][0] = [d.value for d in dataset]

            quantile_maps = models.LossMap.objects.filter(
                output__oq_job=job, statistics='quantile', poe=mm.poe,
                loss_type='structural').order_by('quantile')
            for i, qm in enumerate(quantile_maps, 1):
                dataset = qm.lossmapdata_set.order_by('asset_ref')
                data[j][i] = [d.value for d in dataset]

        # compare with oq-lite means
        means = read_composite_array(
            self._test_path('expected/mean-structural-loss_maps.csv'))
        aae(means['poe~0.1'], data[0, 0], decimal=4)  # (P, 0, N)
        aae(means['poe~0.5'], data[1, 0])
        aae(means['poe~0.9'], data[2, 0])

        # compare with oq-lite first quantile
        q025 = read_composite_array(
            self._test_path('expected/quantile-0.25-structural-loss_maps.csv'))
        aae(q025['poe~0.1'], data[0, 1], decimal=4)  # (P, 1, N)
        aae(q025['poe~0.5'], data[1, 1], decimal=4)
        aae(q025['poe~0.9'], data[2, 1], decimal=4)
예제 #2
0
 def test_read_written(self):
     dtype = numpy.dtype([('a', float), ('b', float, 2)])
     written = numpy.array([(.1, [.2, .3]), (.3, [.4, .5])], dtype)
     dest = tempfile.NamedTemporaryFile().name
     write_csv(dest, written)
     read = read_composite_array(dest)
     numpy.testing.assert_equal(read, written)
예제 #3
0
 def test_read_written(self):
     dtype = numpy.dtype([('a', float), ('b', float, 2)])
     written = numpy.array([(.1, [.2, .3]), (.3, [.4, .5])], dtype)
     with tempfile.NamedTemporaryFile() as dest:
         write_csv(dest.name, written)
         read = read_composite_array(dest.name)
     numpy.testing.assert_equal(read, written)
예제 #4
0
 def test_read_ok(self):
     got = read_composite_array(fname)
     expected = numpy.array([(b'a0', 81.2985, 0.0, 29.1098, 0.0, 542.1328),
                             (b'a1', 83.0823, 0.0, 27.9006, 0.0, 254.7904),
                             (b'a2', 85.7477, 0.0, 27.9015, 0.0, 653.871),
                             (b'a3', 85.7477, 0.0, 27.9015, 0.0, 806.2714)],
                            got.dtype)
     numpy.testing.assert_equal(got, expected)
예제 #5
0
 def test_read_ok(self):
     got = read_composite_array(fname)
     expected = numpy.array(
         [(b'a0', 81.2985, 0.0, 29.1098, 0.0, 542.1328),
          (b'a1', 83.0823, 0.0, 27.9006, 0.0, 254.7904),
          (b'a2', 85.7477, 0.0, 27.9015, 0.0, 653.871),
          (b'a3', 85.7477, 0.0, 27.9015, 0.0, 806.2714)],
         got.dtype)
     numpy.testing.assert_equal(got, expected)
예제 #6
0
    def test_assetcol(self):
        expected = writetmp('''\
asset_ref:|S100:,site_id:uint32:,taxonomy:uint32:,fatalities:float64:,structural:float64:,deductible~structural:float64:,insurance_limit~structural:float64:
a0,0,1,10,3000,.25,1.0
a1,1,0,20,2000,0.25,0.5
a2,2,2,30,1000,0.2,0.8
a3,2,1,0,5000,2.0,6.0
a4,3,1,50,500000,2.0,6.0
''')
        assetcol = riskinput.build_asset_collection(self.assets_by_site)
        numpy.testing.assert_equal(assetcol,
                                   readers.read_composite_array(expected))
예제 #7
0
    def test_assetcol(self):
        expected = writetmp('''\
asset_ref:|S20:,site_id:uint32:,structural:float64:,deductible~structural:float64:,insurance_limit~structural:float64:
a0,0,3000,25,100
a1,1,2000,0.1,0.2
a2,2,1000,0.02,0.08
a3,2,5000,1000,3000
a4,3,500000,1000,3000
''')
        assetcol = riskinput.build_asset_collection(self.assets_by_site)
        numpy.testing.assert_equal(
            assetcol, readers.read_composite_array(expected))
예제 #8
0
    def test_assetcol(self):
        expected = writetmp('''\
asset_ref:|S100:,site_id:uint32:,taxonomy:uint32:,fatalities:float64:,structural:float64:,deductible~structural:float64:,insurance_limit~structural:float64:
a0,0,1,10,3000,.25,1.0
a1,1,0,20,2000,0.25,0.5
a2,2,2,30,1000,0.2,0.8
a3,2,1,0,5000,2.0,6.0
a4,3,1,50,500000,2.0,6.0
''')
        assetcol = riskinput.build_asset_collection(self.assets_by_site)
        numpy.testing.assert_equal(
            assetcol, readers.read_composite_array(expected))
예제 #9
0
 def test_read_err2(self):
     with self.assertRaises(InvalidFile) as ctx:
         read_composite_array(wrong2)
     self.assertIn("Could not cast '0.0 0.0' in file", str(ctx.exception))
예제 #10
0
 def test_read_err1(self):
     with self.assertRaises(InvalidFile) as ctx:
         read_composite_array(wrong1)
     self.assertIn('expected 6 columns, found 5 in file',
                   str(ctx.exception))
예제 #11
0
 def test_read_err2(self):
     with self.assertRaises(InvalidFile) as ctx:
         read_composite_array(wrong2)
     self.assertIn("Could not cast '0.0 0.0' in file",
                   str(ctx.exception))
예제 #12
0
 def test_read_err1(self):
     with self.assertRaises(InvalidFile) as ctx:
         read_composite_array(wrong1)
     self.assertIn('expected 6 columns, found 5 in file',
                   str(ctx.exception))