add options and postpone imports to massively reduce memory usage
This commit is contained in:
parent
0e5b10b586
commit
d7f175f7ef
12 changed files with 89 additions and 61 deletions
|
@ -11,7 +11,6 @@ from django.urls import reverse
|
|||
from django.utils.functional import cached_property
|
||||
from django.utils.text import format_lazy
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from scipy.sparse.csgraph._shortest_path import dijkstra
|
||||
from shapely import prepared
|
||||
from shapely.affinity import scale
|
||||
from shapely.geometry import JOIN_STYLE, LineString, MultiPolygon
|
||||
|
@ -352,6 +351,7 @@ class AltitudeArea(LevelGeometryMixin, models.Model):
|
|||
|
||||
repeat = True
|
||||
|
||||
from scipy.sparse.csgraph._shortest_path import dijkstra
|
||||
while repeat:
|
||||
repeat = False
|
||||
# noinspection PyTupleAssignmentBalance
|
||||
|
|
|
@ -14,7 +14,6 @@ from shapely.ops import unary_union
|
|||
from c3nav.mapdata.render.geometry.mesh import Mesh
|
||||
from c3nav.mapdata.utils.geometry import assert_multipolygon
|
||||
from c3nav.mapdata.utils.mesh import triangulate_polygon
|
||||
from c3nav.mapdata.utils.mpl import shapely_to_mpl
|
||||
|
||||
|
||||
def hybrid_union(geoms):
|
||||
|
@ -57,6 +56,7 @@ class HybridGeometry:
|
|||
"""
|
||||
if isinstance(geom, (LineString, MultiLineString)):
|
||||
return HybridGeometry(geom, ())
|
||||
from c3nav.mapdata.utils.mpl import shapely_to_mpl # moved in here to save memory
|
||||
faces = tuple(
|
||||
set(np.argwhere(shapely_to_mpl(subgeom).contains_points(face_centers)).flatten())
|
||||
for subgeom in assert_multipolygon(geom)
|
||||
|
|
|
@ -4,7 +4,6 @@ from functools import reduce
|
|||
from itertools import chain
|
||||
|
||||
import numpy as np
|
||||
from scipy.interpolate import NearestNDInterpolator
|
||||
from shapely import prepared
|
||||
from shapely.geometry import GeometryCollection
|
||||
from shapely.ops import unary_union
|
||||
|
@ -309,6 +308,8 @@ class LevelGeometries:
|
|||
vertex_values[i_vertices] = value_func(item, i_vertices)
|
||||
vertex_value_mask[i_vertices] = True
|
||||
|
||||
from scipy.interpolate import NearestNDInterpolator # moved in here to save memory
|
||||
|
||||
if np.any(vertex_value_mask) and not np.all(vertex_value_mask):
|
||||
interpolate = NearestNDInterpolator(self.vertices[vertex_value_mask],
|
||||
vertex_values[vertex_value_mask])
|
||||
|
|
|
@ -7,7 +7,6 @@ from typing import Optional
|
|||
|
||||
import numpy as np
|
||||
from django.conf import settings
|
||||
from scipy.interpolate import NearestNDInterpolator
|
||||
from shapely import Geometry, MultiPolygon, prepared
|
||||
from shapely.geometry import GeometryCollection
|
||||
from shapely.ops import unary_union
|
||||
|
@ -68,6 +67,8 @@ class LevelRenderData:
|
|||
# todo: we should check that levels on top come before their levels as they should
|
||||
|
||||
themes = [None, *Theme.objects.values_list('pk', flat=True)]
|
||||
from scipy.interpolate import NearestNDInterpolator # moved in here to save memory
|
||||
|
||||
from c3nav.mapdata.render.theme import ColorManager
|
||||
|
||||
for theme in themes:
|
||||
|
|
|
@ -3,11 +3,8 @@ from collections import deque, namedtuple
|
|||
from itertools import chain
|
||||
from typing import List, Sequence, Union
|
||||
|
||||
import matplotlib.pyplot as plt
|
||||
from django.core import checks
|
||||
from django.utils.functional import cached_property
|
||||
from matplotlib.patches import PathPatch
|
||||
from matplotlib.path import Path
|
||||
from shapely import prepared, speedups
|
||||
from shapely.geometry import GeometryCollection, LinearRing, LineString, MultiLineString, MultiPolygon, Point, Polygon
|
||||
from shapely.geometry import mapping as shapely_mapping
|
||||
|
@ -120,6 +117,11 @@ def good_representative_point(geometry):
|
|||
|
||||
|
||||
def plot_geometry(geom, title=None, bounds=None):
|
||||
# these imports live here so they are only imported when needed
|
||||
import matplotlib.pyplot as plt
|
||||
from matplotlib.patches import PathPatch
|
||||
from matplotlib.path import Path
|
||||
|
||||
fig = plt.figure()
|
||||
axes = fig.add_subplot(111)
|
||||
if bounds is None:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue