diff --git a/pyglance/glance/io.py b/pyglance/glance/io.py index 5ea4c71911ce6943ac8aeaf83a22f2189c22e6dc..bb2f9987aaa295c922a873c0b7fee20e9d636401 100644 --- a/pyglance/glance/io.py +++ b/pyglance/glance/io.py @@ -988,19 +988,54 @@ class tiff (object): _tiff = None + GRAY_NAME = "grayscale value" + RED_NAME = "red" + GREEN_NAME = "green" + BLUE_NAME = "blue" + IR_NAME = "infrared" + ALPHA_NAME = "alpha" + + # if we are using meaningful names, we will translate between # the band index numbers and these names (otherwise bands use generic names) EXPECTED_BAND_NAME_KEY = { - 1: ["grayscale value"], - 3: ["red", "green", "blue"], - 4: ["red", "green", "blue", "alpha"], + 1: [GRAY_NAME], + 2: [GRAY_NAME, ALPHA_NAME], + 3: [RED_NAME, GREEN_NAME, BLUE_NAME], + 4: [RED_NAME, GREEN_NAME, BLUE_NAME, ALPHA_NAME], + 5: [RED_NAME, GREEN_NAME, BLUE_NAME, IR_NAME, ALPHA_NAME], } - SPECIAL_NAMES_TO_IDX = { - "grayscale value": 1, - "red": 1, - "green": 2, - "blue": 3, - "alpha": 4, + + # a reverse look up to help disambigurate what meaningful name goes with + # which number (one of these dictionaries will be selected based on the + # number of bands in the geotiff) + REV_INFO = { + 1: { + GRAY_NAME: 1, + }, + 2: { + GRAY_NAME: 1, + ALPHA_NAME: 2, + }, + 3: { + RED_NAME: 1, + GREEN_NAME: 2, + BLUE_NAME: 3, + }, + 4: { + RED_NAME: 1, + GREEN_NAME: 2, + BLUE_NAME: 3, + ALPHA_NAME: 4, + }, + 5: { + RED_NAME: 1, + GREEN_NAME: 2, + BLUE_NAME: 3, + IR_NAME: 4, + ALPHA_NAME: 5, + }, + } def _get_generic_band_name (self, number) : @@ -1012,14 +1047,14 @@ class tiff (object): """get an index for the band from a name name may be either a meaningful name from the list that shows - up in SPECIAL_NAMES_TO_IDX's keys or a generic name that was + up in the reverse index keys or a generic name that was generated by _get_generic_band_name """ to_return = None - if name in self.SPECIAL_NAMES_TO_IDX.keys() : - to_return = self.SPECIAL_NAMES_TO_IDX[name] + if name in self.revIndex.keys() : + to_return = self.revIndex[name] else : to_return = int(name.split(' ')[-1]) @@ -1036,6 +1071,7 @@ class tiff (object): self._tiff = gdal.Open(filename) self.niceNames = useMeaningfulNames + self.revIndex = self.REV_INFO[self._tiff.RasterCount] def __call__(self): "yield names of variables to be compared" @@ -1155,7 +1191,9 @@ class tiff (object): return True # people also name tiff files with one f... -tif = tiff +tif = tiff +# Nick has special tiff files with alpha... +tifa = tiff def _search_xml(pathname): xs = '.xml'