4. Along track distance#

[ ]:
%load_ext autoreload
%autoreload 2


import geopandas as gpd
import pandas as pd
import plotly.io as pio

import airbornegeo

pio.renderers.default = "notebook"
/home/airbornegeo/airbornegeo/src/airbornegeo/levelling.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html
  from tqdm.autonotebook import tqdm
[2]:
data_df = pd.read_csv("../data/AGAP_gravity_survey.csv")
data_df = data_df[["easting", "northing", "line", "unixtime"]]
data_df = data_df.sort_values(["line", "unixtime"]).reset_index(drop=True)
data_df
[2]:
easting northing line unixtime
0 1.000024e+06 226237.330771 1 1.229507e+09
1 1.000083e+06 226246.631269 1 1.229507e+09
2 1.000142e+06 226255.809132 1 1.229507e+09
3 1.000201e+06 226264.969079 1 1.229507e+09
4 1.000260e+06 226274.156809 1 1.229507e+09
... ... ... ... ...
333988 1.587964e+06 496507.950674 100 1.230382e+09
333989 1.587973e+06 496454.987752 100 1.230382e+09
333990 1.587983e+06 496401.908627 100 1.230382e+09
333991 1.587992e+06 496348.713306 100 1.230382e+09
333992 1.588001e+06 496295.434766 100 1.230382e+09

333993 rows × 4 columns

[ ]:
# plot the survey colored by line number
airbornegeo.plotly_points(
    data_df[::10],
    color_col="line",
    robust=False,
    size=3,
)
[4]:
# turn to geopandas geodataframe
data_df = gpd.GeoDataFrame(
    data_df,
    geometry=gpd.points_from_xy(x=data_df.easting, y=data_df.northing),
    crs="EPSG:3031",
)

4.1. Along track distance per line#

[ ]:
data_df["line_distance"] = airbornegeo.along_track_distance(
    data_df,
    groupby_column="line",
)

airbornegeo.plotly_points(
    data_df[::10],
    color_col="line_distance",
    hover_cols=["line"],
    robust=False,
    size=3,
)
data_df
easting northing line unixtime geometry line_distance
0 1.000024e+06 226237.330771 1 1.229507e+09 POINT (1000023.79 226237.331) 0.000000
1 1.000083e+06 226246.631269 1 1.229507e+09 POINT (1000082.905 226246.631) 59.842447
2 1.000142e+06 226255.809132 1 1.229507e+09 POINT (1000142.048 226255.809) 119.693401
3 1.000201e+06 226264.969079 1 1.229507e+09 POINT (1000201.195 226264.969) 179.545645
4 1.000260e+06 226274.156809 1 1.229507e+09 POINT (1000260.224 226274.157) 239.285174
... ... ... ... ... ... ...
333988 1.587964e+06 496507.950674 100 1.230382e+09 POINT (1587964.113 496507.951) 78906.532032
333989 1.587973e+06 496454.987752 100 1.230382e+09 POINT (1587973.377 496454.988) 78960.299070
333990 1.587983e+06 496401.908627 100 1.230382e+09 POINT (1587982.56 496401.909) 79014.166666
333991 1.587992e+06 496348.713306 100 1.230382e+09 POINT (1587991.661 496348.713) 79068.134996
333992 1.588001e+06 496295.434766 100 1.230382e+09 POINT (1588000.787 496295.435) 79122.189437

333993 rows × 6 columns

4.2. Along track distance for the whole survey#

[ ]:
data_df["survey_distance"] = airbornegeo.along_track_distance(
    data_df,
)

airbornegeo.plotly_points(
    data_df[::10],
    color_col="survey_distance",
    robust=False,
    size=3,
)
data_df
easting northing line unixtime geometry line_distance survey_distance
0 1.000024e+06 226237.330771 1 1.229507e+09 POINT (1000023.79 226237.331) 0.000000 0.000000e+00
1 1.000083e+06 226246.631269 1 1.229507e+09 POINT (1000082.905 226246.631) 59.842447 5.984245e+01
2 1.000142e+06 226255.809132 1 1.229507e+09 POINT (1000142.048 226255.809) 119.693401 1.196934e+02
3 1.000201e+06 226264.969079 1 1.229507e+09 POINT (1000201.195 226264.969) 179.545645 1.795456e+02
4 1.000260e+06 226274.156809 1 1.229507e+09 POINT (1000260.224 226274.157) 239.285174 2.392852e+02
... ... ... ... ... ... ... ...
333988 1.587964e+06 496507.950674 100 1.230382e+09 POINT (1587964.113 496507.951) 78906.532032 3.978976e+07
333989 1.587973e+06 496454.987752 100 1.230382e+09 POINT (1587973.377 496454.988) 78960.299070 3.978981e+07
333990 1.587983e+06 496401.908627 100 1.230382e+09 POINT (1587982.56 496401.909) 79014.166666 3.978986e+07
333991 1.587992e+06 496348.713306 100 1.230382e+09 POINT (1587991.661 496348.713) 79068.134996 3.978992e+07
333992 1.588001e+06 496295.434766 100 1.230382e+09 POINT (1588000.787 496295.435) 79122.189437 3.978997e+07

333993 rows × 7 columns

4.3. Distances without time data#

The above functions assume the data is sorted by time. If you don’t have time data, but your data is still sorted by time, the functions will work. If you are unsure if your data is sorted by time, then you can use set guess_start_position to True. This will use which ever end of the segment is furthers left as the starting point and calculate distances relative to that point.

[7]:
# un sort the data to demonstrate
unsorted_data_df = data_df.sample(frac=1).reset_index(drop=True)
unsorted_data_df.head()
[7]:
easting northing line unixtime geometry line_distance survey_distance
0 1.324816e+06 338605.203520 69 1.231327e+09 POINT (1324815.858 338605.204) 134058.786280 2.902679e+07
1 1.382454e+06 383820.744145 64 1.229982e+09 POINT (1382454.422 383820.744) 167883.732406 2.759927e+07
2 1.218181e+06 184977.326945 39 1.231092e+09 POINT (1218180.876 184977.327) 128081.744031 1.613290e+07
3 1.597463e+06 527434.184141 43 1.231156e+09 POINT (1597463.336 527434.184) 301856.786828 1.810998e+07
4 1.457011e+06 321990.423141 78 1.231332e+09 POINT (1457010.638 321990.423) 14196.831241 3.179632e+07
[ ]:
unsorted_data_df["line_distance"] = airbornegeo.along_track_distance(
    unsorted_data_df[::10],
    groupby_column="line",
    guess_start_position=True,
)

airbornegeo.plotly_points(
    unsorted_data_df,
    color_col="line_distance",
    robust=False,
    size=3,
)
unsorted_data_df.head()
easting northing line unixtime geometry line_distance survey_distance
0 1.324816e+06 338605.203520 69 1.231327e+09 POINT (1324815.858 338605.204) 25766.339236 2.902679e+07
1 1.382454e+06 383820.744145 64 1.229982e+09 POINT (1382454.422 383820.744) NaN 2.759927e+07
2 1.218181e+06 184977.326945 39 1.231092e+09 POINT (1218180.876 184977.327) NaN 1.613290e+07
3 1.597463e+06 527434.184141 43 1.231156e+09 POINT (1597463.336 527434.184) NaN 1.810998e+07
4 1.457011e+06 321990.423141 78 1.231332e+09 POINT (1457010.638 321990.423) NaN 3.179632e+07
[ ]: