def test_zarr(self): """Check reading of zarr dataset in ww3 format.""" filename = os.path.join(FILES_DIR, "ww3file.zarr") dset = read_ww3(filename, file_format="zarr") outfile = os.path.join(self.tmp_dir, "tmp.nc") dset.spec.to_netcdf(outfile) dset2 = read_netcdf(outfile) dset.equals(dset2)
def test_ww3(self): for testfile in WW3_TEST_FILES: print("Reading %s" % testfile) self.s = read_ww3(testfile) fileout = os.path.join( TMP_DIR, os.path.basename(testfile).replace('.nc', '.oct')) print("Writing %s" % fileout) SpecDataset(self.s.isel(site=0)).to_octopus(fileout)
def test_ww3(self): for testfile in WW3_TEST_FILES: print("Reading %s" % testfile) self.s = read_ww3(testfile) fileout = os.path.join( TMP_DIR, os.path.basename(testfile).replace('.nc', '.json')) print("Writing %s" % fileout) self.s.spec.to_json(fileout)
def setup_class(self): """Read test spectra from file.""" self.dset = read_ww3(os.path.join(FILES_DIR, "ww3file.nc")) # First two sites are exact matches, third site is in between self.lons = [92.00, 92.10, 92.05] self.lats = [19.80, 19.95, 19.88] self.lons_exact = self.lons[:2] self.lats_exact = self.lats[:2] self.lons_inexact = self.lons[-1:] self.lats_inexact = self.lats[-1:]
""" Watershed parameters ==================== Partition spectra and plot parameters """ import matplotlib.pyplot as plt from wavespectra import read_ww3 dset = read_ww3("../_static/ww3file.nc") dspart = dset.spec.partition(dset.wspd, dset.wdir, dset.dpt) pstats = dspart.spec.stats(["hs", "tp", "dpm"]) fig, (ax1, ax2, ax3) = plt.subplots(3, 1, figsize=(8, 8)) # Hs p1 = dset.spec.hs().isel(site=0).plot(ax=ax1, label="Full spectrum", marker="o") p2 = pstats.hs.isel(part=0, site=0).plot(ax=ax1, label="Partition 0 (sea)", marker="o") p3 = pstats.hs.isel(part=1, site=0).plot( ax=ax1, label="Partition 1 (swell 1)", marker="o" ) p4 = pstats.hs.isel(part=2, site=0).plot( ax=ax1, label="Partition 2 (swell 2)", marker="o" ) p5 = pstats.hs.isel(part=3, site=0).plot( ax=ax1, label="Partition 3 (swell 3)", marker="o" ) ax1.set_ylabel("$Hs$ (m)")
def setup_class(self): """Read test spectra from file.""" self.dset = read_ww3(os.path.join(FILES_DIR, "ww3file.nc"))
if method is None: kwargs.update({"exact": True}) # Providing station coordinates is a lot more efficient for chunked datasets if dset_lons is None: dset_lons = self.dset[attrs.LONNAME].values if dset_lats is None: dset_lats = self.dset[attrs.LATNAME].values dsout = func( dset=self.dset, lons=lons, lats=lats, tolerance=tolerance, dset_lons=dset_lons, dset_lats=dset_lats, **kwargs ) return dsout if __name__ == "__main__": from wavespectra import read_ww3 here = os.path.dirname(os.path.abspath(__file__)) # filename = os.path.join(here, "../tests/sample_files/swanfile.spec") filename = os.path.join(here, "../tests/sample_files/spec20170101T00_spec.nc") dset = read_ww3(filename) lons = [283.5, 284, 284.4974365234375] lats = [-53.500091552734375, -53.500091552734375, -53.500091552734375] ds = dset.spec.sel(lons, lats, method="nearest", tolerance=2.0)
def dset2(): _ds = read_ww3(str(FILES_DIR / 'ww3file.nc')) yield _ds
Copied as a function so it can be used in a generic context. Args: - spec (ndarray): wave spectrum array - freqs (darray): wave frequency array - dirs (darray): wave direction array - tail (bool): if True fit high-frequency tail before integrating spectra """ df = abs(freqs[1:] - freqs[:-1]) if len(dirs) > 1: ddir = abs(dirs[1] - dirs[0]) E = ddir * spec.sum(1) else: E = np.squeeze(spec) Etot = 0.5 * sum(df * (E[1:] + E[:-1])) if tail and freqs[-1] > 0.333: Etot += 0.25 * E[-1] * freqs[-1] return 4.0 * np.sqrt(Etot) if __name__ == "__main__": from wavespectra import read_ww3 dset = read_ww3("/wave/socean/spec20120101T00_spec.nc", chunks={"station": 1}) ds = dset.isel(site=2000) ret = dset.spec.dspr() # part = ds.spec.partition(ds.wspd, ds.wdir, ds.dpt) # print(part.isel(time=0).spec.hs().values)