Esempio n. 1
0
def test_uniform_bathy():
    """ Test that ocean can be initialized with uniform bathymetry"""
    #o = Ocean(default=False, cache=False, load_bathymetry=-500.5)
    o = Ocean(load_bathymetry=500.5, **bounds)

    assert o.bathy(test_lat, test_lon) == 500.5
    assert o.temp(test_lat, test_lon, test_depth) == 0
Esempio n. 2
0
def test_interp_hycom_temp_chs_bathy():
    """ Test that ocean can be initialized with temperature data 
        from HYCOM with automatic fetching enabled and using 
        start/end args.
    """
    kwargs = dict(
            south=43.1, west=-59.8, 
            north=43.8, east=-59.2,
            top=-100, bottom=3000,
            start=datetime(2015,1,1),
            end=datetime(2015,1,2)
        )
    o = Ocean(#fetch=True, #cache=False,
        load_temp='hycom', 
        load_bathymetry='chs',
        **kwargs
        )
    lats = [43.4, 43.5]
    lons = [-59.6, -59.5]
    depths = [200, 300]
    #(temp,lats,lons,depths) = o.temp()
    temp = o.temp(lats, lons, depths)
    assert  43.1 <= np.min(lats) and np.max(lats) <=  43.8 #check that lats are within limits
    assert -59.8 <= np.min(lons) and np.max(lons) <= -59.2 #check that lons are within limits
    assert 3000 >= np.max(depths) and np.min(depths) >= -100 #check that depths are within limits
    assert len(temp) > 0   #check that some data was retrieved
    assert len(depths) > 1 #check that more than one depth was fetched
    assert np.all(np.abs(temp - temp.astype(int) > 1e-12)) # check that temperatures are not integers
    # interpolate temperature at seafloor
    seafloor_depth = o.bathy(lats, lons)
    temp = o.temp(lats, lons, seafloor_depth)
    assert np.all(np.logical_and(temp > -5, temp < 105)) # check sensible temperature at bottom

    # load hycom temperature data
    temp, lat, lon, epoch, depth = hycom().load_temp(**kwargs)
    # select a location close to the center of the region
    df = pd.DataFrame({'temp': temp, 'lat': lat, 'lon': lon, 'epoch': epoch, 'depth': depth})
    lat_close = df.lat.values[np.argmin(np.abs(df.lat.values - 43.45))]
    lon_close = df.lon.values[np.argmin(np.abs(df.lon.values - 59.5))]
    df = df[(df.lat == lat_close) & (df.lon == lon_close)]
    # query temps from ocean interpolator    
    depths = np.unique(df.depth.values)
    temp_ocean = o.temp(lat_close, lon_close, depths, grid=True)
    df = df.set_index(['depth','epoch'])
    df = df.groupby(level=[0]).mean()
    # check that interpolated temps and original temps agree
    assert np.all(temp_ocean == df.temp.values)
Esempio n. 3
0
def test_null_ocean():
    """ Test that ocean is initialized with all variables set to 
        null (0) when default=False"""
    #o = Ocean(default=False, cache=False)
    
    # changed to make ocean null by default
    o = Ocean(**bounds)
    
    assert o.bathy(test_lat, test_lon) == 0
    assert o.temp(test_lat, test_lon, test_depth) == 0
    assert o.salinity(test_lat, test_lon, test_depth) == 0
    assert o.wavedir(test_lat, test_lon) == 0
    assert o.waveheight(test_lat, test_lon) == 0
    assert o.waveperiod(test_lat, test_lon) == 0
    assert o.wind_uv(test_lat, test_lon) == 0
    assert o.origin == (45, -63.5)
    assert o.boundaries == bounds
Esempio n. 4
0
def test_interp_uniform_temp():
    """ Test that we can interpolate a uniform ocean temperature 
        on any set of coordinates"""
    #o = Ocean(default=False, cache=False, load_temp=16.1)
    o = Ocean(load_temp=16.1, **bounds)
    assert o.temp(lat=41.2, lon=-66.0, depth=-33.0) == 16.1