def get_gmfs_by_imt(fname, sitecol, imts): """ Return a list of dictionaries with a ground motion field per IMT, one dictionary per rupture. :param fname: path to the CSV file :param sitecol: the underlying site collection :param imts: the IMTs corresponding to the columns in the CSV file """ dicts = [] with open(fname) as f: for row in csv.reader(f): indices = map(int, row[1].split()) sc = FilteredSiteCollection(indices, sitecol) dic = AccumDict() for imt, col in zip(imts, row[2:]): gmf = numpy.array(map(float, col.split())) dic[imt] = sc.expand(gmf, 0) dic.tag = row[0] dicts.append(dic) return sorted(dicts, key=lambda dic: dic.tag)