From 1ac7911369d7f26b45039c42d52cd937d7280af6 Mon Sep 17 00:00:00 2001 From: Lewin Probst <info@emirror.de> Date: Sun, 28 Jun 2020 10:30:00 +0200 Subject: [PATCH] Added SATFIX-ETA to TOA plot. --- VERSION | 2 +- .../+controller/+edit/updateAvailablePlots.m | 6 +- lib/+artoa/+controller/+file/loadInterim.m | 1 + lib/+artoa/+controller/+file/loadRfb.m | 1 + lib/+artoa/+controller/+file/reloadRfb.m | 3 + .../+controller/+file/reloadSoundSourceFile.m | 3 + lib/+artoa/+controller/+main/open.m | 1 + .../+satfixEtaToToa/calculateDifference.m | 55 ++++++++++++++ .../+controller/+show/+satfixEtaToToa/close.m | 31 ++++++++ .../+controller/+show/+satfixEtaToToa/open.m | 21 +++++ .../+controller/+show/+satfixEtaToToa/plot.m | 46 +++++++++++ lib/+artoa/+controller/updateMenuButtons.m | 2 + lib/+artoa/+gui/+show/satfixEtaToToa.m | 46 +++++++++++ lib/+artoa/+gui/main.m | 16 ++++ lib/+artoa/+satdata/calculateSatfixEta.m | 76 +++++++++++++++++++ .../+soundsources/+colorregister/getColor.m | 11 +++ 16 files changed, 317 insertions(+), 4 deletions(-) create mode 100644 lib/+artoa/+controller/+show/+satfixEtaToToa/calculateDifference.m create mode 100644 lib/+artoa/+controller/+show/+satfixEtaToToa/close.m create mode 100644 lib/+artoa/+controller/+show/+satfixEtaToToa/open.m create mode 100644 lib/+artoa/+controller/+show/+satfixEtaToToa/plot.m create mode 100644 lib/+artoa/+gui/+show/satfixEtaToToa.m create mode 100644 lib/+artoa/+satdata/calculateSatfixEta.m create mode 100644 lib/+artoa/+soundsources/+colorregister/getColor.m diff --git a/VERSION b/VERSION index a9d8b73..ce83bd9 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -257 \ No newline at end of file +258 \ No newline at end of file diff --git a/lib/+artoa/+controller/+edit/updateAvailablePlots.m b/lib/+artoa/+controller/+edit/updateAvailablePlots.m index 8fa204a..fcad21b 100644 --- a/lib/+artoa/+controller/+edit/updateAvailablePlots.m +++ b/lib/+artoa/+controller/+edit/updateAvailablePlots.m @@ -3,9 +3,9 @@ function [] = updateAvailablePlots() global artoaGui; -plotsToUpdate = {'editTemperature', 'editPressure', 'editTimeOfArrival', 'trajectoryOutput'}; -controllerPackageNames = {'temperature', 'pressure', 'timeOfArrival', 'trajectoryOutput'}; -controllerCategoryNames = {'edit', 'edit', 'edit', 'track'}; +plotsToUpdate = {'editTemperature', 'editPressure', 'editTimeOfArrival', 'satfixEtaToToa', 'trajectoryOutput'}; +controllerPackageNames = {'temperature', 'pressure', 'timeOfArrival', 'satfixEtaToToa', 'trajectoryOutput'}; +controllerCategoryNames = {'edit', 'edit', 'edit', 'show', 'track'}; for i = 1:length(plotsToUpdate) if ~isfield(artoaGui, plotsToUpdate{i}) diff --git a/lib/+artoa/+controller/+file/loadInterim.m b/lib/+artoa/+controller/+file/loadInterim.m index e106778..77ebdc4 100644 --- a/lib/+artoa/+controller/+file/loadInterim.m +++ b/lib/+artoa/+controller/+file/loadInterim.m @@ -21,6 +21,7 @@ artoa.controller.edit.pressure.close(); artoa.controller.edit.temperature.close(); artoa.controller.edit.timeOfArrival.close(); artoa.controller.track.trajectoryOutput.close(); +artoa.controller.show.satfixEtaToToa.close(); %% Load mat file load(fullfile(pathname, filename), '-mat'); diff --git a/lib/+artoa/+controller/+file/loadRfb.m b/lib/+artoa/+controller/+file/loadRfb.m index fc2d651..2ec5171 100644 --- a/lib/+artoa/+controller/+file/loadRfb.m +++ b/lib/+artoa/+controller/+file/loadRfb.m @@ -30,6 +30,7 @@ artoa.controller.edit.pressure.close(); artoa.controller.edit.temperature.close(); artoa.controller.edit.timeOfArrival.close(); artoa.controller.track.trajectoryOutput.close(); +artoa.controller.show.satfixEtaToToa.close(); %% Load file into memory artoaDataInput.rfb = artoa.load.rfb(filepath); diff --git a/lib/+artoa/+controller/+file/reloadRfb.m b/lib/+artoa/+controller/+file/reloadRfb.m index 6db3c98..acf3667 100644 --- a/lib/+artoa/+controller/+file/reloadRfb.m +++ b/lib/+artoa/+controller/+file/reloadRfb.m @@ -68,6 +68,9 @@ artoaWorkspace.editOffsets.offsets = artoa.offsets.generateOffsetTable( ... artoa.controller.track.parameter.updateGui(); artoa.controller.edit.offsets.updateGui(); +%% Update plots +artoa.controller.edit.updateAvailablePlots(); + %% Update status text in main window artoa.controller.main.updateLoadedFloatInformation(); diff --git a/lib/+artoa/+controller/+file/reloadSoundSourceFile.m b/lib/+artoa/+controller/+file/reloadSoundSourceFile.m index bfad902..847deee 100644 --- a/lib/+artoa/+controller/+file/reloadSoundSourceFile.m +++ b/lib/+artoa/+controller/+file/reloadSoundSourceFile.m @@ -47,5 +47,8 @@ artoa.controller.edit.offsets.updateWorkspaceOffsetsTable(true); artoa.controller.edit.offsets.updateGui(); artoa.controller.edit.offsets.updateMeasuredSoundspeed(); +%% Replot +artoa.controller.edit.updateAvailablePlots(); + end diff --git a/lib/+artoa/+controller/+main/open.m b/lib/+artoa/+controller/+main/open.m index 13cd7fc..c7ba663 100644 --- a/lib/+artoa/+controller/+main/open.m +++ b/lib/+artoa/+controller/+main/open.m @@ -29,6 +29,7 @@ callbacks.reloadRfbFile = @artoa.controller.file.reloadRfb; callbacks.openEditTemperature = @artoa.controller.edit.temperature.open; callbacks.openEditPressure = @artoa.controller.edit.pressure.open; callbacks.openEditTimeOfArrival = @artoa.controller.edit.timeOfArrival.open; +callbacks.openShowSatfixEtaToToa = @artoa.controller.show.satfixEtaToToa.open; callbacks.openEditOffsets = @artoa.controller.edit.offsets.open; callbacks.openTrackParameter = @artoa.controller.track.parameter.open; callbacks.openTrackTrajectoryOutput = @artoa.controller.track.trajectoryOutput.open; diff --git a/lib/+artoa/+controller/+show/+satfixEtaToToa/calculateDifference.m b/lib/+artoa/+controller/+show/+satfixEtaToToa/calculateDifference.m new file mode 100644 index 0000000..9965af5 --- /dev/null +++ b/lib/+artoa/+controller/+show/+satfixEtaToToa/calculateDifference.m @@ -0,0 +1,55 @@ +function [results] = calculateDifference() +%CALCULATE Summary of this function goes here +% Detailed explanation goes here + +global artoaWorkspace artoaConfig artoaDataInput; + +%% Calculate SATFIX ETA +[satfixEtas] = artoa.satdata.calculateSatfixEta( ... + artoaDataInput.rfb, ... + artoaWorkspace.filteredSoundsources, ... + artoaWorkspace.editOffsets.offsets, ... + artoa.controller.selectSoundspeed(), ... + artoaConfig.leapseconds); + +%% Calculate difference +fnames = fieldnames(artoaWorkspace.filteredSoundsources); + +results = struct(); +for i = 1:length(fnames) + results.(fnames{i}) = struct(); + results.(fnames{i}).difference = []; + selection = strcmp(artoaWorkspace.toaData.soundSource, fnames(i)); + toas = artoaWorkspace.toaData.toa(selection); + toaDates = ceil(artoaWorkspace.toaData.toaDate(selection)); + if length(toaDates) > 1 + % interpolate toa data + [ ... + toaDates, ... + toas, ... + ~ ... + ] = artoa.data.interpolateRafosData( ... + toaDates, ... + toas, ... + artoaWorkspace.trackParameter.interpolationInterval, ... + artoaWorkspace.trackParameter.gapSize, ... + lower(artoaWorkspace.trackParameter.interpolationMethodString) ... + ); + + % interpolate + %toas = interp1(toaDates, toas, min(toaDates):1:max(toaDates))'; + %toaDates = min(toaDates):1:max(toaDates)'; + end + dates = intersect(toaDates, satfixEtas.(fnames{i}).satDate); + indicesToa = ismember(toaDates, dates); + indicesSatfix = ismember(satfixEtas.(fnames{i}).satDate, dates); + if all(isnan(dates)) | isempty(dates) + continue; + end + results.(fnames{i}).difference = toas(indicesToa) - satfixEtas.(fnames{i}).satToa(indicesSatfix); + results.(fnames{i}).date = dates; +end + + +end + diff --git a/lib/+artoa/+controller/+show/+satfixEtaToToa/close.m b/lib/+artoa/+controller/+show/+satfixEtaToToa/close.m new file mode 100644 index 0000000..5e2242b --- /dev/null +++ b/lib/+artoa/+controller/+show/+satfixEtaToToa/close.m @@ -0,0 +1,31 @@ +function [ ] = close(pSource, ~) +%CLOSE Cleans up all variables that are used by the editPressure GUI. +% Changes to the data is not being modified. + +global artoaGui artoaWorkspace; + +%% Setup variables +figureName = 'satfixEtaToToa'; + +%% Close the figure +if nargin > 1 && isvalid(pSource) + delete(pSource); +elseif isfield(artoaGui.figures, figureName) && isvalid(artoaGui.figures.(figureName)) + delete(artoaGui.figures.(figureName)); +end + +%% Clean up variables + +if artoa.data.hasMember(artoaGui, {figureName}) + artoaGui = rmfield(artoaGui, figureName); +end + +if artoa.data.hasMember(artoaGui, {'figures', figureName}) + artoaGui.figures = rmfield(artoaGui.figures, figureName); +end + +if artoa.data.hasMember(artoaWorkspace, {figureName}) + artoaWorkspace = rmfield(artoaWorkspace, figureName); +end + +end \ No newline at end of file diff --git a/lib/+artoa/+controller/+show/+satfixEtaToToa/open.m b/lib/+artoa/+controller/+show/+satfixEtaToToa/open.m new file mode 100644 index 0000000..a91fab7 --- /dev/null +++ b/lib/+artoa/+controller/+show/+satfixEtaToToa/open.m @@ -0,0 +1,21 @@ +function [] = open(~, ~) +%OPENEDITTEMPERATURE Initializes the pressure editing gui. +% Detailed explanation goes here + +global artoaGui; + +%% Check if the gui is already opened + +if isfield(artoaGui.figures, 'showSatfixEtaToToa') + figure(artoaGui.figures.satfixEtaToToa); + return +end + + +callbacks.CloseRequestFcn = @artoa.controller.show.satfixEtaToToa.close; + +%% Open the gui +artoa.gui.show.satfixEtaToToa(callbacks); + +end + diff --git a/lib/+artoa/+controller/+show/+satfixEtaToToa/plot.m b/lib/+artoa/+controller/+show/+satfixEtaToToa/plot.m new file mode 100644 index 0000000..5aef546 --- /dev/null +++ b/lib/+artoa/+controller/+show/+satfixEtaToToa/plot.m @@ -0,0 +1,46 @@ +function [] = plot() +%PLOT Summary of this function goes here +% Detailed explanation goes here + +global artoaGui artoaWorkspace; + +%% Calculate required variables +[results] = artoa.controller.show.satfixEtaToToa.calculateDifference(); + +%% Create plot + +figureName = artoaGui.figures.satfixEtaToToa; + +axes(figureName); +hold(figureName.CurrentAxes, 'on'); +grid(figureName.CurrentAxes, 'on'); +fnames = fieldnames(artoaWorkspace.filteredSoundsources); +legendNames = {}; +for i = 1:length(fnames) + if isempty(results.(fnames{i}).difference) + continue; + end + color = artoa.soundsources.colorregister.getColor( ... + fnames{i}, ... + artoaWorkspace.soundsourceColorRegister, ... + artoaWorkspace.soundsourceColors ... + ); + legendNames{end + 1} = fnames{i}; + scatter( ... + figureName.CurrentAxes, ... + results.(fnames{i}).date, ... + results.(fnames{i}).difference, ... + [], ... + color, ... + 'filled' ... + ); +end +legend(figureName.CurrentAxes, legendNames); +title(figureName.CurrentAxes, 'Difference SATFIX-ETA - TOA'); +xlabel(figureName.CurrentAxes, 'Rafos date'); +ylabel(figureName.CurrentAxes, 'Difference [s]') +hold(figureName.CurrentAxes, 'off'); + + +end + diff --git a/lib/+artoa/+controller/updateMenuButtons.m b/lib/+artoa/+controller/updateMenuButtons.m index 3b358df..b9cf5a8 100644 --- a/lib/+artoa/+controller/updateMenuButtons.m +++ b/lib/+artoa/+controller/updateMenuButtons.m @@ -18,8 +18,10 @@ end %% If no pressure and temperature is selected, the time of arrival window should be disabled if (any(artoaWorkspace.statusTemperature == 1) && any(artoaWorkspace.statusPressure == 1)) artoaGui.main.menus.editTimeOfArrival.Enable = 'on'; + artoaGui.main.menus.showSatfixEtaToToa.Enable = 'on'; else artoaGui.main.menus.editTimeOfArrival.Enable = 'off'; + artoaGui.main.menus.showSatfixEtaToToa.Enable = 'off'; end end diff --git a/lib/+artoa/+gui/+show/satfixEtaToToa.m b/lib/+artoa/+gui/+show/satfixEtaToToa.m new file mode 100644 index 0000000..0377094 --- /dev/null +++ b/lib/+artoa/+gui/+show/satfixEtaToToa.m @@ -0,0 +1,46 @@ +function [] = satfixEtaToToa(pCallbacks) +%EDITSATFIXETATOTOA Creates the SATFIX-ETA to TOA plot. +% Detailed explanation goes here + +global artoaGui artoaWorkspace; + +%% Initialize required variables + +windowTitle = [ 'ARTOA4 - Float ' num2str(artoaWorkspace.float.floatname) ' - Difference SATFIX ETA to TOA' ]; + + +availableCallbacks = { ... + 'CloseRequestFcn' ... +}; + +for i = 1:length(availableCallbacks) % check if a callback is undefined + if ~isfield(pCallbacks, availableCallbacks{i}) + pCallbacks.(availableCallbacks{i}) = @(~, ~) false; + end +end + +%% Initialize offset details gui + +artoaGui.figures.satfixEtaToToa = figure( ... + 'Name', windowTitle, ... + 'NumberTitle', 'off', ... + 'Units', 'characters' ... +); + +% adjust width +artoaGui.figures.satfixEtaToToa.Position(3) = 120; +artoaGui.figures.satfixEtaToToa.Position(4) = 35; + +artoaGui.satfixEtaToToa = struct(); + +set( ... + artoaGui.figures.satfixEtaToToa, ... + 'CloseRequestFcn', ... + @artoa.controller.show.satfixEtaToToa.close ... +); + +%% Plot the values +artoa.controller.show.satfixEtaToToa.plot(); + +end + diff --git a/lib/+artoa/+gui/main.m b/lib/+artoa/+gui/main.m index 3edc522..6722c67 100644 --- a/lib/+artoa/+gui/main.m +++ b/lib/+artoa/+gui/main.m @@ -23,6 +23,7 @@ availableCallbacks = { ... 'openEditTemperature', ... 'openEditPressure', ... 'openEditTimeOfArrival', ... + 'openShowSatfixEtaToToa', ... 'openEditOffsets', ... 'openTrackParameter', ... 'openTrackTrajectoryOutput', ... @@ -224,6 +225,21 @@ artoaGui.main.menus.editTimeOfArrival = uimenu( ... 'Enable', 'off' ... ); +%% Show menu +artoaGui.main.menus.show = uimenu( ... + artoaGui.figures.main, ... + 'Label', 'Show', ... + 'Enable', 'on' ... +); + +% SATFIX-ETA to TOA +artoaGui.main.menus.showSatfixEtaToToa = uimenu( ... + artoaGui.main.menus.show, ... + 'Label', 'SATFIX-Eta to Toa', ... + 'Callback', pCallbacks.openShowSatfixEtaToToa, ... + 'Enable', 'off' ... +); + %% Initialize track menu artoaGui.main.menus.track = uimenu( ... diff --git a/lib/+artoa/+satdata/calculateSatfixEta.m b/lib/+artoa/+satdata/calculateSatfixEta.m new file mode 100644 index 0000000..540ec5f --- /dev/null +++ b/lib/+artoa/+satdata/calculateSatfixEta.m @@ -0,0 +1,76 @@ +function [satfixEta] = calculateSatfixEta(pRfb, pSoundsources, pOffsets, pSoundvelocities, pLeapsecondsMatrix) +%CALCULATEGPSTOAS Calculates the SAT TOAs of all soundsources. +% Calculates the SAT TOAs by artoa.toa.predictFromGps. Adds the +% soundsource offset and drift if already selected. + +%% Get all soundsources +fnames = fieldnames(pSoundsources); + +satfixEta = struct(); + + +%% Calculate GPS TOAs for every soundsource +for o = 1:length(fnames) + % initialize data storage + satfixEta.(fnames{o}) = struct(); + % calculate rafos dates of soundsource + soundSourceBegin = artoa.convert.dmy2rd(pSoundsources.(fnames{o}).begemis(3), ... + pSoundsources.(fnames{o}).begemis(2), ... + pSoundsources.(fnames{o}).begemis(1)); + soundSourceEnd = artoa.convert.dmy2rd(pSoundsources.(fnames{o}).endemis(3), ... + pSoundsources.(fnames{o}).endemis(2), ... + pSoundsources.(fnames{o}).endemis(1)); + + + [gpsDates, predictedToas, launchDateToa] = artoa.toa.predictFromGps( ... + pRfb, pSoundsources.(fnames{o}), ... + pSoundvelocities{fnames{o}, 1}, ... + pLeapsecondsMatrix ... + ); + + % add soundsource drift + if (~islogical(pOffsets)) ... + && any(contains(pOffsets.Properties.RowNames, fnames{o})) + offset = pOffsets{fnames{o}, 'AppliedOffset'}; + drift = pOffsets{fnames{o}, 'AppliedDrift'}; + % check if Inf + if isinf(offset) + offset = 0; + end + if isinf(drift) + drift = 0; + end + % no sorting required, because fourth parameter contains timesteps + predictedToas = artoa.toa.addDrift( ... + predictedToas, ... + offset, ... + drift, ... + floor(gpsDates - soundSourceBegin) ... + ); + % add offset and drift to launch toa + launchDateToa(2) = artoa.toa.addDrift( ... + launchDateToa(2), ... + offset, ... + drift ... + ); + end + + % remove gps dates that are past end mission of sound source + selection = (gpsDates > soundSourceEnd); + gpsDates(selection) = NaN; + predictedToas(selection) = NaN; + % remove gps dates before deployment of soundsource + selection = (gpsDates < soundSourceBegin); + gpsDates(selection) = NaN; + predictedToas(selection) = NaN; + clear selection; + + % save to workspace + satfixEta.(fnames{o}).satDate = gpsDates; + satfixEta.(fnames{o}).satToa = predictedToas; + satfixEta.(fnames{o}).satLaunchDateToa = launchDateToa; +end + + +end + diff --git a/lib/+artoa/+soundsources/+colorregister/getColor.m b/lib/+artoa/+soundsources/+colorregister/getColor.m new file mode 100644 index 0000000..c119783 --- /dev/null +++ b/lib/+artoa/+soundsources/+colorregister/getColor.m @@ -0,0 +1,11 @@ +function [color] = getColor(pSoundsourceName, pRegister, pColors) +%GETCOLOR Summary of this function goes here +% Detailed explanation goes here + +color = pColors( ... + artoa.soundsources.colorregister.getColorIndex(pSoundsourceName, pRegister), ... + : ... + ); + +end + -- GitLab