-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
234 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import re | ||
from argparse import ArgumentParser | ||
from pathlib import Path | ||
|
||
from damast.cli.base import BaseParser | ||
from damast.core.annotations import Annotation | ||
from damast.core.dataframe import DAMAST_SPEC_SUFFIX, AnnotatedDataFrame | ||
from damast.core.metadata import DataSpecification, MetaData | ||
|
||
|
||
class DataAnnotateParser(BaseParser): | ||
""" | ||
Argparser for creation of the specification / annotating an AnnotatedDataFrame | ||
:param parser: The base parser | ||
""" | ||
|
||
def __init__(self, parser: ArgumentParser): | ||
super().__init__(parser=parser) | ||
|
||
parser.description = "damast annotate - data annotation subcommand called" | ||
parser.add_argument("-f", "--filename", | ||
help="Filename or pattern of the (annotated) data file that should be annotated", | ||
required=True | ||
) | ||
parser.add_argument("-i", "--interactive", | ||
help="Perform the annotation interactively", | ||
default=False, | ||
required=False) | ||
|
||
parser.add_argument("-o", "--output-dir", | ||
help="Output directory", | ||
default=None, | ||
required=False) | ||
|
||
|
||
def execute(self, args): | ||
super().execute(args) | ||
|
||
base = Path(args.filename).parent | ||
name = Path(args.filename).name | ||
files = [x for x in base.glob(name)] | ||
|
||
sum_st_size = 0 | ||
for idx, file in enumerate(files, start=1): | ||
sum_st_size += file.stat().st_size | ||
|
||
print(f"Loading dataframe ({len(files)} files) of total size: {sum_st_size / (1024**2):.2f} MB") | ||
|
||
adf = AnnotatedDataFrame.from_file(filename=args.filename, metadata_required=False) | ||
print(adf.head(10).collect()) | ||
|
||
metadata_filename = Path(args.filename).with_suffix(DAMAST_SPEC_SUFFIX) | ||
if args.output_dir is not None: | ||
output_dir = Path(args.output_dir) | ||
output_dir.mkdir(parents=True, exist_ok=True) | ||
|
||
metadata_filename = output_dir / metadata_filename.name | ||
|
||
metadata = AnnotatedDataFrame.infer_annotation(df=adf.dataframe) | ||
metadata.add_annotation( | ||
Annotation( | ||
name=Annotation.Key.Source, | ||
value=args.filename | ||
) | ||
) | ||
metadata.save_yaml(metadata_filename) | ||
|
||
print(f"Created {metadata_filename}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
columns: | ||
- name: mmsi | ||
is_optional: false | ||
representation_type: Int64 | ||
value_range: | ||
MinMax: | ||
min: 209318000 | ||
max: 230666000 | ||
allow_missing: true | ||
- name: imo_nr | ||
is_optional: false | ||
representation_type: Int64 | ||
value_range: | ||
MinMax: | ||
min: 8911736 | ||
max: 9754446 | ||
allow_missing: true | ||
- name: length | ||
is_optional: false | ||
representation_type: Int64 | ||
value_range: | ||
MinMax: | ||
min: 89 | ||
max: 170 | ||
allow_missing: true | ||
- name: date_time_utc | ||
is_optional: false | ||
representation_type: String | ||
- name: lon | ||
is_optional: false | ||
representation_type: Float64 | ||
value_range: | ||
MinMax: | ||
min: 5.25503 | ||
max: 5.54976 | ||
allow_missing: true | ||
- name: lat | ||
is_optional: false | ||
representation_type: Float64 | ||
value_range: | ||
MinMax: | ||
min: 58.7635 | ||
max: 59.407 | ||
allow_missing: true | ||
- name: sog | ||
is_optional: false | ||
representation_type: Float64 | ||
value_range: | ||
MinMax: | ||
min: 9.4 | ||
max: 18.0 | ||
allow_missing: true | ||
- name: cog | ||
is_optional: false | ||
representation_type: Float64 | ||
value_range: | ||
MinMax: | ||
min: 2.9 | ||
max: 355.7 | ||
allow_missing: true | ||
- name: true_heading | ||
is_optional: false | ||
representation_type: Int64 | ||
value_range: | ||
MinMax: | ||
min: 6 | ||
max: 359 | ||
allow_missing: true | ||
- name: nav_status | ||
is_optional: false | ||
representation_type: Int64 | ||
value_range: | ||
MinMax: | ||
min: 0 | ||
max: 0 | ||
allow_missing: true | ||
- name: message_nr | ||
is_optional: false | ||
representation_type: Int64 | ||
value_range: | ||
MinMax: | ||
min: 1 | ||
max: 1 | ||
allow_missing: true | ||
annotations: | ||
source: tests/damast/data/test_ais.csv |