常规更新

This commit is contained in:
2026-04-20 09:43:21 +08:00
parent 729b283f29
commit dd47ab5f44
40 changed files with 1306 additions and 9935 deletions

View File

@ -1,11 +1,9 @@
"""Functions that organise the data into standard columns in pandas dataframes. Conversion functions (e.g. WGS84 to UTM)
are here but transformations take place in processing.py"""
import geopandas as gpd
import numpy as np
import pandas as pd
from . import plotting
from pyproj import Transformer
from .processing import circ_median
@ -37,19 +35,52 @@ def timestamp_from_four_columns(df):
# add UTM from latitudes and longitudes
def add_utm(df: pd.DataFrame) -> pd.DataFrame:
gdf = gpd.GeoDataFrame( # type: ignore
df,
geometry=gpd.points_from_xy(df["longitude"], df["latitude"], crs="EPSG:4326"),
)
utm = gdf.estimate_utm_crs()
gdf = gdf.to_crs(utm)
if not isinstance(gdf, gpd.GeoDataFrame):
raise TypeError("Failed to reproject to a GeoDataFrame")
gdf["utm_easting"] = gdf.geometry.x
gdf["utm_northing"] = gdf.geometry.y
output_df = pd.DataFrame(gdf.drop(columns="geometry"))
"""
Convert WGS84 coordinates to UTM using pyproj.
return output_df
This function replaces the geopandas implementation with a lighter pyproj-based solution.
"""
# Make a copy to avoid modifying the original DataFrame
df = df.copy()
# Get the average longitude to determine the UTM zone
# For simplicity, we'll use the first valid longitude to determine the zone
# In production, you might want to use the centroid or handle multiple zones
valid_lons = df["longitude"].dropna()
if len(valid_lons) == 0:
raise ValueError("No valid longitude values found")
# Calculate UTM zone from longitude
# UTM zones are 6 degrees wide, starting from -180
lon = valid_lons.iloc[0] # Use first valid longitude
zone_number = int((lon + 180) / 6) + 1
# Determine if it's northern or southern hemisphere
# Use first valid latitude
valid_lats = df["latitude"].dropna()
if len(valid_lats) == 0:
raise ValueError("No valid latitude values found")
lat = valid_lats.iloc[0]
hemisphere = 'north' if lat >= 0 else 'south'
# Create UTM CRS string
utm_crs = f"EPSG:326{zone_number:02d}" if hemisphere == 'north' else f"EPSG:327{zone_number:02d}"
# Create transformer from WGS84 to UTM
transformer = Transformer.from_crs("EPSG:4326", utm_crs, always_xy=True)
# Transform coordinates
utm_easting, utm_northing = transformer.transform(
df["longitude"].values,
df["latitude"].values
)
# Add UTM coordinates to DataFrame
df["utm_easting"] = utm_easting
df["utm_northing"] = utm_northing
return df
# add columns for drone course azimuth and elevation
@ -97,7 +128,9 @@ def remove_outliers(df: pd.DataFrame, column: str, name: str):
iqr = q3 - q1
fence_low = q1 - 3 * iqr
fence_high = q3 + 3 * iqr
fig = plotting.outliers(df[column], fence_high, fence_low)
fig = None # plotting disabled
outliers = df.loc[(df[column] < fence_low) | (df[column] > fence_high)]
if len(outliers) > 0:
print(f"{len(outliers)} outliers removed from {name} {column} data")