Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ruff fixes #31

Merged
merged 2 commits into from
Dec 19, 2024
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
3 changes: 1 addition & 2 deletions rivertopo/cross_lines_z.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import logging
from rivertopo.profile import RegulativProfilSimpel, RegulativProfilSammensat, OpmaaltProfil # import interpolation classes
from rivertopo.snapping import snap_points
from numpy import array_equal
from scipy.interpolate import RegularGridInterpolator

"""
Expand Down Expand Up @@ -209,7 +208,7 @@ def create_lines_with_z(current_line_data, previous_line_data, output_lines_laye
output_lines_layer.CreateFeature(output_line_feature)

# Update the previous line data for the next iteration
previous_perpendicular_line = current_line_data
# previous_perpendicular_line = current_line_data


def main():
Expand Down
10 changes: 1 addition & 9 deletions rivertopo/parameterization.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ def parameterize_grid(grid_xy, linestring):

dist_grid = np.full_like(grid_x, np.inf)
feature_id_grid = np.full_like(grid_x, FEATURE_ID_NODATA, dtype=FEATURE_ID_TYPE)
point_id_grid = np.full_like(grid_x, POINT_ID_NODATA, dtype=POINT_ID_TYPE)
segment_id_grid = np.full_like(grid_x, SEGMENT_ID_NODATA, dtype=SEGMENT_ID_TYPE)
chainage_grid = np.full_like(grid_x, np.nan)

Expand Down Expand Up @@ -61,28 +60,21 @@ def parameterize_grid(grid_xy, linestring):

startpoint_is_nearest = startpoint_dists < segment_dists
segment_dists[startpoint_is_nearest] = startpoint_dists[startpoint_is_nearest]
#segment_dists = np.minimum(segment_dists, startpoint_dists)

endpoint_is_nearest = endpoint_dists < segment_dists
segment_dists[endpoint_is_nearest] = endpoint_dists[endpoint_is_nearest]
#segment_dists = np.minimum(segment_dists, endpoint_dists)

is_within_segment = np.logical_and(raster_projection_params >= 0.0, raster_projection_params <= 1.0)
segment_dists[is_within_segment] = np.minimum(segment_dists[is_within_segment], perpendicular_dists[is_within_segment])

segment_dists *= left_or_right
segment_dists_maxabs = np.max(np.abs(segment_dists))

segment_chainages = np.full((len(raster_vectors),), np.nan)
segment_chainages[startpoint_is_nearest] = linestring_chainages[i]
segment_chainages[endpoint_is_nearest] = linestring_chainages[i+1]
segment_chainages[is_within_segment] = (1.0-raster_projection_params[is_within_segment])*linestring_chainages[i] + raster_projection_params[is_within_segment]*linestring_chainages[i+1]

startpoint_dists_grid = startpoint_dists.reshape(grid_x.shape)
endpoint_dists_grid = endpoint_dists.reshape(grid_x.shape)
perpendicular_dists_grid = perpendicular_dists.reshape(grid_x.shape)
segment_dists_grid = segment_dists.reshape(grid_x.shape)
left_or_right_grid = left_or_right.reshape(grid_x.shape)
segment_chainage_grid = segment_chainages.reshape(grid_x.shape)

delta_x = grid_x[0,1] - grid_x[0,0]
Expand All @@ -93,7 +85,7 @@ def parameterize_grid(grid_xy, linestring):
dist_grid[segment_is_closest] = segment_dists_grid[segment_is_closest]
chainage_grid[segment_is_closest] = segment_chainage_grid[segment_is_closest]
segment_id_grid[segment_is_closest] = i
feature_id_grid[segment_is_closest] = 0
feature_id_grid[segment_is_closest] = feature_id

dist_maxabs = np.max(np.abs(dist_grid))

Expand Down
8 changes: 4 additions & 4 deletions rivertopo/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,13 @@ def __init__(self, feature):
thalweg_coord = np.mean(z_min_coords, axis=0)

endpoint_left = geometry_coords[0]
endpoint_right = geometry_coords[-1]
# endpoint_right = geometry_coords[-1]

# distances between endpoints
delta_x = endpoint_right[0] - endpoint_left[0]
delta_y = endpoint_right[1] - endpoint_left[1]
# delta_x = endpoint_right[0] - endpoint_left[0]
# delta_y = endpoint_right[1] - endpoint_left[1]

azimuth = np.arctan2(-delta_y, delta_x) # TODO generalize to all profile types
# azimuth = np.arctan2(-delta_y, delta_x) # TODO generalize to all profile types

dists_from_left = np.hypot(
geometry_coords[:,0] - endpoint_left[0],
Expand Down
1 change: 0 additions & 1 deletion rivertopo/profile_extraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from scipy.interpolate import RegularGridInterpolator
from collections import namedtuple
import argparse
import os

from rivertopo.cross_lines_z import create_perpendicular_lines

Expand Down
4 changes: 1 addition & 3 deletions rivertopo/profile_plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
import pandas as pd
import numpy as np
import plotly.graph_objects as go
from osgeo import gdal, ogr
import argparse
from shapely.geometry import Point
import geopandas as gpd
import dash
Expand Down Expand Up @@ -116,7 +114,7 @@ def update_map_figure(selected_csv):
profile = profile_path

# Get unique Line_IDs
line_ids = profile['Line_ID'].unique()
# line_ids = profile['Line_ID'].unique()

# Create a GeoDataFrame
geometry = [Point(xy) for xy in zip(profile['X'], profile['Y'])]
Expand Down
2 changes: 1 addition & 1 deletion rivertopo/topology.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def get_layer_topology(layer):

# initialize
for xy in geometry_xy_tuples:
if not xy in point_connections:
if xy not in point_connections:
point_connections[xy] = ConnectedPoints()

# Store upstream and downstream points
Expand Down
2 changes: 1 addition & 1 deletion tests/test_burning.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

def test_cross_lines():
from rivertopo.cross_lines_z import main
pass


2 changes: 0 additions & 2 deletions tests/test_topology.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from rivertopo import topology
from rivertopo.topology import ConnectedPoints, get_layer_topology

from osgeo import ogr
import numpy as np

ogr.UseExceptions()

Expand Down
Loading