Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/622 read bodc #646

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 45 additions & 3 deletions unit_testing/test_tidegauge_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,48 @@ def test_read_gesla_formats(self):
self.assertTrue(check1, "check1")
self.assertTrue(check2, "check2")

def test_read_bodc_and_compare_to_model(self):
sci = coast.Gridded(files.fn_nemo_dat, files.fn_nemo_dom, config=files.fn_config_t_grid)
sci.dataset["landmask"] = sci.dataset.bottom_level == 0
tganalysis = coast.TidegaugeAnalysis()

with self.subTest("Read BODC file"):
date0 = datetime.datetime(2020, 10, 10)
date1 = datetime.datetime(2020, 10, 12)
liv = coast.Tidegauge()
liv.read_bodc(files.fn_tidegauge_bodc, date_start=date0, date_end=date1)
# TEST: Check attribute dictionary and length of sea_level.
check1 = len(liv.dataset.ssh.isel(id_dim=0)) == 193
check2 = liv.dataset.id_name.values[0] == "liverpool,_gladstone_dock"
self.assertTrue(check1, "check1")
self.assertTrue(check2, "check2")

with self.subTest("Plot Single BODC"):
f, a = liv.plot_on_map()
f.savefig(files.dn_fig + "tidegauge_bodc_map.png")
plt.close("all")

with self.subTest("Obs operator"):
liv_interp = liv.obs_operator(sci, time_interp="linear")

# TEST: Check that the resulting interp_sossheig variable is of the same
# length as sea_level and that it is populated.
interp_len = liv_interp.dataset.ssh.shape[0]
orig_len = liv.dataset.ssh.shape[0]
check1 = interp_len == orig_len
check2 = False in np.isnan(liv_interp.dataset.ssh)
self.assertTrue(check1, "check1")
self.assertTrue(check2, "check2")

with self.subTest("Tidegauge BODC CRPS"):
crps = tganalysis.crps(liv.dataset.ssh, sci.dataset.ssh)

# TEST: Check length of crps and that it contains values
check1 = crps.dataset.crps.shape[0] == liv.dataset.ssh.shape[0]
check2 = False in np.isnan(crps.dataset.crps)
self.assertTrue(check1, "check1")
self.assertTrue(check2, "check2")

def test_read_gesla_and_compare_to_model(self):
sci = coast.Gridded(files.fn_nemo_dat, files.fn_nemo_dom, config=files.fn_config_t_grid)
sci.dataset["landmask"] = sci.dataset.bottom_level == 0
Expand All @@ -151,7 +193,7 @@ def test_read_gesla_and_compare_to_model(self):

with self.subTest("Plot Single GESLA"):
f, a = lowestoft.plot_on_map()
f.savefig(files.dn_fig + "tidegauge_map.png")
f.savefig(files.dn_fig + "tidegauge_gesla_map.png")
plt.close("all")

with self.subTest("Obs operator"):
Expand All @@ -166,7 +208,7 @@ def test_read_gesla_and_compare_to_model(self):
self.assertTrue(check1, "check1")
self.assertTrue(check2, "check2")

with self.subTest("Tidegauge CRPS"):
with self.subTest("Tidegauge GESLA CRPS"):
crps = tganalysis.crps(lowestoft.dataset.ssh, sci.dataset.ssh)

# TEST: Check length of crps and that it contains values
Expand Down Expand Up @@ -325,7 +367,7 @@ def test_tidegauge_cubic_spline_extrema(self):
# it assumes it is a GESLA type object
tg = coast.Tidegauge()
# specify the data read as a High Low Water dataset
tg.read_bodc(files.fn_tidegauge2, date_start, date_end)
tg.read_bodc(files.fn_tidegauge_bodc, date_start, date_end)

# Use cubic spline fitting method
extrema_cubc = tganalysis.find_high_and_low_water(tg.dataset.ssh, method="cubic")
Expand Down
19 changes: 10 additions & 9 deletions unit_testing/unit_test_contents.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,16 @@

9. test_tidegauge_methods
a. load_multiple_tidegauge
b. read_gesla_and_compare_to_model
c. read_gesla_formats
d. tidegauge_cubic_spline_extrema
e. tidegauge_finding_extrema
f. tidegauge_for_tabulated_data
g. tidegauge_resample_and_apply_doodsonx0
h. time_mean
i. time_slice
j. time_std
b. read_bodc_and_compare_to_model
c. read_gesla_and_compare_to_model
d. read_gesla_formats
e. tidegauge_cubic_spline_extrema
f. tidegauge_finding_extrema
g. tidegauge_for_tabulated_data
h. tidegauge_resample_and_apply_doodsonx0
i. time_mean
j. time_slice
k. time_std

10. test_eof_methods
a. compute_heofs
Expand Down
1 change: 1 addition & 0 deletions unit_testing/unit_test_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
file_names_amm7 = path.join(dn_files, "nemo_data_T_grid*.nc")
fn_altimetry = path.join(dn_files, "coast_example_altimetry_data.nc")
fn_tidegauge = path.join(dn_files, "tide_gauges/lowestoft-p024-uk-bodc")
fn_tidegauge_bodc = path.join(dn_files, "tide_gauges/LIV200710.txt")
fn_tidegauge2 = path.join(dn_files, "tide_gauges/LIV2010.txt")
fn_tidegauge_v3 = path.join(dn_files, "tide_gauges/lowestoft-p024-uk-bodc")
fn_tidegauge_v5 = path.join(dn_files, "tide_gauges/liverpool_gladstone_dock-liv-gbr-bodc")
Expand Down