dbofs.subset([slat,wlon,nlat,elon]) dbofs.get_grid_info(yindex=dbofs.y,xindex=dbofs.x) else: dbofs.get_grid_info() tlen = len(dbofs.data['time']) for f in flist: print(f) if fnum> 0: dbofs.update(f) if subset: dbofs.get_data(var_map,yindex=dbofs.y,xindex=dbofs.x) else: dbofs.get_data(var_map) fnum = fnum + 1 outdir = os.path.join(data_files_dir,'dbofs_example') if not os.path.exists(outdir): os.mkdir(outdir) ofn = os.path.join(outdir,'dbofs' + str(fnum).zfill(3) + '.nc') #dbofs.reduce_latlon_mesh_for_GNOME() dbofs.write_nc(ofn) nctools.make_filelist_for_GNOME(outdir,'*.nc')
for day in range(17, 20): fl = 'http://data.oceansmap.com/thredds/dodsC/EDS/NAM5K/NAM5K2017' + str( mon).zfill(2) + str(day).zfill(2) + '.nc' print fl var_map = { 'time': 'time', 'longitude': 'longitude', 'latitude': 'latitude', 'u_velocity': 'u', 'v_velocity': 'v' } if firsttime: nam = curv_grid.cgrid(fl) nam.get_dimensions(var_map, get_time=False) nam.data['lon'] = nam.data['lon'] - 360 nam.subset(bbox) firsttime = False nam.update(fl) nam.get_dimensions(var_map, get_xy=False) nam.get_data(var_map, tindex=[0, 8, 1], xindex=nam.x, yindex=nam.y) nam.data['time'] = nam.data['time'][0:8] nam.atts['wind'] = True nam.write_nc(os.path.join(out_dir, 'NAM' + str(mon) + str(day) + '.nc')) nctools.make_filelist_for_GNOME(out_dir, 'NAM*.nc')
hycom = curv_grid.cgrid(url) hycom.get_dimensions(var_map,get_z=True) ts = num2date(hycom.data['time'][:],hycom.atts['time']['units']) tid = np.where(np.logical_and(ts>=sdate,ts<=edate))[0] print 'Number of time steps:', len(tid) #adjust longitude: HYCOM lon goes from 74 --> 1019 ?? lon = np.mod(hycom.data['lon'],360) hycom.data['lon'] = (lon > 180).choose(lon,lon-360) #HYCOM uses time based on 1900 -- GNOME can't handle pre 1970, adjust before writing to file native_tunits = hycom.atts['time']['units'] #Determine geographic subset indices hycom.subset(bbox) #south lat, west lon, north lat, east lon print hycom.x, hycom.y for num,ti in enumerate(tid): print 'getting data time:', ti hycom.get_data(var_map,tindex=[ti,ti+1,1],yindex=hycom.y,xindex=hycom.x,is3d=True) hycom.grid['depth'] = np.ones_like(hycom.data['lon_ss']) * -5000 hycom.make_vel_mask() hycom.data['time_ss'],hycom.atts['time']['units'] = nctools.adjust_time(hycom.data['time_ss'],native_tunits) print num2date(hycom.data['time_ss'],hycom.atts['time']['units']) hycom.write_nc(os.path.join(out_dir,'HYCOM_example_ ' + str(num).zfill(3) + '.nc'),is3d=True) nctools.make_filelist_for_GNOME(out_dir,'HYCOM_example_*.nc',outfilename='HYCOM_filelist.txt')
out_dir = data_files_dir mon = 10 bbox = [22,-80,28,-73] firsttime = True for day in range(17,20): fl = 'http://data.oceansmap.com/thredds/dodsC/EDS/NAM5K/NAM5K2017' + str(mon).zfill(2) +str(day).zfill(2) + '.nc' print fl var_map = {'time':'time','longitude':'longitude','latitude':'latitude','u_velocity':'u','v_velocity':'v'} if firsttime: nam = curv_grid.cgrid(fl) nam.get_dimensions(var_map,get_time=False) nam.data['lon'] = nam.data['lon'] - 360 nam.subset(bbox) firsttime = False nam.update(fl) nam.get_dimensions(var_map,get_xy=False) nam.get_data(var_map,tindex=[0,8,1],xindex=nam.x,yindex=nam.y) nam.data['time'] = nam.data['time'][0:8] nam.atts['wind'] = True nam.write_nc(os.path.join(out_dir,'NAM' + str(mon) + str(day) + '.nc')) nctools.make_filelist_for_GNOME(out_dir,'NAM*.nc')
var_map = { 'time':'MT', 'lon': 'Longitude', 'lat': 'Latitude', 'u': 'u', 'v': 'v', } hycom = curv_grid.cgrid(url) hycom.get_dimensions(var_map) ts = num2date(hycom.data['time'][:],hycom.atts['time']['units']) tid = np.where(np.logical_and(ts>=sdate,ts<=edate))[0] #adjust longitude: HYCOM lon goes from 74 --> 1019 ?? lon = np.mod(hycom.data['lon'],360) hycom.data['lon'] = (lon > 180).choose(lon,lon-360) #HYCOM uses time based on 1900 -- GNOME can't handle pre 1970, adjust before writing to file native_tunits = hycom.atts['time']['units'] #Determine geographic subset indices hycom.subset(bbox) #south lat, west lon, north lat, east lon for num,ti in enumerate(tid): hycom.get_data(var_map,tindex=[ti,ti+1,1],yindex=hycom.y,xindex=hycom.x,zindex=0,is3d=False) hycom.make_vel_mask() hycom.data['time_ss'],hycom.atts['time']['units'] = nctools.adjust_time(hycom.data['time_ss'],native_tunits) print num2date(hycom.data['time_ss'],hycom.atts['time']['units']) hycom.write_nc(os.path.join(out_dir,'HYCOM_example_ ' + str(num).zfill(3) + '.nc'),is3d=False) nctools.make_filelist_for_GNOME(out_dir,'HYCOM_example_*.nc',outfilename='HYCOM_filelist.txt')