Skip to content

Commit

Permalink
Merge pull request #2 from HakaiInstitute/update-deps
Browse files Browse the repository at this point in the history
Update dependencies, switch to Python 3.11
  • Loading branch information
tayden authored Aug 2, 2023
2 parents 84f483f + 915143a commit db39c2a
Show file tree
Hide file tree
Showing 18 changed files with 683 additions and 359 deletions.
24 changes: 12 additions & 12 deletions .github/workflows/gui-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ jobs:
runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: Set up Python 3.9
- name: Set up Python 3.11
uses: actions/setup-python@v4
with:
python-version: "3.9"
python-version: "3.11"

- name: Setup Poetry
uses: abatilo/actions-poetry@v2.0.0
uses: abatilo/actions-poetry@v2.3.0
with:
poetry-version: 1.2.2

Expand All @@ -38,13 +38,13 @@ jobs:
- name: Install Linux dependencies
if: ${{ runner.os == 'Linux' }}
run: >
sudo apt-get install
'^libxcb.*-dev'
libx11-xcb-dev
libglu1-mesa-dev
libxrender-dev
libxi-dev
libxkbcommon-dev
sudo apt-get install
'^libxcb.*-dev'
libx11-xcb-dev
libglu1-mesa-dev
libxrender-dev
libxi-dev
libxkbcommon-dev
libxkbcommon-x11-dev
- name: Install dependencies
Expand Down Expand Up @@ -86,7 +86,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: Get tag
id: tag
Expand Down
2 changes: 1 addition & 1 deletion .idea/Las-TRX.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/aws.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/other.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/watcherTasks.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-added-large-files
- repo: https://github.com/python-poetry/poetry
rev: 1.4.0
hooks:
- id: poetry-check
- id: poetry-lock
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.265
hooks:
- id: ruff
args: [ --fix ]
- repo: https://github.com/psf/black
rev: 23.3.0
hooks:
- id: black
13 changes: 7 additions & 6 deletions las_trx/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
sync_missing_grid_files,
utm_zone_to_coord_type,
resource_path,
get_upgrade_version
get_upgrade_version,
)
from las_trx.worker import TransformWorker

Expand All @@ -50,7 +50,8 @@ def __init__(self):
self.label_upgrade_link.setText(
f"<a href=\"{upgrade_version['html_url']}\">"
f"New version available (v{upgrade_version['tag_name']})"
f"</a>")
f"</a>"
)

self.done_msg_box = QMessageBox(self)
self.done_msg_box.setText("File(s) converted successfully")
Expand Down Expand Up @@ -287,15 +288,15 @@ def run(self):
window = MainWindow()

if os.getenv("DEBUG"):
# self.lineEdit_input_file.setText(
# "/mnt/aco-uvic/2020_Acquisitions/02_processed/20_3028_01_FraserRiver_ChimmneyCreek_WestWilliams_Canyon/01_LiDAR/01_Deliverables/02_QC/02_Classified_tiles/546000_5768000_5m_stp_arch_grnd_denoised.laz")
window.lineEdit_input_file.setText(
"/home/taylor/PycharmProjects/Las-TRX/testfiles/20_3028_01/*.laz")
"/home/taylor/PycharmProjects/Las-TRX/testfiles/20_3028_01/*.laz"
)
window.comboBox_input_reference.setCurrentText("ITRF2014")
window.dateEdit_input_epoch.setDate(date(2020, 8, 12))

window.lineEdit_output_file.setText(
"/home/taylor/PycharmProjects/Las-TRX/testfiles/20_3028_01_converted/{}.laz")
"/home/taylor/PycharmProjects/Las-TRX/testfiles/20_3028_01_converted/{}.laz"
)
window.checkBox_epoch_trans.setChecked(True)
window.dateEdit_output_epoch.setEnabled(True)
window.dateEdit_output_epoch.setDate(date(2002, 1, 1))
Expand Down
16 changes: 12 additions & 4 deletions las_trx/config.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from datetime import date
from typing import Union

from pydantic import BaseModel, validator
from pydantic import BaseModel, field_validator, FieldValidationInfo
from pyproj.crs import (
CRS,
CompoundCRS,
Expand All @@ -27,9 +27,17 @@ class TransformConfig(BaseModel):
s_coords: Union[enums.CoordType, str]
t_coords: Union[enums.CoordType, str]

# validators
_normalize_s_epoch = validator("s_epoch", allow_reuse=True)(date_to_decimal_year)
_normalize_t_epoch = validator("t_epoch", allow_reuse=True)(date_to_decimal_year)
@classmethod
@field_validator("s_epoch", "t_epoch")
def check_decimal_date(
cls, v: Union[float, date], info: FieldValidationInfo
) -> float:
if isinstance(v, float):
return v
elif isinstance(v, date):
return date_to_decimal_year(v)
else:
raise TypeError(f"Invalid type for {info.field_name}: {type(v)}")

@property
def t_crs(self) -> CRS:
Expand Down
17 changes: 9 additions & 8 deletions las_trx/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ def date_to_decimal_year(d: date) -> float:
...


def date_to_decimal_year(d: T) -> T:
if not isinstance(d, date):
return d
def date_to_decimal_year(d: date) -> float:
year_part = d - date(d.year, 1, 1)
year_length = date(d.year + 1, 1, 1) - date(d.year, 1, 1)
return d.year + year_part / year_length
Expand Down Expand Up @@ -138,12 +136,14 @@ def resource_path(relative_path):

def _get_available_versions() -> Optional[List[Mapping[str, Any]]]:
import requests

headers = {
"Accept": "application/vnd.github+json",
"X-GitHub-Api-Version": "2022-11-28"
"X-GitHub-Api-Version": "2022-11-28",
}
r = requests.get("https://api.github.com/repos/HakaiInstitute/LAS-TRX/releases",
headers=headers)
r = requests.get(
"https://api.github.com/repos/HakaiInstitute/LAS-TRX/releases", headers=headers
)
if r.status_code == requests.codes.ok:
return list(
{
Expand Down Expand Up @@ -172,8 +172,9 @@ def get_upgrade_version(version) -> Optional[Mapping[str, str]]:
idx = len(available_versions)

# Only recommend stable releases for upgrade
newer_stable_versions = [v for v in available_versions[:idx] if
not v["prerelease"] and not v["draft"]]
newer_stable_versions = [
v for v in available_versions[:idx] if not v["prerelease"] and not v["draft"]
]

if len(newer_stable_versions) == 0:
return None
Expand Down
27 changes: 14 additions & 13 deletions las_trx/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ class TransformWorker(QThread):
success = Signal()
error = Signal(BaseException)

def __init__(self, config: TransformConfig, input_files: list[Path],
output_files: list[Path]):
def __init__(
self, config: TransformConfig, input_files: list[Path], output_files: list[Path]
):
super().__init__(parent=None)
self.config = config
self.input_files = input_files
Expand Down Expand Up @@ -119,11 +120,11 @@ def run(self):


def transform(
config: dict,
input_file: Path,
output_file: Path,
lock: multiprocessing.RLock,
cur: multiprocessing.Value,
config: dict,
input_file: Path,
output_file: Path,
lock: multiprocessing.RLock,
cur: multiprocessing.Value,
):
transformer = CSRSTransformer(**config)
config = TransformConfig(**config)
Expand All @@ -139,7 +140,7 @@ def transform(
logger.debug(f"{laz_backend=}")

with laspy.open(
str(output_file), mode="w", header=new_header, laz_backend=laz_backend
str(output_file), mode="w", header=new_header, laz_backend=laz_backend
) as out_las:
for points in in_las.chunk_iterator(CHUNK_SIZE):
# Convert the coordinates
Expand All @@ -160,7 +161,7 @@ def transform(


def write_header_offsets(
header: "LasHeader", input_file: Path, transformer: "CSRSTransformer"
header: "LasHeader", input_file: Path, transformer: "CSRSTransformer"
) -> "LasHeader":
with laspy.open(str(input_file)) as in_las:
points = next(in_las.chunk_iterator(CHUNK_SIZE))
Expand All @@ -179,10 +180,10 @@ def clear_header_geokeys(header: "LasHeader") -> "LasHeader":
# Update GeoKeyDirectoryVLR
# check and remove any existing crs vlrs
for crs_vlr_name in (
"WktCoordinateSystemVlr",
"GeoKeyDirectoryVlr",
"GeoAsciiParamsVlr",
"GeoDoubleParamsVlr",
"WktCoordinateSystemVlr",
"GeoKeyDirectoryVlr",
"GeoAsciiParamsVlr",
"GeoDoubleParamsVlr",
):
try:
header.vlrs.extract(crs_vlr_name)
Expand Down
Loading

0 comments on commit db39c2a

Please sign in to comment.