Skip to content

Commit

Permalink
Merge 23155f9 into 80e8b2a
Browse files Browse the repository at this point in the history
  • Loading branch information
JoranAngevaare committed Aug 9, 2023
2 parents 80e8b2a + 23155f9 commit 4ea90b1
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 19 deletions.
10 changes: 0 additions & 10 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,5 @@
# Regexes for lines to exclude from consideration
exclude_lines =
if __name__ == .__main__.:
raise
print
warn
plt.show()
message =
log.warning
get_logger().warning
log.error
get_logger().error


ignore_errors = True
12 changes: 7 additions & 5 deletions optim_esm_tools/analyze/clustering.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def build_clusters(
db_fit = DBSCAN(eps=max_distance_km / 6371.0, **cluster_opts).fit(
X=coordinates_rad, sample_weight=weights
)
except ValueError as e:
except ValueError as e: # pragma: no cover
raise ValueError(
f'With {coordinates_rad.shape} and {getattr(weights, "shape", None)} {coordinates_rad}, {weights}'
) from e
Expand Down Expand Up @@ -181,7 +181,7 @@ def _check_input(data, lat_coord, lon_coord):
# In an older version, this would have been the default.
lat, lon = lat_coord, lon_coord

if data.shape != lon.shape or data.shape != lat.shape:
if data.shape != lon.shape or data.shape != lat.shape: # pragma: no cover
message = f'Wrong input {data.shape} != {lon.shape, lat.shape}'
raise ValueError(message)
return lat, lon
Expand All @@ -192,7 +192,9 @@ def _build_cluster_with_kw(lat, lon, show_tqdm=False, **cluster_kw):
masks = []
clusters = [np.rad2deg(cluster) for cluster in build_clusters(**cluster_kw)]
if lat.shape != lon.shape:
raise ValueError(f'Got inconsistent input {lat.shape} != {lon.shape}')
raise ValueError(
f'Got inconsistent input {lat.shape} != {lon.shape}'
) # pragma: no cover
for cluster in clusters:
mask = np.zeros(lat.shape, np.bool_)
for coord_lat, coord_lon in tqdm(
Expand Down Expand Up @@ -273,7 +275,7 @@ def _calculate_distance_map(lat, lon):
continue
alt_coord = (lat[alt_lat], lon[alt_lon])
if alt_coord == current:
continue
raise ValueError('How can this happen?') # pragma: no cover
neighbors[i] = _distance_bf_coord(*current, *alt_coord)
distances[lat_i][lon_i] = np.max(neighbors)
return distances
Expand All @@ -286,7 +288,7 @@ def _distance(coords, force_math=False):
from geopy.distance import geodesic

return geodesic(*coords).km
except (ImportError, ModuleNotFoundError):
except (ImportError, ModuleNotFoundError): # pragma: no cover
pass
if len(coords) != 4:
coords = [c for cc in coords for c in cc]
Expand Down
10 changes: 6 additions & 4 deletions optim_esm_tools/analyze/cmip_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ def add_conditions_to_ds(
if len(set(desc := (c.short_description for c in calculate_conditions))) != len(
calculate_conditions
):
raise ValueError(f'One or more non unique descriptions {desc}')
raise ValueError(
f'One or more non unique descriptions {desc}'
) # pragma: no cover
if condition_kwargs is None:
condition_kwargs = dict()

Expand Down Expand Up @@ -117,7 +119,7 @@ def read_ds(
)

if not isinstance(variable_of_interest, str):
raise ValueError('Only single vars supported')
raise ValueError('Only single vars supported') # pragma: no cover
if kwargs:
log.error(f'Not really advised yet to call with {kwargs}')
_cache = False
Expand All @@ -137,11 +139,11 @@ def read_ds(
if os.path.exists(res_file) and _cache:
return oet.analyze.io.load_glob(res_file)

if not os.path.exists(data_path):
if not os.path.exists(data_path): # pragma: no cover
message = f'No dataset at {data_path}'
if strict:
raise FileNotFoundError(message)
warn(message)
log.warning(message)
return None

if pre_process:
Expand Down
5 changes: 5 additions & 0 deletions test/test_clustering.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ def test_geopy_alternative():
clustering._distance(coords),
rtol=0.1,
)
assert np.isclose(
clustering._distance_bf_coord(*flat_coord),
clustering._distance(coords, force_math=True),
rtol=0.1,
)


def test_infer_step_size():
Expand Down
8 changes: 8 additions & 0 deletions test/test_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ def test_map_maker_time_series(self, **kw):
def test_map_maker_time_series_only_running_mean(self):
self.test_map_maker_time_series(only_rm=True)

def read_w_no_cache(self):
oet.read_ds(
os.path.split(self.ayear_file)[0],
_file_name=self.name_merged,
apply_transform=False,
pre_process=False,
)

def test_date_out_of_range(self):
with self.assertRaises(oet.analyze.pre_process.NoDataInTimeRangeError):
oet.read_ds(
Expand Down

0 comments on commit 4ea90b1

Please sign in to comment.