Skip to content

Commit 380dca1

Browse files
Fix for windows
* fix: file access windows * fix commentaires * test * rewrite fn * rewrite standardize --------- Co-authored-by: Nathan Lenglet <nathan.lenglet@ign.fr>
1 parent b4d1736 commit 380dca1

20 files changed

+246
-127
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: cicd_light_windows
2+
3+
on:
4+
# Run tests for non-draft pull request on dev
5+
pull_request:
6+
branches:
7+
- dev
8+
9+
10+
jobs:
11+
test_light_windows:
12+
runs-on: ${{ matrix.os }}
13+
strategy:
14+
matrix:
15+
os: [windows-latest]
16+
permissions:
17+
contents: read
18+
packages: write
19+
20+
steps:
21+
- name: Checkout branch
22+
uses: actions/checkout@v4
23+
24+
# See https://github.com/marketplace/actions/setup-micromamba
25+
- name: setup-micromamba
26+
uses: mamba-org/setup-micromamba@v1.9.0
27+
with:
28+
micromamba-version: '1.5.8-0' # temporary fix as setup-mircomamba hangs with later mamba version
29+
environment-file: environment.yml
30+
environment-name: pdaltools # activate the environment
31+
cache-environment: true
32+
cache-downloads: true
33+
generate-run-shell: true
34+
35+
- name: Run tests with pytest
36+
shell: cmd
37+
run: micromamba run -n pdaltools python -m pytest ./test -s --log-cli-level DEBUG -m "not geopf"

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
- [fix] fix use of temporary file in windows
2+
13
# 1.15.5
24
- [optimization] replace_area_plointcloud: select polygons in replace_area that intersect target LAS.
35
- make the normal case faster

environment.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: pdaltools
22
channels:
33
- conda-forge
44
dependencies:
5-
- python=3.11.*
5+
- python=3.12.*
66
- numpy
77
- conda-forge:pdal>=2.9.*
88
- conda-forge:python-pdal>=3.4

pdaltools/add_points_in_pointcloud.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ def add_points_to_las(
156156
new_points.z = z_coords.astype(new_points.z.dtype)
157157
new_points.classification = classes.astype(new_points.classification.dtype)
158158

159-
with tempfile.NamedTemporaryFile(suffix="_new_points.las") as tmp:
159+
with tempfile.NamedTemporaryFile(suffix="_new_points.las", delete_on_close=False) as tmp:
160160
with laspy.open(tmp.name, mode="w", header=header) as las_file:
161161
las_file.write_points(new_points)
162162

pdaltools/color.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def color(
101101

102102
tmp_ortho = None
103103
if color_rvb_enabled:
104-
tmp_ortho = tempfile.NamedTemporaryFile(suffix="_rvb.tif")
104+
tmp_ortho = tempfile.NamedTemporaryFile(suffix="_rvb.tif", delete_on_close=False)
105105
download_image(
106106
proj,
107107
stream_RGB,
@@ -124,7 +124,7 @@ def color(
124124

125125
tmp_ortho_irc = None
126126
if color_ir_enabled:
127-
tmp_ortho_irc = tempfile.NamedTemporaryFile(suffix="_irc.tif")
127+
tmp_ortho_irc = tempfile.NamedTemporaryFile(suffix="_irc.tif", delete_on_close=False)
128128
download_image(
129129
proj,
130130
stream_IRC,

pdaltools/create_random_laz.py

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
import numpy as np
2-
import laspy
3-
from pathlib import Path
41
import argparse
5-
from pyproj import CRS
2+
from pathlib import Path
63
from typing import List, Tuple
74

5+
import laspy
6+
import numpy as np
7+
from pyproj import CRS
8+
89

910
def create_random_laz(
1011
output_file: str,
@@ -27,7 +28,7 @@ def create_random_laz(
2728
(default: (650000, 6810000) ; around Paris)
2829
extra_dims: List of tuples (dimension_name, dimension_type) where type can be:
2930
'float32', 'float64', 'int8', 'int16', 'int32', 'int64', 'uint8', 'uint16', 'uint32', 'uint64'
30-
classifications: Optional list of classification values.
31+
classifications: Optional list of classification values.
3132
"""
3233

3334
# Create a new point cloud
@@ -103,7 +104,6 @@ def create_random_laz(
103104

104105

105106
def test_output_file(result: dict, output_file: str):
106-
107107
# Validate output file path
108108
output_path = Path(output_file)
109109
if not output_path.exists():
@@ -126,12 +126,14 @@ def parse_args():
126126
)
127127
parser.add_argument("--crs", type=int, default=2154, help="Projection code")
128128
parser.add_argument(
129-
"--center", type=float, nargs=2, default=[650000.0, 6810000.0],
130-
help="Center coordinates (x y) of the area to generate points in (space-separated)"
129+
"--center",
130+
type=float,
131+
nargs=2,
132+
default=[650000.0, 6810000.0],
133+
help="Center coordinates (x y) of the area to generate points in (space-separated)",
131134
)
132135
parser.add_argument(
133-
"--classifications", type=int, nargs='+',
134-
help="List of classification values (space-separated)"
136+
"--classifications", type=int, nargs="+", help="List of classification values (space-separated)"
135137
)
136138
return parser.parse_args()
137139

@@ -145,19 +147,13 @@ def main():
145147

146148
# Parse center
147149
center = tuple(args.center[:2]) # Only take first 2 values if more are provided
148-
150+
149151
# Parse classifications if provided
150152
classifications = args.classifications
151153

152154
# Call create_random_laz
153155
result = create_random_laz(
154-
args.output_file,
155-
args.point_format,
156-
args.num_points,
157-
args.crs,
158-
center,
159-
extra_dims,
160-
classifications
156+
args.output_file, args.point_format, args.num_points, args.crs, center, extra_dims, classifications
161157
)
162158

163159
# Test output file

pdaltools/download_image.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ def download_image(proj, layer, minx, miny, maxx, maxy, pixel_per_meter, outfile
185185
tmp_gpg_ortho.append(cells_ortho_paths)
186186

187187
# merge the cells
188-
with tempfile.NamedTemporaryFile(suffix="_gpf.vrt") as tmp_vrt:
188+
with tempfile.NamedTemporaryFile(suffix="_gpf.vrt", delete_on_close=False) as tmp_vrt:
189189
gdal.BuildVRT(tmp_vrt.name, tmp_gpg_ortho)
190190
gdal.Translate(outfile, tmp_vrt.name)
191191

pdaltools/las_add_buffer.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ def remove_points_from_buffer(input_file: str, output_file: str):
153153
input_file (str): path to the input file containing the "is_in_original" dimension
154154
output_file (str): path to the output_file
155155
"""
156-
with tempfile.NamedTemporaryFile(suffix="_with_additional_dim.las") as tmp_las:
156+
with tempfile.NamedTemporaryFile(suffix="_with_additional_dim.las", delete_on_close=False) as tmp_las:
157157
pipeline = pdal.Pipeline() | pdal.Reader.las(input_file)
158158
pipeline |= pdal.Filter.range(limits=f"{ORIGINAL_TILE_TAG}[1:1]")
159159
pipeline |= pdal.Writer.las(filename=tmp_las.name, forward="all", extra_dims="all")
@@ -217,8 +217,8 @@ def wrapper(*args, **kwargs):
217217
)
218218

219219
with (
220-
tempfile.NamedTemporaryFile(suffix="_buffered_input.laz", dir=".") as buf_in,
221-
tempfile.NamedTemporaryFile(suffix="_buffered_output.laz", dir=".") as buf_out,
220+
tempfile.NamedTemporaryFile(suffix="_buffered_input.laz", dir=".", delete_on_close=False) as buf_in,
221+
tempfile.NamedTemporaryFile(suffix="_buffered_output.laz", dir=".", delete_on_close=False) as buf_out,
222222
):
223223
create_las_with_buffer(
224224
Path(input_file).parent,

pdaltools/las_comparison.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import laspy
2-
from pathlib import Path
3-
import numpy as np
41
import argparse
2+
from pathlib import Path
53
from typing import Tuple
64

5+
import laspy
6+
import numpy as np
7+
78

89
def compare_las_dimensions(file1: Path, file2: Path, dimensions: list = None) -> Tuple[bool, int, float]:
910
"""

pdaltools/las_rename_dimension.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66

77
import argparse
88
import logging
9-
import pdal
109
import sys
1110
from pathlib import Path
12-
from pdaltools.las_remove_dimensions import remove_dimensions_from_points
11+
12+
import pdal
13+
1314
from pdaltools.las_info import las_info_metadata
15+
from pdaltools.las_remove_dimensions import remove_dimensions_from_points
1416

1517

1618
def rename_dimension(input_file: str, output_file: str, old_dims: list[str], new_dims: list[str]):

0 commit comments

Comments
 (0)