From 7d3f4d6a76e6c7f27456edd4580bc69b4ee74c9c Mon Sep 17 00:00:00 2001 From: Lewin Probst <info@emirror.de> Date: Tue, 26 Nov 2019 12:17:18 +0100 Subject: [PATCH] The time divergence is now based on interpolated dates and positions. --- .../+track/+trajectoryOutput/plot.m | 6 +- lib/+artoa/+float/calculateTrajectory.m | 60 +++++++++++++++---- .../+trajectory/plotTimeDivergenceToGps.m | 3 + .../plotTimeDivergenceToGpsPositions.m} | 14 ++--- 4 files changed, 62 insertions(+), 21 deletions(-) rename lib/+artoa/{+controller/+track/+trajectoryOutput/plotTrajectorySurfacePositions.m => +trajectory/plotTimeDivergenceToGpsPositions.m} (72%) diff --git a/lib/+artoa/+controller/+track/+trajectoryOutput/plot.m b/lib/+artoa/+controller/+track/+trajectoryOutput/plot.m index 94a4b9e..5e3a516 100644 --- a/lib/+artoa/+controller/+track/+trajectoryOutput/plot.m +++ b/lib/+artoa/+controller/+track/+trajectoryOutput/plot.m @@ -72,10 +72,9 @@ for i = 1:length(trajectories) [ ... artoaGui.trajectoryOutput.trajectoryHandles{i}.scatterSurfacePositions, ... artoaGui.trajectoryOutput.trajectoryHandles{i}.textSurfacePositions ... - ] = artoa.controller.track.trajectoryOutput.plotTrajectorySurfacePositions( ... + ] = artoa.trajectory.plotTimeDivergenceToGpsPositions( ... artoaGui.trajectoryOutput.axesTrajectoryOutput, ... trajectories{i}, ... - artoaWorkspace.satData, ... trajectoryColor, ... pPlotAsMap ... ); @@ -124,7 +123,8 @@ for i = 1:length(trajectories) end artoa.controller.setPlotHandleVisibility( ... { ... - artoaGui.trajectoryOutput.trajectoryHandles{i}.textPositions ... + artoaGui.trajectoryOutput.trajectoryHandles{i}.textPositions, ... + artoaGui.trajectoryOutput.trajectoryHandles{i}.textSurfacePositions ... }, ... artoaWorkspace.trajectoryOutput.showPositionDates ... ); diff --git a/lib/+artoa/+float/calculateTrajectory.m b/lib/+artoa/+float/calculateTrajectory.m index 6ceb01b..c4cb103 100644 --- a/lib/+artoa/+float/calculateTrajectory.m +++ b/lib/+artoa/+float/calculateTrajectory.m @@ -189,6 +189,9 @@ trajectoryDates = []; trajectoryClockError = []; trajectoryResiduals = struct(); trajectoryTimeDivergenceToGps = struct(); +trajectoryTimeDivergenceToGps.latitude = []; +trajectoryTimeDivergenceToGps.longitude = []; +trajectoryTimeDivergenceToGps.date = []; for i = 1:length(involvedSoundsourceNames) trajectoryResiduals.(involvedSoundsourceNames{i}) = []; trajectoryTimeDivergenceToGps.(involvedSoundsourceNames{i}) = []; @@ -284,14 +287,46 @@ for oCombination = 1:size(soundsourceCombinations, 1) trajectoryVelocities.vertical = [trajectoryVelocities.vertical; segmentVerticalVelocity]; trajectoryVelocities.verticalDates = [trajectoryVelocities.verticalDates; segmentVerticalDates]; - % calculate time divergence to gps - % get all sat dates + if isempty(segmentDates) + continue; + end + + % Calculate time divergence to gps + % interpolate the trajectory linearly to have a position every day + [ ... + segmentInterpolatedDates, ... + segmentInterpolatedLat ... + ] = artoa.data.interpolateRafosData( ... + segmentDates, ... + segmentPositions(:, 1), ... + 24, ... + 9999, ... + 'linear' ... + ); + [ ... + ~, ... + segmentInterpolatedLon ... + ] = artoa.data.interpolateRafosData( ... + segmentDates, ... + segmentPositions(:, 2), ... + 24, ... + 9999, ... + 'linear' ... + ); + segmentInterpolatedPositions = [ segmentInterpolatedLat, segmentInterpolatedLon]; + % get all sat dates and positions satDates = artoa.convert.dmy2rd(pSatData.day_sat, pSatData.month_sat, pSatData.year_sat); + satPositions = [pSatData.lat_sat(:), pSatData.lon_sat(:)]; + tmpIndex = ~isnan(satDates) & ~any(isnan(satPositions), 2); + % remove nans + satDates = satDates(tmpIndex); + satPositions = satPositions(tmpIndex, :); + clear tmpIndex; % get all dates that intersect with segment - [~, segmentDatesIndex, satIndex] = intersect(round(segmentDates), round(satDates)); - intersectedSegmentPositions = segmentPositions(segmentDatesIndex, :); - intersectedSegmentDates = segmentDates(segmentDatesIndex, :); - satPositions = [pSatData.lat_sat(satIndex), pSatData.lon_sat(satIndex)]; + [~, segmentDatesIndex, segmentSatIndex] = intersect(floor(segmentInterpolatedDates), satDates); + intersectedSegmentPositions = segmentInterpolatedPositions(segmentDatesIndex, :); + intersectedSegmentDates = round(segmentInterpolatedDates(segmentDatesIndex, :)); + segmentSatPositions = satPositions(segmentSatIndex, :); % get all soundsources of segment segmentSoundsources = artoa.data.extractSoundsourcesFromStruct( ... strsplit(soundsourceCombinations.soundsources{oCombination}), ... @@ -306,19 +341,24 @@ for oCombination = 1:size(soundsourceCombinations, 1) pSoundVelocity(oCombination, oSoundsource) ... ); [gpsDivergence, usedIndices] = artoa.data.calculateTimeDivergence( ... - repmat(currentSoundsource.position, size(satPositions, 1), 1), ... - satPositions, ... + repmat(currentSoundsource.position, size(segmentSatPositions, 1), 1), ... + segmentSatPositions, ... pSoundVelocity(oCombination, oSoundsource) ... ); if isempty(usedIndices) || isempty(soundsourceDivergence) || isempty(gpsDivergence) continue; end - difference = (soundsourceDivergence(usedIndices) - gpsDivergence); + difference = (soundsourceDivergence(usedIndices) - gpsDivergence(:)); trajectoryTimeDivergenceToGps.(currentSoundsource.sourcename) = [ ... trajectoryTimeDivergenceToGps.(currentSoundsource.sourcename); - segmentDates(usedIndices), difference + intersectedSegmentDates(usedIndices), difference ]; end + % save positions and dates that have been interpolated and used for time divergence + trajectoryTimeDivergenceToGps.latitude = [trajectoryTimeDivergenceToGps.latitude; intersectedSegmentPositions(:, 1)]; + trajectoryTimeDivergenceToGps.longitude = [trajectoryTimeDivergenceToGps.longitude; intersectedSegmentPositions(:, 2)]; + trajectoryTimeDivergenceToGps.date = [trajectoryTimeDivergenceToGps.date; floor(intersectedSegmentDates)]; end + end \ No newline at end of file diff --git a/lib/+artoa/+trajectory/plotTimeDivergenceToGps.m b/lib/+artoa/+trajectory/plotTimeDivergenceToGps.m index 255f03a..9d5869e 100644 --- a/lib/+artoa/+trajectory/plotTimeDivergenceToGps.m +++ b/lib/+artoa/+trajectory/plotTimeDivergenceToGps.m @@ -16,6 +16,9 @@ cla(pAxesHandle); hold(pAxesHandle, 'on'); counter = 1; for i = 1:length(fnames) + if any(strcmp(fnames{i}, {'latitude', 'longitude', 'date'})) + continue; + end current = pTrajectory.timeDivergenceToGps.(fnames{i}); if isempty(current) continue; diff --git a/lib/+artoa/+controller/+track/+trajectoryOutput/plotTrajectorySurfacePositions.m b/lib/+artoa/+trajectory/plotTimeDivergenceToGpsPositions.m similarity index 72% rename from lib/+artoa/+controller/+track/+trajectoryOutput/plotTrajectorySurfacePositions.m rename to lib/+artoa/+trajectory/plotTimeDivergenceToGpsPositions.m index b79a49b..f4c2a35 100644 --- a/lib/+artoa/+controller/+track/+trajectoryOutput/plotTrajectorySurfacePositions.m +++ b/lib/+artoa/+trajectory/plotTimeDivergenceToGpsPositions.m @@ -1,13 +1,11 @@ -function [scatterHandle, textHandles] = plotTrajectorySurfacePositions(pAxesHandle, pTrajectory, pSatData, pColor, pPlotAsMap) +function [scatterHandle, textHandles] = plotTimeDivergenceToGpsPositions(pAxesHandle, pTrajectory, pColor, pPlotAsMap) %PLOTTRAJECTORYSURFACEPOSITIONS Summary of this function goes here % Detailed explanation goes here %% Get required data -satDates = artoa.convert.dmy2rd(pSatData.day_sat, pSatData.month_sat, pSatData.year_sat); -trajectoryDates = pTrajectory.date; -[~, ~, surfaceDates] = intersect(round(satDates), round(trajectoryDates)); -x = pTrajectory.longitude(surfaceDates); -y = pTrajectory.latitude(surfaceDates); +x = pTrajectory.timeDivergenceToGps.longitude; +y = pTrajectory.timeDivergenceToGps.latitude; +dates = pTrajectory.timeDivergenceToGps.date; %% Hold axes @@ -36,8 +34,8 @@ else ); end -t = artoa.convert.rd2dmy(trajectoryDates(surfaceDates)); -trd = round(trajectoryDates(surfaceDates)); +t = artoa.convert.rd2dmy(dates); +trd = round(dates); textHandles = cell(1, length(t)); if pPlotAsMap for i = 1:length(x) -- GitLab