CombineCropRows¶
Qualified name: crop_row_connector.combine_crop_rows.CombineCropRows
- class CombineCropRows(angle_tolerance, vegetation_threshold, min_unhealthy_vegetation_length, max_segment_length, distance_tolerance, *, output_path_connected_crop_rows=None, output_path_vegetation_points=None, output_path_healthy_vegetation_segments=None, output_path_unhealthy_vegetation_segments=None, max_workers=None)[source]¶
Bases:
objectCombine crop rows from different tiles into one line.
- Parameters:
angle_tolerance (float) – Maximum angle difference in degrees for rows to be considered for connection.
vegetation_threshold (float) – Grayscale threshold (0-255) for classifying vegetation as healthy.
min_unhealthy_vegetation_length (float) – Minimum spatial extent in meters for unhealthy vegetation segments to be recorded.
max_segment_length (float) – Maximum length in meters for vegetation classification segments.
output_path_connected_crop_rows (Path | None) – Path to save connected crop rows to CSV.
output_path_vegetation_points (Path | None) – Path to save all vegetation points associated with connected rows.
output_path_healthy_vegetation_segments (Path | None) – Path to save segments with healthy vegetation.
output_path_unhealthy_vegetation_segments (Path | None) – Path to save segments with unhealthy vegetation.
max_workers (int | None) – Maximum number of parallel workers for processing.
distance_tolerance (float)
Methods
Connect two tiles by linking crop rows if their angles are within the allowed tolerance.
Execute the complete crop row connection pipeline.
Connect crop rows across neighboring tiles in the grid.
Write the connected crop rows to a csv file.
Create a 2D grid of tile numbers in their respective positions, with -1 for empty cells.
Calculate total lengths of healthy and unhealthy vegetation segments.
Load a CSV file containing row information into a NumPy array.
Merge all points from connected crop rows into a single DataFrame, removing overlapping points based on a distance tolerance.
Define healthy and unhealthy vegetation segments and optionally write them to shapefiles.
Split row information into tile objects keyed by tile number.
- connect_2_tiles(tile_1, tile_2)[source]¶
Connect two tiles by linking crop rows if their angles are within the allowed tolerance.
- connect_crop_rows(path_row_information, path_points_in_rows)[source]¶
Execute the complete crop row connection pipeline. And save desired output.
- Parameters:
- Return type:
None
- connect_rows_in_tiles(grid, tiles, tqdm_disable=False)[source]¶
Connect crop rows across neighboring tiles in the grid.
For each tile in the grid: - Connect to its right neighbor (if any) - Connect to its bottom neighbor (if any)
After all connections are made: - Add any uncombined rows to the connected crop rows
- connected_crop_rows_to_csv(connected_crop_rows)[source]¶
Write the connected crop rows to a csv file.
- Parameters:
connected_crop_rows (ndarray) – 2D array containing connected crop row information.
- Return type:
None
- create_tile_grid(row_information, tiles)[source]¶
Create a 2D grid of tile numbers in their respective positions, with -1 for empty cells.
Notes
X indexes columns, Y indexes rows (grid[y, x])
The grid is padded by 1 row and 1 column to simplify neighbor connections.
- length_of_segments(segments)[source]¶
Calculate total lengths of healthy and unhealthy vegetation segments.
Notes
Uses segment endpoints instead of point-to-point distances.
Each segment is treated as a straight line.
- load_csv(path)[source]¶
Load a CSV file containing row information into a NumPy array.
Notes
Each row corresponds to a crop row.
- Columns contain:
[tile_number, x_position, y_position, angle, row, x_start, y_start, x_end, y_end, x_mid, y_mid]
- merge_all_points_in_all_crop_rows_remove(connected_crop_rows, DF_vegetation_rows, row_information, tiles)[source]¶
Merge all points from connected crop rows into a single DataFrame, removing overlapping points based on a distance tolerance.
- Parameters:
connected_crop_rows (ndarray) – 2D array containing connected crop row information.
path_points_in_rows – Path to CSV containing raw vegetation points per row.
row_information (ndarray) – Original row information array.
tiles (dict[int, Tile]) – Dictionary mapping tile numbers to tile objects.
DF_vegetation_rows (DataFrame)
- Returns:
Merged and sorted crop rows including vegetation and duplicate information.
- Return type:
pd.DataFrame
- separate_healthy_and_unhealthy_vegetation_segments(DF_crop_rows)[source]¶
Define healthy and unhealthy vegetation segments and optionally write them to shapefiles.
Notes
Uses self.vegetation_threshold to separate healthy from unhealthy vegetation.
Each segment is represented as a line between two points.
Returns segments so they can be reused for further analysis (e.g. length calculation).
X indexes columns, Y indexes rows (DF_crop_rows[‘x’], DF_crop_rows[‘y’]).
- separate_row_information_to_tile(row_information)[source]¶
Split row information into tile objects keyed by tile number.
- Parameters:
row_information (ndarray) – A NumPy array containing row information for all tiles. Each row corresponds to a crop row and contains the following columns: [tile_number, x_position, y_position, angle, row, x_start, y_start, x_end, y_end]
- Returns:
Dictionary mapping each tile number to a tile object.
- Return type: