Skip to content

Commit

Permalink
style(#3): small coderabbit fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrianSolberg committed Oct 26, 2025
1 parent 4d72a31 commit fc1d707
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
5 changes: 3 additions & 2 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ The main steps are:

Before running the script, make sure your project folder has the following structure:

```
```text
lasConverter.py
surveys/
├── survey_name_1/
Expand All @@ -32,7 +32,8 @@ metadata/
- Each survey folder contains the CSV files for that survey (arbitrarily named).

### `metadata/metadata.csv`
- Must include the columns: `fid`, `survey_name`, `survey_area`, `geom`, `epsg`.
- Must include the columns: `fid`, `survey_name`, `survey_area`, `geom`, `epsg`.
- Script assumes bounding polygons in `geom` use EPSG:4258.
- Each row corresponds to a survey.

### `metadata/level1_h3_cells.csv`
Expand Down
15 changes: 9 additions & 6 deletions lasConverter.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def prepare_cells(metadata: pd.DataFrame, level1_cells: List[str]) -> Tuple[Defa
poly = Polygon([(lng, lat) for lat, lng in coords])
cell_polygons[c2] = transform(transformer_4326_to_4978.transform, poly)

# Transfrom survey polygons from EPSG:4258 to EPSG:4978
# Transform survey polygons from EPSG:4258 to EPSG:4978
metadata["geom"] = metadata["geom"].apply(wkt.loads)
transform_4258_to_4978 = Transformer.from_crs("EPSG:4258", "EPSG:4978", always_xy=True)
metadata["geom_4978"] = metadata["geom"].apply(lambda g: transform(transform_4258_to_4978.transform, g))
Expand Down Expand Up @@ -143,7 +143,7 @@ def CSV_2_LAS(metadata: pd.DataFrame, chunk_size_bytes: str ="64MB") -> None:
header = laspy.LasHeader(point_format=6, version="1.4")

# Add extra dimensions
header.add_extra_dim(laspy.ExtraBytesParams(name="accepted", type=np.uint8))
header.add_extra_dim(laspy.ExtraBytesParams(name="Accepted", type=np.uint8))
header.add_extra_dim(laspy.ExtraBytesParams(name="TVU", type=np.float32))
header.add_extra_dim(laspy.ExtraBytesParams(name="THU", type=np.float32))

Expand All @@ -153,7 +153,7 @@ def CSV_2_LAS(metadata: pd.DataFrame, chunk_size_bytes: str ="64MB") -> None:
las.z = z

# Set extra dimensions
las["accepted"] = accepted
las["Accepted"] = accepted
las["TVU"] = tvu
las["THU"] = thu
las.point_source_id = ids
Expand All @@ -166,6 +166,9 @@ def CSV_2_LAS(metadata: pd.DataFrame, chunk_size_bytes: str ="64MB") -> None:
# Merging chunked LAS files into single LAS
print("Merging LAS chunks into final LAS...")
las_files = sorted(temp_folder.glob(f"{survey_name}_chunk_*.las"))
if not las_files:
print(f"⚠️ No LAS chunks produced for {survey_name}, skipping merge.")
continue
first_las = laspy.read(str(las_files[0]))
merged_header = first_las.header

Expand All @@ -182,7 +185,7 @@ def CSV_2_LAS(metadata: pd.DataFrame, chunk_size_bytes: str ="64MB") -> None:
temp_folder.rmdir()


def group_by_h3_cell(cell_to_surveys: DefaultDict[str, List[int]], cell_polygons: Dict[str, Polygon]):
def group_by_h3_cell(metadata: pd.DataFrame, cell_to_surveys: DefaultDict[str, List[str]], cell_polygons: Dict[str, Polygon]):
"""
Groups survey LAS files by H3 level-2 cells and crops them using PDAL.
Expand All @@ -205,7 +208,7 @@ def group_by_h3_cell(cell_to_surveys: DefaultDict[str, List[int]], cell_polygons
for fid in survey_fids:
survey_name = metadata.loc[metadata['fid'] == fid, 'survey_name'].item()

src = Path("converted_surveys") / f"{survey_name}.las"
src = CONVERTED_PATH / f"{survey_name}.las"
if not src.exists():
continue

Expand Down Expand Up @@ -267,4 +270,4 @@ def group_by_h3_cell(cell_to_surveys: DefaultDict[str, List[int]], cell_polygons

CSV_2_LAS(metadata)

group_by_h3_cell(cell_to_surveys, cell_polygons)
group_by_h3_cell(metadata, cell_to_surveys, cell_polygons)

0 comments on commit fc1d707

Please sign in to comment.