Return the percentage of pixels that are either cloud or snow with
        high confidence (> 67%).
770938
def _calculate_cloud_ice_perc(self):
        
        self.output('Calculating cloud and snow coverage from QA band', normal=True, arrow=True)
        a = rasterio.open(join(self.scene_path, self._get_full_filename('QA'))).read_band(1)

        cloud_high_conf = int('1100000000000000', 2)
        snow_high_conf = int('0000110000000000', 2)
        fill_pixels = int('0000000000000001', 2)
        cloud_mask = numpy.bitwise_and(a, cloud_high_conf) == cloud_high_conf
        snow_mask = numpy.bitwise_and(a, snow_high_conf) == snow_high_conf
        fill_mask = numpy.bitwise_and(a, fill_pixels) == fill_pixels

        perc = numpy.true_divide(numpy.sum(cloud_mask | snow_mask),
                                 a.size - numpy.sum(fill_mask)) * 100.0
        self.output('cloud/snow coverage: %s' % round(perc, 2), indent=1, normal=True, color='green')
        return perc
694151
def average_true_range_percent(close_data, period):
    
    catch_errors.check_for_period_error(close_data, period)
    atrp = (atr(close_data, period) / np.array(close_data)) * 100
    return atrp
704443
def _count_pixels_on_line(self, y, p):
        """"""
        h = line(y, self._effective_thickness(p), 0.0)
        return h.sum()
13758
def percent_point(self, y, V):
        
        self.check_fit()

        if self.theta < 0:
            return V

        else:
            a = np.power(y, self.theta / (-1 - self.theta))
            b = np.power(V, self.theta)
            u = np.power((a + b - 1) / b, -1 / self.theta)
            return u
454831
def from_sky(cls, skycoord, wcs, origin=_DEFAULT_WCS_ORIGIN, mode=_DEFAULT_WCS_MODE):
        
        x, y = skycoord.to_pixel(wcs=wcs, origin=origin, mode=mode)
        return cls(x=x, y=y)
729559
def threshold(image, block_size=DEFAULT_BLOCKSIZE, mask=None):
    
    if mask is None:
        mask = np.zeros(image.shape[:2], dtype=np.uint8)
        mask[:] = 255

    if len(image.shape) > 2 and image.shape[2] == 4:
        image = cv2.cvtColor(image, cv2.COLOR_BGRA2GRAY)
    res = _calc_block_mean_variance(image, mask, block_size)
    res = image.astype(np.float32) - res.astype(np.float32) + 255
    _, res = cv2.threshold(res, 215, 255, cv2.THRESH_BINARY)
    return res
588321
def pixels(self, zoom=None):
        """"""
        meter_x, meter_y = self.meters
        pixel_x = (meter_x + ORIGIN_SHIFT) / resolution(zoom=zoom)
        pixel_y = (meter_y - ORIGIN_SHIFT) / resolution(zoom=zoom)
        return abs(round(pixel_x)), abs(round(pixel_y))
1011704
def storage_color(self, user_storage):
        
        p = user_storage.percentage
        if p >= 0 and p < 60:
            return "success"
        if p >= 60 and p < 90:
            return "warning"
        if p >= 90 and p <= 100:
            return "danger"
        raise ValueError("percentage out of range")
1332751
function (data, colorFunc, state) {
        var gradientPixels = this._gradientPixels;
        var pixelsSingleState = gradientPixels[state] || (gradientPixels[state] = new Uint8ClampedArray(256 * 4));
        var color = [0, 0, 0, 0];
        var off = 0;
        for (var i = 0; i < 256; i++) {
            colorFunc[state](i / 255, true, color);
            pixelsSingleState[off++] = color[0];
            pixelsSingleState[off++] = color[1];
            pixelsSingleState[off++] = color[2];
            pixelsSingleState[off++] = color[3];
        }
        return pixelsSingleState;
    }
101729
def percentSame(image1, image2):
        '''
        
        '''

        # If the images differ in size, return 0% same.
        size_x1, size_y1 = image1.size
        size_x2, size_y2 = image2.size
        if (size_x1 != size_x2 or
                    size_y1 != size_y2):
            return 0

        # Images are the same size
        # Return the percent of pixels that are equal.
        numPixelsSame = 0
        numPixelsTotal = size_x1 * size_y1
        image1Pixels = image1.load()
        image2Pixels = image2.load()

        # Loop over all pixels, comparing pixel in image1 to image2
        for x in range(size_x1):
            for y in range(size_y1):
                if image1Pixels[x, y] == image2Pixels[x, y]:
                    numPixelsSame += 1

        return numPixelsSame / float(numPixelsTotal)
734802
def full_pixels(space, data, gap_pixels=1):
    
    available = space - (len(data) - 1) * gap_pixels # 8 recs 7 gaps

    res = []
    for i, val in enumerate(data):
        # convert data to 0..1 scale so we deal with fractions
        data_sum = sum(data[i:])
        norm = val * 1.0 / data_sum


        w = max(int(round(available * norm)), 1)
        res.append(w)
        available -= w
    return res
1046327
def percent_b(data, period, upper_bb_std=2.0, lower_bb_std=2.0):
    
    lb = lower_bollinger_band(data, period, lower_bb_std)
    ub = upper_bollinger_band(data, period, upper_bb_std)
    percent_b = ((np.array(data) - lb) / (ub - lb)) * 100
    return percent_b
946740
def get_ceiling_cloud_layer(self):
        
        lowest_layer = None
        for layer in self.cloud_layers:
            if layer.coverage not in [CloudLayer.BROKEN, CloudLayer.OVERCAST]:
                continue
            if lowest_layer is None:
                lowest_layer = layer
                continue
            if layer.height > lowest_layer.height:
                continue
            if layer.height < lowest_layer.height or \
                    lowest_layer.get_coverage_percentage() < layer.get_coverage_percentage():
                lowest_layer = layer
        return lowest_layer
1086966
def _vis_calibrate(data,
                   chn,
                   calib_type,
                   pre_launch_coeffs=False,
                   calib_coeffs=None,
                   mask=False):
    
    # Calibration count to albedo, the calibration is performed separately for
    # two value ranges.

    if calib_type not in ['counts', 'radiance', 'reflectance']:
        raise ValueError('Calibration ' + calib_type + ' unknown!')

    arr = data["hrpt"][:, :, chn]
    mask |= arr == 0

    channel = arr.astype(np.float)
    if calib_type == 'counts':
        return channel

    if calib_type == 'radiance':
        logger.info("Radiances are not yet supported for " +
                    "the VIS/NIR channels!")

    if pre_launch_coeffs:
        coeff_idx = 2
    else:
        # check that coeffs are valid
        if np.all(data["calvis"][:, chn, 0, 4] == 0):
            logger.info(
                "No valid operational coefficients, fall back to pre-launch")
            coeff_idx = 2
        else:
            coeff_idx = 0

    intersection = data["calvis"][:, chn, coeff_idx, 4]

    if calib_coeffs is not None:
        logger.info("Updating from external calibration coefficients.")
        # intersection = np.expand_dims
        slope1 = np.expand_dims(calib_coeffs[0], 1)
        intercept1 = np.expand_dims(calib_coeffs[1], 1)
        slope2 = np.expand_dims(calib_coeffs[2], 1)
        intercept2 = np.expand_dims(calib_coeffs[3], 1)
    else:
        slope1 = np.expand_dims(data["calvis"][:, chn, coeff_idx, 0] * 1e-10,
                                1)
        intercept1 = np.expand_dims(data["calvis"][:, chn, coeff_idx, 1] *
                                    1e-7, 1)
        slope2 = np.expand_dims(data["calvis"][:, chn, coeff_idx, 2] * 1e-10,
                                1)
        intercept2 = np.expand_dims(data["calvis"][:, chn, coeff_idx, 3] *
                                    1e-7, 1)

        if chn == 2:
            slope2[slope2 < 0] += 0.4294967296

    mask1 = channel <= np.expand_dims(intersection, 1)
    mask2 = channel > np.expand_dims(intersection, 1)

    channel[mask1] = (channel * slope1 + intercept1)[mask1]

    channel[mask2] = (channel * slope2 + intercept2)[mask2]

    channel = channel.clip(min=0)

    return np.where(mask, np.nan, channel)
1250196
def _vis_calibrate(self, data, key):
        """"""
        # radiance to reflectance taken as in mipp/xrit/MSG.py
        # again FCI User Guide is not clear on how to do this

        sirr = self.nc[
            '/data/{}/measured/channel_effective_solar_irradiance'
            .format(key.name)][...]

        # reflectance = radiance / sirr * 100
        data.data[:] /= sirr
        data.data[:] *= 100
799553
def pixel(self, x, y, size=None):
        """"""
        if (size is None):
            size = self.sz
        # Have we go to the smallest element?
        if (size <= 3):
            if (_not_diagonal(x, y)):
                return None
            else:
                return (0, 0, 0)
        divisor = size // 3
        if (_not_diagonal(x // divisor, y // divisor)):
            return None
        return self.pixel(x % divisor, y % divisor, divisor)
910625
def pix2sky(self, pixel):
        
        pixbox = numpy.array([pixel, pixel])
        skybox = self.wcs.all_pix2world(pixbox, 1)
        return [float(skybox[0][0]), float(skybox[0][1])]