Beispiel #1
0
import builder as b
ds = b.fetch_ds('ocean_his_4000.nc')
x = ds.variables['lon_rho'][:]
y = ds.variables['lat_rho'][:]
x = ds.variables['lon_rho'][:]
y = ds.variables['lat_rho'][:]
north = y.max()
south = y.min()
east    = x.max()
west  = x.min()
print "{0}, {1}     {2}, {3}".format(north, west, south, east)
Beispiel #2
0
def get_basic_info(fn):
    """
    Gets grid, vertical coordinate, and time info from a ROMS NetCDF
    history file with full name 'fn'
    
    Input: the filename
    
    Output: dicts G, S, and T
    
    Notes: I should add some keyword arguments to allow the user to just get
    G or S or T (onlyG=False)
    """
    
    
    
    ds = b.fetch_ds(fn)
    
    # get grid and bathymetry info
    g_varlist = ['h', 'lon_rho', 'lat_rho', 'lon_u', 'lat_u', 'lon_v', 'lat_v',
    'lon_psi', 'lat_psi', 'mask_rho', 'mask_u', 'mask_v', 'pm', 'pn',]
    G = dict()
    for vv in g_varlist:
        G[vv] = ds.variables[vv][:]    
    G['DX'] = 1/G['pm']
    G['DY'] = 1/G['pn']
    G['M'], G['L'] = np.shape(G['lon_rho']) # M = rows, L = columns
    # make the masks boolean
    G['mask_rho'] = G['mask_rho'] == 1
    G['mask_u'] = G['mask_u'] == 1
    G['mask_v'] = G['mask_v'] == 1
    
    # get vertical sigma-coordinate info (vectors are bottom to top)
    s_varlist = ['s_rho', 's_w', 'hc', 'Cs_r', 'Cs_w', 'Vtransform']
    S = dict()
    for vv in s_varlist:
        S[vv] = ds.variables[vv][:]
    S['N'] = len(S['s_rho']) # number of vertical levels
    
    # get time info
    t_varlist = ['ocean_time', 'dstart']
    T = dict()
    for vv in t_varlist:
        T[vv] = ds.variables[vv][:]
    #
    # find  time reference    
    dstart = ds.variables['dstart']
    tu = dstart.units
    import re
    isdash = [m.start() for m in re.finditer('-', tu)]
    iscolon = [m.start() for m in re.finditer(':', tu)]
    #
    year = int(tu[isdash[0]-4:isdash[0]])
    month = int(tu[isdash[1]-2:isdash[1]])
    day = int(tu[isdash[1]+1:isdash[1]+3])
    #
    hour = int(tu[iscolon[0]-2:iscolon[0]])
    minute = int(tu[iscolon[1]-2:iscolon[1]])
    second = int(tu[iscolon[1]+1:iscolon[1]+3])
    #
    tt = datetime.datetime(year, month, day, hour, minute, second)
    delta = datetime.timedelta(0, int(T['ocean_time']))
    T['tm0'] = tt
    T['tm'] = tt + delta
    
    return G, S, T
Beispiel #3
0
# imports
import os; import sys
import zfun
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
import numpy as np
import netCDF4 as nc 
import scipy.io
import builder as b

# GET DATA
G, S, T = zfun.get_basic_info(fn)
  
ds = b.fetch_ds(fn)

h = G['h']
zeta = ds.variables['zeta'][:]
zeta = zeta.squeeze()
zr = zfun.get_z(h, zeta, S, only_rho=True)
salt = ds.variables['salt'][:]
salt = salt.squeeze()

L = G['L']
M = G['M']
N = S['N']

lon = G['lon_rho']
lat = G['lat_rho']
mask = G['mask_rho']
Beispiel #4
0
def get_basic_info(fn):
    """
    Gets grid, vertical coordinate, and time info from a ROMS NetCDF
    history file with full name 'fn'
    
    Input: the filename
    
    Output: dicts G, S, and T
    
    Notes: I should add some keyword arguments to allow the user to just get
    G or S or T (onlyG=False)
    """

    ds = b.fetch_ds(fn)

    # get grid and bathymetry info
    g_varlist = [
        'h',
        'lon_rho',
        'lat_rho',
        'lon_u',
        'lat_u',
        'lon_v',
        'lat_v',
        'lon_psi',
        'lat_psi',
        'mask_rho',
        'mask_u',
        'mask_v',
        'pm',
        'pn',
    ]
    G = dict()
    for vv in g_varlist:
        G[vv] = ds.variables[vv][:]
    G['DX'] = 1 / G['pm']
    G['DY'] = 1 / G['pn']
    G['M'], G['L'] = np.shape(G['lon_rho'])  # M = rows, L = columns
    # make the masks boolean
    G['mask_rho'] = G['mask_rho'] == 1
    G['mask_u'] = G['mask_u'] == 1
    G['mask_v'] = G['mask_v'] == 1

    # get vertical sigma-coordinate info (vectors are bottom to top)
    s_varlist = ['s_rho', 's_w', 'hc', 'Cs_r', 'Cs_w', 'Vtransform']
    S = dict()
    for vv in s_varlist:
        S[vv] = ds.variables[vv][:]
    S['N'] = len(S['s_rho'])  # number of vertical levels

    # get time info
    t_varlist = ['ocean_time', 'dstart']
    T = dict()
    for vv in t_varlist:
        T[vv] = ds.variables[vv][:]
    #
    # find  time reference
    dstart = ds.variables['dstart']
    tu = dstart.units
    import re
    isdash = [m.start() for m in re.finditer('-', tu)]
    iscolon = [m.start() for m in re.finditer(':', tu)]
    #
    year = int(tu[isdash[0] - 4:isdash[0]])
    month = int(tu[isdash[1] - 2:isdash[1]])
    day = int(tu[isdash[1] + 1:isdash[1] + 3])
    #
    hour = int(tu[iscolon[0] - 2:iscolon[0]])
    minute = int(tu[iscolon[1] - 2:iscolon[1]])
    second = int(tu[iscolon[1] + 1:iscolon[1] + 3])
    #
    tt = datetime.datetime(year, month, day, hour, minute, second)
    delta = datetime.timedelta(0, int(T['ocean_time']))
    T['tm0'] = tt
    T['tm'] = tt + delta

    return G, S, T
Beispiel #5
0
# imports
import os
import sys
import zfun
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
import numpy as np
import netCDF4 as nc
import scipy.io
import builder as b

# GET DATA
G, S, T = zfun.get_basic_info(fn)

ds = b.fetch_ds(fn)

h = G['h']
zeta = ds.variables['zeta'][:]
zeta = zeta.squeeze()
zr = zfun.get_z(h, zeta, S, only_rho=True)
salt = ds.variables['salt'][:]
salt = salt.squeeze()

L = G['L']
M = G['M']
N = S['N']

lon = G['lon_rho']
lat = G['lat_rho']
mask = G['mask_rho']