Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def add_contour_layer(self, layer: DocBasicLayer, p: Presentation, overview_content: np.ndarray):
verts = overview_content[:, :2]
connects = overview_content[:, 2].astype(np.bool)
level_indexes = overview_content[:, 3]
level_indexes = level_indexes[~np.isnan(level_indexes)].astype(np.int)
levels = layer["contour_levels"]
cmap = self.document.find_colormap(p.colormap)
proj4_str = layer[Info.PROJ]
parent = self.proxy_nodes.get(proj4_str)
if parent is None:
parent = ContourGroupNode(parent=self.main_map)
parent.transform = PROJ4Transform(layer[Info.PROJ], inverse=True)
self.proxy_nodes[proj4_str] = parent
contour_visual = PrecomputedIsocurve(verts, connects, level_indexes,
levels=levels, color_lev=cmap,
clim=p.climits,
parent=parent,
name=str(layer[Info.UUID]))
contour_visual.transform *= STTransform(translate=(0, 0, -50.0))
self.image_elements[layer[Info.UUID]] = contour_visual
self.layer_set.add_layer(contour_visual)
self.on_view_change(None)
self.main_view.events.mouse_press.connect(self.on_mouse_press_region)
self.change_tool(Tool.PAN_ZOOM)
z_level_transform = MatrixTransform()
# near/far is backwards it seems:
camera_z_scale = 1e-6
z_level_transform.set_ortho(-1., 1., -1., 1., -100.0 * camera_z_scale, 100.0 * camera_z_scale)
# Head node of all visualizations, needed mostly to scale Z level
self.main_map_parent = scene.Node(name="HeadNode", parent=self.main_view.scene)
self.main_map_parent.transform = z_level_transform
# Head node of the map graph
proj_info = self.document.projection_info()
self.main_map = MainMap(name="MainMap", parent=self.main_map_parent)
self.main_map.transform = PROJ4Transform(proj_info['proj4_str'])
self.proxy_nodes = {}
self._borders_color_idx = 0
self.borders = NEShapefileLines(self.border_shapefile, double=True,
color=self._color_choices[self._borders_color_idx], parent=self.main_map)
self.borders.transform = STTransform(translate=(0, 0, 40))
self.conus_states = NEShapefileLines(self.conus_states_shapefile, double=True,
color=self._color_choices[self._borders_color_idx], parent=self.main_map)
self.conus_states.transform = STTransform(translate=(0, 0, 45))
self._latlon_grid_color_idx = 1
self.latlon_grid = self._init_latlon_grid_layer(color=self._color_choices[self._latlon_grid_color_idx])
self.latlon_grid.transform = STTransform(translate=(0, 0, 45))
self.create_test_image()
if self.glsl_map is None or self.glsl_imap is None:
raise ValueError("Spheroid transform for {} not implemented yet".format(proj_dict['proj']))
else:
# ellipsoid
self.glsl_map = proj_funcs[1]
self.glsl_imap = proj_funcs[3]
if self.glsl_map is None or self.glsl_imap is None:
raise ValueError("Ellipsoid transform for {} not implemented yet".format(proj_dict['proj']))
self.glsl_map = self.glsl_map.format(**proj_args)
self.glsl_imap = self.glsl_imap.format(**proj_args)
if self._proj4_inverse:
self.glsl_map, self.glsl_imap = self.glsl_imap, self.glsl_map
super(PROJ4Transform, self).__init__()
# Add common definitions and functions
for d in COMMON_DEFINITIONS + (pj_tsfn, pj_phi2, hypot):
self._shader_map._add_dep(d)
self._shader_imap._add_dep(d)
if proj_args['over']:
self._shader_map._add_dep(adjlon_func)
self._shader_imap._add_dep(adjlon_func)
# Add special handling of possible infinity lon/lat values
self._shader_map['pre'] = """
if (abs(pos.x) > 1e30 || abs(pos.y) > 1e30)
origin_y,
cell_size,
cell_size,
name="Test Image",
clim=(0., 1.),
gamma=1.,
interpolation='nearest',
method='tiled',
cmap=self.document.find_colormap('grays'),
double=False,
texture_shape=DEFAULT_TEXTURE_SHAPE,
wrap_lon=False,
parent=self.main_map,
projection=proj4_str,
)
image.transform = PROJ4Transform(proj4_str, inverse=True)
image.transform *= STTransform(translate=(0, 0, -50.0))
self._test_img = image
layer[Info.ORIGIN_Y],
layer[Info.CELL_WIDTH],
layer[Info.CELL_HEIGHT],
name=str(uuid),
clim=p.climits,
gamma=p.gamma,
interpolation='nearest',
method='tiled',
cmap=None,
double=False,
texture_shape=DEFAULT_TEXTURE_SHAPE,
wrap_lon=False,
parent=self.main_map,
projection=layer[Info.PROJ],
)
element.transform = PROJ4Transform(layer[Info.PROJ], inverse=True)
element.transform *= STTransform(translate=(0, 0, -50.0))
self.composite_element_dependencies[uuid] = dep_uuids
self.layer_set.add_layer(element)
if new_order:
self.layer_set.set_layer_order(new_order)
self.on_view_change(None)
element.determine_reference_points()
self.update()
return True
elif p.kind in [Kind.COMPOSITE, Kind.IMAGE]:
# algebraic layer
return self.add_basic_layer(new_order, uuid, p)
layer[Info.ORIGIN_Y],
layer[Info.CELL_WIDTH],
layer[Info.CELL_HEIGHT],
name=str(uuid),
clim=p.climits,
gamma=p.gamma,
interpolation='nearest',
method='tiled',
cmap=self.document.find_colormap(p.colormap),
double=False,
texture_shape=DEFAULT_TEXTURE_SHAPE,
wrap_lon=False,
parent=self.main_map,
projection=layer[Info.PROJ],
)
image.transform = PROJ4Transform(layer[Info.PROJ], inverse=True)
image.transform *= STTransform(translate=(0, 0, -50.0))
self.image_elements[uuid] = image
self.layer_set.add_layer(image)
image.determine_reference_points()
self.on_view_change(None)