Skip to content

Commit f164d41

Browse files
cosmetics
1 parent 3f799c5 commit f164d41

File tree

2 files changed

+25
-29
lines changed

2 files changed

+25
-29
lines changed

climada/hazard/tc_tracks.py

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import re
2929
import shutil
3030
import warnings
31-
from operator import itemgetter
3231
from pathlib import Path
3332
from typing import List, Optional
3433

@@ -347,7 +346,8 @@ def subset_year(
347346
Raises:
348347
-------
349348
ValueError
350-
- If there's a mismatch between `start_*` and `end_*` values (e.g., one is set to `True` while the other is `False`).
349+
- If there's a mismatch between `start_*` and `end_*` values (e.g., one is set to
350+
`True` while the other is `False`).
351351
- If no tracks are found within the specified date range.
352352
- If `start_date` or `end_date` are incorrectly ordered (start > end).
353353
@@ -611,7 +611,7 @@ def from_ibtracs_netcdf(
611611
"""
612612
if correct_pres:
613613
LOGGER.warning(
614-
"`correct_pres` is deprecated. " "Use `estimate_missing` instead."
614+
"`correct_pres` is deprecated. Use `estimate_missing` instead."
615615
)
616616
estimate_missing = True
617617
if estimate_missing and not rescale_windspeeds:
@@ -662,7 +662,6 @@ def from_ibtracs_netcdf(
662662
", ..." if len(invalid_sids) > 5 else ".",
663663
)
664664
)
665-
storm_id = list(np.array(storm_id)[~invalid_mask])
666665
storm_id_encoded = [i.encode() for i in storm_id]
667666
non_existing_mask = ~np.isin(storm_id_encoded, ibtracs_ds.sid.values)
668667
if np.count_nonzero(non_existing_mask) > 0:
@@ -674,9 +673,6 @@ def from_ibtracs_netcdf(
674673
", ..." if len(non_existing_sids) > 5 else ".",
675674
)
676675
)
677-
storm_id_encoded = list(
678-
np.array(storm_id_encoded)[~non_existing_mask]
679-
)
680676
match &= ibtracs_ds.sid.isin(storm_id_encoded)
681677
if year_range is not None:
682678
years = ibtracs_ds.sid.str.slice(0, 4).astype(int)
@@ -688,9 +684,9 @@ def from_ibtracs_netcdf(
688684
if np.count_nonzero(match) == 0:
689685
LOGGER.info("No tracks in basin %s.", basin)
690686
if genesis_basin is not None:
691-
# Here, we only filter for the basin at *any* eye position. We will filter again later
692-
# for the basin of the *first* eye position, but only after restricting to the valid
693-
# time steps in the data.
687+
# Here, we only filter for the basin at *any* eye position. We will filter again
688+
# later for the basin of the *first* eye position, but only after restricting to
689+
# the valid time steps in the data.
694690
match &= (ibtracs_ds.basin == genesis_basin.encode()).any(
695691
dim="date_time"
696692
)
@@ -753,8 +749,9 @@ def from_ibtracs_netcdf(
753749
)
754750

755751
if tc_var == "lon":
756-
# Most IBTrACS longitudes are either normalized to [-180, 180] or to [0, 360], but
757-
# some aren't normalized at all, so we have to make sure that the values are okay:
752+
# Most IBTrACS longitudes are either normalized to [-180, 180] or to [0, 360],
753+
# but some aren't normalized at all, so we have to make sure that the values
754+
# are okay:
758755
lons = ibtracs_ds[tc_var].values.copy()
759756
lon_valid_mask = np.isfinite(lons)
760757
lons[lon_valid_mask] = u_coord.lon_normalize(
@@ -972,8 +969,8 @@ def from_ibtracs_netcdf(
972969
] + additional_variables:
973970
values = track_ds[varname].data
974971
if track_ds[varname].dtype.kind == "S":
975-
# This converts the `bytes` (dtype "|S*") in IBTrACS to the more common `str`
976-
# objects (dtype "<U*") that we use in CLIMADA.
972+
# This converts the `bytes` (dtype "|S*") in IBTrACS to the more common
973+
# `str` objects (dtype "<U*") that we use in CLIMADA.
977974
values = values.astype(str)
978975
if values.ndim == 0:
979976
attrs[varname] = values.item()
@@ -1300,8 +1297,8 @@ def from_simulations_storm(cls, path, years=None):
13001297
>>> # or, alternatively,
13011298
>>> years = [int(tr.attrs['sid'].split("-")[-2]) for tr in tc_tracks.data]
13021299
1303-
If a windfield is generated from these tracks using the method ``TropCylcone.from_tracks()``,
1304-
the following should be considered:
1300+
If a windfield is generated from these tracks using the method
1301+
``TropCylcone.from_tracks()``, the following should be considered:
13051302
13061303
1. The frequencies will be set to ``1`` for each storm. Thus, in order to compute annual
13071304
values, the frequencies of the TropCylone should be changed to ``1/number of years``.
@@ -2048,7 +2045,7 @@ def _one_interp_data(track, time_step_h, land_geom=None):
20482045
return track
20492046
if track["time"].size < 2:
20502047
LOGGER.warning(
2051-
"Track interpolation not done. " "Not enough elements for %s",
2048+
"Track interpolation not done. Not enough elements for %s",
20522049
track.name,
20532050
)
20542051
track_int = track
@@ -2101,12 +2098,12 @@ def compute_track_density(
21012098
wind_max: float = None,
21022099
) -> tuple[np.ndarray, np.ndarray, np.ndarray]:
21032100
"""Compute tropical cyclone track density. Before using this function,
2104-
apply the same temporal resolution to all tracks by calling :py:meth:`equal_timestep` on the
2105-
TCTrack object. Due to the computational cost of the this function, it is not recommended to
2106-
use a grid resolution higher tha 0.1°. First, this function creates 2D bins of the specified
2107-
resolution (e.g. 1° x 1°). Second, since tracks are not lines but a series of points, it counts
2108-
the number of points per bin. Lastly, it returns the absolute count per bin.
2109-
To plot the output of this function use :py:meth:`plot_track_density`.
2101+
apply the same temporal resolution to all tracks by calling :py:meth:`equal_timestep` on
2102+
the TCTrack object. Due to the computational cost of the this function, it is not
2103+
recommended to use a grid resolution higher tha 0.1°. First, this function creates 2D bins
2104+
of the specified resolution (e.g. 1° x 1°). Second, since tracks are not lines but a series
2105+
of points, it counts the number of points per bin. Lastly, it returns the absolute count
2106+
per bin. To plot the output of this function use :py:meth:`plot_track_density`.
21102107
21112108
Parameters:
21122109
----------
@@ -2130,8 +2127,8 @@ def compute_track_density(
21302127
Returns:
21312128
-------
21322129
hist_count: np.ndarray
2133-
2D matrix containing the the absolute count per grid cell of track point or the normalized
2134-
number of track points, depending on the norm parameter.
2130+
2D matrix containing the the absolute count per grid cell of track point or the
2131+
normalized number of track points, depending on the norm parameter.
21352132
lat_bins: np.ndarray
21362133
latitude bins in which the point were counted
21372134
lon_bins: np.ndarray
@@ -2399,8 +2396,8 @@ def _raise_if_legacy_or_unknown_hdf5_format(file_name):
23992396
# The legacy format only has data in the subgroups, not in the root.
24002397
# => This cannot be the legacy file format!
24012398
return
2402-
# After this line, it is sure that the format is not supported (since there is no data in the
2403-
# root group). Before raising an exception, we double-check if it is the legacy format.
2399+
# After this line, it is sure that the format is not supported (since there is no data in
2400+
# the root group). Before raising an exception, we double-check if it is the legacy format.
24042401
try:
24052402
# Check if the file has groups 'track{i}' by trying to access the first group.
24062403
with xr.open_dataset(file_name, group="track0") as ds_track:

climada/util/coordinates.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@
4646
import shapely.vectorized
4747
import shapely.wkt
4848
from cartopy.io import shapereader
49-
from pyproj import Geod
50-
from shapely.geometry import MultiPolygon, Point, Polygon, box
49+
from shapely.geometry import MultiPolygon, Point, box
5150
from sklearn.neighbors import BallTree
5251

5352
import climada.util.hdf5_handler as u_hdf5

0 commit comments

Comments
 (0)