Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"""user has clicked on a point probe; determine relative and absolute values for all document image layers
"""
# if the point probe was turned off then we don't want to have the equalizer
if not state:
self.didCalculateLayerEqualizerValues.emit({})
return
if uuids is None:
uuid_prezs = [(pinf.uuid, pinf) for pinf in self.current_layer_set]
else:
uuid_prezs = self.prez_for_uuids(uuids)
zult = {}
for uuid, pinf in uuid_prezs:
try:
lyr = self._layer_with_uuid[uuid]
if lyr[Info.KIND] in {Kind.IMAGE, Kind.COMPOSITE, Kind.CONTOUR}:
zult[uuid] = self._get_equalizer_values_image(lyr, pinf, xy_pos)
elif lyr[Info.KIND] == Kind.RGB:
zult[uuid] = self._get_equalizer_values_rgb(lyr, pinf, xy_pos)
except ValueError:
LOG.warning("Could not get equalizer values for {}".format(uuid))
zult[uuid] = (0, 0, 0)
self.didCalculateLayerEqualizerValues.emit(zult) # is picked up by layer list model to update display
# PUG states radiance at index [0,0] extends between coordinates [0,0] to [1,1] on a quadrille
# centers of pixels are therefore at +0.5, +0.5
# for a (e.g.) H x W image this means [H/2,W/2] coordinates are image center
# for now assume all scenes are even-dimensioned (e.g. 5424x5424)
# given that coordinates are evenly spaced in angular -> nadir-meters space,
# technically this should work with any two neighbor values
# d[Info.CELL_WIDTH] = x[midxi+1] - x[midxi]
# d[Info.CELL_HEIGHT] = y[midyi+1] - y[midyi]
cell_size = pug.cell_size
d[Info.CELL_HEIGHT], d[Info.CELL_WIDTH] = cell_size
shape = pug.shape
d[Info.SHAPE] = shape
generate_guidebook_metadata(d)
d[Info.FAMILY] = '{}:{}:{}:{:5.2f}µm'.format(Kind.IMAGE.name, 'geo', d[Info.STANDARD_NAME], d[
Info.CENTRAL_WAVELENGTH]) # kind:pointofreference:measurement:wavelength
d[Info.CATEGORY] = 'NOAA-PUG:{}:{}:{}'.format(d[Info.PLATFORM].name, d[Info.INSTRUMENT].name,
d[Info.SCENE]) # system:platform:instrument:target
d[Info.SERIAL] = d[Info.SCHED_TIME].strftime("%Y%m%dT%H%M%S")
LOG.debug(repr(d))
return d
def change_layer_image_kind_menu(self, menu, lbox, selected_uuids, *args):
current_kind = self.doc.prez_for_uuid(selected_uuids[0]).kind
kind_menu = QMenu("Change Image Kind", menu)
action_group = QActionGroup(menu, exclusive=True)
actions = {}
action_kinds = {}
def _change_layers_image_kind(action, action_kinds=action_kinds):
if not action.isChecked():
# can't uncheck an image kind
LOG.debug("Selected Kind action is not checked")
return
kind = action_kinds[action]
return self.doc.change_layers_image_kind(selected_uuids, kind)
for kind in [Kind.IMAGE, Kind.CONTOUR]:
action = action_group.addAction(QAction(kind.name, menu, checkable=True))
action_kinds[action] = kind
action.setChecked(kind == current_kind)
actions[action] = _change_layers_image_kind
kind_menu.addAction(action)
menu.addMenu(kind_menu)
return actions
def _product_overview_content(self, session, prod: Product = None, uuid: UUID = None,
kind: Kind = Kind.IMAGE) -> Content:
if prod is None and uuid is not None:
# Get Product object
try:
prod = session.query(Product).filter(Product.uuid_str == str(uuid)).one()
except NoResultFound:
LOG.error("No product with UUID {} found".format(uuid))
return None
contents = session.query(Content).filter(Content.product_id == prod.id).order_by(Content.lod).all()
contents = [c for c in contents if c.info.get(Info.KIND, Kind.IMAGE) == kind]
return None if 0 == len(contents) else contents[0]
def create_rgb(self, action=None, families=[]):
if len(families) == 0:
# get the layers to composite from current selection
uuids = list(self.layer_list_model.current_selected_uuids())
families = [self.doc[u][Info.FAMILY] for u in uuids]
if len(families) < 3: # pad with None
families = families + ([None] * (3 - len(families)))
# Don't use non-basic layers as starting points for the new composite
families = [f for f in families if
f is None or self.doc.family_info(f)[Info.KIND] in [Kind.IMAGE, Kind.COMPOSITE]]
layer = next(self.doc.create_rgb_composite(families[0],
families[1],
families[2]))
if layer is not None:
self.layer_list_model.select([layer.uuid])
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)
def get_content(self, dsi_or_uuid, lod=None, kind=Kind.IMAGE):
"""
By default, get the best-available (closest to native) np.ndarray-compatible view of the full dataset
:param dsi_or_uuid: existing datasetinfo dictionary, or its UUID
:param lod: desired level of detail to focus (0 for overview)
:return:
"""
if dsi_or_uuid is None:
return None
elif isinstance(dsi_or_uuid, UUID):
uuid = dsi_or_uuid
elif isinstance(dsi_or_uuid, str):
uuid = UUID(dsi_or_uuid)
else:
uuid = dsi_or_uuid[Info.UUID]
# prod = self._product_with_uuid(dsi_or_uuid)
# TODO: this causes a locking exception when run in a secondary thread.
def _product_native_content(self, session, prod: Product = None, uuid: UUID = None,
kind: Kind = Kind.IMAGE) -> Content:
# NOTE: This assumes the last Content object is the best resolution
# but it is untested
if prod is None and uuid is not None:
# Get Product object
try:
prod = session.query(Product).filter(Product.uuid_str == str(uuid)).one()
except NoResultFound:
LOG.error("No product with UUID {} found".format(uuid))
return None
contents = session.query(Content).filter(Content.product_id == prod.id).order_by(Content.lod.desc()).all()
contents = [c for c in contents if c.info.get(Info.KIND, Kind.IMAGE) == kind]
return None if 0 == len(contents) else contents[-1]