66import numpy as np
77from matplotlib .transforms import offset_copy
88
9- from ..tools import generate_monte_carlo_ellipses , import_optional_dependency , inverted_haversine , haversine
9+ from ..tools import (
10+ generate_monte_carlo_ellipses ,
11+ import_optional_dependency ,
12+ inverted_haversine ,
13+ haversine ,
14+ )
1015from .plot_helpers import show_or_save_plot
1116
1217
@@ -50,7 +55,7 @@ def _get_background_map(self, background, xlim, ylim):
5055 "contextily library is required for automatic map background. "
5156 "Install it via 'pip install contextily' or 'pip install rocketpy[monte-carlo]'. "
5257 "Plotting without background." ,
53- UserWarning
58+ UserWarning ,
5459 )
5560 return None , None
5661
@@ -113,11 +118,18 @@ def _get_background_map(self, background, xlim, ylim):
113118 dist = (x ** 2 + y ** 2 ) ** 0.5
114119 # Calculate bearing: 0 is North (Y), 90 is East (X)
115120 bearing = np .degrees (np .arctan2 (x , y ))
116- lat , lon = inverted_haversine (origin_lat , origin_lon , dist , bearing , earth_radius )
121+ lat , lon = inverted_haversine (
122+ origin_lat , origin_lon , dist , bearing , earth_radius
123+ )
117124 req_lats .append (lat )
118125 req_lons .append (lon )
119126
120- west , south , east , north = min (req_lons ), min (req_lats ), max (req_lons ), max (req_lats )
127+ west , south , east , north = (
128+ min (req_lons ),
129+ min (req_lats ),
130+ max (req_lons ),
131+ max (req_lats ),
132+ )
121133
122134 bg , mercator_extent = contextily .bounds2img (
123135 west , south , east , north , source = source_provider , ll = True
@@ -127,32 +139,52 @@ def _get_background_map(self, background, xlim, ylim):
127139 def mercator_to_wgs84 (x , y ):
128140 r_major = 6378137.0
129141 lon = x / r_major * 180.0 / math .pi
130- lat = (2 * math .atan (math .exp (y / r_major )) - math .pi / 2.0 ) * 180.0 / math .pi
142+ lat = (
143+ (2 * math .atan (math .exp (y / r_major )) - math .pi / 2.0 )
144+ * 180.0
145+ / math .pi
146+ )
131147 return lat , lon
132148
133149 # Convert corners of the fetched image
134- bg_lat_min , bg_lon_min = mercator_to_wgs84 (mercator_extent [0 ], mercator_extent [2 ]) # Bottom-Left
135- bg_lat_max , bg_lon_max = mercator_to_wgs84 (mercator_extent [1 ], mercator_extent [3 ]) # Top-Right
150+ bg_lat_min , bg_lon_min = mercator_to_wgs84 (
151+ mercator_extent [0 ], mercator_extent [2 ]
152+ ) # Bottom-Left
153+ bg_lat_max , bg_lon_max = mercator_to_wgs84 (
154+ mercator_extent [1 ], mercator_extent [3 ]
155+ ) # Top-Right
136156
137157 # Calculate X/Y meters relative to origin (lat0, lon0) using haversine
138158 # X = Distance along longitude (East-West)
139159 # Y = Distance along latitude (North-South)
140160
141161 # Calculate X min (Left)
142- x_min = haversine (origin_lat , origin_lon , origin_lat , bg_lon_min , earth_radius )
143- if bg_lon_min < origin_lon : x_min = - x_min
162+ x_min = haversine (
163+ origin_lat , origin_lon , origin_lat , bg_lon_min , earth_radius
164+ )
165+ if bg_lon_min < origin_lon :
166+ x_min = - x_min
144167
145168 # Calculate X max (Right)
146- x_max = haversine (origin_lat , origin_lon , origin_lat , bg_lon_max , earth_radius )
147- if bg_lon_max < origin_lon : x_max = - x_max
169+ x_max = haversine (
170+ origin_lat , origin_lon , origin_lat , bg_lon_max , earth_radius
171+ )
172+ if bg_lon_max < origin_lon :
173+ x_max = - x_max
148174
149175 # Calculate Y min (Bottom)
150- y_min = haversine (origin_lat , origin_lon , bg_lat_min , origin_lon , earth_radius )
151- if bg_lat_min < origin_lat : y_min = - y_min
176+ y_min = haversine (
177+ origin_lat , origin_lon , bg_lat_min , origin_lon , earth_radius
178+ )
179+ if bg_lat_min < origin_lat :
180+ y_min = - y_min
152181
153182 # Calculate Y max (Top)
154- y_max = haversine (origin_lat , origin_lon , bg_lat_max , origin_lon , earth_radius )
155- if bg_lat_max < origin_lat : y_max = - y_max
183+ y_max = haversine (
184+ origin_lat , origin_lon , bg_lat_max , origin_lon , earth_radius
185+ )
186+ if bg_lat_max < origin_lat :
187+ y_max = - y_max
156188
157189 return bg , [x_min , x_max , y_min , y_max ]
158190
@@ -216,7 +248,7 @@ def ellipses(
216248 "The image file was not found. Please check the path."
217249 ) from e
218250
219- bg , local_extent = None , None
251+ bg , local_extent = None , None
220252 if image is None and background is not None :
221253 bg , local_extent = self ._get_background_map (background , xlim , ylim )
222254
@@ -311,19 +343,14 @@ def ellipses(
311343 )
312344
313345 elif bg is not None and local_extent is not None :
314- plt .imshow (
315- bg ,
316- extent = local_extent ,
317- zorder = 0 ,
318- interpolation = "bilinear"
319- )
346+ plt .imshow (bg , extent = local_extent , zorder = 0 , interpolation = "bilinear" )
320347
321348 plt .axhline (0 , color = "black" , linewidth = 0.5 )
322349 plt .axvline (0 , color = "black" , linewidth = 0.5 )
323350 plt .xlim (* xlim )
324351 plt .ylim (* ylim )
325352 # Set equal aspect ratio to ensure consistent display regardless of background
326- ax .set_aspect (' equal' )
353+ ax .set_aspect (" equal" )
327354
328355 if save :
329356 plt .savefig (
@@ -511,8 +538,7 @@ def ellipses_comparison(
511538 "The image file was not found. Please check the path."
512539 ) from e
513540
514-
515- bg ,local_extent = None , None
541+ bg , local_extent = None , None
516542 if image is None and background is not None :
517543 bg , local_extent = self ._get_background_map (background , xlim , ylim )
518544
@@ -637,18 +663,13 @@ def ellipses_comparison(
637663 ],
638664 )
639665 elif bg is not None and local_extent is not None :
640- plt .imshow (
641- bg ,
642- extent = local_extent ,
643- zorder = 0 ,
644- interpolation = "bilinear"
645- )
666+ plt .imshow (bg , extent = local_extent , zorder = 0 , interpolation = "bilinear" )
646667
647668 plt .axhline (0 , color = "black" , linewidth = 0.5 )
648669 plt .axvline (0 , color = "black" , linewidth = 0.5 )
649670 plt .xlim (* xlim )
650671 plt .ylim (* ylim )
651- plt .aspect (' equal' )
672+ plt .aspect (" equal" )
652673
653674 if save :
654675 plt .savefig (
0 commit comments