This tutorial shows how to mask data
In some case earth system model output are interpolated to som standard pressure levels, this can lead to data being generated bellow the ground
This tutorial shows how to mask these erroneous data. Data courtesy of Jerry Potter
The CDAT software was developed by LLNL. This tutorial was written by Charles Doutriaux. This work was performed under the auspices of the U.S. Department of Energy by Lawrence Livermore National Laboratory under Contract DE-AC52-07NA27344.
from __future__ import print_function
import cdms2
import numpy
import vcs
import requests
import os
for filename in ['ps.nc','ta.nc']:
if not os.path.exists(filename):
r = requests.get("https://cdat.llnl.gov/cdat/sample_data/notebooks/{}".format(filename), stream=True)
with open(filename,"wb") as f:
for chunk in r.iter_content(chunk_size=1024):
if chunk: # filter local_filename keep-alive new chunks
f.write(chunk)
PS_file = cdms2.open("ps.nc")
TA_file = cdms2.open("ta.nc")
ps = PS_file("ps")
ta = TA_file("ta")
print("Shaped: ps {} and ta {}".format(ps.shape,ta.shape))
ps = ps.regrid(ta.getGrid())
print("ps new shape:",ps.shape)
# Loop through levels and mask where pressure is less than ps
levels = ta.getLevel()
print("Levels are:", levels[:])
for i,level in enumerate(levels):
low = numpy.less(ps,level)
ta[:,i] = numpy.ma.masked_where(low,ta[:,i])
x = vcs.init(bg=True,geometry=(600,400))
x.plot(ta[:,0])