diff --git a/lib/+artoa/+controller/+track/+trajectoryOutput/plot.m b/lib/+artoa/+controller/+track/+trajectoryOutput/plot.m index 94a4b9ef6abbfe8cd472827391894b675f5bc7f7..5e3a516fdb1b2df186b2f15cf6dcffcdbd9da35f 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 6ceb01b337f9e83c5062293ef0ec1adc4928d726..c4cb103752df2354902b05a27cefe17d6c853e16 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 255f03a9e347f2e1f414217937d64582cde572bd..9d5869e6b016c53fb2985503f8c82aa939ce673c 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 b79a49b1188d032b5f8e89c7b222021f7022a1ad..f4c2a35c7905d7c08826c907bc6f7a0abbe9b890 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)