Skip to content

Commit 68b6083

Browse files
authored
Merge pull request #591 from jonlorax/16bit_work_staging
16bit work staging
2 parents 7877e7b + 8860dc9 commit 68b6083

File tree

4 files changed

+69
-55
lines changed

4 files changed

+69
-55
lines changed

sarpy/processing/sidd/sidd_product_creation.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ def create_detected_image_sidd(
167167
ortho_bounds = ortho_iterator.ortho_bounds
168168
sidd_structure = create_sidd_structure(
169169
ortho_helper, ortho_bounds,
170-
product_class='Detected Image', pixel_type='MONO{}I'.format(remap_function.bit_depth), remap_function=remap_function, version=version)
170+
product_class='Detected Image', pixel_type='MONO{}I'.format(remap_function.bit_depth), version=version, remap_function=remap_function)
171171
# set suggested name
172172
sidd_structure.NITF['SUGGESTED_NAME'] = ortho_helper.sicd.get_suggested_name(ortho_helper.index)+'_IMG'
173173

@@ -256,7 +256,7 @@ def create_csi_sidd(
256256
ortho_bounds = ortho_iterator.ortho_bounds
257257
sidd_structure = create_sidd_structure(
258258
ortho_helper, ortho_bounds,
259-
product_class='Color Subaperture Image', pixel_type='RGB24I', version=version)
259+
product_class='Color Subaperture Image', pixel_type='RGB24I', version=version, remap_function=remap_function)
260260
# set suggested name
261261
sidd_structure.NITF['SUGGESTED_NAME'] = csi_calculator.sicd.get_suggested_name(csi_calculator.index)+'_CSI'
262262

@@ -352,7 +352,7 @@ def create_dynamic_image_sidd(
352352
ortho_bounds = ortho_iterator.ortho_bounds
353353
sidd_structure = create_sidd_structure(
354354
ortho_helper, ortho_bounds,
355-
product_class='Dynamic Image', pixel_type='MONO{}I'.format(remap_function.bit_depth), version=version)
355+
product_class='Dynamic Image', pixel_type='MONO{}I'.format(remap_function.bit_depth), version=version, remap_function=remap_function)
356356
# set suggested name
357357
sidd_structure.NITF['SUGGESTED_NAME'] = subap_calculator.sicd.get_suggested_name(subap_calculator.index)+'__DI'
358358
the_sidds = []

sarpy/processing/sidd/sidd_structure_creation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ def _create_exploitation_v1():
521521
##########################
522522
# Switchable version SIDD structure
523523

524-
def create_sidd_structure(ortho_helper, bounds, product_class, pixel_type, remap_function=None, version=3):
524+
def create_sidd_structure(ortho_helper, bounds, product_class, pixel_type, version=3, remap_function=None):
525525
"""
526526
Create a SIDD structure, with version specified, based on the orthorectification
527527
helper and pixel bounds.

sarpy/visualization/remap.py

Lines changed: 41 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ class based solution which allows state variables associated with the remap
3333

3434
_DEFAULTS_REGISTERED = False
3535
_REMAP_DICT = OrderedDict() # type: Dict[str, RemapFunction]
36-
newRegMap = OrderedDict()
3736

3837
###########
3938
# helper functions
@@ -1828,12 +1827,17 @@ def register_remap(
18281827
"""
18291828

18301829
if isinstance(remap_function, type) and issubclass(remap_function, RemapFunction):
1831-
remap_function = remap_function()
1830+
remap_function = remap_function( bit_depth=bit_depth)
18321831
if not isinstance(remap_function, RemapFunction):
18331832
raise TypeError('remap_function must be an instance of RemapFunction.')
18341833

1835-
remap_name = remap_function.name
1834+
1835+
if remap_function.bit_depth == 16:
1836+
remap_name = remap_function.name + '_' + str( remap_function.bit_depth )
1837+
else:
1838+
remap_name = remap_function.name
18361839

1840+
18371841
if remap_name not in _REMAP_DICT:
18381842
_REMAP_DICT[remap_name] = remap_function
18391843
elif overwrite:
@@ -1848,15 +1852,25 @@ def _register_defaults():
18481852
if _DEFAULTS_REGISTERED:
18491853
return
18501854

1851-
# register class as opposed to instance of class that it was
1852-
register_remap(NRL, overwrite=False )
1853-
register_remap(Linear, overwrite=False )
1854-
register_remap(Density, overwrite=False )
1855-
register_remap(High_Contrast, overwrite=False )
1856-
register_remap(Brighter, overwrite=False )
1857-
register_remap(Darker, overwrite=False )
1858-
register_remap(Logarithmic, overwrite=False )
1859-
register_remap(PEDF, overwrite=False )
1855+
# register instance of class
1856+
register_remap(NRL( bit_depth=8), overwrite=False)
1857+
register_remap(Density( bit_depth=8), overwrite=False)
1858+
register_remap(High_Contrast( bit_depth=8), overwrite=False)
1859+
register_remap(Brighter( bit_depth=8), overwrite=False)
1860+
register_remap(Darker( bit_depth=8), overwrite=False)
1861+
register_remap(Linear( bit_depth=8), overwrite=False)
1862+
register_remap(Logarithmic( bit_depth=8), overwrite=False)
1863+
register_remap(PEDF( bit_depth=8), overwrite=False)
1864+
1865+
register_remap(NRL( bit_depth=16), overwrite=False)
1866+
register_remap(Density( bit_depth=16), overwrite=False)
1867+
register_remap(High_Contrast( bit_depth=16), overwrite=False)
1868+
register_remap(Brighter( bit_depth=16), overwrite=False)
1869+
register_remap(Darker( bit_depth=16), overwrite=False)
1870+
register_remap(Linear( bit_depth=16), overwrite=False)
1871+
register_remap(Logarithmic( bit_depth=16), overwrite=False)
1872+
register_remap(PEDF( bit_depth=16), overwrite=False)
1873+
18601874

18611875
if plt is not None:
18621876
try:
@@ -1875,32 +1889,6 @@ def _register_defaults():
18751889
register_remap(LUT8bit(NRL(bit_depth=8), 'bone', use_alpha=False), overwrite=False)
18761890
except KeyError:
18771891
pass
1878-
# joz
1879-
newRegMap[ 'nrl' ] = NRL
1880-
newRegMap[ 'linear' ] = Linear
1881-
newRegMap[ 'density' ] = Density
1882-
newRegMap[ 'high_contrast' ] = High_Contrast
1883-
newRegMap[ 'brighter' ] = Brighter
1884-
newRegMap[ 'darker' ] = Darker
1885-
newRegMap[ 'log' ] = Logarithmic
1886-
newRegMap[ 'pedf' ] = PEDF
1887-
if plt is not None:
1888-
try:
1889-
newRegMap[ 'viridis' ] = LUT8bit(NRL(bit_depth=8), 'viridis', use_alpha=False)
1890-
except KeyError:
1891-
pass
1892-
try:
1893-
newRegMap[ 'magma' ] = LUT8bit(NRL(bit_depth=8), 'magma', use_alpha=False)
1894-
except KeyError:
1895-
pass
1896-
try:
1897-
newRegMap[ 'rainbow' ] = LUT8bit(NRL(bit_depth=8), 'rainbow', use_alpha=False)
1898-
except KeyError:
1899-
pass
1900-
try:
1901-
newRegMap[ 'bone' ] = LUT8bit(NRL(bit_depth=8), 'bone', use_alpha=False)
1902-
except KeyError:
1903-
pass
19041892

19051893
_DEFAULTS_REGISTERED = True
19061894

@@ -1916,7 +1904,7 @@ def get_remap_names() -> List[str]:
19161904

19171905
if not _DEFAULTS_REGISTERED:
19181906
_register_defaults()
1919-
return list(newRegMap.keys())
1907+
return list( _REMAP_DICT.keys())
19201908

19211909

19221910
def get_remap_list() -> List[Tuple[str, RemapFunction]]:
@@ -1940,10 +1928,10 @@ def get_remap_list() -> List[Tuple[str, RemapFunction]]:
19401928

19411929
def get_registered_remap(
19421930
remap_name: str,
1943-
bit_depth=8,
1944-
default: Optional[RemapFunction] = None) -> RemapFunction:
1931+
default: Optional[RemapFunction] = None,
1932+
bit_depth=8) -> RemapFunction:
19451933
"""
1946-
Gets a remap Class/constructor/init from it's registered name.
1934+
Gets a remap instance via its registered name.
19471935
# add 16 bit ability by newRegMap is dict of class/constructors
19481936
19491937
@@ -1963,15 +1951,18 @@ def get_registered_remap(
19631951

19641952
if not _DEFAULTS_REGISTERED:
19651953
_register_defaults()
1954+
1955+
if int( bit_depth ) not in [ 8, 16 ]:
1956+
raise KeyError('Unregistered remap name `{}` with bit_depth `{}`'.format( remap_name, bit_depth ))
1957+
1958+
if int( bit_depth ) == 16:
1959+
rm_name = remap_name + '_' + str( bit_depth )
1960+
else:
1961+
rm_name = remap_name
1962+
1963+
if rm_name in _REMAP_DICT:
1964+
return _REMAP_DICT[ rm_name ]
19661965

1967-
if remap_name in newRegMap:
1968-
# Try new regerst map return class/Constructor
1969-
myFunc = newRegMap[ remap_name ]
1970-
newRemap = myFunc( remap_name, bit_depth)
1971-
return newRemap
1972-
1973-
if remap_name in _REMAP_DICT:
1974-
return _REMAP_DICT[remap_name]
19751966
if default is not None:
19761967
return default
19771968
raise KeyError('Unregistered remap name `{}`'.format(remap_name))

tests/visualization/test_remap.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,8 +329,31 @@ def test_remap_names(self):
329329
def test_get_registered_remap(self):
330330
with self.assertRaises(KeyError):
331331
remap.get_registered_remap("__fake__")
332-
self.assertEqual(remap.get_registered_remap("__fake__", "default"), "default")
332+
self.assertEqual(remap.get_registered_remap("__fake__", "default", 8 ), "default")
333+
334+
def test_get_registered_remap_required_param_only(self):
335+
self.assertEqual(remap.get_registered_remap("linear" ).name, "linear")
336+
337+
def test_get_registered_remap_required_param_default(self):
338+
self.assertEqual(remap.get_registered_remap("linear", "default" ).name, "linear")
339+
340+
def test_get_registered_remap_required_param_default_bit_depth(self):
341+
self.assertEqual(remap.get_registered_remap("linear" ).name, "linear")
342+
self.assertEqual(remap.get_registered_remap("linear" ).bit_depth, 8)
343+
344+
345+
def test_get_registered_remap_bitdepth_param(self):
346+
self.assertEqual(remap.get_registered_remap("linear", bit_depth= 16 ).name, "linear")
347+
self.assertEqual(remap.get_registered_remap("linear", bit_depth= 16 ).bit_depth, 16)
348+
349+
def test_get_registered_remap_falure_bitdepth_param(self):
350+
with self.assertRaises(KeyError):
351+
remap.get_registered_remap("linear", bit_depth= 32 )
333352

353+
def test_get_registered_remap_falure_not_registered(self):
354+
with self.assertRaises(KeyError):
355+
remap.get_registered_remap("steve" )
356+
334357
def test_get_remap_list(self):
335358
remap_list = remap.get_remap_list()
336359
self.assertSetEqual(set(item[0] for item in remap_list), set(remap.get_remap_names()))

0 commit comments

Comments
 (0)