MCPcopy Create free account
hub / github.com/plotly/plotly.py / _compute_wgs84_hexbin

Function _compute_wgs84_hexbin

plotly/figure_factory/_hexbin_map.py:226–302  ·  view source on GitHub ↗

Computes the lat-lon aggregation at hexagonal bin level. Latitude and longitude need to be projected to WGS84 before aggregating in order to display regular hexagons on the map. Parameters ---------- lat : np.ndarray Array of latitudes (shape N) lon : np.ndarray

(
    lat=None,
    lon=None,
    lat_range=None,
    lon_range=None,
    color=None,
    nx=None,
    agg_func=None,
    min_count=None,
    native_namespace=None,
)

Source from the content-addressed store, hash-verified

224
225
226def _compute_wgs84_hexbin(
227 lat=None,
228 lon=None,
229 lat_range=None,
230 lon_range=None,
231 color=None,
232 nx=None,
233 agg_func=None,
234 min_count=None,
235 native_namespace=None,
236):
237 """
238 Computes the lat-lon aggregation at hexagonal bin level.
239 Latitude and longitude need to be projected to WGS84 before aggregating
240 in order to display regular hexagons on the map.
241
242 Parameters
243 ----------
244 lat : np.ndarray
245 Array of latitudes (shape N)
246 lon : np.ndarray
247 Array of longitudes (shape N)
248 lat_range : np.ndarray
249 Min and max latitudes (shape 2)
250 lon_range : np.ndarray
251 Min and max longitudes (shape 2)
252 color : np.ndarray
253 Metric to aggregate at hexagon level (shape N)
254 nx : int
255 Number of hexagons horizontally
256 agg_func : function
257 Numpy compatible aggregator, this function must take a one-dimensional
258 np.ndarray as input and output a scalar
259 min_count : int
260 Minimum number of points in the hexagon for the hexagon to be displayed
261
262 Returns
263 -------
264 np.ndarray
265 Lat coordinates of each hexagon (shape M x 6)
266 np.ndarray
267 Lon coordinates of each hexagon (shape M x 6)
268 nw.Series
269 Unique id for each hexagon, to be used in the geojson data (shape M)
270 np.ndarray
271 Aggregated value in each hexagon (shape M)
272
273 """
274 # Project to WGS 84
275 x, y = _project_latlon_to_wgs84(lat, lon)
276
277 if lat_range is None:
278 lat_range = np.array([lat.min(), lat.max()])
279 if lon_range is None:
280 lon_range = np.array([lon.min(), lon.max()])
281
282 x_range, y_range = _project_latlon_to_wgs84(lat_range, lon_range)
283

Callers 1

create_hexbin_mapFunction · 0.85

Calls 5

_project_latlon_to_wgs84Function · 0.85
_compute_hexbinFunction · 0.85
_project_wgs84_to_latlonFunction · 0.85
arrayMethod · 0.45
minMethod · 0.45

Tested by

no test coverage detected