Skip to content

Commit

Permalink
ENH: Move tests to dedicated folder (#783)
Browse files Browse the repository at this point in the history
  • Loading branch information
mgrover1 authored Jan 9, 2024
1 parent 52f88bd commit ea2aeef
Show file tree
Hide file tree
Showing 111 changed files with 282 additions and 221 deletions.
7 changes: 0 additions & 7 deletions act/tests/discovery/test_surfrad.py

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ def test_correct_rl():
ds = act.io.arm.read_arm_netcdf(files)

ds = act.corrections.raman_lidar.correct_rl(ds, range_normalize_log_values=True)
np.testing.assert_almost_equal(
np.max(ds['depolarization_counts_high'].values), 9.91, decimal=2
)
np.testing.assert_almost_equal(np.max(ds['depolarization_counts_high'].values), 9.91, decimal=2)
np.testing.assert_almost_equal(
np.min(ds['depolarization_counts_high'].values), -7.00, decimal=2
)
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,4 @@ def test_arm_doi():
assert 'Kyrouac' in doi

doi = act.discovery.get_arm_doi('test', startdate, enddate)
assert "No DOI Found" in doi
assert 'No DOI Found' in doi
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@ def test_neon():
assert '2022-11' in result

output_dir = os.path.join(os.getcwd(), site_code + '_' + product_code)
result = act.discovery.download_neon_data(site_code, product_code, '2022-10', output_dir=output_dir)
result = act.discovery.download_neon_data(
site_code, product_code, '2022-10', output_dir=output_dir
)
assert len(result) == 20
assert any('readme' in r for r in result)
assert any('sensor_position' in r for r in result)

result = act.discovery.download_neon_data(site_code, product_code, '2022-09',
end_date='2022-10', output_dir=output_dir)
result = act.discovery.download_neon_data(
site_code, product_code, '2022-09', end_date='2022-10', output_dir=output_dir
)
assert len(result) == 40
assert any('readme' in r for r in result)
assert any('sensor_position' in r for r in result)
File renamed without changes.
9 changes: 9 additions & 0 deletions tests/discovery/test_surfrad.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import act


def test_download_surfrad():
results = act.discovery.download_surfrad_data(
site='tbl', startdate='20230601', enddate='20230602'
)
assert len(results) == 2
assert 'tbl23152.dat' in results[0]
29 changes: 15 additions & 14 deletions act/tests/io/test_arm.py → tests/io/test_arm.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from pathlib import Path
import tempfile
from pathlib import Path

import numpy as np

Expand All @@ -25,18 +25,23 @@ def test_read_arm_netcdf():
assert 'time' in ds

ds = act.io.arm.read_arm_netcdf([act.tests.EXAMPLE_MET_TEST2])
assert ds['time'].values[10].astype('datetime64[ms]') == np.datetime64('2019-01-01T00:10:00', 'ms')
assert ds['time'].values[10].astype('datetime64[ms]') == np.datetime64(
'2019-01-01T00:10:00', 'ms'
)

ds = act.io.arm.read_arm_netcdf(act.tests.EXAMPLE_MET1, use_base_time=True, drop_variables='time')
ds = act.io.arm.read_arm_netcdf(
act.tests.EXAMPLE_MET1, use_base_time=True, drop_variables='time'
)
assert 'time' in ds
assert np.issubdtype(ds['time'].dtype, np.datetime64)
assert ds['time'].values[10].astype('datetime64[ms]') == np.datetime64('2019-01-01T00:10:00', 'ms')
assert ds['time'].values[10].astype('datetime64[ms]') == np.datetime64(
'2019-01-01T00:10:00', 'ms'
)

del ds


def test_keep_variables():

var_names = [
'temp_mean',
'rh_mean',
Expand All @@ -57,9 +62,7 @@ def test_keep_variables():
'pwd_cumul_rain',
]
var_names = var_names + ['qc_' + ii for ii in var_names]
drop_variables = act.io.arm.keep_variables_to_drop_variables(
act.tests.EXAMPLE_MET1, var_names
)
drop_variables = act.io.arm.keep_variables_to_drop_variables(act.tests.EXAMPLE_MET1, var_names)

expected_drop_variables = [
'wdir_vec_std',
Expand Down Expand Up @@ -159,8 +162,8 @@ def test_io_dod():
with np.testing.assert_raises(ValueError):
ds = act.io.arm.create_ds_from_arm_dod('vdis.b1', {}, version='1.2')
ds = act.io.arm.create_ds_from_arm_dod(
sample_files.EXAMPLE_DOD, dims, version=1.2, scalar_fill_dim='time',
local_file=True)
sample_files.EXAMPLE_DOD, dims, version=1.2, scalar_fill_dim='time', local_file=True
)
assert 'moment1' in ds
assert len(ds['base_time'].values) == 1440
assert len(ds['drop_diameter'].values) == 50
Expand Down Expand Up @@ -288,7 +291,5 @@ def test_read_mmcr():
ds = act.io.arm.read_arm_mmcr(results)
assert 'MeanDopplerVelocity_PR' in ds
assert 'SpectralWidth_BL' in ds
np.testing.assert_almost_equal(
ds['Reflectivity_GE'].mean(), -34.62, decimal=2)
np.testing.assert_almost_equal(
ds['MeanDopplerVelocity_Receiver1'].max(), 9.98, decimal=2)
np.testing.assert_almost_equal(ds['Reflectivity_GE'].mean(), -34.62, decimal=2)
np.testing.assert_almost_equal(ds['MeanDopplerVelocity_Receiver1'].max(), 9.98, decimal=2)
File renamed without changes.
7 changes: 2 additions & 5 deletions act/tests/io/test_icartt.py → tests/io/test_icartt.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@

import numpy as np
import pytest

import act


@pytest.mark.skipif(not act.io.icartt._ICARTT_AVAILABLE,
reason="ICARTT is not installed.")
@pytest.mark.skipif(not act.io.icartt._ICARTT_AVAILABLE, reason='ICARTT is not installed.')
def test_read_icartt():
result = act.io.icartt.read_icartt(act.tests.EXAMPLE_AAF_ICARTT)
assert 'pitch' in result
assert len(result['time'].values) == 14087
assert result['true_airspeed'].units == 'm/s'
assert 'Revision' in result.attrs
np.testing.assert_almost_equal(
result['static_pressure'].mean(), 708.75, decimal=2)
np.testing.assert_almost_equal(result['static_pressure'].mean(), 708.75, decimal=2)
File renamed without changes.
4 changes: 3 additions & 1 deletion act/tests/io/test_neon.py → tests/io/test_neon.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ def test_read_neon():
assert 'tempSingleMean' in ds
assert ds['tempSingleMean'].values[0] == -0.6003

ds = act.io.neon.read_neon_csv(data_file, variable_files=variable_file, position_files=position_file)
ds = act.io.neon.read_neon_csv(
data_file, variable_files=variable_file, position_files=position_file
)
assert ds['northOffset'].values == -5.79
assert ds['tempSingleMean'].attrs['units'] == 'celsius'
assert 'lat' in ds
Expand Down
2 changes: 1 addition & 1 deletion act/tests/io/test_noaagml.py → tests/io/test_noaagml.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import numpy as np

import act
from act.tests import sample_files
from act.io import read_gml
from act.tests import sample_files


def test_read_gml():
Expand Down
58 changes: 26 additions & 32 deletions act/tests/io/test_noaapsl.py → tests/io/test_noaapsl.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import pytest

import act
from act.tests import sample_files
from act.io import read_psl_surface_met, read_psl_wind_profiler_temperature
from act.tests import sample_files


def test_read_psl_wind_profiler():
Expand All @@ -19,9 +19,7 @@ def test_read_psl_wind_profiler():
assert test_ds_hi.dims['HT'] == 50

# test coordinates
assert (
test_ds_low.coords['HT'][0:5] == np.array([0.151, 0.254, 0.356, 0.458, 0.561])
).all()
assert (test_ds_low.coords['HT'][0:5] == np.array([0.151, 0.254, 0.356, 0.458, 0.561])).all()
assert (
test_ds_low.coords['time'][0:2]
== np.array(
Expand All @@ -37,10 +35,12 @@ def test_read_psl_wind_profiler():
assert test_ds_low.attrs['latitude'] == 34.66
assert test_ds_low.attrs['longitude'] == -87.35
assert test_ds_low.attrs['elevation'] == 187.0
assert (test_ds_low.attrs['beam_azimuth'] == np.array(
[38.0, 38.0, 308.0], dtype='float32')).all()
assert (test_ds_low.attrs['beam_elevation'] == np.array(
[90.0, 74.7, 74.7], dtype='float32')).all()
assert (
test_ds_low.attrs['beam_azimuth'] == np.array([38.0, 38.0, 308.0], dtype='float32')
).all()
assert (
test_ds_low.attrs['beam_elevation'] == np.array([90.0, 74.7, 74.7], dtype='float32')
).all()
assert test_ds_low.attrs['consensus_average_time'] == 24
assert test_ds_low.attrs['oblique-beam_vertical_correction'] == 0
assert test_ds_low.attrs['number_of_beams'] == 3
Expand All @@ -63,17 +63,13 @@ def test_read_psl_wind_profiler():
# test fields
assert test_ds_low['RAD1'].shape == (4, 49)
assert test_ds_hi['RAD1'].shape == (4, 50)
assert (test_ds_low['RAD1'][0, 0:5] == np.array(
[0.2, 0.1, 0.1, 0.0, -0.1])).all()
assert (test_ds_hi['RAD1'][0, 0:5] == np.array(
[0.1, 0.1, -0.1, 0.0, -0.2])).all()
assert (test_ds_low['RAD1'][0, 0:5] == np.array([0.2, 0.1, 0.1, 0.0, -0.1])).all()
assert (test_ds_hi['RAD1'][0, 0:5] == np.array([0.1, 0.1, -0.1, 0.0, -0.2])).all()

assert test_ds_low['SPD'].shape == (4, 49)
assert test_ds_hi['SPD'].shape == (4, 50)
assert (test_ds_low['SPD'][0, 0:5] == np.array(
[2.5, 3.3, 4.3, 4.3, 4.8])).all()
assert (test_ds_hi['SPD'][0, 0:5] == np.array(
[3.7, 4.6, 6.3, 5.2, 6.8])).all()
assert (test_ds_low['SPD'][0, 0:5] == np.array([2.5, 3.3, 4.3, 4.3, 4.8])).all()
assert (test_ds_hi['SPD'][0, 0:5] == np.array([3.7, 4.6, 6.3, 5.2, 6.8])).all()

# test transpose
test_ds_low, test_ds_hi = act.io.noaapsl.read_psl_wind_profiler(
Expand All @@ -87,8 +83,7 @@ def test_read_psl_wind_profiler():


def test_read_psl_wind_profiler_temperature():
ds = read_psl_wind_profiler_temperature(
act.tests.EXAMPLE_NOAA_PSL_TEMPERATURE)
ds = read_psl_wind_profiler_temperature(act.tests.EXAMPLE_NOAA_PSL_TEMPERATURE)

assert ds.attrs['site_identifier'] == 'CTD'
assert ds.attrs['elevation'] == 600.0
Expand All @@ -109,41 +104,40 @@ def test_read_psl_surface_met():


def test_read_psl_parsivel():
url = ['https://downloads.psl.noaa.gov/psd2/data/realtime/DisdrometerParsivel/Stats/ctd/2022/002/ctd2200200_stats.txt',
'https://downloads.psl.noaa.gov/psd2/data/realtime/DisdrometerParsivel/Stats/ctd/2022/002/ctd2200201_stats.txt',
'https://downloads.psl.noaa.gov/psd2/data/realtime/DisdrometerParsivel/Stats/ctd/2022/002/ctd2200202_stats.txt']
url = [
'https://downloads.psl.noaa.gov/psd2/data/realtime/DisdrometerParsivel/Stats/ctd/2022/002/ctd2200200_stats.txt',
'https://downloads.psl.noaa.gov/psd2/data/realtime/DisdrometerParsivel/Stats/ctd/2022/002/ctd2200201_stats.txt',
'https://downloads.psl.noaa.gov/psd2/data/realtime/DisdrometerParsivel/Stats/ctd/2022/002/ctd2200202_stats.txt',
]

ds = act.io.noaapsl.read_psl_parsivel(url)
assert 'number_density_drops' in ds
assert np.max(ds['number_density_drops'].values) == 355
assert ds['number_density_drops'].values[10, 10] == 201

ds = act.io.noaapsl.read_psl_parsivel(
'https://downloads.psl.noaa.gov/psd2/data/realtime/DisdrometerParsivel/Stats/ctd/2022/002/ctd2200201_stats.txt')
'https://downloads.psl.noaa.gov/psd2/data/realtime/DisdrometerParsivel/Stats/ctd/2022/002/ctd2200201_stats.txt'
)
assert 'number_density_drops' in ds


def test_read_psl_fmcw_moment():
result = act.discovery.download_noaa_psl_data(
site='kps', instrument='Radar FMCW Moment',
startdate='20220815', hour='06'
site='kps', instrument='Radar FMCW Moment', startdate='20220815', hour='06'
)
ds = act.io.noaapsl.read_psl_radar_fmcw_moment([result[-1]])
assert 'range' in ds
np.testing.assert_almost_equal(
ds['reflectivity_uncalibrated'].mean(), 2.37, decimal=2)
assert ds['range'].max() == 10040.
np.testing.assert_almost_equal(ds['reflectivity_uncalibrated'].mean(), 2.37, decimal=2)
assert ds['range'].max() == 10040.0
assert len(ds['time'].values) == 115


def test_read_psl_sband_moment():
result = act.discovery.download_noaa_psl_data(
site='ctd', instrument='Radar S-band Moment',
startdate='20211225', hour='06'
site='ctd', instrument='Radar S-band Moment', startdate='20211225', hour='06'
)
ds = act.io.noaapsl.read_psl_radar_sband_moment([result[-1]])
assert 'range' in ds
np.testing.assert_almost_equal(
ds['reflectivity_uncalibrated'].mean(), 1.00, decimal=2)
assert ds['range'].max() == 9997.
np.testing.assert_almost_equal(ds['reflectivity_uncalibrated'].mean(), 1.00, decimal=2)
assert ds['range'].max() == 9997.0
assert len(ds['time'].values) == 37
6 changes: 2 additions & 4 deletions act/tests/io/test_sodar.py → tests/io/test_sodar.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@ def test_read_sodar():
assert len(ds.data_vars) == 26
assert ds['dir'].shape == (96, 58)
direction = ds['dir'][0, 0:5].values
np.testing.assert_allclose(
direction, [129.9, 144.2, 147.5, 143.5, 143.0], rtol=1e-6)
np.testing.assert_allclose(direction, [129.9, 144.2, 147.5, 143.5, 143.0], rtol=1e-6)
pgz = ds['PGz'][0, 0:5].values
np.testing.assert_allclose(
pgz, [4, 4, 4, 5, 5])
np.testing.assert_allclose(pgz, [4, 4, 4, 5, 5])

assert ds['dir'].attrs['variable_name'] == 'wind direction'
assert ds['dir'].attrs['symbol'] == 'dir'
Expand Down
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import pytest

import act
from act.tests import sample_files
from act.plotting import ContourDisplay
from act.tests import sample_files

matplotlib.use('Agg')

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import matplotlib

import numpy as np
import pytest
import pandas as pd
import pytest
import xarray as xr
from numpy.testing import assert_allclose

import act
from act.tests import sample_files
from act.plotting import DistributionDisplay
from act.tests import sample_files

matplotlib.use('Agg')

Expand Down Expand Up @@ -276,7 +275,11 @@ def test_size_distribution2():
sigma = 10
mu = 50
bins = pd.date_range('2023-01-01', '2023-01-02', periods=mu)
ydata = 1 / (sigma * np.sqrt(2 * np.pi)) * np.exp(-((np.array(range(len(bins))) - mu) ** 2) / (2 * sigma**2))
ydata = (
1
/ (sigma * np.sqrt(2 * np.pi))
* np.exp(-((np.array(range(len(bins))) - mu) ** 2) / (2 * sigma**2))
)
y_array = xr.DataArray(ydata, dims={'time': bins})
bins = xr.DataArray(bins, dims={'time': bins})
my_fake_ds = xr.Dataset({'time': bins, 'ydata': y_array})
Expand Down Expand Up @@ -399,7 +402,8 @@ def test_scatter2():
# Create a DistributionDisplay object to compare fields
display = DistributionDisplay(ds)
display.plot_scatter(
'wspd_arith_mean', 'wspd_vec_mean',
'wspd_arith_mean',
'wspd_vec_mean',
)
display.set_ratio_line()
ds.close()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import matplotlib
import pytest
import numpy as np
import pytest

import act
from act.tests import sample_files
from act.plotting import GeographicPlotDisplay
from act.tests import sample_files

try:
import cartopy
Expand All @@ -16,7 +17,7 @@


@pytest.mark.skipif(not CARTOPY_AVAILABLE, reason='Cartopy is not installed.')
@pytest.mark.mpl_image_compare(style="default", tolerance=30)
@pytest.mark.mpl_image_compare(style='default', tolerance=30)
def test_geoplot():
sonde_ds = act.io.arm.read_arm_netcdf(sample_files.EXAMPLE_SONDE1)
geodisplay = GeographicPlotDisplay({'sgpsondewnpnC1.b1': sonde_ds}, figsize=(15, 8))
Expand Down Expand Up @@ -45,7 +46,7 @@ def test_geoplot():


@pytest.mark.skipif(not CARTOPY_AVAILABLE, reason='Cartopy is not installed.')
@pytest.mark.mpl_image_compare(style="default", tolerance=30)
@pytest.mark.mpl_image_compare(style='default', tolerance=30)
def test_geoplot_tile():
sonde_ds = act.io.arm.read_arm_netcdf(sample_files.EXAMPLE_SONDE1)
geodisplay = GeographicPlotDisplay({'sgpsondewnpnC1.b1': sonde_ds}, figsize=(15, 8))
Expand Down
Loading

0 comments on commit ea2aeef

Please sign in to comment.