Commit 3a2219eb authored by Tyler Thatcher's avatar Tyler Thatcher Committed by GitHub
Browse files

Merge pull request #105 from jlaura/master

Fixes #104
parents 52c5322b a2a38107
Loading
Loading
Loading
Loading
+553 −0

File added.

Preview size limit exceeded, changes collapsed.

+117 KiB

File added.

No diff preview for this file type.

+16 −5
Original line number Original line Diff line number Diff line
@@ -24,7 +24,7 @@ class Spectral_Profiler(object):
              with key as the spectra index and value as the start byte offset
              with key as the spectra index and value as the start byte offset
    """
    """


    def __init__(self, input_data, cleaned=True, qa_threshold=2000):
    def __init__(self, input_data, label=None, cleaned=True, qa_threshold=2000):
        """
        """
        Read the .spc file, parse the label, and extract the spectra
        Read the .spc file, parse the label, and extract the spectra


@@ -34,6 +34,9 @@ class Spectral_Profiler(object):
        input_data : string
        input_data : string
                     The PATH to the input .spc file
                     The PATH to the input .spc file


        label : string
                The PATH to an optional detached label associated with the .spc

        cleaned : boolean
        cleaned : boolean
                  If True, mask the data based on the QA array.
                  If True, mask the data based on the QA array.


@@ -49,7 +52,9 @@ class Spectral_Profiler(object):
                        'MSB_INTEGER':'i',
                        'MSB_INTEGER':'i',
                        'MSB_UNSIGNED_INTEGER':'u'}
                        'MSB_UNSIGNED_INTEGER':'u'}



        if label:
            label = pvl.load(label)
        else:
            label = pvl.load(input_data)
            label = pvl.load(input_data)
        self.label = label
        self.label = label
        self.input_data = input_data
        self.input_data = input_data
@@ -63,7 +68,10 @@ class Spectral_Profiler(object):
            columns = []
            columns = []
            bytelengths = []
            bytelengths = []
            datatypes = []
            datatypes = []
            ancillary_data_offset = find_in_dict(label, "^ANCILLARY_AND_SUPPLEMENT_DATA").value
            try:
                ancillary_data_offset = find_in_dict(self.label, "^ANCILLARY_AND_SUPPLEMENT_DATA").value
            except:
                ancillary_data_offset = find_in_dict(self.label, "^ANCILLARY_AND_SUPPLEMENT_DATA")[1].value
            indata.seek(ancillary_data_offset - 1)
            indata.seek(ancillary_data_offset - 1)
            for i in ancillary_data.items():
            for i in ancillary_data.items():
                if i[0] == 'COLUMN':
                if i[0] == 'COLUMN':
@@ -109,7 +117,10 @@ class Spectral_Profiler(object):
                search_key = '^SP_SPECTRUM_{}'.format(d)
                search_key = '^SP_SPECTRUM_{}'.format(d)
                result = find_in_dict(label, search_key)
                result = find_in_dict(label, search_key)
                if result:
                if result:
                    try:
                        array_offsets.append(result.value)
                        array_offsets.append(result.value)
                    except:
                        array_offsets.append(result[1].value) # 2C V3.0
                    keys.append('SP_SPECTRUM_{}'.format(d))
                    keys.append('SP_SPECTRUM_{}'.format(d))


            offsets = dict(zip(keys, array_offsets))
            offsets = dict(zip(keys, array_offsets))
+11 −0
Original line number Original line Diff line number Diff line
@@ -30,5 +30,16 @@ class Test_Spectral_Profiler_IO(unittest.TestCase):
        self.assertIsInstance(ds.browse, GeoDataset)
        self.assertIsInstance(ds.browse, GeoDataset)
        self.assertEqual(ds.browse.read_array().shape, (512, 456))
        self.assertEqual(ds.browse.read_array().shape, (512, 456))


class Test_Spectral_Profiler_IO_Detached(unittest.TestCase):
    
    def setUp(self):
        self.examplefile = get_path('SP_2C_03_04184_N187_E0053.spc')
        self.examplelabel = get_path('SP_2C_03_04184_N187_E0053.lbl')
        
    def test_openspc(self):
        ds = io_spectral_profiler.Spectral_Profiler(self.examplefile, self.examplelabel)
        self.assertEqual(ds.nspectra, 38)
        self.assertEqual(ds.spectra[0].columns.tolist(), ['RAW', 'REF1', 'REF2', 'QA', 'RAD'])

if __name__ == '__main__':
if __name__ == '__main__':
    unittest.main()
    unittest.main()
+1 −1
Original line number Original line Diff line number Diff line
@@ -8,7 +8,7 @@ with open('README.md', 'r') as f:
def setup_package():
def setup_package():
    setup(
    setup(
        name = "plio",
        name = "plio",
        version = '1.1.0',
        version = '1.2.0',
        author = "Jay Laura",
        author = "Jay Laura",
        author_email = "jlaura@usgs.gov",
        author_email = "jlaura@usgs.gov",
        description = ("I/O API to support planetary data formats."),
        description = ("I/O API to support planetary data formats."),