Example #1
0
import os

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')
Example #2
0
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')
Example #3
0
edate = datetime.datetime(2016,9,2,0,0) #Last day to download
bbox = [25,-93.5,31.5,-85.5] #Geographic domain [South Lat, West Lon, North Lat, East Lon]
out_dir = data_files_dir
#out_dir = os.path.join(data_files_dir,'Indian_Ocean') #Where to write files (default is libgoods/data_files )
#!!!!!!!!


var_map = { 'time':'MT',
            'longitude': 'Longitude',
            'latitude': 'Latitude',
            'u_velocity': 'u',
            'v_velocity': 'v',
            'z': 'Depth',
            } 
            
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
Example #4
0
        flist.append(os.path.join(acnfs_dir, fn))
print flist

bbox = [69, -172, 72.5,
        -155]  #Geographic domain [South Lat, West Lon, North Lat, East Lon]
out_dir = data_files_dir  #Where to write files (in this case libgoods/data_files )

var_map = {
    'time': 'time',
    'longitude': 'lon',
    'latitude': 'lat',
    'u_velocity': 'uocn',
    'v_velocity': 'vocn',
}

acnfs = curv_grid.cgrid(flist)
acnfs.get_dimensions(var_map)

#meshgrid lon/lat for curvilinear grid
acnfs.data['lon'], acnfs.data['lat'] = np.meshgrid(acnfs.data['lon'],
                                                   acnfs.data['lat'])

#Determine geographic subset indices and get data
acnfs.subset(bbox)  #south lat, west lon, north lat, east lon
acnfs.get_data(var_map,
               yindex=acnfs.y,
               xindex=acnfs.x,
               zindex=0,
               is3d=False,
               extra_2dvars=['hi', 'aice', 'uvel', 'vvel'])
from libgoods import curv_grid, nctools, data_files_dir
import os


url = 'http://opendap.co-ops.nos.noaa.gov/thredds/dodsC/NYOFS/fmrc/Aggregated_7_day_NYOFS_Fields_Forecast_best.ncd'

var_map = nctools.get_var_map(url,var_list=['lon','lat','time','u','v'])

nyofs = curv_grid.cgrid(url)
nyofs.get_dimensions(var_map)

subset = 1
tlen = len(nyofs.data['time'])

if subset:
    nyofs.subset([40.566,-74.114,40.654,-74.012])
    nyofs.get_grid_info(yindex=nyofs.y,xindex=nyofs.x)
    nyofs.get_data(var_map,yindex=nyofs.y,xindex=nyofs.x)
    ofn = os.path.join(data_files_dir,'nyofs_example.nc')
    nyofs.write_nc(ofn)
else:
    nyofs.get_grid_info()
    nyofs.get_data(var_map,tindex=[tlen-5,tlen,1])
    ofn = os.path.join(data_files_dir,'nyofs_example.nc')
    nyofs.write_nc(ofn)
from libgoods import curv_grid, nctools, data_files_dir, noaa_coops
import datetime as dt
import os

flist = noaa_coops.make_server_filelist('nyofs',
                                        5,
                                        dt.date(2018, 12, 10),
                                        end=None,
                                        test_exist=True)
url = 'http://opendap.co-ops.nos.noaa.gov/thredds/dodsC/NYOFS/fmrc/Aggregated_7_day_NYOFS_Fields_Forecast_best.ncd'

var_map = nctools.get_var_map(
    url,
    var_list=['longitude', 'latitude', 'time', 'u_velocity', 'v_velocity'])

nyofs = curv_grid.cgrid(url)
nyofs.get_dimensions(var_map)

subset = 1
tlen = len(nyofs.data['time'])

if subset:
    nyofs.subset([40.566, -74.114, 40.654, -74.012])
    nyofs.get_grid_info(var_map, yindex=nyofs.y, xindex=nyofs.x)
    nyofs.get_data(var_map, yindex=nyofs.y, xindex=nyofs.x)
    ofn = os.path.join(data_files_dir, 'nyofs_example.nc')
    nyofs.write_nc(ofn)
else:
    nyofs.get_grid_info(var_map)
    nyofs.get_data(var_map, tindex=[tlen - 5, tlen, 1])
    ofn = os.path.join(data_files_dir, 'nyofs_example.nc')
sdate = datetime.datetime(2015,3,8,0,0) #First day to download
edate = datetime.datetime(2015,3,10,0,0) #Last day to download
bbox = [-41,30,26,126] #Geographic domain [South Lat, West Lon, North Lat, East Lon]
out_dir = data_files_dir
#out_dir = os.path.join(data_files_dir,'Indian_Ocean') #Where to write files (default is libgoods/data_files )
#!!!!!!!!


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):
flist = []
for t in range(0,168+24,24):
    flist.append(os.path.join(acnfs_dir,'t' + str(t).zfill(3) + '.nc'))


bbox = [69,-172,72.5,-155] #Geographic domain [South Lat, West Lon, North Lat, East Lon]
out_dir = data_files_dir #Where to write files (default is libgoods/data_files )

var_map = { 'time':'time',
            'lon': 'lon',
            'lat': 'lat',
            'u': 'uocn',
            'v': 'vocn',
            } 
            
acnfs = curv_grid.cgrid(flist)
acnfs.get_dimensions(var_map)

#meshgrid lon/lat for curvilinear grid
acnfs.data['lon'],acnfs.data['lat'] = np.meshgrid(acnfs.data['lon'],acnfs.data['lat'])

#Determine geographic subset indices and get data
acnfs.subset(bbox) #south lat, west lon, north lat, east lon
acnfs.get_data(var_map,yindex=acnfs.y,xindex=acnfs.x,zindex=0,is3d=False,extra_2dvars=['hi','aice','uvel','vvel'])     

#make mask
mask = (acnfs.data['u'][0,:,:] == acnfs.atts['u']['missing_value']).choose(1,0)
acnfs.grid['mask'] = mask

#rename ice vars
rename_dict = {'hi':'ice_thickness','aice':'ice_fraction','uvel':'ice_u','vvel':'ice_v'}
Example #9
0
import os
import numpy as np
import datetime
from netCDF4 import date2num

var_map = {
    'time': 'time',
    'u_velocity': 'U10',
    'v_velocity': 'V10',
    'longitude': 'XLONG',
    'latitude': 'XLAT',
    'longitude': 'XLONG',
    'latitude': 'XLAT'
}

wrf = curv_grid.cgrid(os.path.join('ROMS_ucla', 'wrf_grid.nc'))
wrf.get_dimensions(var_map, get_time=False)

wrf.data['lon'] = wrf.data['lon'].squeeze()
wrf.data['lat'] = wrf.data['lat'].squeeze()

in_dir = os.path.join('ROMS_ucla', 'wind')
flist = os.listdir(in_dir)

out_dir = os.path.join('gnome_ucla', 'wind')
if not os.path.exists(out_dir):
    os.mkdir(out_dir)

t_units = 'hours since 2004-01-01 00:00:00'
for f in flist:
    print f