@@ -2100,10 +2100,12 @@ def compute_track_density(
21002100 """Compute tropical cyclone track density. Before using this function,
21012101 apply the same temporal resolution to all tracks by calling :py:meth:`equal_timestep` on
21022102 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`.
2103+ recommended to use a grid resolution higher tha 0.1°. Also note that the time step (in hours)
2104+ must be equal or smaller than your desired resolution (in degrees) divided by 1.1.
2105+ First, this function creates 2D bins of the specified resolution (e.g. 1° x 1°). Second,
2106+ since tracks are not lines but a series of points, it counts the number of points per bin. Lastly,
2107+ it returns the absolute count per bin. To plot the output of this function,
2108+ use :py:meth:`plot_track_density`.
21072109
21082110 Parameters:
21092111 ----------
@@ -2127,8 +2129,7 @@ def compute_track_density(
21272129 Returns:
21282130 -------
21292131 hist_count: np.ndarray
2130- 2D matrix containing the absolute count per grid cell of track point or the
2131- normalized number of track points, depending on the norm parameter.
2132+ 2D matrix containing the absolute count per grid cell of track point.
21322133 lat_bins: np.ndarray
21332134 latitude bins in which the point were counted
21342135 lon_bins: np.ndarray
@@ -2138,20 +2139,20 @@ def compute_track_density(
21382139 --------
21392140 >>> tc_tracks = TCTrack.from_ibtracs_netcdf("path_to_file")
21402141 >>> tc_tracks.equal_timestep(time_step_h = 1)
2141- >>> hist_count, _, _ = compute_track_density(tc_track = tc_tracks, res = 1 )
2142+ >>> hist_count, _, _ = compute_track_density(tc_track = tc_tracks, res = 2 )
21422143 >>> ax = plot_track_density(hist_count)
21432144
21442145 """
21452146
21462147 limit_ratio : float = (
2147- 1.12 * 1.1
2148- ) # record tc speed 112km/h -> 1.12 °/h + 10% margin
2148+ 1 * 1.1
2149+ ) # record tc speed 112km/h -> 1°/h + 10% margin = 1.1°/h
21492150 time_value : float = self .data [0 ].time_step [0 ].values .astype (float )
21502151
21512152 if time_value > (res / limit_ratio ):
21522153 warnings .warn (
21532154 "The time step is too big for the current resolution. For the desired resolution, \n "
2154- f"apply a time step of { res / limit_ratio } h."
2155+ f"apply a time step equal or lower than { res / limit_ratio } h."
21552156 )
21562157 elif res < 0.1 :
21572158 warnings .warn (
@@ -2251,7 +2252,9 @@ def plot_track_density(
22512252 hist : np .ndarray ,
22522253 axis = None ,
22532254 projection = ccrs .Mollweide (),
2254- add_features : dict = None ,
2255+ land : bool = True ,
2256+ coastline : bool = True ,
2257+ borders : bool = False ,
22552258 title : str = None ,
22562259 figsize = (12 , 6 ),
22572260 div_cmap = False ,
@@ -2275,9 +2278,12 @@ def plot_track_density(
22752278 Existing Cartopy axis.
22762279 projection: cartopy.crs, optional
22772280 Projection for the map.
2278- add_features: dict
2279- Dictionary of map features to add. Keys can be 'land', 'coastline', 'borders', and
2280- 'lakes'. Values are Booleans indicating whether to include each feature.
2281+ land: bool, Default True
2282+ If True it adds the land on the map
2283+ coastline: bool, Default True
2284+ If True it adds the coastline on the map
2285+ border: bool, Default False
2286+ If True it adds the borders on the map
22812287 title: str
22822288 Title of the plot.
22832289 figsize: tuple
@@ -2305,28 +2311,16 @@ def plot_track_density(
23052311 ... cbar_kwargs={'shrink': 0.8,
23062312 'label': 'Cyclone Density [n° tracks / km²]',
23072313 'pad': 0.1},
2308- ... add_features={
2309- ... 'land': True,
2310- ... 'coastline': True,
2311- ... 'borders': False,
2312- ... 'lakes': False
2313- ... },
2314+ ... land = True,
2315+ ... coastline = True,
2316+ ... borders = False,
23142317 ... title='My Tropical Cyclone Track Density Map',
23152318 ... figsize=(10, 5),
23162319 ... levels=20
23172320 ... )
23182321
23192322 """
23202323
2321- # Default features
2322- default_features = {
2323- "land" : True ,
2324- "coastline" : True ,
2325- "borders" : False ,
2326- "lakes" : False ,
2327- }
2328- add_features = add_features or default_features
2329-
23302324 # Sample data
23312325 lon = np .linspace (- 180 , 180 , hist .shape [1 ])
23322326 lat = np .linspace (- 90 , 90 , hist .shape [0 ])
@@ -2336,7 +2330,7 @@ def plot_track_density(
23362330 _ , axis = plt .subplots (figsize = figsize , subplot_kw = {"projection" : projection })
23372331
23382332 # Add requested features
2339- if add_features . get ( " land" , False ) :
2333+ if land :
23402334 land = cfeature .NaturalEarthFeature (
23412335 category = "physical" ,
23422336 name = "land" ,
@@ -2345,12 +2339,10 @@ def plot_track_density(
23452339 alpha = 0.6 ,
23462340 )
23472341 axis .add_feature (land )
2348- if add_features . get ( " coastline" , False ) :
2342+ if coastline :
23492343 axis .add_feature (cfeature .COASTLINE , linewidth = 0.5 )
2350- if add_features . get ( " borders" , False ) :
2344+ if borders :
23512345 axis .add_feature (cfeature .BORDERS , linestyle = ":" )
2352- if add_features .get ("lakes" , False ):
2353- axis .add_feature (cfeature .LAKES , alpha = 0.4 , edgecolor = "black" )
23542346
23552347 if div_cmap :
23562348 norm = mcolors .TwoSlopeNorm (
0 commit comments