Skip to content

Instantly share code, notes, and snippets.

@nmathewa
Last active February 26, 2021 02:51
Show Gist options
  • Save nmathewa/323d3dd91816b6e307c49df3d6956e1a to your computer and use it in GitHub Desktop.
Save nmathewa/323d3dd91816b6e307c49df3d6956e1a to your computer and use it in GitHub Desktop.
importing libraries
import wrf
import pandas as pd
import numpy as np
import plotly.figure_factory as FF
import plotly.graph_objects as go
import time
from scipy.spatial import Delaunay
from netCDF4 import Dataset
direc = "wrfoutput_location"
datain = Dataset(direc)
def cloud_find(datain,time):
qclo = wrf.getvar(datain,'QCLOUD',timeidx=time)
interp_level = np.arange(0,12,0.01)
qclo = wrf.vinterp(datain,qclo,"ght_msl",interp_levels=interp_level)
qclo = qclo.to_dataframe()
fil_dt = qclo[qclo["QCLOUD"].gt(0.001)]
fil_dt.reset_index(inplace=True)
new_dt = fil_dt[fil_dt["interp_level"].between(4,6)]
return new_dt
st_time = int(input("Enter start timestep: "))
en_time = int(input("Enter end timestep: "))
date=[]
time_tt = []
for jj in range(int(en_time-st_time)+1):
time_t = str(wrf.extract_times(Dataset(direc),jj))
date += [time_t[0:10]]
time_tt += [time_t[11:19]]
terrain = wrf.getvar(datain,"ter",timeidx=0)
qwe = terrain.to_dataframe()
qwe.reset_index(inplace=True)
lat_ter = np.array(qwe["XLAT"])
lon_ter = np.array(qwe["XLONG"])
alt_ter = np.array(qwe["terrain"]/1000)
xx=lon_ter.flatten()
yy=lat_ter.flatten()
points2d = np.vstack([xx,yy]).T
tri = Delaunay(points2d)
simplices = tri.simplices
dft = cloud_find(datain,12)
x,y,z= np.array(dft["XLONG"]),np.array(dft["XLAT"]),np.array(dft["interp_level"])
fig = FF.create_trisurf(x=xx, y=yy, z=alt_ter,
simplices=simplices,show_colorbar=False)
#fig['colorbar'] = False
tme = np.arange(st_time,en_time)
#for jj in range(len(tme)):
# dft = cloud_find(datain,int(jj+st_time))
# print(int(jj+st_time))
# fig.add_trace(go.Scatter3d(x=dft["XLONG"],y=dft["XLAT"],z=dft["interp_level"],mode="markers",hovertext=dft["QCLOUD"]*1000,name=str(time_tt[jj]),marker=dict(
# size=1,
# colorscale='viridis',
# color = dft["QCLOUD"],
# colorbar=dict(x=-0.5,y=0.5,thickness=20,showticklabels=None,title="cloud mixing ratio")
# )))
fig.add_trace(go.Scatter3d(x=x,y=y,z=z,mode="markers",name="cloud",
hovertext=["QCLOUD"]*1000,marker=dict(
size=1,
colorscale='viridis',
color = dft["QCLOUD"]
)))
ext = [78.3, 78.8,30.2, 30.8]
tme = np.arange(st_time,en_time)
fig.update_layout(
title="Amount of supercooled liquid water content",
scene = dict(
xaxis_title="Longitude",
yaxis_title='Latitude',
zaxis_title='Altitude (km)',
xaxis = dict(nticks=10, range=[ext[0],ext[1]],),
yaxis = dict(nticks=10, range=[ext[2],ext[3]],),
zaxis = dict(nticks=20, range=[0,12],),),
width=1000)
#margin=dict(r=20, l=10, b=5, t=10))
fig.update_yaxes(automargin=True)
fig.write_html("/home/nma/Desktop/3dtrajwithjhys.html")#uncomment to save
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment