How to use uwsift - 10 common examples

To help you get started, we’ve selected a few uwsift examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ssec / sift / uwsift / control / layer_tree.py View on Github external
def composite_layer_menu(self, menu, lbox: QTreeView, selected_uuids: list, *args):
        """
        provide common options for RGB or other composite layers, eventually with option to go to a compositing dialog

        """
        actions = {}
        requests = {}
        if len(selected_uuids) > 3 or \
                any(self.doc[u][Info.KIND] not in [Kind.IMAGE, Kind.COMPOSITE] for u in selected_uuids):
            LOG.warning('Need 3 image layers to create a composite')
            return {}

        def _make_rgb_composite(action, requests=requests):
            request = requests.get(action, None)
            if request is not None:
                LOG.debug('RGB creation using {0!r:s}'.format(request))
                self.didRequestRGBCreation.emit(request)

        rgb_menu = QMenu("Create RGB From Selections...", menu)
        for rgb in sorted(set(x[:len(selected_uuids)] for x in ['RGB', 'RBG', 'GRB', 'GBR', 'BRG', 'BGR']),
                          reverse=True):
            # Only include the number of channels selected
            rgb = rgb[:len(selected_uuids)]
            action = rgb_menu.addAction(rgb)
            request = dict((channel.lower(), uuid) for (channel, uuid) in zip(rgb, selected_uuids))
github ssec / sift / uwsift / model / document.py View on Github external
def _unit_format_func(layer, units):
    units = unit_symbol(units)

    if layer[Info.STANDARD_NAME] in ('toa_brightness_temperature', 'brightness_temperature'):
        # BT data limits, Kelvin to degC
        def _format_unit(val, numeric=True, include_units=True):
            return '{:.02f}{units}'.format(val, units=units if include_units else "")
    elif "flag_values" in layer:
        # flag values don't have units
        if "flag_meanings" in layer:
            flag_masks = layer["flag_masks"] if "flag_masks" in layer else [-1] * len(layer["flag_values"])
            flag_info = tuple(zip(layer["flag_meanings"], layer["flag_values"], flag_masks))

            def _format_unit(val, numeric=True, include_units=True, flag_info=flag_info):
                val = int(val)
                if numeric:
                    return '{:d}'.format(val)

                meanings = []
                for fmean, fval, fmask in flag_info:
github ssec / sift / uwsift / model / document.py View on Github external
def change_layers_image_kind(self, uuids, new_kind):
        """Change an image or contour layer to present as a different kind."""
        nfo = {}
        layer_set = self.current_layer_set
        assert new_kind in Kind
        all_uuids = set()
        for u in uuids:
            fam = self.family_for_product_or_layer(u)
            all_uuids.update(self._families[fam])
        for idx, pz, layer in self.current_layers_where(uuids=all_uuids):
            if pz.kind not in [Kind.IMAGE, Kind.CONTOUR]:
                LOG.warning("Can't change image kind for Kind: %s", pz.kind.name)
                continue
            new_pz = pz._replace(kind=new_kind)
            nfo[layer.uuid] = new_pz
            layer_set[idx] = new_pz
        self.didChangeImageKind.emit(nfo)
github ssec / sift / uwsift / workspace / importer.py View on Github external
return

        from uuid import uuid1
        scn = self.load_all_datasets()
        for ds_id, ds in scn.datasets.items():
            # don't recreate a Product for one we already have
            if ds_id in existing_ids:
                yield existing_ids[ds_id]
                continue

            existing_ids.get(ds_id, None)
            meta = ds.attrs
            uuid = uuid1()
            meta[Info.UUID] = uuid
            now = datetime.utcnow()
            prod = Product(
                uuid_str=str(uuid),
                atime=now,
            )
            prod.resource.extend(resources)

            assert (Info.OBS_TIME in meta)
            assert (Info.OBS_DURATION in meta)
            prod.update(meta)  # sets fields like obs_duration and obs_time transparently
            assert (prod.info[Info.OBS_TIME] is not None and prod.obs_time is not None)
            assert (prod.info[Info.VALID_RANGE] is not None)
            LOG.debug('new product: {}'.format(repr(prod)))
            self._S.add(prod)
            self._S.commit()
            yield prod
github ssec / sift / uwsift / workspace / importer.py View on Github external
if res is None:
            LOG.debug('no resources for {}'.format(self.source_path))
            return []

        if len(res.product):
            zult = list(res.product)
            # LOG.debug('pre-existing products {}'.format(repr(zult)))
            return zult

        # else probe the file and add product metadata, without importing content
        from uuid import uuid1
        uuid = uuid1()
        meta = self.product_metadata()
        meta[Info.UUID] = uuid

        prod = Product(
            uuid_str=str(uuid),
            atime=now,
        )
        prod.resource.append(res)
        assert (Info.OBS_TIME in meta)
        assert (Info.OBS_DURATION in meta)
        prod.update(meta)  # sets fields like obs_duration and obs_time transparently
        assert (prod.info[Info.OBS_TIME] is not None and prod.obs_time is not None)
        assert (prod.info[Info.VALID_RANGE] is not None)
        LOG.debug('new product: {}'.format(repr(prod)))
        self._S.add(prod)
        self._S.commit()
        return [prod]
github ssec / sift / uwsift / model / document.py View on Github external
"""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
github ssec / sift / uwsift / workspace / importer.py View on Github external
def _metadata_for_path(pathname):
        meta = {}
        if not pathname:
            return meta

        # Old but still necesary, get some information from the filename instead of the content
        m = re.match(r'HS_H(\d\d)_(\d{8})_(\d{4})_B(\d\d)_([A-Za-z0-9]+).*', os.path.split(pathname)[1])
        if m is not None:
            plat, yyyymmdd, hhmm, bb, scene = m.groups()
            when = datetime.strptime(yyyymmdd + hhmm, '%Y%m%d%H%M')
            plat = Platform('Himawari-{}'.format(int(plat)))
            band = int(bb)
            #
            # # workaround to make old files work with new information
            # from uwsift.model.guidebook import AHI_HSF_Guidebook
            # if band in AHI_HSF_Guidebook.REFL_BANDS:
            #     standard_name = "toa_bidirectional_reflectance"
            # else:
            #     standard_name = "toa_brightness_temperature"

            meta.update({
                Info.PLATFORM: plat,
                Info.BAND: band,
                Info.INSTRUMENT: Instrument.AHI,
                Info.SCHED_TIME: when,
                Info.OBS_TIME: when,
                Info.OBS_DURATION: DEFAULT_GTIFF_OBS_DURATION,
github ssec / sift / uwsift / workspace / importer.py View on Github external
data=img_data)

        yield zult

        # Finally, update content mtime and atime
        c.atime = c.mtime = datetime.utcnow()
        # self._S.commit()


# map .platform_id in PUG format files to SIFT platform enum
PLATFORM_ID_TO_PLATFORM = {
    'G16': Platform.GOES_16,
    'G17': Platform.GOES_17,
    # hsd2nc export of AHI data as PUG format
    'Himawari-8': Platform.HIMAWARI_8,
    'Himawari-9': Platform.HIMAWARI_9,
    # axi2cmi export as PUG, more consistent with other uses
    'H8': Platform.HIMAWARI_8,
    'H9': Platform.HIMAWARI_9
}


class GoesRPUGImporter(aSingleFileWithSingleProductImporter):
    """
    Import from PUG format GOES-16 netCDF4 files
    """

    @staticmethod
    def _basic_pug_metadata(pug):
        return {
            Info.PLATFORM: PLATFORM_ID_TO_PLATFORM[pug.platform_id],  # e.g. G16, H8
            Info.BAND: pug.band,
github ssec / sift / uwsift / view / tile_calculator.py View on Github external
@jit(nb_types.UniTuple(nb_types.NamedUniTuple(float64, 2, Resolution), 2)(
    int64,
    int64,
    int64,
    int64,
    int64,
    int64,
    int64,
    int64
), nopython=True, cache=True, nogil=True)
def calc_tile_fraction(tiy, tix, stride_y, stride_x, image_y, image_x, tile_y, tile_x):  # image_shape, tile_shape):
    # def calc_tile_fraction(tiy, tix, stride, image_shape, tile_shape):
    # mt = max_tiles_available(image_shape, tile_shape, stride)
    mt = max_tiles_available(Point(image_y, image_x), Point(tile_y, tile_x), Point(stride_y, stride_x))

    if tix < -mt[1] / 2. + 0.5:
        # left edge tile
github ssec / sift / uwsift / model / document.py View on Github external
for prod in que.all():
                    frm = self.frame_info_for_product(prod, when_overlaps=when)
                    if frm is not None:
                        frames.append(frm)
                if not frames:
                    LOG.warning("track {} with no frames - skipping (missing files or resources?)".format(track))
                    continue
                LOG.debug("found {} frames for track {}".format(len(frames), track))
                frames.sort(key=lambda x: x.when.s)
                track_span = Span.from_s_e(frames[0].when.s, frames[-1].when.e) if frames else None
                trk = TrackInfo(
                    track=track,
                    presentation=self.doc.family_presentation.get(track),
                    when=track_span,
                    frames=frames,
                    state=Flags(),  # FIXME
                    primary=' '.join(reversed(fam.split(FCS_SEP))),  # fam_nfo[Info.DISPLAY_FAMILY],
                    secondary=' '.join(reversed(ctg.split(FCS_SEP)))
                )
                yield z, trk