Visualizing the cloud-capped boundary layer

Data is from a large eddy simulation of trade cumulus clouds.

  • Single timestep at 12.5 m x, y, z grid spacing

  • Variable is QN – cloud liquid water (g/kg)

adjust path to point to file

the_file = Path().resolve() / 'bomex_qv_qn.nc'
print(the_file)
the_file.exists()
/home/phil/repos/vapor-python-cookbook/notebooks/bomex_qv_qn.nc
True

Inspect the xarray dataset

bomex_data = xr.open_dataset(the_file)
bomex_data
<xarray.Dataset>
Dimensions:  (x: 512, y: 512, z: 256, time: 1)
Coordinates:
  * x        (x) float32 0.0 12.5 25.0 37.5 ... 6.362e+03 6.375e+03 6.388e+03
  * y        (y) float32 0.0 12.5 25.0 37.5 ... 6.362e+03 6.375e+03 6.388e+03
  * z        (z) float32 12.5 25.0 37.5 50.0 ... 3.175e+03 3.188e+03 3.2e+03
  * time     (time) float32 0.1264
Data variables:
    p        (z) float32 ...
    QV       (time, z, y, x) float32 ...
    QN       (time, z, y, x) float32 ...

open as a Vapor dataset

ses = session.Session()
data = ses.OpenDataset(dataset.CF, [str(the_file)])
ses.Load('session.vs3')
0
print("Time Coordinate Variable Name:", data.GetTimeCoordVarName())
print("Coordinate Variable Names:", data.GetCoordVarNames())

print("Dimensions:")
for dim in data.GetDimensionNames():
    print(f"  {dim}:", data.GetDimensionLength(dim, 0))

print("Data Variables:")
for var in data.GetDataVarNames():
    print(f"  {var}")
    print(f"    Time Varying:", bool(data.IsTimeVarying(var)))
    print(f"    Dimensionality:", data.GetVarGeometryDim(var))
    print(f"    Coordinates:", data.GetVarCoordVars(var, True))
    print("     Data Range:", data.GetDataRange(var))
Time Coordinate Variable Name: time
Coordinate Variable Names: ['time', 'x', 'y', 'z']
Dimensions:
  time: 1
  x: 512
  y: 512
  z: 256
Data Variables:
  QN
    Time Varying: True
    Dimensionality: 3
    Coordinates: ['x', 'y', 'z']
     Data Range: [0.0, 2.0163745880126953]
  QV
    Time Varying: True
    Dimensionality: 3
    Coordinates: ['x', 'y', 'z']
     Data Range: [2.760067939758301, 18.385417938232422]

Show gridcells

  • Red: watervapor

  • Grey: cloud liquid water

Top view of cloud field, with condensation threshold set to 0.01 g/kg

ren = data.NewRenderer(renderer.VolumeIsoRenderer)
ren.SetVariableName(data.GetDataVarNames(3)[0]) # Set to first 3D data variable
ren.SetIsoValues([0.01])

ses.GetCamera().ViewAll()
ses.Show()
Dataset: 'bomex_qv_qn.nc'
../_images/6ec5b29dd1055efb3d248206a1550691e43f764053bc2b6b02563ea7fde636f1.png

Create visualizer widget

from jupyter_vapor_widget import *

viz = VaporVisualizerWidget(ses)
viz

Add a slider bar

tf = ren.GetPrimaryTransferFunction()
dataRange = tf.GetMinMaxMapValue()

def sliderChanged(change):
    ren.SetIsoValues([change.new])
    viz.Render(fast=True)

slider = widgets.FloatSlider(value=ren.GetIsoValues()[0], min=dataRange[0], max=dataRange[1], step=(dataRange[1]-dataRange[0])/100)
slider.observe(sliderChanged, names='value')

widgets.VBox([
    viz,
    widgets.HBox([widgets.Label("Iso value:"), slider])
])