def test_create_mask_value():
    simple_var = SimpleVariableWithFlagsDef()
    bits_def = simple_var.flags_definition

    assert create_mask_value(bits_def, contiguous=True) == (256, 256)
    assert create_mask_value(bits_def, contiguous=False) == (256, 0)
    assert create_mask_value(bits_def, contiguous=True, land_sea='land') == (
        768, 768)
    assert create_mask_value(bits_def, contiguous=False, land_sea='land') == (768, 512)
def test_create_mask_value():
    simple_var = SimpleVariableWithFlagsDef()
    bits_def = simple_var.flags_definition

    assert create_mask_value(bits_def, contiguous=True) == (256, 256)
    assert create_mask_value(bits_def, contiguous=False) == (256, 0)
    assert create_mask_value(bits_def, contiguous=True,
                             land_sea='land') == (768, 768)
    assert create_mask_value(bits_def, contiguous=False,
                             land_sea='land') == (768, 512)
def test_create_multi_mask_value():
    multi_var = VariableWithMultiBitFlags()
    multi_flags_def = multi_var.flags_definition

    assert create_mask_value(multi_flags_def, filled=True) == (1, 1)
    assert create_mask_value(multi_flags_def,
                             water_confidence='water') == (0b011000, 0b011000)

    assert create_mask_value(multi_flags_def,
                             water_confidence='water',
                             filled=True) == (0b011001, 0b011001)
    assert create_mask_value(multi_flags_def,
                             water_confidence='not_determined') == (0b011000,
                                                                    0b0)
    assert create_mask_value(multi_flags_def,
                             water_confidence='no_water') == (0b11000, 0b01000)
    assert create_mask_value(multi_flags_def,
                             veg_confidence='maybe_veg') == (0b110000000,
                                                             0b100000000)
    assert create_mask_value(multi_flags_def,
                             veg_confidence='maybe_veg',
                             water_confidence='water') == (0b110011000,
                                                           0b100011000)
    assert create_mask_value(multi_flags_def,
                             veg_confidence='maybe_veg',
                             water_confidence='water',
                             filled=True) == (0b110011001, 0b100011001)

    assert create_mask_value(multi_flags_def,
                             water_confidence='maybe_water') == (0b011000,
                                                                 0b10000)
    def measurements(self, input_measurements):
        nodata = -1
        bit_defs = input_measurements[0].flags_definition

        if self._nodata_flags is not None:
            self._valid_pq_mask = mk_masker(*create_mask_value(bit_defs, **self._nodata_flags), invert=True)

        for v in self._vars:
            flags = v['flags']
            v['_mask'] = create_mask_value(bit_defs, **flags)
            v['mask'] = mk_masker(*v['_mask'])

        return [Measurement(name=v['name'], dtype='int16', units='1', nodata=nodata)
                for v in self._vars]
    def numpy_mask(variable, **flags):
        """
        :rtype: ndarray
        """
        mask, mask_value = create_mask_value(defn, **flags)

        return variable & mask == mask_value
def test_create_multi_mask_value():
    multi_var = VariableWithMultiBitFlags()
    multi_flags_def = multi_var.flags_definition

    assert create_mask_value(multi_flags_def, filled=True) == (1, 1)
    assert create_mask_value(multi_flags_def, water_confidence='water') == (0b011000, 0b011000)

    assert create_mask_value(multi_flags_def, water_confidence='water', filled=True) == (0b011001, 0b011001)
    assert create_mask_value(multi_flags_def, water_confidence='not_determined') == (0b011000, 0b0)
    assert create_mask_value(multi_flags_def, water_confidence='no_water') == (0b11000, 0b01000)
    assert create_mask_value(multi_flags_def, veg_confidence='maybe_veg') == (0b110000000, 0b100000000)
    assert create_mask_value(multi_flags_def,
                             veg_confidence='maybe_veg',
                             water_confidence='water') == (0b110011000, 0b100011000)
    assert create_mask_value(multi_flags_def,
                             veg_confidence='maybe_veg',
                             water_confidence='water', filled=True) == (0b110011001, 0b100011001)

    assert create_mask_value(multi_flags_def, water_confidence='maybe_water') == (0b011000, 0b10000)
def test_ga_good_pixel():
    simple_var = SimpleVariableWithFlagsDef()
    bits_def = simple_var.flags_definition

    assert create_mask_value(bits_def, ga_good_pixel=True) == (16383, 16383)
def test_ga_good_pixel():
    simple_var = SimpleVariableWithFlagsDef()
    bits_def = simple_var.flags_definition

    assert create_mask_value(bits_def, ga_good_pixel=True) == (16383, 16383)