Beispiel #1
0
def test_convert_tiles_to_compact(llc_mds_datadirs, mydir, fname, nk, nl, skip,
                                  use_xmitgcm):
    """Read in tiles data, convert to compact.
    Verify this equals reading in compact data
    """

    if mydir == 'xmitgcm':
        mydir, _ = llc_mds_datadirs

    data_tiles = ecco.read_llc_to_tiles(fdir=mydir,
                                        fname=fname,
                                        llc=90,
                                        nk=nk,
                                        nl=nl,
                                        filetype='>f4',
                                        skip=skip,
                                        less_output=False,
                                        use_xmitgcm=False)
    data_compact = ecco.read_llc_to_compact(fdir=mydir,
                                            fname=fname,
                                            llc=90,
                                            nk=nk,
                                            nl=nl,
                                            filetype='>f4',
                                            skip=skip,
                                            less_output=False)

    data_converted = ecco.llc_tiles_to_compact(data_tiles)
    assert np.all(np.equal(data_converted, data_compact))
Beispiel #2
0
def test_convert_faces_to_tiles(llc_mds_datadirs, mydir, fname, nk, nl, skip):
    """Read in faces data, convert to tiles.
    Verify this equals reading in face data
    """

    if mydir == 'xmitgcm':
        mydir, _ = llc_mds_datadirs

    data_faces = ecco.read_llc_to_faces(fdir=mydir,
                                        fname=fname,
                                        llc=90,
                                        nk=nk,
                                        nl=nl,
                                        filetype='>f4',
                                        skip=skip,
                                        less_output=False)
    data_tiles = ecco.read_llc_to_tiles(fdir=mydir,
                                        fname=fname,
                                        llc=90,
                                        nk=nk,
                                        nl=nl,
                                        filetype='>f4',
                                        skip=skip,
                                        less_output=False)

    data_converted = ecco.llc_faces_to_tiles(data_faces)
    assert np.all(np.equal(data_converted, data_tiles))
Beispiel #3
0
def test_convert_tiles_to_faces(llc_mds_datadirs, mydir, fname, nk, nl, skip,
                                use_xmitgcm):
    """Read in tiles data, convert to faces.
    Verify this equals reading in face data
    """

    if mydir == 'xmitgcm':
        mydir, _ = llc_mds_datadirs

    data_tiles = ecco.read_llc_to_tiles(fdir=mydir,
                                        fname=fname,
                                        llc=90,
                                        nk=nk,
                                        nl=nl,
                                        skip=skip,
                                        filetype='>f4',
                                        less_output=False,
                                        use_xmitgcm=False)

    data_faces = ecco.read_llc_to_faces(fdir=mydir,
                                        fname=fname,
                                        llc=90,
                                        nk=nk,
                                        nl=nl,
                                        skip=skip,
                                        filetype='>f4',
                                        less_output=False)

    data_converted = ecco.llc_tiles_to_faces(data_tiles)
    for f in range(1, len(data_faces) + 1):
        assert np.all(np.equal(data_converted[f], data_faces[f]))
Beispiel #4
0
def test_convert_tiles_to_faces():
    """Read in tiles data, convert to faces. 
    Verify this equals reading in face data
    """

    # Loop through 2D, 3D, 4D cases
    for fname, nk, nl in zip(_TEST_FILES, _TEST_NK, _TEST_RECS):
        data_tiles = ecco.read_llc_to_tiles(fdir=_DATA_DIR,
                                            fname=fname,
                                            llc=90,
                                            nk=nk,
                                            nl=nl,
                                            filetype='>f4',
                                            less_output=False)
        data_faces = ecco.read_llc_to_faces(fdir=_DATA_DIR,
                                            fname=fname,
                                            llc=90,
                                            nk=nk,
                                            nl=nl,
                                            filetype='>f4',
                                            less_output=False)

        data_converted = ecco.llc_tiles_to_faces(data_tiles)
        for f in range(1, len(data_faces) + 1):
            assert np.all(np.equal(data_converted[f], data_faces[f]))
Beispiel #5
0
def test_each_basin_masks(get_global_ds):
    """make sure we can make the basin masks
    """

    ds = get_global_ds
    all_basins = ecco_v4_py.read_llc_to_tiles(os.path.join(
        _test_dir, '..', '..', 'binary_data'),
                                              'basins.data',
                                              less_output=True)
    ext_names = ['atlExt', 'pacExt', 'indExt']
    for i, basin in enumerate(ecco_v4_py.get_available_basin_names(), start=1):
        mask = ecco_v4_py.get_basin_mask(basin, ds.maskC.isel(k=0))
        assert np.all(mask.values == (all_basins == i))
Beispiel #6
0
def get_test_array(is_xda=False):
    """define a numpy and xarray DataArray for testing"""

    # read in as numpy array
    test_arr = ecco.read_llc_to_tiles(fdir=_DATA_DIR,
                                      fname=_TEST_FILES[0],
                                      less_output=True)

    if is_xda:
        test_arr = ecco.llc_tiles_to_xda(test_arr,
                                         var_type='c',
                                         less_output=True)

    return test_arr
Beispiel #7
0
def test_convert_tiles_to_xda(llc_mds_datadirs, get_global_ds, mydir, fname,
                              nk, nl, skip, grid_da, var_type, use_xmitgcm):

    if mydir == 'xmitgcm':
        mydir, _ = llc_mds_datadirs

    ds = get_global_ds

    data_tiles = ecco.read_llc_to_tiles(fdir=mydir,
                                        fname=fname,
                                        llc=90,
                                        nk=nk,
                                        nl=nl,
                                        filetype='>f4',
                                        skip=skip,
                                        less_output=False,
                                        use_xmitgcm=use_xmitgcm)
    if grid_da:
        grid_da = ds[f'hFac{var_type.upper()}'].isel(
            k=0) if var_type != 'z' else ds['XG']
        if nk > 1:
            recdim = xr.DataArray(np.arange(nk), {'k': np.arange(nk)}, ('k', ))
            grid_da = grid_da.broadcast_like(recdim)
        if nl > 1:
            recdim = xr.DataArray(np.arange(nl), {'time': np.arange(nl)},
                                  ('time', ))
            grid_da = grid_da.broadcast_like(recdim)
    if nk > 1 and nl > 1:
        d4 = 'k'
        d5 = 'time'
    elif nk > 1 and nl == 1:
        d4 = 'k'
        d5 = None
    elif nl > 1:
        d4 = 'time'
        d5 = None
    else:
        d4 = None
        d5 = None

    xda = ecco.llc_tiles_to_xda(np.squeeze(data_tiles),
                                var_type='c',
                                grid_da=grid_da,
                                less_output=False,
                                dim4=d4,
                                dim5=d5)

    assert np.all(xda.values == np.squeeze(data_tiles))
Beispiel #8
0
def test_convert_tiles_to_compact():
    """Read in tiles data, convert to compact. 
    Verify this equals reading in compact data
    """

    # Loop through 2D, 3D, 4D cases
    for fname, nk, nl in zip(_TEST_FILES, _TEST_NK, _TEST_RECS):
        data_tiles = ecco.read_llc_to_tiles(fdir=_DATA_DIR,
                                            fname=fname,
                                            llc=90,
                                            nk=nk,
                                            nl=nl,
                                            filetype='>f4',
                                            less_output=False)
        data_compact = ecco.read_llc_to_compact(fdir=_DATA_DIR,
                                                fname=fname,
                                                llc=90,
                                                nk=nk,
                                                nl=nl,
                                                filetype='>f4',
                                                less_output=False)

        data_converted = ecco.llc_tiles_to_compact(data_tiles)
        assert np.all(np.equal(data_converted, data_compact))
# In[54]:

# Full-depth sea surface forcing (W/m^2)
forcH = xr.concat([forcH_surf, forcH_subsurf[:, :, 1:]],
                  dim='k').transpose('time', 'tile', 'k', 'j', 'i')

# ### Geothermal flux

# The geothermal flux contribution is not accounted for in any of the standard model diagnostics provided as output. Rather, this term, which is time invariant, is provided in the input file `geothermalFlux.bin` and can be downloaded from the PO.DAAC drive (https://ecco.jpl.nasa.gov/drive/files/Version4/Release3/input_init/geothermalFlux.bin).
# > **Note**: Here, `geothermalFlux.bin` has been placed in `base_dir`.

# In[55]:

# Load the geothermal heat flux using the routine 'read_llc_to_tiles'
geoflx = ecco.read_llc_to_tiles(base_dir, 'geothermalFlux.bin')

# The geothermal flux dataset needs to be saved as an xarray data array with the same format as the model output.

# In[56]:

# Convert numpy array to an xarray DataArray with matching dimensions as the monthly mean fields
geoflx_llc = xr.DataArray(geoflx,
                          coords={
                              'tile': ecco_monthly_mean.tile.values,
                              'j': ecco_monthly_mean.j.values,
                              'i': ecco_monthly_mean.i.values
                          },
                          dims=['tile', 'j', 'i'])

# In[57]:
title='ECCO Geometry Parameters for the 0.5 degree Lat-Lon Model Grid (Version 4 Release 4'

mixing_dir = Path('/home/ifenty/ian1/ifenty/ECCOv4/binary_output/3dmixingparameters')

#%%

output_dir = Path('/home/ifenty/tmp/time-invariant_20210317/')
output_dir.mkdir(parents=True, exist_ok=True)

#%%
plt.close('all')

ecco_grid = xr.open_dataset(ecco_grid_dir / 'GRID_GEOMETRY_ECCO_V4r4_native_llc0090.nc')

#%%
xx_diffkr = ecco.read_llc_to_tiles(mixing_dir, 'xx_diffkr.effective.0000000129.data', nk=50)
xx_diffkr_DA = xr.ones_like(ecco_grid.hFacC)
xx_diffkr_DA.name = 'DIFFKR'
xx_diffkr_DA.attrs = dict()
xx_diffkr_DA.values = xx_diffkr
xx_diffkr_DA = xx_diffkr_DA.where(ecco_grid.hFacC > 0)
ecco.plot_tiles(xx_diffkr_DA.isel(k=10), layout='latlon',rotate_to_latlon=True, show_colorbar=True,
                show_tile_labels=(False))
print(xx_diffkr_DA )


#%%
xx_kapgm = ecco.read_llc_to_tiles(mixing_dir, 'xx_kapgm.effective.0000000129.data', nk=50)
xx_kapgm_DA = xr.ones_like(ecco_grid.hFacC)
xx_kapgm_DA.name = 'KAPGM'
xx_kapgm_DA.attrs = dict()
Beispiel #11
0
# 
# The file 'bathy_eccollc_90x50_min2pts.bin' contains the 2D array of bathymetry for the model. 

# In[3]:


input_dir = '/Users/ifenty/tmp/input_init/'
input_file = 'bathy_eccollc_90x50_min2pts.bin'


# *read_llc_to_tiles* actually runs several other subroutines: *load_binary_array* which does the lower level reading of the binary file, *llc_compact_to_faces* which converts the array to 5 'faces', and finally *llc_faces_to_tiles* which extracts the 13 tiles from the 5 faces:

# In[4]:


bathy = ecco.read_llc_to_tiles(input_dir, input_file)


# *bathy* is a numpy float32 array with dimension [13, 90, 90]

# ### Plot the 13 tiles bathymetry data 

# In[5]:


# Use plot_tiles to make a quick plot of the 13 tiles.  See the tutorial on plotting for more examples.
ecco.plot_tiles(bathy, layout='latlon',rotate_to_latlon=True,show_tile_labels=False, show_colorbar=True);


# ## Load ecco-grid information to make a fancier lat-lon plot
#