Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop method for identifying STAC object type and version number #47

Closed
lossyrob opened this issue Nov 6, 2019 · 2 comments · Fixed by #50
Closed

Develop method for identifying STAC object type and version number #47

lossyrob opened this issue Nov 6, 2019 · 2 comments · Fixed by #50

Comments

@lossyrob
Copy link
Member

lossyrob commented Nov 6, 2019

Develop a method that takes in a dict, and returns a tuple (object_type, version, [extensions]).

This will be used to identify the STAC objects that are contained in dictionaries. This will be useful for two things:

This method is probably not going to be very pretty - it's hard to imagine a version that is a set of conditionals that looks like when you take headphones out of a messy drawer. The idea is, if we put this method in PySTAC, we can centralize that messy logic to one place so that no duplicates have to exist. This follows what I call the One Monster Rule: if you're going to create a monster, make sure it's only created once.

Another approach we tries was to use jsonschema with a large combined oneOf reference that included all schemas from the STAC repo - jsonschema will try to validate each of the schemas to determine what works. However, if multiple schemas pass validation, this throws an error, which makes a lot of sense.

Any suggestions on how to better solve this are welcome!

/cc Team Validation @ the Arlington STAC Sprint @jbants @anayeaye

@lossyrob
Copy link
Member Author

lossyrob commented Nov 6, 2019

Incomplete strawdog I'm using while developing the stac-spec example validation:

class ObjectType:
    CATALOG = 'CATALOG'
    COLLECTION = 'COLLECTION'
    ITEM = 'ITEM'
    ITEMCOLLECTION = 'ITEMCOLLECTION'

def identify_stac_object(d):
    """Determines they object type, version, and extensions of the STAC Object
    represented by a dictionary.

    Args:
        d (dict): The dict to identify

    Returns:
        Tuple[str, str, List[str]]: Tuple of (object_type, version, extensions)
    """
    stac_version = d.get('stac_version', None)
    stac_extensions = set(d.get('stac_extensions', []))
    object_type = None
    if 'type' in d:
        if d['type'] == 'FeatureCollection':
            object_type = ObjectType.ITEMCOLLECTION

            if 'collections' in d:
                extensions.add('single-file-stac')
        else:
            object_type = ObjectType.ITEM
    elif 'extent' in d:
        object_type = ObjectType.COLLECTION
    else:
        object_type = ObjectType.CATALOG

    return (object_type, stac_version, stac_extensions)

@jbants
Copy link

jbants commented Nov 6, 2019

This is the issue I was describing about relative paths and refs.
python-jsonschema/jsonschema#343

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants