Commit 935bf92d authored by jlaura's avatar jlaura Committed by GitHub
Browse files

Updates for ISD Generation (#28)

* Makes gdal an optional dependency

* Refactors all bae I/O into a single namespace.

* typos

* Fixes the gdal dependency test

* Adds tests for the JSON

* Tests fail without test data

* Updates for comments from @thareUSGS

* Adds ISIS3 V2 ControlNetwork Reader
parent 8f00a1f3
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
__version__ = "0.1.1"
__version__ = "0.1.2"

# Submodule imports
from . import io
+248 KiB

File added.

No diff preview for this file type.

+2 −0
Original line number Diff line number Diff line
SEMI_MAJOR_AXIS 3.39619000000000e+006
ECCENTRICITY 1.08339143554195e-001
 No newline at end of file
+940 −0

File added.

Preview size limit exceeded, changes collapsed.

+138 −87
Original line number Diff line number Diff line
import json
import re

import numpy as np
import pandas as pd

def socetset_keywords_to_json(keywords, ell=None):
    """
    Convert a SocetCet keywords.list file to JSON

    Parameters
    ----------
    keywords : str
               Path to the socetset keywords.list file

    Returns
    -------
     : str
       The serialized JSON string.
    """
    matcher = re.compile(r'\b(?!\d)\w+\b')
    numeric_matcher = re.compile(r'\W-?(?:0|[1-9]\d*)(?:\.\d*)?(?:[eE][+\-]?\d+)?')
    stream = {}

    def parse(fi):
        with open(fi, 'r') as f:
            for l in f:
                l = l.rstrip()
                if not l:
                    continue
                matches = matcher.findall(l)
                if matches:
                    key = matches[0]
                    stream[key] = []
                    # Case where the kw are strings after the key
                    if len(matches) > 1:
                        stream[key] = matches[1:]
                    # Case where the kw are numeric types after the key
                    else:
                        nums = numeric_matcher.findall(l)
                        if len(nums) == 1:
                            stream[key] = float(nums[0])
                        else:
                            stream[key] += map(float, nums)
                else:
                    # Case where the values are on a newline after the key
                    nums = numeric_matcher.findall(l)
                    stream[key] += map(float, nums)
    
    parse(keywords)
    if ell:
        parse(ell)
    return json.dumps(stream)
    
def read_gpf(input_data):
    """
    Read a socet gpf file into a pandas data frame
Loading