1- from pathlib import Path
2-
31import numpy as np
42import pytest
53import xarray as xr
64import yaml
75
86import pyglider .seaexplorer as seaexplorer
9-
10- library_dir = Path (__file__ ).parent .parent .absolute ()
11- example_dir = library_dir / 'tests/example-data/'
7+ from tests .utils import EXAMPLE_DIR , LIBRARY_DIR
128
139# Create an L0 timeseries from seaexplorer data and test that the resulting netcdf
1410# is identical to the test data
15- rawdir = str (example_dir / 'example-seaexplorer/realtime_raw/' ) + '/'
16- rawncdir = str (example_dir / 'example-seaexplorer/realtime_rawnc/' ) + '/'
17- deploymentyaml = str (example_dir / 'example-seaexplorer/deploymentRealtime.yml' )
18- l0tsdir = str (example_dir / 'example-seaexplorer/L0-timeseries-test/' ) + '/'
11+ rawdir = str (EXAMPLE_DIR / 'example-seaexplorer/realtime_raw/' ) + '/'
12+ rawncdir = str (EXAMPLE_DIR / 'example-seaexplorer/realtime_rawnc/' ) + '/'
13+ deploymentyaml = str (EXAMPLE_DIR / 'example-seaexplorer/deploymentRealtime.yml' )
14+ l0tsdir = str (EXAMPLE_DIR / 'example-seaexplorer/L0-timeseries-test/' ) + '/'
1915seaexplorer .raw_to_rawnc (rawdir , rawncdir , deploymentyaml )
2016seaexplorer .merge_parquet (rawncdir , rawncdir , deploymentyaml , kind = 'sub' )
2117outname = seaexplorer .raw_to_L0timeseries (rawncdir , l0tsdir , deploymentyaml , kind = 'sub' )
2218output = xr .open_dataset (outname )
2319# Open test data file
2420test_data = xr .open_dataset (
25- library_dir
21+ LIBRARY_DIR
2622 / 'tests/expected/example-seaexplorer/L0-timeseries/dfo-eva035-20190718.nc'
2723)
2824variables = list (output .variables )
@@ -61,12 +57,12 @@ def test_example_seaexplorer_metadata():
6157# Test that interpolation over nans does not change the output with nrt data
6258with open (deploymentyaml ) as fin :
6359 deployment = yaml .safe_load (fin )
64- interp_yaml = str (example_dir / 'example-seaexplorer/deploymentRealtimeInterp.yml' )
60+ interp_yaml = str (EXAMPLE_DIR / 'example-seaexplorer/deploymentRealtimeInterp.yml' )
6561deployment ['netcdf_variables' ]['interpolate' ] = True
6662with open (interp_yaml , 'w' ) as fout :
6763 yaml .dump (deployment , fout )
6864l0tsdir_interp = (
69- str (example_dir / 'example-seaexplorer/L0-timeseries-test-interp/' ) + '/'
65+ str (EXAMPLE_DIR / 'example-seaexplorer/L0-timeseries-test-interp/' ) + '/'
7066)
7167
7268outname_interp = seaexplorer .raw_to_L0timeseries (
@@ -91,10 +87,10 @@ def test_example_seaexplorer_interp_nrt(var):
9187
9288
9389# Test raw (full resolution) seaexplorer data.
94- rawdir = str (example_dir / 'example-seaexplorer-raw/delayed_raw/' ) + '/'
95- rawncdir = str (example_dir / 'example-seaexplorer-raw/delayed_rawnc/' ) + '/'
96- deploymentyaml_raw = str (example_dir / 'example-seaexplorer-raw/deployment.yml' )
97- l0tsdir = str (example_dir / 'example-seaexplorer-raw/L0-timeseries-test/' ) + '/'
90+ rawdir = str (EXAMPLE_DIR / 'example-seaexplorer-raw/delayed_raw/' ) + '/'
91+ rawncdir = str (EXAMPLE_DIR / 'example-seaexplorer-raw/delayed_rawnc/' ) + '/'
92+ deploymentyaml_raw = str (EXAMPLE_DIR / 'example-seaexplorer-raw/deployment.yml' )
93+ l0tsdir = str (EXAMPLE_DIR / 'example-seaexplorer-raw/L0-timeseries-test/' ) + '/'
9894seaexplorer .raw_to_rawnc (rawdir , rawncdir , deploymentyaml_raw )
9995seaexplorer .merge_parquet (rawncdir , rawncdir , deploymentyaml_raw , kind = 'raw' )
10096outname_raw = seaexplorer .raw_to_L0timeseries (
@@ -103,7 +99,7 @@ def test_example_seaexplorer_interp_nrt(var):
10399output_raw = xr .open_dataset (outname_raw )
104100# Open test data file
105101test_data_raw = xr .open_dataset (
106- library_dir
102+ LIBRARY_DIR
107103 / 'tests/expected/example-seaexplorer-raw/L0-timeseries/dfo-bb046-20200908.nc'
108104)
109105
@@ -138,12 +134,12 @@ def test_example_seaexplorer_metadata_raw():
138134# Test that interpolation over nans in raw data results in a greater or equal number of non-nan values
139135with open (deploymentyaml_raw ) as fin :
140136 deployment_raw = yaml .safe_load (fin )
141- interp_yaml = str (example_dir / 'example-seaexplorer-raw/deploymentDelayedInterp.yml' )
137+ interp_yaml = str (EXAMPLE_DIR / 'example-seaexplorer-raw/deploymentDelayedInterp.yml' )
142138deployment_raw ['netcdf_variables' ]['interpolate' ] = True
143139with open (interp_yaml , 'w' ) as fout :
144140 yaml .dump (deployment_raw , fout )
145141l0tsdir_interp_raw = (
146- str (example_dir / 'example-seaexplorer-raw/L0-timeseries-test-interp/' ) + '/'
142+ str (EXAMPLE_DIR / 'example-seaexplorer-raw/L0-timeseries-test-interp/' ) + '/'
147143)
148144
149145outname_interp_raw = seaexplorer .raw_to_L0timeseries (
0 commit comments