Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from netCDF4 import Dataset
- import glob
- import os
- #ffiles = '*.nc'
- ffiles = glob.glob('*.nc')
- ff0 = Dataset(ffiles[0])
- latt = ff0.variables['latitude'][:]
- lonn = ff0.variables['longitude'][:]
- for xx in range(len(lonn[:,1])):
- for yy in range(len(lonn[1,:])):
- if lonn[xx,yy]>=45 and lonn[xx,yy]<=60 and latt[xx,yy]>=67 and latt[xx,yy]<=72:
- ff_txt=open('txt\\%.2f-%.2f.txt' % (latt[xx,yy],lonn[xx,yy]),'w')
- for ifile in ffiles:
- iifile = Dataset(ifile)
- u = iifile.variables['meridional_motion'][0,xx,yy]
- v = iifile.variables['zonal_motion'][0,xx,yy]
- if u<>32767 and u<>'':
- ff_txt.write('%s;%.0f;%.0f\n' % (ifile.split('.')[0],u,v))
- else:
- ff_txt.write('%s;999.;999.\n' % ifile.split('.')[0])
- try:
- ff_txt.close()
- except:
- pass
- txt_files = glob.glob('txt\\*.txt')
- for ifile in txt_files:
- statinfo = os.stat(ifile)
- if statinfo.st_size==0:
- os.remove(ifile)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement