def main(): # test_files=["BCCA12K", "BCSD12K", "BCSDdisag12K", "MAURER12K"] bd="/glade/scratch/gutmann/usbr/SW_tests/" test_files=glob.glob("*") for d in test_files: print(d) files=glob.glob(d+"/*Forcing*.nc") means=None n=0 if len(files)>1: for f in files: try: data=io.read_nc(f,"sw").data except Exception as e: print(e,f) if means==None: means=np.zeros(data.shape[1:]) means+=data.mean(axis=0) n+=1 if means!=None: means/=n print(bd+d+"_sw_mean") io.write(bd+d+"_sw_mean",means)
def main(): filename = "init" nx, nz, ny = (200., 10., 200) dims = [nz, ny, nx] lonmin = -110.0 lonmax = -100.0 dlon = (lonmax - lonmin) / nx latmin = 35.0 latmax = 45.0 dlat = (latmax - latmin) / ny base = Bunch(u=10.0, w=0.0, v=0.0, qv=0.0013, qc=0.0, p=100000.0, th=np.arange(273.0, 300, (300 - 273.0) / nz).reshape( (nz, 1, 1)), dz=400.0) base.z = np.arange(0, nz * base.dz, base.dz) if glob.glob("sounding.txt"): update_base(base, "sounding.txt", nz) nz = base.th.size dims = [nz, ny, nx] u = np.zeros(dims, dtype="f") + base.u w = np.zeros(dims, dtype="f") + base.w v = np.zeros(dims, dtype="f") + base.v qv = np.zeros(dims, dtype="f") + base.qv qc = np.zeros(dims, dtype="f") + base.qc coscurve = np.cos(np.arange(dims[2]) / dims[2] * 2 * np.pi + np.pi) + 1 hgt = (coscurve * 1000).reshape((1, nx)).repeat(ny, axis=0) lon = np.arange(lonmin, lonmax, dlon) lat = np.arange(latmin, latmax, dlat) lon, lat = np.meshgrid(lon, lat) dz = np.zeros(dims) + base.dz z = np.zeros(dims, dtype="f") + base.z.reshape((nz, 1, 1)) + hgt.reshape( (1, ny, nx)) layer1 = (dz[0, :, :] / 2) z[0, :, :] += layer1 for i in range(1, int(nz)): z[i, :, :] = z[i - 1, :, :] + (dz[i - 1, :, :] + dz[i, :, :]) / 2.0 p = np.zeros(dims, dtype="f") + base.p adjust_p(p, 0.0, z) th = np.zeros(dims, dtype="f") + base.th d3dname = ("z", "y", "x") d2dname = ("y", "x") othervars = [ Bunch(data=v, name="V", dims=d3dname, dtype="f", attributes=dict(units="m/s", description="Horizontal (y) wind speed")), Bunch(data=w, name="W", dims=d3dname, dtype="f", attributes=dict(units="m/s", description="Vertical wind speed")), Bunch(data=qv, name="QVAPOR", dims=d3dname, dtype="f", attributes=dict(units="kg/kg", description="Water vapor mixing ratio")), Bunch(data=qc, name="QCLOUD", dims=d3dname, dtype="f", attributes=dict(units="kg/kg", description="Cloud water mixing ratio")), Bunch(data=p, name="P", dims=d3dname, dtype="f", attributes=dict(units="Pa", description="Pressure")), Bunch(data=th, name="T", dims=d3dname, dtype="f", attributes=dict(units="K", description="Potential temperature")), Bunch(data=dz, name="dz", dims=d3dname, dtype="f", attributes=dict(units="m", description="Layer thickness")), Bunch(data=z, name="Z", dims=d3dname, dtype="f", attributes=dict(units="m", description="Layer Height AGL")), Bunch(data=lat, name="XLAT", dims=d2dname, dtype="f", attributes=dict(units="deg", description="Latitude")), Bunch(data=lon, name="XLONG", dims=d2dname, dtype="f", attributes=dict(units="deg", description="Longitude")), Bunch(data=hgt, name="HGT", dims=d2dname, dtype="f", attributes=dict(units="m", description="Terrain Elevation")) ] fileexists = glob.glob(filename) or glob.glob(filename + ".nc") if fileexists: print("Removing : " + fileexists[0]) os.remove(fileexists[0]) io.write(filename, u, varname="U", dims=d3dname, dtype="f", attributes=dict(units="m/s", description="Horizontal (x) wind speed"), extravars=othervars)
def main(): filename="bc" nx,ny,nz,nt=(20.,20,10,24) dims=[nt,nz,ny,nx] lonmin=-110.0; lonmax=-100.0; dlon=(lonmax-lonmin)/nx latmin=35.0; latmax=45.0; dlat=(latmax-latmin)/ny base=Bunch(u=10.0,w=0.0,v=0.0, qv=0.0013,qc=0.0, p=100000.0, th=np.arange(273.0,300,(300-273.0)/nz).reshape((1,nz,1,1)), dz=400.0) base.z=np.arange(0,nz*base.dz,base.dz) if glob.glob("sounding.txt"): update_base(base,"sounding.txt",nz) nz=base.th.size dims=[nt,nz,ny,nx] u=np.zeros(dims,dtype="f")+base.u w=np.zeros(dims,dtype="f")+base.w v=np.zeros(dims,dtype="f")+base.v qv=np.zeros(dims,dtype="f")+base.qv qc=np.zeros(dims,dtype="f")+base.qc coscurve=np.cos(np.arange(dims[2])/dims[2]*2*np.pi+np.pi)+1 hgt=(coscurve*1000).reshape((1,nx)).repeat(ny,axis=0) lon=np.arange(lonmin,lonmax,dlon) lat=np.arange(latmin,latmax,dlat) lon,lat=np.meshgrid(lon,lat) dz=np.zeros(dims)+base.dz z=np.zeros(dims,dtype="f")+base.z.reshape((1,nz,1,1))+hgt.reshape((1,1,ny,nx)) layer1=(dz[0,0,:,:]/2) z[0,0,:,:]+=layer1 for i in range(1,int(nz)): z[:,i,:,:]=z[:,i-1,:,:]+(dz[:,i-1,:,:]+dz[:,i,:,:])/2.0 p=np.zeros(dims,dtype="f")+base.p adjust_p(p,0.0,z) th=np.zeros(dims,dtype="f")+base.th d4dname=("t","z","y","x") d3dname=("z","y","x") d2dname=("y","x") othervars=[Bunch(data=v, name="V", dims=d4dname,dtype="f",attributes=dict(units="m/s", description="Horizontal (y) wind speed")), Bunch(data=w, name="W", dims=d4dname,dtype="f",attributes=dict(units="m/s", description="Vertical wind speed")), Bunch(data=qv, name="QVAPOR",dims=d4dname,dtype="f",attributes=dict(units="kg/kg",description="Water vapor mixing ratio")), Bunch(data=qc, name="QCLOUD",dims=d4dname,dtype="f",attributes=dict(units="kg/kg",description="Cloud water mixing ratio")), Bunch(data=p, name="P", dims=d4dname,dtype="f",attributes=dict(units="Pa", description="Pressure")), Bunch(data=th, name="T", dims=d4dname,dtype="f",attributes=dict(units="K", description="Potential temperature")), Bunch(data=dz, name="dz", dims=d4dname,dtype="f",attributes=dict(units="m", description="Layer thickness")), Bunch(data=z, name="Z", dims=d4dname,dtype="f",attributes=dict(units="m", description="Layer Height AGL")), Bunch(data=lat,name="XLAT", dims=d2dname,dtype="f",attributes=dict(units="deg", description="Latitude")), Bunch(data=lon,name="XLONG", dims=d2dname,dtype="f",attributes=dict(units="deg", description="Longitude")), Bunch(data=hgt,name="HGT", dims=d2dname,dtype="f",attributes=dict(units="m", description="Terrain Elevation")) ] fileexists=glob.glob(filename) or glob.glob(filename+".nc") if fileexists: print("Removing : "+fileexists[0]) os.remove(fileexists[0]) io.write(filename, u,varname="U", dims=d4dname,dtype="f",attributes=dict(units="m/s",description="Horizontal (x) wind speed"), extravars=othervars)
def main(): filename = "ideal_{}_{}".format(case_study, int(wind_speed)) print(filename) nx, nz, ny = master_dims[case_study] dims = [1, nz, ny, nx] # this is just arbitrary for now dlon = dx / 111.1 dlat = dx / 111.1 lonmin = -110.0 lonmax = lonmin + nx * dlon latmin = 40.0 latmax = latmin + ny * dlat base = Bunch(u=wind_speed, w=0.0, v=0.0, qv=0.0013, qc=0.0, p=100000.0, th=np.arange(273.0, 300, (300 - 273.0) / nz).reshape( (nz, 1, 1)), dz=100.0) base.z = np.arange(0, nz * base.dz, base.dz) if glob.glob("sounding.txt"): update_base(base, "sounding.txt", nz) nz = base.th.size dims = [1, nz, ny, nx] udims = copy(dims) udims[-1] += 1 vdims = copy(dims) vdims[-2] += 1 u = np.zeros(udims, dtype="f") + base.u w = np.zeros(dims, dtype="f") + base.w v = np.zeros(vdims, dtype="f") + base.v qv = np.zeros(dims, dtype="f") + base.qv qc = np.zeros(dims, dtype="f") + base.qc # simple topography = a cosine # coscurve=np.cos(np.arange(dims[3])/dims[3]*2*np.pi+np.pi)+1 # hgt=(coscurve*1000).reshape((1,nx)).repeat(ny,axis=0) hgt = build_topography(case_study, dims) lon = np.arange(lonmin, lonmax, dlon)[:nx] lat = np.arange(latmin, latmax, dlat)[:ny] lon, lat = np.meshgrid(lon, lat) ulon = np.arange(lonmin - dlon / 2, lonmax + dlon / 2, dlon)[:nx + 1] ulat = np.arange(latmin, latmax, dlat)[:ny] ulon, ulat = np.meshgrid(ulon, ulat) vlon = np.arange(lonmin, lonmax, dlon)[:nx] vlat = np.arange(latmin - dlat / 2, latmax + dlat / 2, dlat)[:ny + 1] vlon, vlat = np.meshgrid(vlon, vlat) dz = np.zeros(dims) + base.dz z = np.zeros(dims, dtype="f") + base.z.reshape( (1, nz, 1, 1)) + hgt.reshape((1, 1, ny, nx)) layer1 = (dz[0, :, :] / 2) z[0, :, :] += layer1 for i in range(1, int(nz)): z[:, i, :, :] = z[:, i - 1, :, :] + (dz[:, i - 1, :, :] + dz[:, i, :, :]) / 2.0 p = np.zeros(dims, dtype="f") + base.p adjust_p(p, 0.0, z) th = np.zeros(dims, dtype="f") + base.th lat = lat.reshape((1, ny, nx)) lon = lon.reshape((1, ny, nx)) hgt = hgt.reshape((1, ny, nx)) d3dname = ("t", "z", "y", "x") ud3dname = ("t", "z", "y", "xu") ud2dname = ("t", "y", "xu") vd3dname = ("t", "z", "yv", "x") vd2dname = ("t", "yv", "x") d2dname = ("t", "y", "x") g = 9.81 othervars = [ Bunch(data=v, name="V", dims=vd3dname, dtype="f", attributes=dict(units="m/s", description="Horizontal (y) wind speed")), Bunch(data=w, name="W", dims=d3dname, dtype="f", attributes=dict(units="m/s", description="Vertical wind speed")), Bunch(data=qv, name="QVAPOR", dims=d3dname, dtype="f", attributes=dict(units="kg/kg", description="Water vapor mixing ratio")), Bunch(data=qc, name="QCLOUD", dims=d3dname, dtype="f", attributes=dict(units="kg/kg", description="Cloud water mixing ratio")), Bunch(data=qc, name="QICE", dims=d3dname, dtype="f", attributes=dict(units="kg/kg", description="Cloud ice mixing ratio")), Bunch(data=p * 0, name="P", dims=d3dname, dtype="f", attributes=dict(units="Pa", description="Pressure (perturbation)")), Bunch(data=p, name="PB", dims=d3dname, dtype="f", attributes=dict(units="Pa", description="Pressure (base)")), Bunch(data=th - 300, name="T", dims=d3dname, dtype="f", attributes=dict(units="K", description="Potential temperature")), Bunch(data=dz, name="dz", dims=d3dname, dtype="f", attributes=dict(units="m", description="Layer thickness")), Bunch(data=z, name="Z", dims=d3dname, dtype="f", attributes=dict(units="m", description="Layer Height AGL (also ASL here)")), Bunch(data=z * 0, name="PH", dims=d3dname, dtype="f", attributes=dict( units="m2/s2", description="Geopotential Height ASL (perturbation)")), Bunch(data=z * g, name="PHB", dims=d3dname, dtype="f", attributes=dict(units="m2/s2", description="Geopotential Height ASL (base)")), Bunch(data=lat, name="XLAT", dims=d2dname, dtype="f", attributes=dict(units="deg", description="Latitude")), Bunch(data=lon, name="XLONG", dims=d2dname, dtype="f", attributes=dict(units="deg", description="Longitude")), Bunch(data=ulat, name="XLAT_U", dims=ud2dname, dtype="f", attributes=dict(units="deg", description="Latitude on U stagger")), Bunch(data=ulon, name="XLONG_U", dims=ud2dname, dtype="f", attributes=dict(units="deg", description="Longitude on U stagger")), Bunch(data=vlat, name="XLAT_V", dims=vd2dname, dtype="f", attributes=dict(units="deg", description="Latitude on V stagger")), Bunch(data=vlon, name="XLONG_V", dims=vd2dname, dtype="f", attributes=dict(units="deg", description="Longitude on V stagger")), Bunch(data=hgt, name="HGT", dims=d2dname, dtype="f", attributes=dict(units="m", description="Terrain Elevation")) ] fileexists = glob.glob(filename) or glob.glob(filename + ".nc") if fileexists: print("Removing : " + fileexists[0]) os.remove(fileexists[0]) io.write(filename, u, varname="U", dims=ud3dname, dtype="f", attributes=dict(units="m/s", description="Horizontal (x) wind speed"), extravars=othervars)
def main(): filename="ideal_{}_{}".format(case_study,int(wind_speed)) print(filename) nx,nz,ny=master_dims[case_study] dims=[1,nz,ny,nx] # this is just arbitrary for now dlon=dx/111.1 dlat=dx/111.1 lonmin=-110.0; lonmax=lonmin+nx*dlon latmin=40.0; latmax=latmin+ny*dlat base=Bunch(u=wind_speed,w=0.0,v=0.0, qv=0.0013,qc=0.0, p=100000.0, th=np.arange(273.0,300,(300-273.0)/nz).reshape((nz,1,1)), dz=100.0) base.z=np.arange(0,nz*base.dz,base.dz) if glob.glob("sounding.txt"): update_base(base,"sounding.txt",nz) nz=base.th.size dims=[1,nz,ny,nx] udims=copy(dims) udims[-1]+=1 vdims=copy(dims) vdims[-2]+=1 u=np.zeros(udims,dtype="f")+base.u w=np.zeros(dims,dtype="f")+base.w v=np.zeros(vdims,dtype="f")+base.v qv=np.zeros(dims,dtype="f")+base.qv qc=np.zeros(dims,dtype="f")+base.qc # simple topography = a cosine # coscurve=np.cos(np.arange(dims[3])/dims[3]*2*np.pi+np.pi)+1 # hgt=(coscurve*1000).reshape((1,nx)).repeat(ny,axis=0) hgt=build_topography(case_study,dims) lon=np.arange(lonmin,lonmax,dlon)[:nx] lat=np.arange(latmin,latmax,dlat)[:ny] lon,lat=np.meshgrid(lon,lat) ulon=np.arange(lonmin-dlon/2,lonmax+dlon/2,dlon)[:nx+1] ulat=np.arange(latmin,latmax,dlat)[:ny] ulon,ulat=np.meshgrid(ulon,ulat) vlon=np.arange(lonmin,lonmax,dlon)[:nx] vlat=np.arange(latmin-dlat/2,latmax+dlat/2,dlat)[:ny+1] vlon,vlat=np.meshgrid(vlon,vlat) dz=np.zeros(dims)+base.dz z=np.zeros(dims,dtype="f")+base.z.reshape((1,nz,1,1))+hgt.reshape((1,1,ny,nx)) layer1=(dz[0,:,:]/2) z[0,:,:]+=layer1 for i in range(1,int(nz)): z[:,i,:,:]=z[:,i-1,:,:]+(dz[:,i-1,:,:]+dz[:,i,:,:])/2.0 p=np.zeros(dims,dtype="f")+base.p adjust_p(p,0.0,z) th=np.zeros(dims,dtype="f")+base.th lat=lat.reshape((1,ny,nx)) lon=lon.reshape((1,ny,nx)) hgt=hgt.reshape((1,ny,nx)) d3dname=("t","z","y","x") ud3dname=("t","z","y","xu") ud2dname=("t","y","xu") vd3dname=("t","z","yv","x") vd2dname=("t","yv","x") d2dname=("t","y","x") g=9.81 othervars=[Bunch(data=v, name="V", dims=vd3dname,dtype="f",attributes=dict(units="m/s", description="Horizontal (y) wind speed")), Bunch(data=w, name="W", dims=d3dname,dtype="f",attributes=dict(units="m/s", description="Vertical wind speed")), Bunch(data=qv, name="QVAPOR",dims=d3dname,dtype="f",attributes=dict(units="kg/kg",description="Water vapor mixing ratio")), Bunch(data=qc, name="QCLOUD",dims=d3dname,dtype="f",attributes=dict(units="kg/kg",description="Cloud water mixing ratio")), Bunch(data=qc, name="QICE", dims=d3dname,dtype="f",attributes=dict(units="kg/kg",description="Cloud ice mixing ratio")), Bunch(data=p*0,name="P", dims=d3dname,dtype="f",attributes=dict(units="Pa", description="Pressure (perturbation)")), Bunch(data=p, name="PB", dims=d3dname,dtype="f",attributes=dict(units="Pa", description="Pressure (base)")), Bunch(data=th-300, name="T", dims=d3dname,dtype="f",attributes=dict(units="K", description="Potential temperature")), Bunch(data=dz, name="dz", dims=d3dname,dtype="f",attributes=dict(units="m", description="Layer thickness")), Bunch(data=z, name="Z", dims=d3dname,dtype="f",attributes=dict(units="m", description="Layer Height AGL (also ASL here)")), Bunch(data=z*0,name="PH", dims=d3dname,dtype="f",attributes=dict(units="m2/s2",description="Geopotential Height ASL (perturbation)")), Bunch(data=z*g,name="PHB", dims=d3dname,dtype="f",attributes=dict(units="m2/s2",description="Geopotential Height ASL (base)")), Bunch(data=lat,name="XLAT", dims=d2dname,dtype="f",attributes=dict(units="deg", description="Latitude")), Bunch(data=lon,name="XLONG", dims=d2dname,dtype="f",attributes=dict(units="deg", description="Longitude")), Bunch(data=ulat,name="XLAT_U",dims=ud2dname,dtype="f",attributes=dict(units="deg", description="Latitude on U stagger")), Bunch(data=ulon,name="XLONG_U",dims=ud2dname,dtype="f",attributes=dict(units="deg", description="Longitude on U stagger")), Bunch(data=vlat,name="XLAT_V",dims=vd2dname,dtype="f",attributes=dict(units="deg", description="Latitude on V stagger")), Bunch(data=vlon,name="XLONG_V",dims=vd2dname,dtype="f",attributes=dict(units="deg", description="Longitude on V stagger")), Bunch(data=hgt,name="HGT", dims=d2dname,dtype="f",attributes=dict(units="m", description="Terrain Elevation")) ] fileexists=glob.glob(filename) or glob.glob(filename+".nc") if fileexists: print("Removing : "+fileexists[0]) os.remove(fileexists[0]) io.write(filename, u,varname="U", dims=ud3dname,dtype="f",attributes=dict(units="m/s",description="Horizontal (x) wind speed"), extravars=othervars)
def main(): filename="init" nx,nz,ny=(20.,10.,19) dims=[nx,nz,ny] # po=np.log(100000.0) # p1=np.log(50000.0) # dp=(po-p1)/nz # p=np.exp(np.arange(po,p1,-dp)), lonmin=-110.0; lonmax=-100.0; dlon=(lonmax-lonmin)/nx latmin=35.0; latmax=45.0; dlat=(latmax-latmin)/ny base=Bunch(u=10.0,w=0.0,v=0.0, qv=0.0013,qc=0.0, p=100000.0, th=np.arange(273.0,300,(300-273.0)/nz), dz=400.0) base.z=np.arange(0,nz*base.dz,base.dz) if glob.glob("sounding.txt"): update_base(base,"sounding.txt",nz) nz=base.th.size dims=[nx,nz,ny] # base.p=base.p[:nz] u=np.zeros(dims,dtype="f")+base.u w=np.zeros(dims,dtype="f")+base.w v=np.zeros(dims,dtype="f")+base.v qv=np.zeros(dims,dtype="f")+base.qv # qv+=np.sin(np.arange(dims[1])/dims[1]*2*np.pi)+1 qc=np.zeros(dims,dtype="f")+base.qc coscurve=np.cos(np.arange(dims[0])/dims[0]*2*np.pi+np.pi)+1 # p-=coscurve.reshape((nx,1,1))*15000 hgt=(coscurve*1000).reshape((nx,1)).repeat(ny,axis=1) lon=np.arange(lonmin,lonmax,dlon) lat=np.arange(latmin,latmax,dlat) lat,lon=np.meshgrid(lat,lon) #note that this appears "backwards" but these are C-style, fortran will be reversed dz=np.zeros(dims)+base.dz z=np.zeros(dims,dtype="f")+base.z.reshape((1,nz,1))+hgt.reshape((nx,1,ny)) layer1=(dz[:,0,:]/2) z[:,0,:]+=layer1 for i in range(1,int(nz)): z[:,i,:]=z[:,i-1,:]+(dz[:,i-1,:]+dz[:,i,:])/2.0 p=np.zeros(dims,dtype="f")+base.p# .reshape((1,nz,1)) adjust_p(p,0.0,z) th=np.zeros(dims,dtype="f")+base.th.reshape((1,nz,1)) d3dname=("x","z","y") d2dname=("x","y") othervars=[Bunch(data=lat,name="XLAT", dims=d2dname,dtype="f",attributes=dict(units="deg", description="Latitude")), Bunch(data=lon,name="XLONG",dims=d2dname,dtype="f",attributes=dict(units="deg", description="Longitude")), Bunch(data=v, name="v", dims=d3dname,dtype="f",attributes=dict(units="m/s", description="Horizontal (y) wind speed")), Bunch(data=w, name="w", dims=d3dname,dtype="f",attributes=dict(units="m/s", description="Vertical wind speed")), Bunch(data=qv, name="qv", dims=d3dname,dtype="f",attributes=dict(units="kg/kg",description="Water vapor mixing ratio")), Bunch(data=qc, name="qc", dims=d3dname,dtype="f",attributes=dict(units="kg/kg",description="Cloud water mixing ratio")), Bunch(data=p, name="p", dims=d3dname,dtype="f",attributes=dict(units="Pa", description="Pressure")), Bunch(data=th, name="th", dims=d3dname,dtype="f",attributes=dict(units="K", description="Potential temperature")), Bunch(data=dz, name="dz", dims=d3dname,dtype="f",attributes=dict(units="m", description="Layer thickness")), Bunch(data=z, name="z", dims=d3dname,dtype="f",attributes=dict(units="m", description="Layer Height AGL")), Bunch(data=hgt,name="hgt", dims=d2dname,dtype="f",attributes=dict(units="m", description="Terrain Elevation")) ] print(filename) fileexists=glob.glob(filename) or glob.glob(filename+".nc") if fileexists: print("Removing : "+fileexists[0]) os.remove(fileexists[0]) print(u.shape) print(lat.shape) print(hgt.shape) print(lon.shape) io.write(filename, u,varname="u", dims=d3dname,dtype="f",attributes=dict(units="m/s",description="Horizontal (x) wind speed"), extravars=othervars)
def write_file(filename,data,lat,lon): """write the result as a 2D netCDF grid""" io.write(filename,data.astype("d"),dtype='d',lat=lat,lon=lon)
def main(): filename = "init" nx, nz, ny = (20., 10., 19) dims = [nx, nz, ny] # po=np.log(100000.0) # p1=np.log(50000.0) # dp=(po-p1)/nz # p=np.exp(np.arange(po,p1,-dp)), lonmin = -110.0 lonmax = -100.0 dlon = (lonmax - lonmin) / nx latmin = 35.0 latmax = 45.0 dlat = (latmax - latmin) / ny base = Bunch(u=10.0, w=0.0, v=0.0, qv=0.0013, qc=0.0, p=100000.0, th=np.arange(273.0, 300, (300 - 273.0) / nz), dz=400.0) base.z = np.arange(0, nz * base.dz, base.dz) if glob.glob("sounding.txt"): update_base(base, "sounding.txt", nz) nz = base.th.size dims = [nx, nz, ny] # base.p=base.p[:nz] u = np.zeros(dims, dtype="f") + base.u w = np.zeros(dims, dtype="f") + base.w v = np.zeros(dims, dtype="f") + base.v qv = np.zeros(dims, dtype="f") + base.qv # qv+=np.sin(np.arange(dims[1])/dims[1]*2*np.pi)+1 qc = np.zeros(dims, dtype="f") + base.qc coscurve = np.cos(np.arange(dims[0]) / dims[0] * 2 * np.pi + np.pi) + 1 # p-=coscurve.reshape((nx,1,1))*15000 hgt = (coscurve * 1000).reshape((nx, 1)).repeat(ny, axis=1) lon = np.arange(lonmin, lonmax, dlon) lat = np.arange(latmin, latmax, dlat) lat, lon = np.meshgrid( lat, lon ) #note that this appears "backwards" but these are C-style, fortran will be reversed dz = np.zeros(dims) + base.dz z = np.zeros(dims, dtype="f") + base.z.reshape((1, nz, 1)) + hgt.reshape( (nx, 1, ny)) layer1 = (dz[:, 0, :] / 2) z[:, 0, :] += layer1 for i in range(1, int(nz)): z[:, i, :] = z[:, i - 1, :] + (dz[:, i - 1, :] + dz[:, i, :]) / 2.0 p = np.zeros(dims, dtype="f") + base.p # .reshape((1,nz,1)) adjust_p(p, 0.0, z) th = np.zeros(dims, dtype="f") + base.th.reshape((1, nz, 1)) d3dname = ("x", "z", "y") d2dname = ("x", "y") othervars = [ Bunch(data=lat, name="XLAT", dims=d2dname, dtype="f", attributes=dict(units="deg", description="Latitude")), Bunch(data=lon, name="XLONG", dims=d2dname, dtype="f", attributes=dict(units="deg", description="Longitude")), Bunch(data=v, name="v", dims=d3dname, dtype="f", attributes=dict(units="m/s", description="Horizontal (y) wind speed")), Bunch(data=w, name="w", dims=d3dname, dtype="f", attributes=dict(units="m/s", description="Vertical wind speed")), Bunch(data=qv, name="qv", dims=d3dname, dtype="f", attributes=dict(units="kg/kg", description="Water vapor mixing ratio")), Bunch(data=qc, name="qc", dims=d3dname, dtype="f", attributes=dict(units="kg/kg", description="Cloud water mixing ratio")), Bunch(data=p, name="p", dims=d3dname, dtype="f", attributes=dict(units="Pa", description="Pressure")), Bunch(data=th, name="th", dims=d3dname, dtype="f", attributes=dict(units="K", description="Potential temperature")), Bunch(data=dz, name="dz", dims=d3dname, dtype="f", attributes=dict(units="m", description="Layer thickness")), Bunch(data=z, name="z", dims=d3dname, dtype="f", attributes=dict(units="m", description="Layer Height AGL")), Bunch(data=hgt, name="hgt", dims=d2dname, dtype="f", attributes=dict(units="m", description="Terrain Elevation")) ] print(filename) fileexists = glob.glob(filename) or glob.glob(filename + ".nc") if fileexists: print("Removing : " + fileexists[0]) os.remove(fileexists[0]) print(u.shape) print(lat.shape) print(hgt.shape) print(lon.shape) io.write(filename, u, varname="u", dims=d3dname, dtype="f", attributes=dict(units="m/s", description="Horizontal (x) wind speed"), extravars=othervars)