def test_values_to_labels(self, values, expected): mb = Maskbit(name=name, schema=schema, description=description) if values is None: mb.mask = mask actual = mb.values_to_labels(values=values) assert actual == expected
def _mask_nocov(dapmap, mask, ivar=None): """Mask spaxels that are not covered by the IFU. Parameters: dapmap (marvin.tools.map.Map): Marvin Map object. mask (array): Mask for image. ivar (array): Inverse variance for image. Default is None. Returns: array: Boolean array for mask (i.e., True corresponds to value to be masked out). """ assert (dapmap is not None) or (mask is not None) or (ivar is not None), \ 'Must provide ``dapmap``, ``mask`` or ``ivar``.' if dapmap is None: pixmask = Maskbit('MANGA_DAPPIXMASK') pixmask.mask = mask else: pixmask = dapmap.pixmask try: return pixmask.get_mask('NOCOV') except (MarvinError, AttributeError, IndexError, TypeError): return ivar == 0
def test_get_mask_nonpresent_label(self, labels): mb = Maskbit(name=name, schema=schema, description=description) with pytest.raises(ValueError) as ee: mb.get_mask(labels) assert 'label \'BITFAKE\' not found in the maskbit schema.' in str(ee)
def test_values_to_bits_no_value_error(self, name=name, schema=schema, description=description): mb = Maskbit(name=name, schema=schema, description=description) with pytest.raises(AssertionError) as ee: mb.values_to_bits(values=None) assert 'Must provide values.' in str(ee.value)
def test_maskbit_init_with_schema(self, name=name, schema=schema, description=description): mb = Maskbit(name=name, schema=schema, description=description) assert np.all(mb.schema == schema) assert mb.name == name assert mb.description == description assert str(mb) == "<Maskbit 'MYMASK' None>".format(schema)
def MPL4_dappixmask(): schema = pd.DataFrame( [(0, 'DONOTUSE', 'Do not use this spaxel for science')], columns=['bit', 'label', 'description']) return Maskbit( name='MANGA_DAPPIXMASK', schema=schema, description= '2d image bitmap used to describe the quality of individual pixel ' 'measurements in the DAP MAPS file.')
def buildMapDict(cube, params, dapver, bintemp=None): ''' Build a list of dictionaries of maps params - list of string parameter names in form of category_channel NOT GENERALIZED ''' # split the bintemp if bintemp: bintype, temp = bintemp.split('-', 1) else: bintype, temp = (None, None) mapdict = [] params = params if isinstance(params, list) else [params] for param in params: param = str(param) try: parameter, channel = param.split(':') except ValueError as e: parameter, channel = (param, None) webmap, mapmsg = getWebMap(cube, parameter=parameter, channel=channel, bintype=bintype, template=temp) plotparams = datamodel[dapver].get_plot_params(prop=parameter) mask = Maskbit('MANGA_DAPPIXMASK') baddata_labels = [it for it in plotparams['bitmasks'] if it != 'NOCOV'] baddata_bits = { it.lower(): int(mask.labels_to_bits(it)[0]) for it in baddata_labels } plotparams['bits'] = { 'nocov': int(mask.labels_to_bits('NOCOV')[0]), 'badData': baddata_bits } mapdict.append({ 'data': webmap, 'msg': mapmsg, 'plotparams': plotparams }) anybad = [m['data'] is None for m in mapdict] if any(anybad): bad_params = ', '.join([p for i, p in enumerate(params) if anybad[i]]) raise MarvinError( 'Could not get map for: {0}. Please select another.'.format( bad_params), ignore_git=True) return mapdict
def get_maskbits(release): maskbits = { 'MANGA_TARGET1': Maskbit('MANGA_TARGET1', description='Targeting bits for all galaxy targets.'), 'MANGA_TARGET2': Maskbit('MANGA_TARGET2', description='Targeting bits for all non-galaxy targets.'), 'MANGA_TARGET3': Maskbit('MANGA_TARGET3', description='Targeting bits for ancillary targets.'), 'MANGA_DRP3QUAL': Maskbit('MANGA_DRP3QUAL', description= 'Describes the quality of the final cubes and RSS files.'), 'MANGA_DAPQUAL': Maskbit('MANGA_DAPQUAL', description='Describes the overall quality of the data.'), 'MANGA_DRP3PIXMASK': Maskbit( 'MANGA_DRP3PIXMASK', description= 'Describes whether a given spaxel should be used for science analyses.' ), 'MANGA_DAPPIXMASK': Maskbit('MANGA_DAPPIXMASK', description='2d image bitmap used to describe the quality of ' 'individual pixel measurements in the DAP MAPS file.'), 'MANGA_DAPSPECMASK': Maskbit('MANGA_DAPSPECMASK', description='3d cube bitmap used to describe the quality of ' 'individual spaxel fits in the DAP model data cube file.') } if release == 'MPL-4': maskbits['MANGA_DAPPIXMASK'] = MPL4_dappixmask() __ = maskbits.pop('MANGA_DAPQUAL') return maskbits
def test_bits_to_labels(self, bits_in, expected): mb = Maskbit(name=name, schema=schema, description=description) actual = mb._bits_to_labels(bits_in) assert actual == expected
def test_value_to_bits(self, value, expected): mb = Maskbit(name=name, schema=schema, description=description) actual = mb._value_to_bits(value, schema.bit.values) assert actual == expected
def test_maskbit_init_from_name(self, name): mb = Maskbit(name=name) assert mb.name == name assert isinstance(mb.schema, pd.DataFrame) assert mb.description is None
def test_get_mask_empty(self, labels, dtype, expected): mb = Maskbit(name=name, schema=schema, description=description) mb.mask = mask actual = mb.get_mask(labels, mask=custom_mask, dtype=dtype) assert (actual == expected).all()
def test_get_mask_bool(self, labels, expected): mb = Maskbit(name=name, schema=schema, description=description) mb.mask = mask actual = mb.get_mask(labels, dtype=bool) assert (actual == expected).all()
def test_labels_to_bits(self, labels, expected): mb = Maskbit(name=name, schema=schema, description=description) actual = mb.labels_to_bits(labels) assert actual == expected