コード例 #1
0
ファイル: compute.py プロジェクト: jclark754/THREDDS-Images
def get_data(lon_w, lon_e, lat_s, lat_n, variable):
    """TODO
        Add reset, change colors of map, variable selection, model selection, lat/long validator
    """
    cat_url = 'http://thredds-jumbo.unidata.ucar.edu/thredds/catalog/grib/NCEP/GFS/Global_0p25deg/catalog.xml'
    latest_gfs = get_latest_access_url(cat_url, 'NetcdfSubset')
    ncss = NCSS(latest_gfs)

    query = ncss.query()
    query.lonlat_box(west=lon_w, east=lon_e, south=lat_s, north=lat_n).all_times()
    query.accept('netcdf4')
    query.variables(variable_dict(variable))
    data = ncss.get_data(query)
    list(data.variables.keys())
    var1 = data.variables[variable_dict(variable)]

    # only works if has name time+... or only has 1 dimension
    for dim in var1.dimensions:
        if 'time' in dim:
            time_name = dim
    if time_name is None:
        raise ValueError("Couldn't find a time dimension for " + var1.name)
    time_1d = data.variables[time_name]
    lat_1d = data.variables['lat']
    lon_1d = data.variables['lon']

    # Reduce the dimensions of the data
    lat_1d = lat_1d[:].squeeze()
    lon_1d = lon_1d[:].squeeze()

    # Convert the number of hours since the reference time to an actual date
    time_val = num2date(time_1d[:].squeeze(), time_1d.units)

    # Combine latitude and longitudes
    lon_2d, lat_2d = np.meshgrid(lon_1d, lat_1d)

    # Flatten() combines all the lists from meshgrid into one list
    full_lat_1d = lat_2d.flatten()
    full_lon_1d = lon_2d.flatten()

    # Create one list that pairs longs and lats
    lonlat_list = zip(full_lon_1d, full_lat_1d)

    return lon_2d, lat_2d, var1, time_val, lonlat_list
コード例 #2
0
def test_get_latest():
    'Test latest dataset helper function'
    url = ('http://thredds-test.unidata.ucar.edu/thredds/catalog/'
           'grib/NCEP/RAP/CONUS_13km/catalog.xml')
    latest_url = get_latest_access_url(url, "OPENDAP")
    assert latest_url
コード例 #3
0
ファイル: test_catalog.py プロジェクト: OnionNinja/siphon
def test_get_latest():
    'Test latest dataset helper function'
    url = ('http://thredds-test.unidata.ucar.edu/thredds/catalog/'
           'grib/NCEP/RAP/CONUS_13km/catalog.xml')
    latest_url = get_latest_access_url(url, "OPENDAP")
    assert latest_url
コード例 #4
0
#     dist_sq = (lats-latpt)**2 + (lons-lonpt)**2
#     minindex_flattened = dist_sq.argmin()      #1D index of minimum dist_sq elements
#     return np.unravel_index(minindex_flattened, lats.shape)  #get 2D index for latvals and lonvals arrays from 1D indexing
# iy_min, ix_min = getclosest_ij(latvals, lonvals, 50. , -140) # get the closest latitude and longitude values, i want lat 50, lon -140

# # WHAT IS THE TEMPERATURE AT THE SPECIFIC POINT?
# # Read values out of the netCDF file for temperature (Leer los valores del archivo netCDF para la temperatura )
# print ('%7.4f %s' % (temp[0,iy_min, ix_min], temp.units))

# ################### Remote data access via openDAP #######################
#"The following example showcases some nice netCDF features:\n",
#"1. We are seamlessly accessing **remote** data, from a TDS server.\n",
#"2. We are seamlessly accessing **GRIB2** data, as if it were netCDF data.\n",
#"3. We are generating **metadata** on-the-fly."
from siphon.catalog import get_latest_access_url
URL = get_latest_access_url('http://thredds.ucar.edu/thredds/catalog/grib/NCEP/GFS/Global_0p5deg/catalog.xml',
                           'OPENDAP')
gfs = netCDF4.Dataset(URL)

# Look at metadata for a specific variable\n",
# gfs.variables.keys() will show all available variables.\n",
sfctmp = gfs.variables['Temperature_surface']
# get info about sfctmp
print(sfctmp)
# print coord vars associated with this variable
for dname in sfctmp.dimensions:
    print(gfs.variables[dname])

# #################### MISSING VALUES #################
# # - When data == var.misssing_value somewhere , a masked array is returned
# # - illustrate with soil moisture data (only defined over land)\n",
# # - white areas on plot are masked values over water.
コード例 #5
0
ファイル: ena_tools.py プロジェクト: scollis/ACE-ENA-EVA
def give_me_latest_gfs():
    best_gfs = 'http://thredds.ucar.edu/thredds/catalog/grib/NCEP/GFS/Global_0p5deg/catalog.xml'
    latest_gfs = get_latest_access_url(best_gfs, "NetcdfSubset")
    ncss = NCSS(latest_gfs)
    return ncss
コード例 #6
0
ファイル: test_catalog.py プロジェクト: ScottWales/siphon
 def test_get_latest(self):
     url = ('http://thredds-test.unidata.ucar.edu/thredds/catalog/'
            'grib/NCEP/RAP/CONUS_13km/catalog.xml')
     latest_url = get_latest_access_url(url, "OPENDAP")
     assert latest_url
コード例 #7
0
 def test_get_latest(self):
     url = ('http://thredds-test.unidata.ucar.edu/thredds/catalog/'
            'grib/NCEP/RAP/CONUS_13km/catalog.xml')
     latest_url = get_latest_access_url(url, "OPENDAP")
     assert latest_url