Skip to content

Commit

Permalink
v0.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
m-mohr committed Feb 16, 2024
1 parent 9e6f39f commit 3a2abc4
Show file tree
Hide file tree
Showing 11 changed files with 484 additions and 386 deletions.
26 changes: 26 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# EditorConfig is awesome: http://EditorConfig.org

# top-most EditorConfig file
root = true

# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
charset = utf-8

# 4 space indentation
[*.py]
indent_style = space
indent_size = 4

# 2 space indentation
[*.{json,yaml}]
indent_style = space
indent_size = 2

[*.md]
trim_trailing_whitespace = false
indent_style = space
indent_size = 2
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,16 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

- ...

## [v0.0.2] - 2024-02-16

- Basic validation for collection
- Minimal validation for data
- Fixed creation of GeoParquet files

## [v0.0.1] - 2024-02-16

- First release

[Unreleased]: <https://github.com/radiantearth/stac-spec/compare/v0.0.1...main>
[Unreleased]: <https://github.com/radiantearth/stac-spec/compare/v0.0.2...main>
[v0.0.2]: <https://github.com/radiantearth/stac-spec/compare/v0.0.1...v0.0.2>
[v0.0.1]: <https://github.com/radiantearth/stac-spec/tree/v0.0.1>
127 changes: 84 additions & 43 deletions fiboa_cli/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import click
import sys

from .validate import validate as validate_
from .create import create as create_
Expand All @@ -8,58 +9,98 @@
@click.group()
@click.version_option(version=__version__)
def cli():
"""
A simple CLI app.
"""
pass
"""
A simple CLI app.
"""
pass

@click.command()
@click.argument('files', nargs=-1, callback=valid_files_for_cli)
@click.option('--schema', '-s', type=click.Path(exists=True), help='fiboa Schema to validate against. Can be a local file or a URL. If not provided, uses the fiboa version to load the schema for the released version.')
@click.option('--fiboa-version', '-f', type=click.STRING, help='The fiboa version to validate against. Default is the version given in the collection.', default=None)
@click.option('--collection', '-c', type=click.Path(exists=True), help='Points to the STAC collection that defines the fiboa version and extensions.', default=None)
@click.option('--verbose', '-v', type=click.BOOL, help='Run with verbose logging.', default=False)
def validate(files, schema, fiboa_version, collection, verbose):
"""
Validates a fiboa GeoParquet file.
"""
log(f"fiboa CLI {__version__} - Validator\n", "success")
config = {
"schema": schema,
"fiboa_version": fiboa_version,
"collection": collection,
"verbose": verbose
}
for file in files:
log(f"Validating {file}", "info")
try:
result = validate_(file, config)
if result:
log(f" => VALID\n", "success")
else:
log(f" => INVALID\n", "error")
except Exception as e:
log(f" => UNKNOWN: {e}\n", "error")
@click.option(
'--schema', '-s',
type=click.Path(exists=True),
help='fiboa Schema to validate against. Can be a local file or a URL. If not provided, uses the fiboa version to load the schema for the released version.'
)
@click.option(
'--fiboa-version', '-f',
type=click.STRING,
help='The fiboa version to validate against. Default is the version given in the collection.',
default=None
)
@click.option(
'--collection', '-c',
type=click.Path(exists=True),
help='Points to the STAC collection that defines the fiboa version and extensions.',
default=None
)
@click.option(
'--data', '-d',
is_flag=True,
type=click.BOOL,
help='Validate the data in the file. Enabling this might be slow. Default is False.',
default=False
)
def validate(files, schema, fiboa_version, collection, data):
"""
Validates a fiboa GeoParquet file.
"""
log(f"fiboa CLI {__version__} - Validator\n", "success")
config = {
"schema": schema,
"fiboa_version": fiboa_version,
"collection": collection,
"data": data
}
for file in files:
log(f"Validating {file}", "info")
try:
result = validate_(file, config)
if result:
log(" => VALID\n", "success")
else:
log(" => INVALID\n", "error")
sys.exit(1)
except Exception as e:
log(f" => UNKNOWN: {e}\n", "error")
sys.exit(2)

@click.command()
@click.argument('files', nargs=-1, callback=valid_files_for_cli)
@click.option('--out', '-o', type=click.Path(exists=False), help='File to write the file to. If not provided, prints the file to the STDOUT.', required=True)
@click.option('--collection', '-c', callback=valid_file_for_cli, help='Points to the STAC collection that defines the fiboa version and extensions.', required=True)
@click.option('--schema', '-s', type=click.Path(exists=True), help='fiboa Schema to work against. If not provided, uses the fiboa version from the collection to load the schema for the released version.')
@click.option(
'--out', '-o',
type=click.Path(exists=False),
help='File to write the file to. If not provided, prints the file to the STDOUT.',
required=True
)
@click.option(
'--collection', '-c',
callback=valid_file_for_cli,
help='Points to the STAC collection that defines the fiboa version and extensions.',
required=True
)
@click.option(
'--schema', '-s',
type=click.Path(exists=True),
help='fiboa Schema to work against. If not provided, uses the fiboa version from the collection to load the schema for the released version.'
)
def create(files, out, collection, schema):
"""
Create a fiboa file from GeoJSON file(s).
"""
config = {
"files": files,
"out": out,
"schema": schema,
"collection": collection
}
create_(config)
"""
Create a fiboa file from GeoJSON file(s).
"""
config = {
"files": files,
"out": out,
"schema": schema,
"collection": collection
}
try:
create_(config)
except Exception as e:
log(e, "error")
sys.exit(1)

cli.add_command(validate)
cli.add_command(create)

if __name__ == '__main__':
cli()
cli()
130 changes: 65 additions & 65 deletions fiboa_cli/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,79 +3,79 @@
import pandas as pd

GP_TYPE_MAP = {
"boolean": "bool",
"int8": "int8",
"uint8": "uint8",
"int16": "int16",
"uint16": "uint16",
"int32": "int32",
"uint32": "uint32",
"int64": "int64",
"uint64": "uint64",
"float": "float32",
"double": "float64",
"binary": "bytearray", # todo: check
"string": "str",
"array": None, # todo: object?
"object": "object",
"enum": "category", # todo: check
"date": "datetime64[D]",
"date-time": lambda x: pd.to_datetime(x),
"geometry": None, # not a column, don't convert geometry
"bounding-box": None # todo
"boolean": "bool",
"int8": "int8",
"uint8": "uint8",
"int16": "int16",
"uint16": "uint16",
"int32": "int32",
"uint32": "uint32",
"int64": "int64",
"uint64": "uint64",
"float": "float32",
"double": "float64",
"binary": "bytearray", # todo: check
"string": "str",
"array": None, # todo: object?
"object": "object",
"enum": "category", # todo: check
"date": "datetime64[D]",
"date-time": lambda x: pd.to_datetime(x),
"geometry": None, # not a column, don't convert geometry
"bounding-box": None # todo
}

PA_TYPE_MAP = {
"boolean": pa.bool_(),
"int8": pa.int8(),
"uint8": pa.uint8(),
"int16": pa.int16(),
"uint16": pa.uint16(),
"int32": pa.int32(),
"uint32": pa.uint32(),
"int64": pa.int64(),
"uint64": pa.uint64(),
"float": pa.float32(),
"double": pa.float64(),
"binary": pa.binary(),
"string": pa.string(),
"array": lambda type: pa.list_(type),
"object": None, # todo: lambda type: pa.map_(pa.string(), type)
"enum": None, # todo: ENUM (BYTE_ARRAY)
"date": pa.date32(),
"date-time": pa.timestamp("ms", tz="UTC"),
"geometry": pa.binary(),
"bounding-box": None # todo
"boolean": pa.bool_(),
"int8": pa.int8(),
"uint8": pa.uint8(),
"int16": pa.int16(),
"uint16": pa.uint16(),
"int32": pa.int32(),
"uint32": pa.uint32(),
"int64": pa.int64(),
"uint64": pa.uint64(),
"float": pa.float32(),
"double": pa.float64(),
"binary": pa.binary(),
"string": pa.string(),
"array": lambda type: pa.list_(type),
"object": None, # todo: lambda type: pa.map_(pa.string(), type)
"enum": None, # todo: ENUM (BYTE_ARRAY)
"date": pa.date32(),
"date-time": pa.timestamp("ms", tz="UTC"),
"geometry": pa.binary(),
"bounding-box": None # todo
}

PA_TYPE_CHECK = {
"boolean": pat.is_boolean,
"int8": pat.is_int8,
"uint8": pat.is_uint8,
"int16": pat.is_int16,
"uint16": pat.is_uint16,
"int32": pat.is_int32,
"uint32": pat.is_uint32,
"int64": pat.is_int64,
"uint64": pat.is_uint64,
"float": pat.is_float32,
"double": pat.is_float64,
"binary": pat.is_binary,
"string": pat.is_string,
"array": pat.is_list,
"object": pat.is_map,
"enum": None, # ENUM (BYTE_ARRAY)
"date": pat.is_date32,
"date-time": pat.is_timestamp,
"geometry": pat.is_binary, # todo: check more?
"bounding-box": None # todo
"boolean": pat.is_boolean,
"int8": pat.is_int8,
"uint8": pat.is_uint8,
"int16": pat.is_int16,
"uint16": pat.is_uint16,
"int32": pat.is_int32,
"uint32": pat.is_uint32,
"int64": pat.is_int64,
"uint64": pat.is_uint64,
"float": pat.is_float32,
"double": pat.is_float64,
"binary": pat.is_binary,
"string": pat.is_string,
"array": pat.is_list,
"object": pat.is_map,
"enum": None, # ENUM (BYTE_ARRAY)
"date": pat.is_date32,
"date-time": pat.is_timestamp,
"geometry": pat.is_binary, # todo: check more?
"bounding-box": None # todo
}

LOG_STATUS_COLOR = {
"info": "white",
"warning": "yellow",
"error": "red",
"success": "green"
"info": "white",
"warning": "yellow",
"error": "red",
"success": "green"
}

SUPPORTED_PROTOCOLS = ["http", "https", "s3", "gs"]
SUPPORTED_PROTOCOLS = ["http", "https", "s3", "gs"]
Loading

0 comments on commit 3a2abc4

Please sign in to comment.