-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathtest_plot_feature.py
More file actions
62 lines (54 loc) · 4.31 KB
/
test_plot_feature.py
File metadata and controls
62 lines (54 loc) · 4.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
from pyxlma.plot.xlma_plot_feature import *
import xarray as xr
import numpy as np
from datetime import datetime as dt
def test_subset():
lma = xr.open_dataset('tests/truth/lma_netcdf/lma.nc')
lon_subset, lat_subset, alt_subset, time_subset, selection = subset(lma.event_longitude.data, lma.event_latitude.data, lma.event_altitude.data,
lma.event_time.data, lma.event_chi2.data, lma.event_stations.data,
(-101.7, -101.4), (33.4, 34.8), (0, 3000),
(np.datetime64('2023-12-24T00:57:00'), np.datetime64('2023-12-24T00:57:10')), 1, 8)
assert np.allclose(lon_subset, np.array([-101.59106, -101.598236, -101.59939, -101.59875, -101.601425, -101.60555, -101.60554, -101.60838, -101.60368, -101.62052]))
assert np.allclose(lat_subset, np.array([33.68953, 33.684334, 33.68242, 33.67924, 33.678104, 33.676983, 33.675335, 33.677456, 33.67102, 33.666958]))
assert np.allclose(alt_subset, np.array([2974.67, 2986.99, 2936.03, 2920.17, 2797.01, 2933.09, 2659.97, 2886.72, 2716.22, 2943.72]))
assert np.allclose(time_subset.astype(float), np.array(['2023-12-24T00:57:07.731986515', '2023-12-24T00:57:07.800978747', '2023-12-24T00:57:07.803362858', '2023-12-24T00:57:07.805963963',
'2023-12-24T00:57:07.806720943', '2023-12-24T00:57:07.809493631', '2023-12-24T00:57:07.810448100', '2023-12-24T00:57:07.811465266',
'2023-12-24T00:57:07.814960674', '2023-12-24T00:57:07.826344209']).astype(np.datetime64).astype(float))
assert np.sum(selection) == 10
def test_subset_time_mismatch():
lma = xr.open_dataset('tests/truth/lma_netcdf/lma.nc')
time_subset, selection = subset(time_data=lma.event_time.data, tlim=(dt(2023, 12, 24, 0, 57, 0), dt(2023, 12, 24, 0, 57, 10)))
assert np.allclose(time_subset[0:10].astype(float), np.array(['2023-12-24T00:57:01.747284125', '2023-12-24T00:57:01.748099340',
'2023-12-24T00:57:01.748382054', '2023-12-24T00:57:01.749366380',
'2023-12-24T00:57:01.749571321', '2023-12-24T00:57:01.751596868',
'2023-12-24T00:57:01.752419634', '2023-12-24T00:57:01.753047708',
'2023-12-24T00:57:01.754500213', '2023-12-24T00:57:01.757822235']).astype(np.datetime64).astype(float))
assert np.sum(selection) == 2590
def test_color_by_time_datetime_nolimit():
some_datetimes = np.array([dt(2021, 4, 9, 1, 51, 0), dt(2021, 4, 9, 1, 52, 0), dt(2021, 4, 9, 1, 53, 0), dt(2021, 4, 9, 1, 54, 0), dt(2021, 4, 9, 1, 59, 0)])
vmin, vmax, colors = color_by_time(some_datetimes)
assert vmin == 0
assert vmax == 480
assert np.allclose(colors, np.array([0, 60, 120, 180, 480]))
def test_color_by_time_datetime_limit():
some_datetimes = np.array([dt(2021, 4, 9, 1, 51, 0), dt(2021, 4, 9, 1, 52, 0), dt(2021, 4, 9, 1, 53, 0), dt(2021, 4, 9, 1, 54, 0), dt(2021, 4, 9, 1, 59, 0)])
limits = [dt(2021, 4, 9, 1, 50, 0), dt(2021, 4, 9, 2, 0, 0)]
vmin, vmax, colors = color_by_time(some_datetimes, limits)
assert vmin == 0
assert vmax == 600
assert np.allclose(colors, np.array([60, 120, 180, 240, 540]))
def test_color_by_time_xarray():
dataset = xr.open_dataset('tests/truth/lma_netcdf/lma.nc')
vmin, vmax, colors = color_by_time(dataset.event_time)
assert vmin == 0
assert np.isclose(vmax, 57.943683385849)
assert np.isclose(np.mean(colors), 30.483982899376258)
assert np.isclose(np.std(colors), 17.25687093241869)
def test_setup_hist():
lma = xr.open_dataset('tests/truth/lma_netcdf/lma.nc')
alt_lon, alt_lat, alt_time, lat_lon = setup_hist(lma.event_longitude.data, lma.event_latitude.data, lma.event_altitude.data,
lma.event_time.data, 2, 2, 2, 2)
assert np.allclose(alt_lon, np.array([[21082, 1], [0, 1]]))
assert np.allclose(alt_lat, np.array([[5, 21077], [1, 1]]))
assert np.allclose(alt_time, np.array([[9991, 1], [11091, 1]]))
assert np.allclose(lat_lon, np.array([[6, 21077], [0, 1]]))