def test_locations_prob(self): self.wo.opdict['outdir'] = 'TEST' self.wo.opdict['probloc_spaceonly'] = True self.wo.verify_location_options() base_path = self.wo.opdict['base_path'] outdir = self.wo.opdict['outdir'] loc_fname = os.path.join(base_path, 'out', outdir, 'loc', 'locations.dat') prob_fname = os.path.join(base_path, 'out', outdir, 'loc', 'locations_prob.dat') hdf5_fname = os.path.join(base_path, 'out', outdir, 'loc', 'locations_prob.hdf5') do_locations_prob_setup_and_run(self.wo.opdict) locs = read_locs_from_file(loc_fname) prob_locs = read_prob_locs_from_file(prob_fname) f_marginals = h5py.File(hdf5_fname, 'r') self.assertEqual(len(locs), len(prob_locs)) for i in xrange(len(locs)): loc = locs[i] prob_loc = prob_locs[i] self.assertGreater(prob_loc['o_time'], loc['o_time'] - loc['o_err_left']) self.assertLess(prob_loc['o_time'], loc['o_time'] + loc['o_err_right']) self.assertLess(np.abs(loc['o_time'] - prob_loc['o_time']), prob_loc['o_err']) self.assertLess(np.abs(loc['x_mean'] - prob_loc['x_mean']), prob_loc['x_sigma']) self.assertLess(np.abs(loc['y_mean'] - prob_loc['y_mean']), prob_loc['y_sigma']) self.assertLess(np.abs(loc['z_mean'] - prob_loc['z_mean']), prob_loc['z_sigma']) grp = f_marginals[prob_loc['o_time'].isoformat()] nx = grp['x'].shape[0] ny = grp['y'].shape[0] nz = grp['z'].shape[0] self.assertEqual(grp['prob_x'].shape, (nx, )) self.assertEqual(grp['prob_y'].shape, (ny, )) self.assertEqual(grp['prob_z'].shape, (nz, )) self.assertEqual(grp['prob_xy'].shape, (nx, ny)) self.assertEqual(grp['prob_xz'].shape, (nx, nz)) self.assertEqual(grp['prob_yz'].shape, (ny, nz)) # if is a 4D grid if 't' in grp: nt = grp['t'].shape[0] self.assertEqual(grp['prob_t'].shape, (nt, )) self.assertEqual(grp['prob_xt'].shape, (nx, nt)) self.assertEqual(grp['prob_yt'].shape, (ny, nt)) self.assertEqual(grp['prob_zt'].shape, (nz, nt)) f_marginals.close()
def test_locations_prob(self): self.wo.opdict['outdir'] = 'TEST' self.wo.opdict['probloc_spaceonly'] = True self.wo.verify_location_options() base_path = self.wo.opdict['base_path'] outdir = self.wo.opdict['outdir'] loc_fname = os.path.join(base_path, 'out', outdir, 'loc', 'locations.dat') prob_fname = os.path.join(base_path, 'out', outdir, 'loc', 'locations_prob.dat') hdf5_fname = os.path.join(base_path, 'out', outdir, 'loc', 'locations_prob.hdf5') do_locations_prob_setup_and_run(self.wo.opdict) locs = read_locs_from_file(loc_fname) prob_locs = read_prob_locs_from_file(prob_fname) f_marginals = h5py.File(hdf5_fname, 'r') self.assertEqual(len(locs), len(prob_locs)) for i in xrange(len(locs)): loc = locs[i] prob_loc = prob_locs[i] self.assertGreater(prob_loc['o_time'], loc['o_time']-loc['o_err_left']) self.assertLess(prob_loc['o_time'], loc['o_time']+loc['o_err_right']) self.assertLess(np.abs(loc['o_time']-prob_loc['o_time']), prob_loc['o_err']) self.assertLess(np.abs(loc['x_mean']-prob_loc['x_mean']), prob_loc['x_sigma']) self.assertLess(np.abs(loc['y_mean']-prob_loc['y_mean']), prob_loc['y_sigma']) self.assertLess(np.abs(loc['z_mean']-prob_loc['z_mean']), prob_loc['z_sigma']) grp = f_marginals[prob_loc['o_time'].isoformat()] nx = grp['x'].shape[0] ny = grp['y'].shape[0] nz = grp['z'].shape[0] self.assertEqual(grp['prob_x'].shape, (nx, )) self.assertEqual(grp['prob_y'].shape, (ny, )) self.assertEqual(grp['prob_z'].shape, (nz, )) self.assertEqual(grp['prob_xy'].shape, (nx, ny)) self.assertEqual(grp['prob_xz'].shape, (nx, nz)) self.assertEqual(grp['prob_yz'].shape, (ny, nz)) # if is a 4D grid if 't' in grp: nt = grp['t'].shape[0] self.assertEqual(grp['prob_t'].shape, (nt, )) self.assertEqual(grp['prob_xt'].shape, (nx, nt)) self.assertEqual(grp['prob_yt'].shape, (ny, nt)) self.assertEqual(grp['prob_zt'].shape, (nz, nt)) f_marginals.close()
def do_probloc_plotting_setup_and_run(opdict): """ Plot the results of a wavloc run (migration and location using probability density). All options and parameters are taken from an opdict. :param opdict: WavlocOptions.opdict that contains the options / parameters. """ # get / set info base_path = opdict['base_path'] space_only = opdict['probloc_spaceonly'] locfile = os.path.join(base_path, 'out', opdict['outdir'], 'loc', 'locations.dat') problocfile = os.path.join(base_path, 'out', opdict['outdir'], 'loc', 'locations_prob.dat') problocgrid = os.path.join(base_path, 'out', opdict['outdir'], 'loc', 'locations_prob.hdf5') figdir = os.path.join(base_path, 'out', opdict['outdir'], 'fig') # read locations locs = read_locs_from_file(locfile) prob_locs = read_prob_locs_from_file(problocfile) # open hdf5 file f = h5py.File(problocgrid, 'r') # for each loc for i in xrange(len(locs)): loc = locs[i] prob_loc = prob_locs[i] # hdf5 group name is prob loc origin time as string grp = f[prob_loc['o_time'].isoformat()] # do plotting plotProbLoc(grp, prob_loc, loc, figdir, space_only) f.close()
def do_probloc_plotting_setup_and_run(opdict): # get / set info base_path = opdict['base_path'] space_only = opdict['probloc_spaceonly'] locfile = os.path.join(base_path, 'out', opdict['outdir'], 'loc', 'locations.dat') problocfile = os.path.join(base_path, 'out', opdict['outdir'], 'loc', 'locations_prob.dat') problocgrid = os.path.join(base_path, 'out', opdict['outdir'], 'loc', 'locations_prob.hdf5') output_dir = os.path.join(base_path, 'out', opdict['outdir']) figdir = os.path.join(base_path, 'out', opdict['outdir'], 'fig') # read locations locs = read_locs_from_file(locfile) prob_locs = read_prob_locs_from_file(problocfile) # open hdf5 file f = h5py.File(problocgrid, 'r') # for each loc for i in xrange(len(locs)): loc = locs[i] prob_loc = prob_locs[i] otime = prob_loc['o_time'] # hdf5 group name is prob loc origin time as string grp = f[prob_loc['o_time'].isoformat()] # do plotting plotProbLoc(grp, prob_loc, loc, figdir, space_only) # close hdf5 file f.close()
def do_probloc_plotting_setup_and_run(opdict): # get / set info base_path=opdict['base_path'] space_only=opdict['probloc_spaceonly'] locfile=os.path.join(base_path,'out',opdict['outdir'],'loc','locations.dat') problocfile=os.path.join(base_path,'out',opdict['outdir'],'loc','locations_prob.dat') problocgrid=os.path.join(base_path,'out',opdict['outdir'],'loc','locations_prob.hdf5') output_dir=os.path.join(base_path,'out',opdict['outdir']) figdir=os.path.join(base_path,'out',opdict['outdir'],'fig') # read locations locs=read_locs_from_file(locfile) prob_locs=read_prob_locs_from_file(problocfile) # open hdf5 file f = h5py.File(problocgrid,'r') # for each loc for i in xrange(len(locs)): loc = locs[i] prob_loc = prob_locs[i] otime=prob_loc['o_time'] # hdf5 group name is prob loc origin time as string grp = f[prob_loc['o_time'].isoformat()] # do plotting plotProbLoc(grp,prob_loc,loc,figdir, space_only) # close hdf5 file f.close()