def test_no_file_provided_or_wrong_name(): """Test exception raised if no file is found""" domcfg = open_domain_cfg( datadir=TEST_PATH / "data/domcfg_1_file", ) try: open_nemo(datadir=TEST_PATH, domcfg=domcfg) except FileNotFoundError: pass try: open_nemo( files=(TEST_PATH / "data/domcfg_1_file").glob("domain*"), domcfg=domcfg ) except ValueError: pass
def test_merge_non_linear_free_surface(): datadir_dom = TEST_PATH / "data/domcfg_1_file" datadir_nemo = TEST_PATH / "data/nemo" domcfg_kwargs = dict(datadir=datadir_dom) domcfg = open_domain_cfg(**domcfg_kwargs) nemo_kwargs = dict( datadir=datadir_nemo, domcfg=domcfg, ) nemo_ds = open_nemo(**nemo_kwargs) ds = _merge_nemo_and_domain_cfg(nemo_ds, domcfg, linear_free_surface=False) assert "e3t" in ds assert "e3t_0" in ds assert "t" in ds.e3t.coords assert "e3f" not in ds ds2 = open_nemo_and_domain_cfg( nemo_files=datadir_nemo, domcfg_files=datadir_dom, nemo_kwargs=nemo_kwargs, domcfg_kwargs=domcfg_kwargs, linear_free_surface=False, ) assert (ds == ds2).all() p = TEST_PATH / "data/open_and_merge" ds2 = open_nemo_and_domain_cfg( nemo_files=p, domcfg_files=p, linear_free_surface=False ) assert (ds == ds2).all()
def test_open_nemo_surface(): """Test opening of nemo surface files (no depth dimension)""" domcfg = open_domain_cfg(datadir=TEST_PATH / "data/domcfg_1_file", ) nemo_ds = open_nemo( datadir=TEST_PATH / "data/surface_fields", domcfg=domcfg, )
def test_open_nemo(): """Test opening of nemo files""" domcfg = open_domain_cfg( datadir=TEST_PATH / "data/domcfg_1_file", ) nemo_ds = open_nemo( datadir=TEST_PATH / "data/nemo", domcfg=domcfg, )
def test_open_nemo(): """Test opening of nemo files""" domcfg = open_domain_cfg( datadir=TEST_PATH / "data/domcfg_1_file", ) nemo_ds = open_nemo( datadir=TEST_PATH / "data/nemo", domcfg=domcfg, ) for i in ["uo", "so", "thetao"]: assert nemo_ds[i].chunks is not None
def test_open_nemo_chunks(): """Test opening of nemo files, with chunks""" domcfg = open_domain_cfg( datadir=TEST_PATH / "data/domcfg_1_file", ) nemo_ds = open_nemo( datadir=TEST_PATH / "data/nemo", domcfg=domcfg, chunks={"time_counter": 1}, ) for i in ["uo", "so", "thetao"]: assert nemo_ds[i].chunks is not None assert nemo_ds.chunks["t"] == (1, 1, 1)
def test_save_nemo(): """Test saving of nemo files""" domcfg = open_domain_cfg( datadir="xnemogcm/test/data/domcfg_1_file", load_from_saved=False, save=False, saving_name=None, ) nemo_ds0 = open_nemo( datadir="xnemogcm/test/data/nemo", domcfg=domcfg, load_from_saved=False, save=True, saving_name=None, ) nemo_ds1 = open_nemo( datadir="xnemogcm/test/data/nemo", domcfg=domcfg, load_from_saved=True, save=False, saving_name=None, ) assert (nemo_ds0 == nemo_ds1).all()
def test_open_nemo(): """Test opening of nemo files""" domcfg = open_domain_cfg( datadir="xnemogcm/test/data/domcfg_1_file", load_from_saved=False, save=False, saving_name=None, ) nemo_ds = open_nemo( datadir="xnemogcm/test/data/nemo", domcfg=domcfg, load_from_saved=False, save=False, saving_name=None, )
def test_options_for_files(): """Test options to provide files""" domcfg = open_domain_cfg( datadir=TEST_PATH / "data/domcfg_1_file", ) datadir = TEST_PATH / "data/nemo" # 1. Provide datadir and no files open_nemo(datadir=datadir, files=None, domcfg=domcfg) open_nemo(datadir=datadir, files="", domcfg=domcfg) open_nemo(datadir=datadir, files=[], domcfg=domcfg) # 2. Provide datadir and files files = ["BASIN_grid_T.nc", "BASIN_grid_U.nc"] open_nemo(datadir=datadir, files=files, domcfg=domcfg) # 3. Don't provide datadir but files open_nemo(datadir=None, files=datadir.glob("*grid*.nc"), domcfg=domcfg) open_nemo(datadir="", files=datadir.glob("*grid*.nc"), domcfg=domcfg) open_nemo(datadir=[], files=datadir.glob("*grid*.nc"), domcfg=domcfg) # 4. Don't provide anything => error try: open_nemo(datadir=None, files=None, domcfg=domcfg) except FileNotFoundError: pass