do a spatial-mean reynolds average of a 3d field array3d
        needs dimensions arranged as (z,y,x)
        returns avg(z),perturb(z,y,x)
    """
    avg = array3d.mean(axis=2).mean(axis=1)
    perturb = array3d.T - avg
    perturb = perturb.T
    return avg, perturb


# %% [markdown]
# 2\.  Identify the file structure using ncdump

# %%
with Dataset(a500.data_dir / 'tropical_subset.nc') as ncin:
    ncdump(ncin)

# %% [markdown]
# 3\.  Read a variable using the netCDF4 module:  http://unidata.github.io/netcdf4-python/

# %%
with Dataset(a500.data_dir / 'tropical_subset.nc', 'r') as nc_in:
    print(list(nc_in.variables.keys()))
    the_temp = nc_in.variables['TABS'][0, ...]
    #
    # remove the time dimension since we only have one timestep
    #
    print('temp shape', the_temp.shape)
    the_height = nc_in.variables['z'][...]
    xvals = nc_in.variables['x'][...]
    yvals = nc_in.variables['y'][...]
Example #2
0
        except RuntimeError:
            #
            # only create ncout z vector once
            #
            pass
        ncout.history = 'written by read_cabauw.ipynb'
        for var in ['lat', 'lon']:
            setattr(ncout, var, float(var_attrs[var]))
        ncout.lat_units = 'degrees north'
        ncout.lon_units = 'degrees east'
        filelist = []
        for key, value in data_dict.items():
            filelist.append('{};'.format(value['name']))
        filelista = np.array(filelist)
        setattr(ncout, 'filelist', filelist)

# %%
with Dataset('cabauw_ubc.nc') as input:
    ncdump.ncdump(input)

# %%
from netCDF4 import Dataset
with Dataset('cabauw_ubc.nc', 'r') as nc:
    the_groups = nc.groups
    my_groups = list(the_groups.keys())
    my_H = nc['m201407'].variables['H'][1, :3, 3]
    #print(getattr(my_H,'accuracy'))
    print(my_H)

# %%
Example #3
0
file_dict = {}
for the_file in listFD(url, ext):
    print(the_file)
    out = download(the_file, root=url, dest_folder=a500.data_dir)
    file_dict[the_file] = a500.data_dir / the_file

# %%
import time
time.sleep(5)

# %%
file_dict

# %%
from a500.utils import ncdump
fieldfile = file_dict['fielddump.000.000.001.nc']
with Dataset(fieldfile, 'r') as nc_in:
    ncdump.ncdump(nc_in)

# %%
with Dataset(fieldfile, 'r') as nc_in:
    var_dict = {}
    var_list = ['qt', 'w', 'zt', 'yt', 'xt', 'time']
    for a_var in var_list:
        var_dict[a_var] = nc_in.variables[a_var][...]

# %%
var_dict

# %%
Example #4
0
# %% [markdown]
# # Read ncfile names into a dictionary

# %%
the_files = list(context.data_dir.glob('*.nc'))
file_dict = {item.name: item for item in the_files}
print(list(file_dict.keys()))

# %% [markdown]
# ## Read all attributes and get thetav

# %%
filename = file_dict['profiles.001.nc']
with Dataset(filename, 'r', format="NETCDF4") as prof_nc:
    print(f"opening {filename.name}")
    all_attributes = ncdump(prof_nc, verbose=False)
    print(list(prof_nc.variables))
    print(list(prof_nc.dimensions))
    thetav = prof_nc.variables['thv'][0, :]
    height = prof_nc.variables['zm'][...]

# %% [markdown]
# # make a plot

# %%
fig, ax = plt.subplots(1, 1, figsize=(6, 6))
ax.set(xlabel='thetav (K)', ylabel='height (m)')
ax.grid(True)
ax.plot(thetav, height)

# %%