def test_probability(self): self.assertEqual(valid.probability('1'), 1.0) self.assertEqual(valid.probability('.5'), 0.5) self.assertEqual(valid.probability('0'), 0.0) with self.assertRaises(ValueError): valid.probability('1.1') with self.assertRaises(ValueError): valid.probability('-0.1')
def view_hmap(token, dstore): """ Display the highest 20 points of the mean hazard map. Called as $ oq show hmap:0.1 # 10% PoE """ try: poe = valid.probability(token.split(':')[1]) except IndexError: poe = 0.1 mean = dict(extract(dstore, 'hcurves?kind=mean'))['mean'] oq = dstore['oqparam'] hmap = calc.make_hmap_array(mean, oq.imtls, [poe], len(mean)) dt = numpy.dtype([('sid', U32)] + [(imt, F32) for imt in oq.imtls]) array = numpy.zeros(len(hmap), dt) for i, vals in enumerate(hmap): array[i] = (i, ) + tuple(vals) array.sort(order=list(oq.imtls)[0]) return rst_table(array[:20])
def view_hmap(token, dstore): """ Display the highest 20 points of the mean hazard map. Called as $ oq show hmap:0.1 # 10% PoE """ try: poe = valid.probability(token.split(':')[1]) except IndexError: poe = 0.1 try: mean = dstore['hcurves/mean'] except KeyError: # there is a single realization mean = dstore['hcurves/rlz-000'] oq = dstore['oqparam'] hmap = calc.make_hmap(mean, oq.imtls, [poe]) items = sorted([(hmap[sid].array.sum(), sid) for sid in hmap])[-20:] dt = numpy.dtype([('sid', U32)] + [(imt, F32) for imt in oq.imtls]) array = numpy.zeros(len(items), dt) for i, (maxvalue, sid) in enumerate(reversed(items)): array[i] = (sid, ) + tuple(hmap[sid].array[:, 0]) return rst_table(array)