Skip to content

Commit

Permalink
add more tests and test data; remove tqdm dependency and temporarily …
Browse files Browse the repository at this point in the history
…disable progress bar
  • Loading branch information
dennissergeev committed Jul 16, 2018
1 parent 32021dc commit 5cba439
Show file tree
Hide file tree
Showing 114 changed files with 336 additions and 19 deletions.
3 changes: 2 additions & 1 deletion env_octant.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ dependencies:
- python=3.6
- pytest
- scipy
- tqdm
# - tqdm
# - octant
- xarray
- sphinx
- sphinx-gallery
Expand Down
39 changes: 23 additions & 16 deletions octant/decor.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,30 @@
# -*- coding: utf-8 -*-
"""Bells and whistles."""
# This module is temporarily disabled

# global DISABLE_TQDM
# TODO: global runtime switch
DISABLE_TQDM = False
DISABLE_TQDM = True


def pbar(obj, **tqdm_kw):
"""Empty progress bar."""
return obj


try:
# If tqdm is installed
if not DISABLE_TQDM:
try:
# Check if it's Jupyter Notebook
ipy_str = str(type(get_ipython()))
if 'zmqshell' in ipy_str.lower():
from tqdm import tqdm_notebook as tqdm
else:
# If tqdm is installed
try:
# Check if it's Jupyter Notebook
ipy_str = str(type(get_ipython()))
if 'zmqshell' in ipy_str.lower() and False:
from tqdm import tqdm_notebook as tqdm
else:
from tqdm import tqdm
except NameError:
from tqdm import tqdm
except NameError:
from tqdm import tqdm
from functools import partial
pbar = partial(tqdm, leave=False, disable=DISABLE_TQDM)
except ImportError:
def pbar(obj, **tqdm_kw):
"""Empty progress bar."""
return obj
from functools import partial
pbar = partial(tqdm, leave=False, disable=DISABLE_TQDM) # noqa
except ImportError:
pass
37 changes: 36 additions & 1 deletion octant/tests/test_core.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
"""Test the core submodule."""
from datetime import datetime
from pathlib import Path

import numpy as np

from octant import core

import pandas as pd

import pytest

TEST_DIR = Path(__file__).parent / 'test_data'
TEST_DIR = Path(__file__).parent / 'test_data' / 'era5_run000'
REF_DM = Path(__file__).parent / 'test_data' / 'distance_matrix.npy'
REF_FILE = Path(__file__).parent / 'test_data' / 'pmc_loc_time_ch4_20Mar-02Apr.txt'


@pytest.fixture(scope='module')
Expand All @@ -14,6 +21,22 @@ def trackrun():
return core.TrackRun(TEST_DIR)


@pytest.fixture(scope='module')
def ref_set():
"""Load reference dataset."""
ref = pd.read_csv(REF_FILE, delimiter='\t',
names=['N', 'time', 'lon', 'lat'],
parse_dates=['time'],
date_parser=lambda x: datetime.strptime(x, '%Y%m%d%H%M'))
ref_tracks = []
for i, df in ref.groupby('N'):
ot = core.OctantTrack.from_df(df)
if ot.lifetime_h >= 6:
ref_tracks.append(ot)
assert len(ref_tracks) == 27
return ref_tracks


def test_load_data():
"""Create an empty TrackRun instance and load data afterwards."""
tr = core.TrackRun()
Expand All @@ -38,3 +61,15 @@ def test_conf(trackrun):
assert len(trackrun.conf) == 43
assert len(trackrun.conf.extent) == 4
assert trackrun.conf.extent == [-10, 40, 67, 78]


def test_match_bs2000(trackrun, ref_set):
"""Use cached TrackRun and tracks from ref_set to test match_tracks() method."""
subset = 'moderate'
match_pairs, dm = trackrun.match_tracks(ref_set, subset=subset,
method='bs2000', beta=50.,
return_dist_matrix=True)
assert len(match_pairs) == 5
assert dm.shape == (trackrun.size(subset), len(ref_set))
actual_dm = np.load(REF_DM)
np.testing.assert_almost_equal(actual_dm, dm)
Binary file added octant/tests/test_data/distance_matrix.npy
Binary file not shown.
274 changes: 274 additions & 0 deletions octant/tests/test_data/pmc_loc_time_ch4_20Mar-02Apr.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,274 @@
1 201303201142 9.093 76.719
1 201303201244 8.506 76.525
1 201303201323 7.698 76.400
1 201303201915 8.425 76.831
3 201303240104 7.370 75.174
3 201303240245 7.508 74.715
3 201303240425 8.972 74.014
3 201303240604 10.062 73.854
3 201303240921 12.381 72.541
3 201303240942 12.485 72.394
3 201303241059 14.077 72.270
3 201303241122 14.063 72.202
3 201303241239 15.068 71.885
3 201303241301 15.070 71.683
3 201303241933 17.915 70.122
4 201303250053 15.567 74.069
4 201303250235 16.842 73.852
5 201303250554 10.462 77.934
5 201303250910 9.725 77.670
5 201303250921 10.030 77.619
5 201303251049 9.321 77.544
5 201303251101 9.118 77.515
5 201303251229 8.635 76.724
5 201303251241 8.495 76.715
6 201303250910 9.780 77.037
6 201303250921 9.780 77.037
6 201303251049 9.233 76.917
6 201303251101 9.233 76.917
6 201303251229 8.575 76.772
6 201303251241 8.575 76.772
6 201303251912 6.580 75.968
7 201303250910 10.840 76.274
7 201303250921 11.009 76.249
7 201303251049 10.974 76.213
7 201303251101 10.871 76.173
7 201303251229 10.231 76.032
7 201303251241 10.231 76.032
8 201303251049 -2.838 71.689
8 201303251101 -2.507 71.704
8 201303251229 -1.174 71.797
8 201303251241 -0.984 71.788
8 201303251912 3.341 71.891
8 201303252052 4.923 71.754
9 201303251912 9.380 70.599
9 201303252052 11.055 70.637
9 201303260042 13.645 70.941
9 201303260224 15.150 71.030
9 201303260404 16.923 71.118
9 201303260543 18.060 71.265
9 201303260900 20.108 72.198
9 201303261038 22.110 72.638
9 201303261041 22.229 72.590
9 201303261218 23.420 72.970
9 201303261852 22.600 74.378
9 201303262031 22.801 74.714
10 201303260042 6.578 77.874
10 201303260224 5.441 77.496
10 201303260404 4.742 77.425
10 201303260543 3.879 77.072
11 201303260404 0.946 77.096
11 201303260543 0.731 76.622
12 201303260224 4.174 75.393
12 201303260543 4.842 74.270
12 201303260900 4.393 73.677
12 201303261038 4.466 73.277
12 201303261041 4.412 73.272
12 201303261218 4.621 72.462
12 201303261852 7.592 71.539
12 201303262031 9.187 70.960
12 201303270031 12.060 70.901
12 201303270213 13.648 71.111
12 201303270353 14.883 70.459
12 201303270533 16.100 70.659
12 201303270839 14.980 70.565
12 201303271020 15.370 70.183
12 201303271028 15.940 70.130
12 201303271200 17.431 70.101
12 201303271207 17.179 69.990
12 201303272010 20.723 70.064
13 201303261852 0.886 70.275
13 201303262031 2.475 69.657
13 201303270031 3.838 68.442
13 201303270213 5.542 67.947
13 201303270353 6.372 67.633
13 201303270533 7.377 67.235
14 201303261038 1.438 75.933
14 201303261041 1.438 75.933
14 201303261852 1.451 73.387
14 201303262031 1.007 72.500
14 201303270213 0.967 71.264
14 201303270353 0.367 70.344
14 201303271020 0.499 68.716
14 201303271207 0.295 68.393
14 201303271831 0.454 67.028
15 201303271028 7.116 73.758
15 201303271200 8.087 73.250
15 201303271207 8.348 73.290
15 201303271831 12.115 72.285
15 201303272010 13.432 71.978
15 201303280020 16.559 71.823
15 201303280202 17.171 71.648
15 201303280343 18.140 71.619
16 201303270031 17.886 73.118
16 201303270213 18.129 73.663
16 201303270533 16.837 73.499
16 201303270839 16.756 73.664
16 201303270849 17.225 73.682
16 201303271020 17.242 73.901
16 201303271028 17.242 73.901
16 201303271200 16.770 74.236
16 201303271207 16.657 74.215
16 201303271831 14.405 75.555
16 201303272010 13.708 75.930
16 201303280020 7.648 76.727
16 201303280202 5.248 77.006
16 201303280343 2.939 77.063
16 201303280522 -0.621 77.105
16 201303280959 -7.701 76.678
16 201303281017 -7.847 76.637
17 201303280522 18.348 73.117
17 201303280818 18.628 73.294
17 201303280959 19.499 73.302
17 201303281017 19.808 73.243
17 201303281139 19.908 73.296
17 201303281950 19.956 73.330
17 201303290151 17.325 74.240
17 201303290332 16.123 73.840
18 201303290151 21.935 73.002
18 201303290332 22.561 73.011
18 201303290512 23.077 72.983
19 201303290938 26.485 72.920
19 201303291258 28.628 73.127
19 201303291929 30.245 73.526
19 201303300140 29.838 73.954
19 201303300321 28.884 74.006
19 201303300501 29.096 73.886
19 201303300640 28.825 73.240
19 201303300917 29.314 73.113
19 201303300956 29.833 73.118
19 201303301058 30.667 73.030
19 201303301135 30.894 73.023
19 201303301237 31.029 72.919
19 201303301909 34.470 72.937
20 201303291258 6.968 71.669
20 201303291326 7.773 71.695
20 201303291929 12.422 70.825
20 201303292109 15.939 70.785
20 201303300140 17.648 69.776
21 201303300640 15.607 73.683
21 201303300917 15.360 73.182
21 201303300956 16.490 73.249
21 201303301058 16.247 73.155
21 201303301135 16.848 73.113
21 201303301237 17.136 72.990
21 201303301316 17.517 73.038
21 201303301909 18.754 72.795
21 201303302048 19.661 72.788
21 201303310129 20.081 72.899
21 201303310311 20.165 72.801
21 201303310450 19.880 72.810
21 201303310629 20.739 72.764
21 201303310856 19.965 72.712
21 201303311305 20.505 72.358
21 201303311848 23.583 72.371
21 201304010119 27.052 72.432
21 201304010300 27.559 72.510
22 201303300140 -8.981 69.669
22 201303300321 -8.104 69.334
22 201303300501 -7.907 69.434
22 201303300640 -7.253 69.425
22 201303300917 -7.159 69.371
22 201303300956 -5.816 69.224
22 201303301058 -5.754 69.218
22 201303301135 -5.899 69.244
22 201303301237 -5.826 69.038
22 201303301316 -5.915 69.094
23 201303300956 2.976 77.237
23 201303301058 3.453 76.780
24 201303301909 1.254 78.386
24 201303302048 1.258 78.056
25 201303310129 2.166 75.505
25 201303310311 3.145 75.051
25 201303310450 3.486 74.639
25 201303310629 4.435 74.135
25 201303310856 5.919 73.482
26 201303310129 7.258 75.785
26 201303310311 7.306 75.637
26 201303310450 7.382 75.576
26 201303310629 7.975 75.303
26 201303310856 8.093 75.145
26 201303310945 8.110 75.129
26 201303311037 8.180 75.068
26 201303311125 8.573 74.947
26 201303311217 8.894 74.887
26 201303311305 8.943 74.841
27 201303310311 -0.045 76.901
27 201303310450 0.516 76.572
27 201303310629 1.432 76.316
27 201303310856 1.185 75.716
27 201303310945 1.807 75.555
27 201303311037 2.416 75.392
28 201303310945 -1.579 76.187
28 201303311037 -0.965 76.026
28 201303311125 -0.750 75.838
28 201303311217 -0.316 75.605
28 201303311305 -0.031 75.408
28 201303311848 2.221 74.317
28 201303312027 3.420 74.101
28 201304010119 6.117 73.618
29 201304010119 -4.504 72.522
29 201304010300 -3.369 72.251
29 201304010440 -2.086 71.859
29 201304010619 -0.944 71.481
29 201304010935 1.954 70.567
29 201304011017 1.925 70.338
29 201304011114 2.809 69.977
29 201304011156 5.508 70.753
29 201304011828 12.272 70.433
30 201304010119 7.347 69.878
30 201304010300 8.299 70.242
30 201304010440 9.287 70.600
30 201304010619 9.490 70.966
30 201304010835 9.514 71.432
30 201304010935 10.756 71.368
30 201304011017 10.673 71.543
30 201304011114 10.995 71.667
30 201304011156 11.556 71.757
30 201304011254 10.551 71.632
31 201304010119 1.830 71.380
31 201304010440 3.683 71.407
31 201304010835 5.119 71.606
31 201304010935 5.477 71.425
31 201304011017 5.288 71.354
31 201304011114 5.732 71.335
31 201304011156 5.220 71.075
31 201304011828 12.355 70.455
31 201304012007 13.876 70.266
31 201304020108 15.486 70.215
31 201304020249 16.379 69.697
33 201304010300 9.580 69.057
33 201304010440 10.842 69.434
33 201304010619 12.277 69.975
33 201304010935 13.154 71.229
33 201304011017 13.389 71.260
33 201304011114 13.201 71.558
33 201304011156 12.933 71.574
33 201304011254 12.983 71.577
33 201304011828 15.248 72.164
34 201304010119 12.868 76.479
34 201304010300 13.897 76.331
34 201304010935 16.123 76.080
35 201304020108 11.528 76.131
35 201304020249 12.021 76.043
35 201304020429 12.532 76.004
35 201304020608 12.323 76.009
35 201304020814 12.754 75.982
35 201304020924 12.632 75.812
35 201304020956 12.568 75.809
35 201304021103 12.926 75.860
35 201304021136 13.005 75.766
35 201304021243 12.904 75.728
35 201304021946 13.425 75.574
35 201304022126 13.627 75.568
36 201304020108 33.836 72.824
36 201304020249 34.150 73.004
36 201304020429 35.136 73.168
36 201304020956 34.306 73.905
36 201304021103 33.900 74.020
36 201304021136 33.627 73.950
37 201304021103 29.412 73.034
37 201304021136 29.396 72.970
37 201304021243 29.927 72.910
38 201304021946 -10.973 71.574
38 201304022126 -10.540 71.261
2 changes: 1 addition & 1 deletion octant/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.0.12'
__version__ = '0.0.13'

0 comments on commit 5cba439

Please sign in to comment.