test_processing.py 1.76 KB
Newer Older
matthmey's avatar
matthmey committed
1
import stuett
matthmey's avatar
matthmey committed
2
import datetime as dt
matthmey's avatar
matthmey committed
3
4
import xarray as xr
import numpy as np
matthmey's avatar
matthmey committed
5
import pandas as pd
matthmey's avatar
matthmey committed
6
7
8
9
10

from tests.stuett.sample_data import *

import pytest

matthmey's avatar
matthmey committed
11

matthmey's avatar
matthmey committed
12
class TestMinMaxDownsampling(object):
matthmey's avatar
matthmey committed
13
    def test_minmax(self):
matthmey's avatar
matthmey committed
14
15
16
17
        minmax_default = stuett.data.MinMaxDownsampling()
        minmax_rate2 = stuett.data.MinMaxDownsampling(2)

        np.random.seed(123)
matthmey's avatar
matthmey committed
18
19
20
21
22
23
24
        da = xr.DataArray(
            np.random.rand(9, 2),
            [
                ("time", pd.date_range("2000-01-01", periods=9)),
                ("channel", ["EHE", "EHZ"]),
            ],
        )
matthmey's avatar
matthmey committed
25
26
27
28
29
30
31

        x = minmax_rate2(da)

        x = x.compute()

        # TODO: proper test

32
    @pytest.mark.slow
matthmey's avatar
matthmey committed
33
    def test_seismic(self):
matthmey's avatar
matthmey committed
34

35
        seismic_source = stuett.data.SeismicSource(use_arclink=True)
matthmey's avatar
matthmey committed
36
37
38
39
40
41
42
        minmax_rate2 = stuett.data.MinMaxDownsampling(2)

        x = seismic_source(config)
        x = minmax_rate2(x)

        x.compute()
        # TODO: proper test
matthmey's avatar
matthmey committed
43
44


45
# TestMinMaxDownsampling().test_minmax()
matthmey's avatar
matthmey committed
46
# TestMinMaxDownsampling().test_seismic()
47
48
49


def test_spectrogram():
matthmey's avatar
matthmey committed
50
    spectrogram = stuett.data.Spectrogram(nfft=2, stride=1, dim='time')
51
52
53

    np.random.seed(123)
    da = xr.DataArray(
matthmey's avatar
matthmey committed
54
        np.random.rand(9, 3),
55
56
        [
            ("time", pd.date_range("2000-01-01", periods=9)),
matthmey's avatar
matthmey committed
57
            ("channel", ["EHE", "EHZ", "EHN"]),
58
        ],
matthmey's avatar
matthmey committed
59
        attrs={"sampling_rate":0.000011574}
60
61
62
63
64
65
66
67
    )

    x = spectrogram(da)

    print(x)


test_spectrogram()
matthmey's avatar
matthmey committed
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88



def test_lttbdownsampling():
    lttb_node = stuett.data.LTTBDownsampling(rate=2)

    np.random.seed(123)
    da = xr.DataArray(
        np.random.rand(9, 2),
        [
            ("time", pd.date_range("2000-01-01", periods=9)),
            ("channel", ["EHE", "EHZ"]),
        ],
    )

    x = lttb_node(da)

    print(x)


# test_lttbdownsampling()