Skip to content

Commit d2307c7

Browse files
authored
Merge pull request #598 from ngageoint/staging
Fix for Issue 594
2 parents 727bfa0 + f9b90ca commit d2307c7

File tree

11 files changed

+393
-13
lines changed

11 files changed

+393
-13
lines changed

sarpy/__about__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
from sarpy.__details__ import __classification__, _post_identifier
3030

31-
__version__ = "1.3.61"
31+
__version__ = "1.3.61.1"
3232

3333
__author__ = "National Geospatial-Intelligence Agency"
3434
__url__ = "https://github.com/ngageoint/sarpy"

sarpy/processing/sidd/sidd_product_creation.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,9 @@ 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), version=version, remap_function=remap_function)
170+
product_class='Detected Image',
171+
pixel_type='MONO{}I'.format(remap_function.bit_depth), version=version,
172+
remap_function=remap_function)
171173
# set suggested name
172174
sidd_structure.NITF['SUGGESTED_NAME'] = ortho_helper.sicd.get_suggested_name(ortho_helper.index)+'_IMG'
173175

@@ -256,7 +258,8 @@ def create_csi_sidd(
256258
ortho_bounds = ortho_iterator.ortho_bounds
257259
sidd_structure = create_sidd_structure(
258260
ortho_helper, ortho_bounds,
259-
product_class='Color Subaperture Image', pixel_type='RGB24I', version=version, remap_function=remap_function)
261+
product_class='Color Subaperture Image', pixel_type='RGB24I',
262+
version=version, remap_function=remap_function)
260263
# set suggested name
261264
sidd_structure.NITF['SUGGESTED_NAME'] = csi_calculator.sicd.get_suggested_name(csi_calculator.index)+'_CSI'
262265

@@ -352,7 +355,9 @@ def create_dynamic_image_sidd(
352355
ortho_bounds = ortho_iterator.ortho_bounds
353356
sidd_structure = create_sidd_structure(
354357
ortho_helper, ortho_bounds,
355-
product_class='Dynamic Image', pixel_type='MONO{}I'.format(remap_function.bit_depth), version=version, remap_function=remap_function)
358+
product_class='Dynamic Image',
359+
pixel_type='MONO{}I'.format(remap_function.bit_depth), version=version,
360+
remap_function=remap_function)
356361
# set suggested name
357362
sidd_structure.NITF['SUGGESTED_NAME'] = subap_calculator.sicd.get_suggested_name(subap_calculator.index)+'__DI'
358363
the_sidds = []

sarpy/processing/sidd/sidd_structure_creation.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
from sarpy.io.product.sidd1_elements.Measurement import MeasurementType as MeasurementType1
5555
from sarpy.io.product.sidd1_elements.ExploitationFeatures import ExploitationFeaturesType as ExploitationFeaturesType1
5656
from sarpy.io.product.sidd1_elements.ProductCreation import ProductCreationType as ProductCreationType1
57+
import sarpy.visualization.remap as remap
5758

5859
logger = logging.getLogger(__name__)
5960

@@ -209,7 +210,8 @@ def _create_plane_projection_v3(proj_helper, bounds):
209210
#########################
210211
# Version 3 element creation
211212

212-
def create_sidd_structure_v3(ortho_helper, bounds, product_class, pixel_type, remap_function=None ):
213+
def create_sidd_structure_v3(ortho_helper, bounds, product_class, pixel_type,
214+
remap_function=remap.get_registered_remap('nrl')):
213215
"""
214216
Create a SIDD version 3.0 structure based on the orthorectification helper
215217
and pixel bounds.
@@ -224,6 +226,8 @@ def create_sidd_structure_v3(ortho_helper, bounds, product_class, pixel_type, re
224226
:code:`Dynamic Image, Amplitude Change Detection, Coherent Change Detection`
225227
pixel_type : str
226228
Must be one of `MONO8I, MONO16I` or `RGB24I`.
229+
remap_function: RemapFunction
230+
Must be an instantiation of the RemapFunction class see sarpy/visualation/remap
227231
228232
Returns
229233
-------
@@ -306,6 +310,8 @@ def _create_exploitation_v3():
306310
prod_create = ProductCreationType3.from_sicd(ortho_helper.proj_helper.sicd, product_class)
307311
prod_create.Classification.ISMCATCESVersion = '201903'
308312
prod_create.Classification.compliesWith = 'USGov'
313+
if not isinstance(remap_function, remap.RemapFunction):
314+
raise TypeError("Input 'remap_function' must be a remap.RemapFunction.")
309315

310316
# Display requires more product specifics
311317
display = _create_display_v3()
@@ -326,7 +332,8 @@ def _create_exploitation_v3():
326332
#########################
327333
# Version 2 element creation
328334

329-
def create_sidd_structure_v2(ortho_helper, bounds, product_class, pixel_type, remap_function=None ):
335+
def create_sidd_structure_v2(ortho_helper, bounds, product_class, pixel_type,
336+
remap_function=remap.get_registered_remap('nrl') ):
330337
"""
331338
Create a SIDD version 2.0 structure based on the orthorectification helper
332339
and pixel bounds.
@@ -341,6 +348,8 @@ def create_sidd_structure_v2(ortho_helper, bounds, product_class, pixel_type, re
341348
:code:`Dynamic Image, Amplitude Change Detection, Coherent Change Detection`
342349
pixel_type : str
343350
Must be one of `MONO8I, MONO16I` or `RGB24I`.
351+
remap_function: RemapFunction
352+
Must be an instantiation of the RemapFunction class see sarpy/visualation/remap
344353
345354
Returns
346355
-------
@@ -423,6 +432,8 @@ def _create_exploitation_v2():
423432
prod_create = ProductCreationType2.from_sicd(ortho_helper.proj_helper.sicd, product_class)
424433
prod_create.Classification.ISMCATCESVersion = '201903'
425434
prod_create.Classification.compliesWith = 'USGov'
435+
if not isinstance(remap_function, remap.RemapFunction):
436+
raise TypeError("Input 'remap_function' must be a remap.RemapFunction.")
426437

427438
# Display requires more product specifics
428439
display = _create_display_v2()
@@ -521,7 +532,8 @@ def _create_exploitation_v1():
521532
##########################
522533
# Switchable version SIDD structure
523534

524-
def create_sidd_structure(ortho_helper, bounds, product_class, pixel_type, version=3, remap_function=None):
535+
def create_sidd_structure(ortho_helper, bounds, product_class, pixel_type,
536+
version=3, remap_function=remap.get_registered_remap('nrl')):
525537
"""
526538
Create a SIDD structure, with version specified, based on the orthorectification
527539
helper and pixel bounds.
@@ -538,12 +550,15 @@ def create_sidd_structure(ortho_helper, bounds, product_class, pixel_type, versi
538550
Must be one of `MONO8I, MONO16I` or `RGB24I`.
539551
version : int
540552
The SIDD version, must be either 1, 2, or 3.
553+
remap_function: RemapFunction
554+
Must be an instantiation of the RemapFunction class see sarpy/visualation/remap
541555
542556
Returns
543557
-------
544558
SIDDType1|SIDDType2|SIDDType3
545559
"""
546-
560+
if not isinstance(remap_function, remap.RemapFunction):
561+
raise TypeError("Input 'remap_function' must be a remap.RemapFunction.")
547562
if version not in [1, 2, 3]:
548563
raise ValueError('version must be 1, 2, or 3. Got {}'.format(version))
549564

sarpy/visualization/remap.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1826,8 +1826,6 @@ def register_remap(
18261826
None
18271827
"""
18281828

1829-
if isinstance(remap_function, type) and issubclass(remap_function, RemapFunction):
1830-
remap_function = remap_function( bit_depth=bit_depth)
18311829
if not isinstance(remap_function, RemapFunction):
18321830
raise TypeError('remap_function must be an instance of RemapFunction.')
18331831

@@ -1925,20 +1923,28 @@ def get_remap_list() -> List[Tuple[str, RemapFunction]]:
19251923
# undesirable elements than this method
19261924
return [(the_key, the_value) for the_key, the_value in _REMAP_DICT.items()]
19271925

1928-
19291926
def get_registered_remap(
19301927
remap_name: str,
19311928
default: Optional[RemapFunction] = None,
19321929
bit_depth=8) -> RemapFunction:
19331930
"""
19341931
Gets a remap instance via its registered name.
1935-
# add 16 bit ability by newRegMap is dict of class/constructors
1932+
1933+
Results for the bit_depth parameter options
19361934
1935+
| Option | Remap name | bit_depth | Return |
1936+
|:------:|:-----------:|:---------:|:------:|
1937+
| 1 | linear | n/a | linear |
1938+
| 2 | linear | 8 | linear |
1939+
| 3 | linear | 16 | linera_16 |
1940+
| 4 | linear_16 | n/a | linear_16 |
1941+
| 5 | linera_16 | 16 | linear_16 |
19371942
19381943
Parameters
19391944
----------
19401945
remap_name : str
19411946
default : None|RemapFunction
1947+
bit_depth: int SIDD product pixel bit depth. Valid options are 8 and 16.
19421948
19431949
Returns
19441950
-------

tests/io/complex/sicd_elements/test_sicd_elements_blocks.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,12 @@ def test_blocks_poly1dtype(sicd, poly1d_doc, kwargs):
554554
poly.minimize_order()
555555
assert len(poly.Coefs) == 1
556556

557+
def test_blocks_poly1dtype__eq__(sicd, poly1d_doc, kwargs):
558+
# Smoke test
559+
poly01 = blocks.Poly1DType(Coefs=sicd.Position.ARPPoly.X.Coefs)
560+
poly02 = blocks.Poly1DType(Coefs=sicd.Position.ARPPoly.X.Coefs)
561+
assert(poly01 == poly02)
562+
557563

558564
def test_blocks_poly2dtype(sicd, poly2d_doc, kwargs):
559565
# Smoke test
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"SICD": [
3+
{"path": "sicd/sicd_example_1_PFA_RE32F_IM32F_HH.nitf", "path_type": "relative"},
4+
{"path": "sicd/sicd_example_RMA_RGZERO_RE16I_IM16I.nitf", "path_type": "relative"},
5+
{"path": "sicd/sicd_example_RMA_RGZERO_RE32F_IM32F_cropped_multiple_image_segments.nitf", "path_type": "relative"}]
6+
}
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
import json
2+
import os
3+
import pytest
4+
import unittest
5+
from tests import parse_file_entry
6+
7+
from sarpy.io.complex.converter import conversion_utility, open_complex
8+
from sarpy.processing.ortho_rectify import NearestNeighborMethod
9+
from sarpy.processing.sidd.sidd_product_creation import \
10+
create_detected_image_sidd, create_csi_sidd, create_dynamic_image_sidd
11+
import sarpy.visualization.remap as remap
12+
13+
complex_file_types = {}
14+
this_loc = os.path.abspath(__file__)
15+
# specifies file locations
16+
file_reference = os.path.join(os.path.split(this_loc)[0], \
17+
'complex_file_types.json')
18+
if os.path.isfile(file_reference):
19+
with open(file_reference, 'r') as local_file:
20+
test_files_list = json.load(local_file)
21+
for test_files_type in test_files_list:
22+
valid_entries = []
23+
for entry in test_files_list[test_files_type]:
24+
the_file = parse_file_entry(entry)
25+
if the_file is not None:
26+
valid_entries.append(the_file)
27+
complex_file_types[test_files_type] = valid_entries
28+
29+
sicd_files = complex_file_types.get('SICD', [])
30+
31+
def get_test_reader():
32+
input_file = sicd_files[0]
33+
reader = open_complex(input_file)
34+
return reader
35+
36+
37+
@unittest.skipIf(len(sicd_files) == 0, 'No sicd files found')
38+
def test_create_detected_image_sidd_required_params_only_success(tmp_path):
39+
local_reader = get_test_reader()
40+
ortho_helper = NearestNeighborMethod(local_reader, index=0)
41+
output_directory = tmp_path
42+
test_sidd = create_detected_image_sidd(ortho_helper, output_directory)
43+
44+
@unittest.skipIf(len(sicd_files) == 0, 'No sicd files found')
45+
def test_create_detected_image_sidd_required_params_and_output_file_success(tmp_path):
46+
local_reader = get_test_reader()
47+
ortho_helper = NearestNeighborMethod(local_reader, index=0)
48+
output_directory = tmp_path
49+
output_file = 'output.sidd'
50+
test_sidd = create_detected_image_sidd(ortho_helper, output_directory, output_file)
51+
52+
def test_create_detected_image_sidd_remap_function_fail(tmp_path):
53+
local_reader = get_test_reader()
54+
ortho_helper = NearestNeighborMethod(local_reader, index=0)
55+
output_directory = tmp_path
56+
output_file = 'output.sidd'
57+
local_remap_function = 'bob'
58+
with pytest.raises(TypeError,
59+
match="remap_function must be an instance of " + \
60+
"MonochromaticRemap"):
61+
test_sidd = create_detected_image_sidd(ortho_helper, output_directory, \
62+
output_file, \
63+
remap_function=local_remap_function)
64+
65+
def test_create_detected_image_sidd_remap_function_success(tmp_path):
66+
local_reader = get_test_reader()
67+
ortho_helper = NearestNeighborMethod(local_reader, index=0)
68+
output_directory = tmp_path
69+
output_file = 'output.sidd'
70+
local_remap_function = remap.get_registered_remap('nrl')
71+
test_sidd = create_detected_image_sidd(ortho_helper, output_directory, \
72+
output_file, \
73+
remap_function=local_remap_function)
74+
75+
@unittest.skipIf(len(sicd_files) == 0, 'No sicd files found')
76+
def test_create_csi_sidd_required_params_only_success(tmp_path):
77+
local_reader = get_test_reader()
78+
ortho_helper = NearestNeighborMethod(local_reader, index=0)
79+
output_directory = tmp_path
80+
test_sidd = create_csi_sidd(ortho_helper, output_directory)
81+
82+
@unittest.skipIf(len(sicd_files) == 0, 'No sicd files found')
83+
def test_create_csi_sidd_required_params_and_output_file_success(tmp_path):
84+
local_reader = get_test_reader()
85+
ortho_helper = NearestNeighborMethod(local_reader, index=0)
86+
output_directory = tmp_path
87+
output_file = 'output.sidd'
88+
test_sidd = create_csi_sidd(ortho_helper, output_directory, output_file)
89+
90+
def test_create_csi_sidd_remap_function_fail(tmp_path):
91+
local_reader = get_test_reader()
92+
ortho_helper = NearestNeighborMethod(local_reader, index=0)
93+
output_directory = tmp_path
94+
output_file = 'output.sidd'
95+
local_remap_function = 'bob'
96+
with pytest.raises(TypeError,
97+
match="remap_function must be an instance of " + \
98+
"MonochromaticRemap"):
99+
test_sidd = create_csi_sidd(ortho_helper, output_directory, \
100+
output_file, \
101+
remap_function=local_remap_function)
102+
103+
def test_create_csi_sidd_sidd_remap_function_success(tmp_path):
104+
local_reader = get_test_reader()
105+
ortho_helper = NearestNeighborMethod(local_reader, index=0)
106+
output_directory = tmp_path
107+
output_file = 'output.sidd'
108+
local_remap_function = remap.get_registered_remap('nrl')
109+
test_sidd = create_csi_sidd(ortho_helper, output_directory, \
110+
output_file, \
111+
remap_function=local_remap_function)
112+
113+
@unittest.skipIf(len(sicd_files) == 0, 'No sicd files found')
114+
def test_create_dynamic_image_sidd_required_params_only_success(tmp_path):
115+
local_reader = get_test_reader()
116+
ortho_helper = NearestNeighborMethod(local_reader, index=0)
117+
output_directory = tmp_path
118+
test_sidd = create_dynamic_image_sidd(ortho_helper, output_directory)
119+
120+
@unittest.skipIf(len(sicd_files) == 0, 'No sicd files found')
121+
def test_create_dynamic_image_sidd_required_params_and_output_file_success(tmp_path):
122+
local_reader = get_test_reader()
123+
ortho_helper = NearestNeighborMethod(local_reader, index=0)
124+
output_directory = tmp_path
125+
output_file = 'output.sidd'
126+
test_sidd = create_dynamic_image_sidd(ortho_helper, output_directory, output_file)
127+
128+
def test_create_dynamic_image_sidd_remap_function_fail(tmp_path):
129+
local_reader = get_test_reader()
130+
ortho_helper = NearestNeighborMethod(local_reader, index=0)
131+
output_directory = tmp_path
132+
output_file = 'output.sidd'
133+
local_remap_function = 'bob'
134+
with pytest.raises(TypeError,
135+
match="remap_function must be an instance of " + \
136+
"MonochromaticRemap"):
137+
test_sidd = create_dynamic_image_sidd(ortho_helper, output_directory, \
138+
output_file, \
139+
remap_function=local_remap_function)
140+
141+
def test_create_dynamic_image_sidd_remap_function_success(tmp_path):
142+
local_reader = get_test_reader()
143+
ortho_helper = NearestNeighborMethod(local_reader, index=0)
144+
output_directory = tmp_path
145+
output_file = 'output.sidd'
146+
local_remap_function = remap.get_registered_remap('nrl')
147+
test_sidd = create_dynamic_image_sidd(ortho_helper, output_directory, \
148+
output_file, \
149+
remap_function=local_remap_function)

0 commit comments

Comments
 (0)