Example #1
0
 def testcase02(self):
     """ Reading hcurve header """
     fname = os.path.join(BASE_DATA_PATH, 'hazard_curve-mean-PGA_22072.csv')
     fhandle = open(fname, 'r')
     header = csv._get_header1(fhandle.readline())
     tmpstr = 'investigation_time'
     msgstr = 'The investigation times do not match'
     self.assertEqual(50.0, header[tmpstr], msgstr)
     tmpstr = 'imt'
     msgstr = 'The IMTs do not match'
     self.assertEqual("SA(0.2)", header[tmpstr], msgstr)
Example #2
0
 def testcase03(self):
     """ Reading hcurve header - csv version 3.6"""
     tmpstr = 'hazard_curve-mean-PGA_23538_v3.6.csv'
     fname = os.path.join(BASE_DATA_PATH, tmpstr)
     fhandle = open(fname, 'r')
     header = csv._get_header1(fhandle.readline())
     tmpstr = 'investigation_time'
     msgstr = 'The investigation times do not match'
     self.assertEqual(1.0, header[tmpstr], msgstr)
     #
     tmpstr = 'imt'
     msgstr = 'The IMTs do not match'
     self.assertEqual("PGA", header[tmpstr], msgstr)
     #
     msgstr = 'Wrong engine version'
     expected = 'OpenQuake engine 3.6.0-git3c85fde84e'
     self.assertEqual(expected, header['engine'], msgstr)
def get_hcurves_geodataframe(fname):
    """
    :param fname:
        Name of the file with the hazard curves
    """
    header = _get_header1(open(fname, 'r').readline())
    inv_time = header['investigation_time']
    imt_str = header['imt']
    res_type = header['result_type']
    # Load hazard curve data
    df = pandas.read_csv(fname, skiprows=1)
    df['Coordinates'] = list(zip(df.lon, df.lat))
    df['Coordinates'] = df['Coordinates'].apply(Point)
    map_gdf = gpd.GeoDataFrame(df, geometry='Coordinates')
    # Homogenise hazard curves to the same investigation period
    if inv_time != 1.0:
        map_gdf = recompute_probabilities(map_gdf, inv_time, 1.0)
    return map_gdf, (res_type, inv_time, imt_str)