final commit

This commit is contained in:
2026-06-19 11:15:39 +02:00
parent e2b1b20913
commit d095840037
975 changed files with 1232523 additions and 0 deletions
+20
View File
@@ -0,0 +1,20 @@
import pandas as pd
# Load the full CSV (with all columns)
df = pd.read_csv("in/df_suppressed.csv", encoding='UTF-8', on_bad_lines='skip', delimiter=';') # or 'cp1252' if needed
# Replace "X" and "Y" with your actual column names if needed
x_col = 'Lambert_X'
y_col = 'Lambert_Y'
# Ensure X and Y are numeric, coerce invalid to NaN
df[x_col] = pd.to_numeric(df[x_col], errors='coerce')
df[y_col] = pd.to_numeric(df[y_col], errors='coerce')
# Interpolate only the X and Y columns (other columns untouched)
df[[x_col, y_col]] = df[[x_col, y_col]].interpolate(method='linear', limit_direction='both')
# Save to a new CSV
df.to_csv("out/interpolated_trace.csv", index=False, sep=';')
print("✅ Interpolation done on X/Y. Other columns preserved.")
+24
View File
@@ -0,0 +1,24 @@
import pandas as pd
import geopandas as gpd
from shapely.geometry import Point
# 1. Load the interpolated CSV
df = pd.read_csv("out/interpolated_trace.csv", encoding='UTF-8', on_bad_lines='skip', delimiter=';') # or 'cp1252' if needed
# 2. Define your coordinate column names (replace if needed)
x_col = 'Lambert_X'
y_col = 'Lambert_Y'
# 3. Create geometry from X and Y
geometry = [Point(xy) for xy in zip(df[x_col], df[y_col])]
# 4. Create GeoDataFrame
gdf = gpd.GeoDataFrame(df, geometry=geometry)
# 5. Set CRS (Lambert 93 = EPSG:2154, common in France)
gdf.set_crs(epsg=2154, inplace=True)
# 6. Export to shapefile
gdf.to_file("out/interpolated_trace.shp")
print("✅ Shapefile created: interpolated_trace.shp")
+23
View File
@@ -0,0 +1,23 @@
import pandas as pd
import geopandas as gpd
from shapely.geometry import Point
import sys
def csv_to_shp(in_file: str, out_file: str, x_col: str = 'Lambert_X', y_col: str = 'Lambert_Y'):
# 1. Load the interpolated CSV
df = pd.read_csv(in_file, encoding='UTF-8', on_bad_lines='skip', delimiter=';') # or 'cp1252' if needed
# 3. Create geometry from X and Y
geometry = [Point(xy) for xy in zip(df[x_col], df[y_col])]
# 4. Create GeoDataFrame
gdf = gpd.GeoDataFrame(df, geometry=geometry)
# 5. Set CRS (Lambert 93 = EPSG:2154, common in France)
gdf.set_crs(epsg=2154, inplace=True)
# 6. Export to shapefile
gdf.to_file(out_file)
csv_to_shp(sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4])
+93
View File
@@ -0,0 +1,93 @@
import pandas as pd
import geopandas as gpd
from shapely.geometry import Point
import numpy as np
import pyproj
import math
import sys
# Function to convert WGS84 to Lambert 93 for the entire DataFrame
def convert_to_lambert93(row, transf):
if(math.isnan(row[x_col]) or math.isnan(row[y_col])):
x, y = transf.transform(row[x_inter_col], row[y_inter_col])
row[x_inter_col] = x
row[y_inter_col] = y
return row
def point_position_on_line(pt):
return line.project(pt)
# Load CSV
df = pd.read_csv(sys.argv[1], encoding='UTF-8', on_bad_lines='skip', delimiter=';')
x_col = sys.argv[4]
y_col = sys.argv[5]
x_inter_col = sys.argv[6]
y_inter_col = sys.argv[7]
df[x_col] = pd.to_numeric(df[x_col], errors='coerce')
df[y_col] = pd.to_numeric(df[y_col], errors='coerce')
# Load shapefile (must contain LineString)
line_gdf = gpd.read_file(sys.argv[2])
line = line_gdf.union_all() # merge if multiple lines
# Create geometry
df['geometry'] = df.apply(
lambda row: Point(row[x_col], row[y_col]) if not pd.isna(row[x_col]) and not pd.isna(row[y_col]) else None,
axis=1
)
# Get position
df['distance_on_line'] = df['geometry'].apply(lambda g: line.project(g) if g else np.nan)
# Interpolate
df['distance_on_line'] = df['distance_on_line'].interpolate(method='linear', limit_direction='both')
# Create interpolated points
df['geometry'] = df['distance_on_line'].apply(lambda d: line.interpolate(d))
# Start with original values
df[x_inter_col] = df[x_col]
df[y_inter_col] = df[y_col]
# Update only missing ones
df.loc[df[x_col].isna(), x_inter_col] = df.loc[df[x_col].isna(), 'geometry'].apply(lambda g: g.x)
df.loc[df[y_col].isna(), y_inter_col] = df.loc[df[y_col].isna(), 'geometry'].apply(lambda g: g.y)
# Load CSV and shape
df = pd.read_csv("in/raw.csv", delimiter=';', encoding='utf-8')
df[x_col] = pd.to_numeric(df[x_col], errors='coerce')
df[y_col] = pd.to_numeric(df[y_col], errors='coerce')
# Load the shapefile (must be a LineString)
line = gpd.read_file("in/célé.shp").unary_union # Merge multiple lines if needed
# Assign geometry to known points
df['geometry'] = df.apply(
lambda r: Point(r[x_col], r[y_col]) if pd.notna(r[x_col]) else None,
axis=1
)
# Compute the position of known points along the line
df['distance_on_line'] = df['geometry'].apply(lambda g: line.project(g) if g else np.nan)
# Interpolate missing distances (ensures every point has a valid position)
df['distance_on_line'] = df['distance_on_line'].interpolate(method='linear', limit_direction='both')
# Interpolate new coordinates from the reference shape
df['geometry'] = df['distance_on_line'].apply(lambda d: line.interpolate(d) if pd.notna(d) else None)
df[x_inter_col] = df['geometry'].apply(lambda g: g.x if g else np.nan)
df[y_inter_col] = df['geometry'].apply(lambda g: g.y if g else np.nan)
# Apply the conversion to the entire DataFrame row-wise
wgs84 = pyproj.CRS("EPSG:4326")
lambert93 = pyproj.CRS("EPSG:2154")
transformer = pyproj.Transformer.from_crs(wgs84, lambert93, always_xy=True)
df = df.apply(lambda row : convert_to_lambert93(row, transformer), axis=1)
# Save fixed CSV
df.to_csv(sys.argv[3], sep=';', index=False)
+1
View File
@@ -0,0 +1 @@
UTF-8
Binary file not shown.
+1
View File
@@ -0,0 +1 @@
GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137.0,298.257223563]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]]
+43
View File
@@ -0,0 +1,43 @@
<!DOCTYPE qgis PUBLIC 'http://mrcc.com/qgis.dtd' 'SYSTEM'>
<qgis version="3.22.16-Bia?owie?a">
<identifier></identifier>
<parentidentifier></parentidentifier>
<language></language>
<type>dataset</type>
<title></title>
<abstract></abstract>
<contact>
<name></name>
<organization></organization>
<position></position>
<voice></voice>
<fax></fax>
<email></email>
<role></role>
</contact>
<links/>
<fees></fees>
<encoding></encoding>
<crs>
<spatialrefsys>
<wkt></wkt>
<proj4></proj4>
<srsid>0</srsid>
<srid>0</srid>
<authid></authid>
<description></description>
<projectionacronym></projectionacronym>
<ellipsoidacronym></ellipsoidacronym>
<geographicflag>false</geographicflag>
</spatialrefsys>
</crs>
<extent>
<spatial crs="" minx="0" miny="0" minz="0" dimensions="2" maxz="0" maxx="0" maxy="0"/>
<temporal>
<period>
<start></start>
<end></end>
</period>
</temporal>
</extent>
</qgis>
Binary file not shown.
Binary file not shown.
+22521
View File
File diff suppressed because it is too large Load Diff
+22521
View File
File diff suppressed because it is too large Load Diff
+1
View File
@@ -0,0 +1 @@
Interpolation done on X/Y. Other columns preserved.
@@ -0,0 +1 @@
UTF-8
File diff suppressed because it is too large Load Diff
Binary file not shown.
@@ -0,0 +1 @@
PROJCS["RGF_1993_Lambert_93",GEOGCS["GCS_RGF_1993",DATUM["D_RGF_1993",SPHEROID["GRS_1980",6378137.0,298.257222101]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Lambert_Conformal_Conic"],PARAMETER["False_Easting",700000.0],PARAMETER["False_Northing",6600000.0],PARAMETER["Central_Meridian",3.0],PARAMETER["Standard_Parallel_1",49.0],PARAMETER["Standard_Parallel_2",44.0],PARAMETER["Latitude_Of_Origin",46.5],UNIT["Meter",1.0]]
Binary file not shown.
Binary file not shown.
+22521
View File
File diff suppressed because it is too large Load Diff
+1
View File
@@ -0,0 +1 @@
UTF-8
Binary file not shown.
+1
View File
@@ -0,0 +1 @@
PROJCS["RGF_1993_Lambert_93",GEOGCS["GCS_RGF_1993",DATUM["D_RGF_1993",SPHEROID["GRS_1980",6378137.0,298.257222101]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Lambert_Conformal_Conic"],PARAMETER["False_Easting",700000.0],PARAMETER["False_Northing",6600000.0],PARAMETER["Central_Meridian",3.0],PARAMETER["Standard_Parallel_1",49.0],PARAMETER["Standard_Parallel_2",44.0],PARAMETER["Latitude_Of_Origin",46.5],UNIT["Meter",1.0]]
Binary file not shown.
Binary file not shown.
+96
View File
@@ -0,0 +1,96 @@
# -*- coding: utf-8 -*-
import pyproj
import os
import pandas as pd
directory_path = 'Y:\MISSIONS\Eau\8 - Projet recherche Célé\Lucie\Science\Canoo\continuum Ce guillaume 2020\dossier_brut_2020'
dataframes = []
for filename in os.listdir(directory_path):
if filename.endswith('.csv'):
file_path = os.path.join(directory_path, filename)
df = pd.read_csv(file_path, delimiter=',', skiprows=18, parse_dates=[0])
dataframes.append(df)
merged_dataframe = pd.concat(dataframes, ignore_index=True)
merged_dataframe.sort_values(by=['Date Heure'], inplace=True)
merged_dataframe.reset_index(drop=True, inplace=True)
columns_to_suppress_indices = [4, 5, 7, 9, 10, 11, 12, 21, 22]
if max(columns_to_suppress_indices) >= len(merged_dataframe.columns):
print("Invalid column index found.")
else:
df_suppressed = merged_dataframe.drop(merged_dataframe.columns[columns_to_suppress_indices], axis=1)
#supprimer les données manquantes
#df_suppressed.dropna(subset=['Latitude (°)', 'Longitude (°)'], inplace=True)
# Define the coordinate systems
wgs84 = pyproj.CRS("EPSG:4326")
lambert93 = pyproj.CRS("EPSG:2154")
# Create the Transformer to perform the conversion
transformer = pyproj.Transformer.from_crs(wgs84, lambert93, always_xy=True)
# Function to convert WGS84 to Lambert 93 for the entire DataFrame
def convert_to_lambert93(row):
x, y = transformer.transform(row["Longitude (°)"], row["Latitude (°)"])
row["Lambert_X"] = x
row["Lambert_Y"] = y
return row
# Apply the conversion to the entire DataFrame row-wise
df_suppressed = df_suppressed.apply(convert_to_lambert93, axis=1)
print(df_suppressed)
#alors il faut ensuit calculer l'hypothénuse entre chacun de mes points : peut être résolu de façon booléenne
def distance_entre_points(x1, y1, x2, y2):
distance = ((x2 - x1)**2 + (y2 - y1)**2) ** 0.5
return distance
# Créer une nouvelle colonne 'Distance' dans le DataFrame
df_suppressed['Distance'] = 0.0
# Créer une nouvelle colonne 'Distance Cumulative' pour la somme cumulative des distances
df_suppressed['Distance Cumulative'] = 0.0
# Variable pour garder la somme cumulative des distances
cumulative_distance = 0.0
for i in range(len(df_suppressed) - 3):
x1, y1 = df_suppressed.loc[i, 'Lambert_X'], df_suppressed.loc[i, 'Lambert_Y']
x2, y2 = df_suppressed.loc[i + 1, 'Lambert_X'], df_suppressed.loc[i + 1, 'Lambert_Y']
distance = distance_entre_points(x1, y1, x2, y2)
df_suppressed.loc[i + 1, 'Distance'] = distance
cumulative_distance += distance
df_suppressed.loc[i + 1, 'Distance Cumulative'] = cumulative_distance
# Afficher le DataFrame avec les colonnes 'Distance' et 'Distance Cumulative' mises à jour
print(df_suppressed)
df_suppressed.to_csv('Y:\MISSIONS\Eau\8 - Projet recherche Célé\Lucie\continuum\continuum lucie + fabs + steph\df_suppressedbrut_bon_dernier.csv', index=False)
#faire les graohs des paramètres en fonction de la distance = variations des paramètres
#Essayer tous les paramètres
#comparer avec les données de 2020.
#corriger la pression de la baro.
#Donc changement de stratégie. Je vais essayer de retrouver les données GPS manquante par interpolation de celle-ci.
#Pour cela on va faire un travail en sept étapes:
# 1. Sur Qgis exporter un fichier csv. du cours d'eau sous forme de points avec les coordonnées GPS en Lambert 93.
# 2. J'importe ce nouveau csv dans Python et je calcule la distance entre chaque points sur toute ma rivière.
# 3. A partir de là je calcul la distance cumulative entre chacun de mes points sur tous mon cours d'eau.
# 4. Ensuite je regarde à la mano là où j'ai des trous. Je calcul sur Qgis la distance manquante de point GPS
# 5. Distance manquante / nombres de mesures = distance entre chaque points de mesure (exemple 2m)
# 6. Je calcul la distance cumulative au niveau de mes trous
#7. Je vais chercher dans le tableau 1 le coordonnée GPS correspondant à la distance cumulative similaire.
#8. Le tour est joué.