- Timestamp:
- Oct 17, 2019, 6:27:03 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
dynamico_lmdz/guided/Data/vertical_interpolation_camelot.py
r4159 r4163 1 1 from __future__ import division 2 import argparse3 2 import numpy as np 4 3 from netCDF4 import Dataset 5 import matplotlib.pyplot as plt6 from mpl_toolkits.basemap import Basemap7 import matplotlib.mlab as mlab8 import matplotlib.colors9 4 import sys 10 5 import os 11 6 import math 12 7 from scipy.interpolate import interp1d 13 from matplotlib.ticker import AutoMinorLocator14 8 import netCDF4 as cdf 9 10 11 #levels = [100., 200., 300., 500., 700., 1000., 2000., 3000., 5000., 7000., 10000., 12500., 15000., 17500., 20000., 22500.,25000., 30000., 35000., 40000., 12 # 45000., 50000., 55000., 60000., 65000., 70000., 75000., 77500., 80000., 82500., 85000., 87500., 90000., 92500., 95000., 97500., 100000.] 13 levels = [1., 2., 3., 5., 7., 10., 20., 30., 50., 70., 100., 125., 150., 175., 200., 225.,250., 300., 350., 400., 14 450., 500., 550., 600., 650., 700., 750., 775., 800., 825., 850., 875., 900., 925., 950., 975., 1000.] 15 levels = levels[::-1] 16 print(levels) 15 17 16 18 dw1 = Dataset('2001.nc','r') … … 18 20 dpfulloned = dw1.variables['level'][:] 19 21 dpfull = np.zeros(((len(dpfulloned),dtfull.shape[2],dtfull.shape[3]))) 20 for l in xrange(0, len(dpfulloned)): 22 #------ mb conversion 23 #dpfulloned = dpfulloned *100. 24 for l in range(0, len(dpfulloned)): 21 25 dpfull[l,:,:]= dpfulloned[l] 22 23 26 print(dpfull) 27 24 28 dtfull = dw1.variables['t'][:,:,:,:] 25 29 #dPSfull = dw1.variables['PS'][:,:,:] … … 27 31 lat = dw1.variables['lat'][:] 28 32 lon = dw1.variables['lon'][:] 29 levels = [100., 200., 300., 500., 700., 1000., 2000., 3000., 5000., 7000., 10000., 12500., 15000., 17500., 20000., 22500.,25000., 30000., 35000., 40000.,30 45000., 50000., 55000., 60000., 65000., 70000., 75000., 77500., 80000., 82500., 85000., 87500., 90000., 92500., 95000., 97500., 100000.]31 32 levels = levels[::-1]33 print(levels)34 33 35 34 dim0=dtfull.shape[0] … … 50 49 pfull = dpfull 51 50 52 for t in range(dim 1):51 for t in range(dim0): 53 52 print("time step=",t) 54 53 tfull = dtfull[t,:,:,:] 55 54 out2 = vertical_int2(levels, pfull, tfull) 56 55 out3[t,:,:,:]=out2[:,:,:] 57 58 56 del tfull,dtfull 59 57 60 58 dufull = dw1.variables['u'][:,:,:,:] 61 59 out4 = np.zeros((((dim0,len(levels),dim2,dim3)))) 62 for t in range(dim 1):60 for t in range(dim0): 63 61 print("time step=",t) 64 62 ufull = dufull[t,:,:,:] … … 69 67 dvfull = dw1.variables['v'][:,:,:,:] 70 68 out5 = np.zeros((((dim0,len(levels),dim2,dim3)))) 71 for t in range(dim 1):69 for t in range(dim0): 72 70 print("time step=",t) 73 71 vfull = dvfull[t,:,:,:] … … 76 74 del vfull,dvfull 77 75 76 78 77 print("-----------------------------writing NetCDF--------------------------------") 79 78 print(out3) 80 #sys.exit(0)81 79 try: 82 80 f = cdf.Dataset('interpolated_data.nc', 'w', format='NETCDF4') 83 81 except: 84 82 print("Error occurred while opening new netCDF file, Error: ", sys.exc_info()[0]) 85 levels2 = [levels[i] / 100. for i in range(len(levels))] 83 #levels2 = [levels[i] / 100. for i in range(len(levels))] 84 levels2 = levels 86 85 #levels2 = [int(i) for i in levels2] 87 #print(levels2)88 86 f.createDimension('lon', len(lon)) 89 87 f.createDimension('lat', len(lat))
Note: See TracChangeset
for help on using the changeset viewer.