How to use the trollimage.image.Image function in trollimage

To help you get started, we’ve selected a few trollimage 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 pytroll / mpop / mpop / tools.py View on Github external
height = np.ma.masked_where(height <= 0, height, copy=False) * 1000.

    if False:
        from trollimage.image import Image as trollimage
        from trollimage.colormap import rainbow
        from copy import deepcopy 
        # cloud top height
        prop = height
        min_data = prop.min()
        max_data = prop.max()
        print " estimated CTH(meter) (min/max): ", min_data, max_data
        min_data =     0
        max_data = 12000    
        colormap = deepcopy(rainbow)
        colormap.set_range(min_data, max_data)
        img = trollimage(prop, mode="L") #, fill_value=[0,0,0]
        img.colorize(colormap)
        img.show()

    # return cloud top height in meter
    return height
github pytroll / fogpy / fogpy / filters.py View on Github external
if type == 'tif':
                result_img = GeoImage(filter_img.channels, area,
                                      self.time, fill_value=None,
                                      mode="RGB")
                result_img.save(savedir)
            else:
                filter_img.save(savedir)
            logger.info("{} results are plotted to: {}". format(self.name,
                                                                savedir))
        else:
            filter_img.show()
        # Create mask image
        if isinstance(self.result, np.ma.masked_array):
            mask = self.result.mask.squeeze()
            mask = np.ma.masked_where(mask == 1, mask)
            mask_img = Image(mask, mode='L', fill_value=None)
            mask_img.stretch("crude")
            mask_img.invert()
            mask_img.colorize(maskcol)
            if resize != 0:
                if not isinstance(resize, int):
                    resize = int(resize)
                mask_img.resize((self.result.shape[0] * resize,
                                 self.result.shape[1] * resize))
            # mask_img.merge(bg_img)
            if save:
                if type == 'tif':
                    result_img = GeoImage(mask_img.channels, area,
                                          self.time, fill_value=None,
                                          mode="RGB")
                    result_img.save(maskdir)
                else:
github pytroll / fogpy / fogpy / utils / add_synop.py View on Github external
def add_to_image(image, area, time, bufr, savedir='/tmp', name=None,
                 bgimg=None, resize=None, ptsize=None, save=False):
    """Add synoptical visibility reports from station data to provided
    geolocated image array
    """
    arrshp = image.shape[:2]
    # Add optional background image
    if bgimg is not None:
        # Get background image
        bg_img = Image(bgimg.squeeze(), mode='L', fill_value=None)
        bg_img.stretch("crude")
        bg_img.convert("RGB")
#         bg_img.invert()
        image.merge(bg_img)
    # Import bufr
    stations = read_synop(bufr, 'visibility')
    currentstations = stations[time.strftime("%Y%m%d%H0000")]
    lats = [i[2] for i in currentstations]
    lons = [i[3] for i in currentstations]
    vis = [i[4] for i in currentstations]

    # Create array for synop parameter
    visarr = np.empty(arrshp)
    visarr.fill(np.nan)
    # Red - Violet - Blue - Green
    vis_colset = Colormap((0, (228 / 255.0, 26 / 255.0, 28 / 255.0)),
github pytroll / satpy / satpy / writers / __init__.py View on Github external
def to_image(dataset, copy=True, **kwargs):
    # Only add keywords if they are present
    for key in ["mode", "fill_value", "palette"]:
        if key in dataset.info:
            kwargs.setdefault(key, dataset.info[key])

    if dataset.ndim == 2:
        return Image([dataset], copy=copy, **kwargs)
    elif dataset.ndim == 3:
        return Image([band for band in dataset], copy=copy, **kwargs)
    else:
        raise ValueError(
            "Don't know how to convert array with ndim %d to image" %
            dataset.ndim)
github pytroll / fogpy / fogpy / algorithms.py View on Github external
area = self.area
            except DummyException:
                Warning("Area object not found. Plotting filter result as"
                        " image")
                type = 'png'
        # Create image from data
        if array is None:
            if np.nanmax(self.result) > 1:
                self.plotrange = (np.nanmin(self.result),
                                  np.nanmax(self.result))
            if type == 'tif':
                result_img = GeoImage(self.result.squeeze(), area,
                                      self.time,
                                      mode="L")
            else:
                result_img = Image(self.result.squeeze(), mode='L',
                                   fill_value=None)
        else:
            self.plotrange = (np.nanmin(array), np.nanmax(array))
            if type == 'tif':
                result_img = GeoImage(array.squeeze(), area,
                                      self.time,
                                      mode="L")
            else:
                result_img = Image(array.squeeze(), mode='L', fill_value=None)
        result_img.stretch("crude")
        # Colorize image
        ylorrd.set_range(*self.plotrange)
        logger.info("Set color range to {}".format(self.plotrange))
        if not floating_point:
            result_img.colorize(ylorrd)
        if array is None:
github pytroll / fogpy / fogpy / utils / add_synop.py View on Github external
xpt = np.array([])
        ypt = np.array([])
        for i, j in zip(x, y):
            xmesh, ymesh = np.meshgrid(np.linspace(i - ptsize, i + ptsize,
                                                   ptsize * 2 + 1),
                                       np.linspace(j - ptsize, j + ptsize,
                                                   ptsize * 2 + 1))
            xpt = np.append(xpt, xmesh.ravel())
            ypt = np.append(ypt, ymesh.ravel())
        vispt = np.ma.array([np.full(((ptsize * 2 + 1,
                                       ptsize * 2 + 1)), p) for p in vis_ma])
        visarr[ypt.astype(int), xpt.astype(int)] = vispt.ravel()
    else:
        visarr[y.compressed(), x.compressed()] = vis_ma.compressed()
    visarr_ma = np.ma.masked_invalid(visarr)
    station_img = Image(visarr_ma, mode='L')
    station_img.colorize(vis_colset)
    station_img.merge(arr_img)
    if resize is not None:
        station_img.resize((arrshp[0] * resize, arrshp[1] * resize))
    if name is None:
        timestr = time.strftime("%Y%m%d%H%M")
        name = "fog_filter_example_stations_{}.png".format(timestr)
    if save:
        savepath = os.path.join(savedir, name)
        station_img.save(savepath)

    return(station_img)
github pytroll / fogpy / fogpy / filters.py View on Github external
from trollimage.image import Image
        from trollimage.colormap import Colormap
        # Define custom fog colormap
        fogcol = Colormap((0., (250 / 255.0, 200 / 255.0, 40 / 255.0)),
                          (1., (1.0, 1.0, 229 / 255.0)))
        maskcol = Colormap((1., (250 / 255.0, 200 / 255.0, 40 / 255.0)))
        # Get save directory
        attrdir = os.path.join(dir, self.name + '_' + name + '_' +
                               datetime.strftime(self.time,
                                                 '%Y%m%d%H%M') + '.' + type)
        logger.info("Plotting filter attribute {} to {}".format(name, attrdir))
        # Generate image
        attr = getattr(self, name)
        if attr.dtype == 'bool':
            attr = np.ma.masked_where(attr == 1, attr)
        attr_img = Image(attr.squeeze(), mode='L', fill_value=None)
        attr_img.colorize(fogcol)
        # Get background image
        bg_img = Image(self.bg_img.squeeze(), mode='L', fill_value=None)
        bg_img.stretch("crude")
        bg_img.convert("RGB")
        bg_img.invert()
        if resize != 0:
            if not isinstance(resize, int):
                resize = int(resize)
            bg_img.resize((self.bg_img.shape[0] * resize,
                           self.bg_img.shape[1] * resize))
            attr_img.resize((self.result.shape[0] * resize,
                             self.result.shape[1] * resize))
        try:
            # Merging
            attr_img.merge(bg_img)
github pytroll / fogpy / fogpy / filters.py View on Github external
fogcol = Colormap((0., (250 / 255.0, 200 / 255.0, 40 / 255.0)),
                          (1., (1.0, 1.0, 229 / 255.0)))
        maskcol = Colormap((1., (250 / 255.0, 200 / 255.0, 40 / 255.0)))
        # Get save directory
        attrdir = os.path.join(dir, self.name + '_' + name + '_' +
                               datetime.strftime(self.time,
                                                 '%Y%m%d%H%M') + '.' + type)
        logger.info("Plotting filter attribute {} to {}".format(name, attrdir))
        # Generate image
        attr = getattr(self, name)
        if attr.dtype == 'bool':
            attr = np.ma.masked_where(attr == 1, attr)
        attr_img = Image(attr.squeeze(), mode='L', fill_value=None)
        attr_img.colorize(fogcol)
        # Get background image
        bg_img = Image(self.bg_img.squeeze(), mode='L', fill_value=None)
        bg_img.stretch("crude")
        bg_img.convert("RGB")
        bg_img.invert()
        if resize != 0:
            if not isinstance(resize, int):
                resize = int(resize)
            bg_img.resize((self.bg_img.shape[0] * resize,
                           self.bg_img.shape[1] * resize))
            attr_img.resize((self.result.shape[0] * resize,
                             self.result.shape[1] * resize))
        try:
            # Merging
            attr_img.merge(bg_img)
        except DummyException:
            logger.warning("No merging for attribute plot possible")
        if save: