import yt from yt_velmodel_vis import seis_model as sm from yt_velmodel_vis import shapeplotter as sp import numpy as np import os import matplotlib.pyplot as plt fname='NWUS11-S_percent.nc' out_dir='./output' model=sm.netcdf(fname) # interpolate the cartesian (or load it if it exists) mx=50000 dvs_n=os.path.join(out_dir,fname.split('.')[0]+'_dvs_interp_'+str(mx)+'.npy') if os.path.isfile(dvs_n): model.coordTransform('sphere2cart') print("Loading cartesian-interpolated data from file") dvs = np.load(dvs_n) else: model.interp2cartesian(fields=['dvs'],res=[10000,10000,10000], input_units='m',max_dist=mx) dvs=model.interp['data']['dvs'] np.save(dvs_n,dvs) data={} data['dvs']=dvs # set some gaussians for the TF bnds=[-6,10.] tf = yt.ColorTransferFunction((bnds[0],bnds[1])) # [center location, peak width, (red, green, blue, alpha)] # TF_gausians=[[-2,1,(1.,0.0,0.0,.8)]] # for gau in TF_gausians:
}, 'tfs': [{ 'tftype': 'step', 'values': (-3, -2, [1.0, 0., 0., 1.0]) }, { 'tftype': 'step', 'values': (-2, -1, [1.0, 0.5, 0., .8]) }], 'tf_bounds': [-10., 10.], 'sigma_clip': .4 } out_dir = './output/' + fname.split('.')[0] # output directory for figures # load the model model = sm.netcdf(fname, settings['interp']) shortname = fname.split('.')[0] datafld = settings['interp']['field'] data = {datafld: model.interp['data'][datafld]} # dict container for yt scene # add the transfer functions bnds = settings.get('tf_bounds', [-5, 5]) tf = yt.ColorTransferFunction((bnds[0], bnds[1])) for TFtoadd in settings['tfs']: v = TFtoadd['values'] if TFtoadd['tftype'] == 'step': tf.add_step(v[0], v[1], v[2]) elif TFtoadd['tftype'] == 'gaussian': tf.add_gaussian(v[0], v[1], v[2]) # plot the TF with a histogram
import numpy as np import os import matplotlib.pyplot as plt import geopandas as gpd fname = 'NWUS11-S_percent.nc' # fname='NA07_percent.nc' out_dir = './output' # load model, include interpolation interpDict = dict(field='dvs', res=[10000, 10000, 10000], input_units='m', max_dist=50000, interpChunk=int(1e6)) model = sm.netcdf(fname, interpDict) # load the data as a uniform grid, create the 3d scene data = {'dvs': model.interp['data']['dvs']} sc_mult = 1.0 # scale multiplier bbox = model.cart['bbox'] # list-like [[xmin,xmax],[ymin,ymax],[zmin,zmax]] ds = yt.load_uniform_grid(data, data['dvs'].shape, sc_mult, bbox=bbox, nprocs=1, periodicity=(True, True, True), unit_system="mks") sc = yt.create_scene(ds, 'dvs') # add TF