From a53363e3d6b23bade75e75abb36a1913db4dc1c7 Mon Sep 17 00:00:00 2001
From: Stefan Hendricks <stefan.hendricks@googlemail.com>
Date: Thu, 25 Feb 2021 17:09:49 +0100
Subject: [PATCH] add code example

---
 examples/mosaic-polarstern-refstat-example.py | 76 +++++++++++++++++++
 1 file changed, 76 insertions(+)
 create mode 100644 examples/mosaic-polarstern-refstat-example.py

diff --git a/examples/mosaic-polarstern-refstat-example.py b/examples/mosaic-polarstern-refstat-example.py
new file mode 100644
index 0000000..9530e03
--- /dev/null
+++ b/examples/mosaic-polarstern-refstat-example.py
@@ -0,0 +1,76 @@
+# To add a new cell, type '# %%'
+# To add a new markdown cell, type '# %% [markdown]'
+# %% [markdown]
+# # Ice Drift Correction using the online interface to Polarstern data
+# 
+# This example illustrated steps to convert GPS positions from MOSAiC field data into local (x, y) coordinates. The translation and rotation correction of the drifting ice floe during MOSAiC is based on the position of the GPS1 antenna of Polarstern and the true heading data from the ships gyro heading. The data is automatically downloaded for the required period from the REST interface of dashboard.awi.de, thus an internet connection is required.
+# 
+# This solution is equivalent to the FloeNavi solution when the ship was moored at the same location at the ice floe. The origin of the (x, y) coordinate reference system will be at the position of the Polarstern GPS antenna and the x-axis will be defined by the ships orientation. 
+
+# %%
+import sys
+# Allow to find icedrift 
+# NOTE: this only works if `floenavi` (this module) and `icedrift` are cloned to the same directory
+sys.path.append('../../icedrift/')
+
+
+# %%
+from icedrift import GeoReferenceStation, IceCoordinateSystem, GeoPositionData
+
+# %% [markdown]
+# ### Create reference station object
+# 
+# The reference station is defined either by one geographic position plus the true heading of the x-axis, or by two positions with the true heading between both station defining the true heading of the x-axis. The floenavi master solution provided data for the first option in a file format that can be directly used to initialize the data class. 
+
+# %%
+sys.path.append('../../floenavi/')
+from floenavi.polarstern import PolarsternAWIDashboardPos
+
+# %% [markdown]
+# ### Step 1: Read GPS data 
+# 
+# Create a data container for the GPS data to be converted into the local (x, y) coordinates to determine the temporal coverage required for the Polarstern data extraction. 
+
+# %%
+track_csv_filepath = r"../data/rover/transect-examples/mosaic-transect-20200706-gem2-556-track.csv"
+track = GeoPositionData.from_csv(track_csv_filepath, latlon=True, header=None)
+
+# %% [markdown]
+# ### Step 2: Create reference station from Polarstern navigation data
+# 
+# This step creates an icedrift.GeoReferenceStation directly from Polarstern sensor data that is downloaded at runtime for the requested data period
+
+# %%
+refstat = PolarsternAWIDashboardPos(*track.time_bounds).reference_station
+
+# %% [markdown]
+# ### Step 3: Use icedrift coordinate transformation as usual
+# 
+# This step is identical to the example using the floenavi solution as basis for the coordinate transformation
+
+# %%
+icecs = IceCoordinateSystem(refstat)
+icepos = icecs.get_xy_coordinates(track)
+
+
+# %%
+import matplotlib.pyplot as plt 
+
+
+plt.figure(figsize=(10, 10))
+plt.scatter(icepos.longitude, icepos.latitude, s=6)
+plt.title("GPS coordinates")
+plt.xlabel("Longitude (degrees east)")
+plt.ylabel("Latitude (degrees north)")
+plt.show()
+
+plt.figure(figsize=(10, 10))
+plt.gca().set_aspect('equal')
+plt.scatter(icepos.xc, icepos.yc, s=6)
+plt.title("floe grid coordinates")
+plt.xlabel("x-coordinate (m)")
+plt.ylabel("y-coordinate (m)")
+plt.grid()
+plt.show()
+
+
-- 
GitLab