Skip to content

Commit 231fc65

Browse files
committed
house cleaning :)
1 parent a5fdbe8 commit 231fc65

File tree

4 files changed

+15
-70
lines changed

4 files changed

+15
-70
lines changed

tests/integration/test_integration.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import contextlib
2+
import os
13
import unittest
24
import warnings
35
from os import getcwd
@@ -6,8 +8,8 @@
68

79
import numpy as np
810
import xarray as xr
9-
from parameterized import parameterized
1011
from numpy.testing import assert_allclose, assert_raises
12+
from parameterized import parameterized
1113

1214
from xmca.xarray import xMCA
1315

@@ -16,6 +18,9 @@ class TestIntegration(unittest.TestCase):
1618

1719
@classmethod
1820
def setUpClass(self):
21+
# catch deprecation warnings from cartopy
22+
warnings.simplefilter('ignore', category=DeprecationWarning)
23+
1924
# Load test data
2025
self.path = 'tests/integration/fixtures'
2126
# ignore some deprecation warnings of xarray
@@ -401,7 +406,9 @@ def test_summary(self):
401406
right = self.B
402407
model = xMCA(left, right)
403408
model.solve()
404-
_ = model.summary()
409+
410+
with open(os.devnull, "w") as f, contextlib.redirect_stdout(f):
411+
model.summary()
405412

406413
@classmethod
407414
def tearDownClass(self):

xmca/array.py

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import matplotlib.pyplot as plt
1414
import numpy as np
1515
import yaml
16-
from numpy.polynomial.polynomial import polyfit
1716
from scipy.signal import hilbert
1817
from statsmodels.tsa.forecasting.theta import ThetaModel
1918
from tqdm import tqdm
@@ -216,30 +215,6 @@ def _get_method_id(self):
216215
id = 'mca'
217216
return id
218217

219-
def _get_complex_id(self):
220-
id = int(self._analysis['is_complex'])
221-
return 'c{:}'.format(id)
222-
223-
def _get_rotation_id(self):
224-
if self._analysis['is_rotated']:
225-
id = self._analysis['n_rot']
226-
else:
227-
id = 0
228-
return 'r{:02}'.format(id)
229-
230-
def _get_power_id(self):
231-
id = self._analysis['power']
232-
return 'p{:02}'.format(id)
233-
234-
def _get_analysis_id(self):
235-
method = self._get_method_id()
236-
hilbert = self._get_complex_id()
237-
rotation = self._get_rotation_id()
238-
power = self._get_power_id()
239-
240-
analysis = '_'.join([method, hilbert, rotation, power])
241-
return analysis
242-
243218
def _get_analysis_path(self, path=None):
244219
if path is None:
245220
name_folder = '_'.join(self._field_names.values())
@@ -1124,7 +1099,6 @@ def predict(
11241099

11251100
V = self._get_V(original=True)
11261101
fields_mean = self._field_means
1127-
fields_std = self._field_stds
11281102

11291103
sqrt_svals = np.sqrt(self._get_svals())
11301104
norm = self._get_norm()
@@ -1414,7 +1388,6 @@ def _create_info_file(self, path):
14141388
'This file contains information neccessary to load stored analysis'
14151389
'data from xmca module.')
14161390

1417-
# path_output = os.path.join(path, self._get_analysis_id())
14181391
path_output = os.path.join(path, 'info.xmca')
14191392

14201393
file = open(path_output, 'w+')
@@ -1440,7 +1413,6 @@ def _create_info_file(self, path):
14401413
file.close()
14411414

14421415
def _get_file_names(self, format):
1443-
# base_name = self._get_analysis_id()
14441416

14451417
fields = {}
14461418
eofs = {}

xmca/tools/array.py

Lines changed: 5 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,14 @@
22
# -*- coding: utf-8 -*-
33
''' Collection of tools for numpy.array modifications. '''
44

5-
import textwrap
65
import warnings
76

87
import numpy as np
98

9+
1010
# =============================================================================
1111
# Tools
1212
# =============================================================================
13-
14-
def arrs_are_equal(arr1 ,arr2):
15-
''' True if arrays are the same. Also works for np.nan entries.'''
16-
if arr1.shape == arr2.shape:
17-
return ((np.isnan(arr1) & np.isnan(arr2)) | (arr1 == arr2)).all()
18-
else:
19-
return False
20-
21-
22-
def is_arr(data):
23-
if (isinstance(data,np.ndarray)):
24-
return True
25-
else:
26-
raise TypeError('Data needs to be np.ndarray.')
27-
28-
29-
def check_time_dims(arr1, arr2):
30-
if (arr1.shape[0] == arr2.shape[0]):
31-
pass
32-
else:
33-
raise ValueError('Both input fields need to have same time dimensions.')
34-
35-
3613
def remove_mean(arr):
3714
'''Remove the mean of an array along the first dimension.
3815
@@ -45,7 +22,7 @@ def remove_mean(arr):
4522
return arr - arr.mean(axis=0)
4623

4724

48-
def get_nan_cols(arr):
25+
def get_nan_cols(arr: np.ndarray) -> np.ndarray:
4926
'''Get NaN columns from an array.
5027
5128
Parameters
@@ -64,7 +41,7 @@ def get_nan_cols(arr):
6441
return nan_index
6542

6643

67-
def remove_nan_cols(arr):
44+
def remove_nan_cols(arr: np.ndarray) -> np.ndarray:
6845
'''Remove NaN columns in array.
6946
7047
Parameters
@@ -88,19 +65,8 @@ def has_nan_time_steps(array):
8865
''' Checks if an array has NaN time steps.
8966
9067
Time is assumed to be on axis=0. The array is then reshaped to be 2D with
91-
time along axis 0 and variables along axis 1. A NaN time step is a row which
92-
contain NaN only.
68+
time along axis 0 and variables along axis 1. A NaN time step is a row
69+
which contain NaN only.
9370
'''
9471

9572
return (np.isnan(array).all(axis=tuple(range(1, array.ndim))).any())
96-
97-
98-
def is_not_empty(arr):
99-
if (arr.size > 0):
100-
pass
101-
else:
102-
raise ValueError('Input field is empty or contains NaN only.')
103-
104-
105-
def norm_to_1(arr, axis):
106-
return arr / np.nanmax(abs(arr), axis=axis)

xmca/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '1.0.3'
1+
__version__ = '1.0.4'

0 commit comments

Comments
 (0)