Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ jobs:
- name: Set PATH
run: echo "${HOME}/.local/bin" >> $GITHUB_PATH

- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: "3.8"

- name: Install dependencies
run: |
curl -sSL https://install.python-poetry.org | python - --version 1.2.2
curl -sSL https://install.python-poetry.org | python - --version 1.8.1
poetry install

- name: Run tests
Expand Down
14 changes: 7 additions & 7 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ jobs:
- name: Set PATH
run: echo "${HOME}/.local/bin" >> $GITHUB_PATH

- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Cache pip
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('pyproject.toml') }}-${{ hashFiles('poetry.lock') }}-${ GITHUB_REF }
Expand All @@ -30,7 +30,7 @@ jobs:

- name: Install dependencies
run: |
curl -sSL https://install.python-poetry.org | python - --version 1.2.2
curl -sSL https://install.python-poetry.org | python - --version 1.8.1
poetry install

- name: Run tests
Expand All @@ -48,14 +48,14 @@ jobs:
python-version: [3.8]

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Cache pip
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('docs/source/requirements.txt') }}-${ GITHUB_REF }
Expand Down
27 changes: 14 additions & 13 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,23 @@
#
import os
import sys
sys.path.insert(0, os.path.abspath('../..'))

sys.path.insert(0, os.path.abspath("../.."))
sys.setrecursionlimit(1500)


# -- Project information -----------------------------------------------------

project = 'kmm'
copyright = '2020, Aiwizo'
author = 'Richard Löwenström, Felix Abrahamsson'
project = "kmm"
copyright = "2020, Aiwizo"
author = "Richard Löwenström, Felix Abrahamsson"

# The full version, including alpha/beta/rc tags
# release = '0.1.0'
from pkg_resources import get_distribution, DistributionNotFound

try:
release = get_distribution('kmm').version
release = get_distribution("kmm").version
except DistributionNotFound:
pass

Expand All @@ -37,23 +39,23 @@
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.autosummary',
'recommonmark',
'sphinx.ext.viewcode',
'sphinx_rtd_theme',
"sphinx.ext.autodoc",
"sphinx.ext.autosummary",
"recommonmark",
"sphinx.ext.viewcode",
"sphinx_rtd_theme",
]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
templates_path = ["_templates"]

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = []

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
pygments_style = "sphinx"

# -- Options for HTML output -------------------------------------------------

Expand All @@ -68,4 +70,3 @@
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
# html_static_path = ['_static']

6 changes: 1 addition & 5 deletions kmm/header/car_direction.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@
def car_direction(tree: ElementTree):

root = tree.getroot()
start_tags = [
child.text
for child in root
if child.tag == "Start"
]
start_tags = [child.text for child in root if child.tag == "Start"]

if len(start_tags) != 1:
raise ValueError(f"Expected 1 'Start' tag in header, found {len(start_tags)}")
Expand Down
6 changes: 1 addition & 5 deletions kmm/header/position_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@
def position_sync(tree: ElementTree):

root = tree.getroot()
sync_tags = [
child.text
for child in root
if child.tag == "Sync"
]
sync_tags = [child.text for child in root if child.tag == "Sync"]

if len(sync_tags) == 0:
raise ValueError("Did not find a Sync tag in header.")
Expand Down
12 changes: 10 additions & 2 deletions kmm/positions/positions.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class Config:
def from_path(
path: Path,
raise_on_malformed_data: bool = True,
replace_commas: bool = True,
):
"""
Loads positions from .kmm or .kmm2 file.
Expand All @@ -26,7 +27,9 @@ def from_path(
dataframe = kmm.positions.read_kmm(path)
elif path.suffix == ".kmm2":
dataframe = kmm.positions.read_kmm2(
path, raise_on_malformed_data=raise_on_malformed_data
path,
raise_on_malformed_data=raise_on_malformed_data,
replace_commas=replace_commas,
)
else:
raise ValueError(f"Unable to parse file type {path.suffix}")
Expand All @@ -40,14 +43,19 @@ def read_sync_adjust(
header_path: Path,
adjustment: kmm.PositionAdjustment = kmm.PositionAdjustment.WIRE_CAMERA,
raise_on_malformed_data: bool = True,
replace_commas: bool = True,
):
"""
Loads positions from .kmm or .kmm2 file + .hdr file, then performs
frame index sync, position adjustment and geodetic coordinate transformation.
"""
header = kmm.Header.from_path(header_path, raise_on_malformed_data)
return (
Positions.from_path(kmm_path, raise_on_malformed_data)
Positions.from_path(
kmm_path,
raise_on_malformed_data=raise_on_malformed_data,
replace_commas=replace_commas,
)
.sync_frame_index(header, adjustment, raise_on_malformed_data)
.geodetic()
)
Expand Down
14 changes: 11 additions & 3 deletions kmm/positions/read_kmm.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from io import StringIO
from pathlib import Path

import numpy as np
Expand All @@ -6,12 +7,19 @@


@validate_arguments
def read_kmm(path: Path):
def read_kmm(path: Path, replace_commas: bool = True):
try:
if replace_commas:
with open(path, "r", encoding="latin1") as f:
content = f.read()
content = content.replace(",", ".")
file_obj = StringIO(content)
else:
file_obj = path
return pd.read_csv(
path,
file_obj,
sep="\t",
encoding="latin1",
encoding="latin1" if not replace_commas else None,
names=[
"centimeter",
"track_section",
Expand Down
18 changes: 15 additions & 3 deletions kmm/positions/read_kmm2.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import re
from io import StringIO
from pathlib import Path

import numpy as np
Expand Down Expand Up @@ -46,7 +47,9 @@


@validate_arguments
def read_kmm2(path: Path, raise_on_malformed_data: bool = True):
def read_kmm2(
path: Path, raise_on_malformed_data: bool = True, replace_commas: bool = True
):
skiprows = [
index
for index, line in enumerate(path.read_text(encoding="latin1").splitlines())
Expand All @@ -58,13 +61,22 @@ def read_kmm2(path: Path, raise_on_malformed_data: bool = True):
skiprows = [0] + skiprows
elif raise_on_malformed_data and not line.startswith("POS"):
raise ValueError("Malformed data, first line is not POS or VER")

try:
if replace_commas:
with open(path, "r", encoding="latin1") as f:
content = f.read()
content = content.replace(",", ".")
file_obj = StringIO(content)
else:
file_obj = path

try:
df = pd.read_csv(
path,
file_obj,
skiprows=skiprows,
delimiter="\t",
encoding="latin1",
encoding="latin1" if not replace_commas else None,
low_memory=False,
header=None,
)
Expand Down
Loading