Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update software to v2.3.0 #9

Merged
merged 8 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/matlab.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
if: github.ref == 'refs/heads/main'
needs: test
env:
VERSION: "2.2.1"
VERSION: "2.3.0"
steps:
- name: Check out repository
uses: actions/checkout@v3
Expand Down
Binary file modified app/DataVisualization.mlapp
Binary file not shown.
17 changes: 11 additions & 6 deletions resources/ReleaseNotes.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
- Add cropping of one vector at beginning of each file
- Add more options for sorting processing step
- Hide unnecessary constants in meta data classes
- Make sure custom events have padded y-axis limits
- Fix issue with consecutive figures not opening maximized
- Fix issue with saving figures in folder names with dots
- Improve time estimates of mode change events
- Add method to downsample science data
- Add method to split analysis by time gap
- Add sound when progress bar finishes in app
- Add data ready time difference in processor stats plot
- Allow cropping instrument data with `withtol`
- Only filter one vector for mode changes, and one second for range changes
- Do not show sensor meta data in title when no meta data is detected
- Fix issue with saving figures with colons in name
- Fix issue with saving too large figures causing an error
- Fix small typo in HK data loading
2 changes: 1 addition & 1 deletion src/analyze/+mag/+process/Downsample.m
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
end

% Determine filter coefficients.
actualFrequency = 1 / median(seconds(diff(data.(data.Properties.DimensionNames{1}))));
actualFrequency = 1 / mode(seconds(diff(data.(data.Properties.DimensionNames{1}))));

decimationFactor = actualFrequency / this.TargetFrequency;
assert(round(decimationFactor) == decimationFactor, "Calculated decimation factor (%.3f) must be an integer.", decimationFactor);
Expand Down
32 changes: 32 additions & 0 deletions src/analyze/+mag/@AutomatedAnalysis/AutomatedAnalysis.m
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,38 @@ function load(this)
findFinalNormalMode(this.Results.Secondary.Events, this.Results.Secondary.Time(end)));
end

function periods = splitByTimeGap(this, gap)
% SPLITBYTIMEGAP Split data based on gap in the data of specified
% magnitude.

arguments (Input)
this
gap (1, 1) duration
end

arguments (Output)
periods (1, :) mag.Instrument
end

tPrimary = this.Results.Primary.Time;
dtPrimary = diff(tPrimary);
tSplitPrimary = [tPrimary(1); tPrimary(dtPrimary > gap)];

tSecondary = this.Results.Secondary.Time;
dtSecondary = diff(tSecondary);
tSplitSecondary = [tSecondary(1); tSecondary(dtSecondary > gap)];

if ~isequal(numel(tSplitPrimary), numel(tSplitSecondary))
error("Unequal time splits in primary (%d) and secondary(%d) data. Try a different time gap.", numel(tSplitPrimary), numel(tSplitSecondary));
end

for i = 1:(numel(tSplitPrimary) - 1)

periods(i) = this.applyTimeRangeToInstrument(timerange(tSplitPrimary(i), tSplitPrimary(i + 1), "open"), ...
timerange(tSplitSecondary(i), tSplitSecondary(i + 1), "open")); %#ok<AGROW>
end
end

% EXPORT Export data to specified format.
export(this, exportStrategy, options)
end
Expand Down
2 changes: 1 addition & 1 deletion src/analyze/+mag/@AutomatedAnalysis/loadHKData.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function loadHKData(this, hkMetaData)
end

% Concentrate on recorded timerange.
if ~isempty(this.Results.Primary)
if ~isempty(this.Results.MetaData)

for i = 1:numel(this.Results.HK)
this.Results.HK(i).Data = this.Results.HK(i).Data(timerange(this.Results.MetaData.Timestamp, this.Results.HK(i).Time(end), "closed"), :);
Expand Down
45 changes: 39 additions & 6 deletions src/data/+mag/Instrument.m
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,16 @@ function cropScience(this, primaryFilter, secondaryFilter)

arguments
this
primaryFilter (1, 1) {mustBeA(primaryFilter, ["timerange", "duration"])}
secondaryFilter (1, 1) {mustBeA(secondaryFilter, ["timerange", "duration"])} = primaryFilter
primaryFilter (1, 1) {mustBeA(primaryFilter, ["duration", "timerange", "withtol"])}
secondaryFilter (1, 1) {mustBeA(secondaryFilter, ["duration", "timerange", "withtol"])} = primaryFilter
end

if isa(primaryFilter, "timerange")
[primaryPeriod, secondaryPeriod] = deal(primaryFilter, secondaryFilter);
elseif isa(primaryFilter, "duration")
if isa(primaryFilter, "duration")

primaryPeriod = timerange(this.Primary.Time(1) + primaryFilter, this.Primary.Time(end), "openleft");
secondaryPeriod = timerange(this.Secondary.Time(1) + secondaryFilter, this.Secondary.Time(end), "openleft");
elseif isa(primaryFilter, "timerange") || isa(primaryFilter, "withtol")
[primaryPeriod, secondaryPeriod] = deal(primaryFilter, secondaryFilter);
end

this.Primary.Data = this.Primary.Data(primaryPeriod, :);
Expand All @@ -136,7 +136,9 @@ function cropDataBasedOnScience(this)
timeRange = this.TimeRange;

% Filter events.
this.Events = this.Events(isbetween([this.Events.CommandTimestamp], timeRange(1), timeRange(2), "closed"));
if ~isempty(this.Events)
this.Events = this.Events(isbetween([this.Events.CommandTimestamp], timeRange(1), timeRange(2), "closed"));
end

% Filter HK.
for i = 1:numel(this.HK)
Expand All @@ -148,6 +150,37 @@ function cropDataBasedOnScience(this)
this.Primary.MetaData.Timestamp = timeRange(1);
this.Secondary.MetaData.Timestamp = timeRange(1);
end

function downsample(this, targetFrequency)
% DOWNSAMPLE Downsample primary and secondary data to specified
% frequency.

arguments
this mag.Instrument
targetFrequency (1, 1) double
end

for s = ["Primary", "Secondary"]

actualFrequency = 1 / mode(seconds(diff(this.(s).Time)));
decimationFactor = actualFrequency / targetFrequency;

if round(decimationFactor) ~= decimationFactor
error("Calculated decimation factor (%.3f) must be an integer.", decimationFactor);
end

a = ones(1, decimationFactor) / decimationFactor;
b = conv(a, a);

data = this.(s).Data;
data{:, ["x", "y", "z"]} = filter(b, 1, data{:, ["x", "y", "z"]});

data(1:numel(b), :) = [];

this.(s).Data = downsample(data, decimationFactor);
this.(s).MetaData.DataFrequency = targetFrequency;
end
end
end

methods (Access = protected)
Expand Down
7 changes: 6 additions & 1 deletion src/visualize/+mag/+graphics/+view/Field.m
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,12 @@ function visualize(this)
methods (Static, Access = private)

function value = getFieldTitle(data)
value = sprintf("%s (%s - %s - %s)", data.MetaData.getDisplay("Sensor"), data.MetaData.getDisplay("FEE"), data.MetaData.getDisplay("Model"), data.MetaData.getDisplay("Can"));

if isempty(data.MetaData.FEE) || isempty(data.MetaData.Model) || isempty(data.MetaData.Can)
value = data.MetaData.getDisplay("Sensor");
else
value = sprintf("%s (%s - %s - %s)", data.MetaData.getDisplay("Sensor"), data.MetaData.getDisplay("FEE"), data.MetaData.getDisplay("Model"), data.MetaData.getDisplay("Can"));
end
end
end
end
8 changes: 7 additions & 1 deletion src/visualize/+mag/+graphics/+view/HK.m
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,19 @@ function visualize(this)
end

% Processor HK.
sid15 = this.getHKType("SID15");
procstat = this.getHKType("PROCSTAT");

if ~isempty(procstat)
if ~isempty(sid15) && ~isempty(procstat)

drt = sid15.Data(:, ["ISV_FOB_DTRDYTM", "ISV_FIB_DTRDYTM"]);
drt.DIFF = 1000 * (drt.ISV_FOB_DTRDYTM - drt.ISV_FIB_DTRDYTM);

this.Figures(4) = mag.graphics.visualize( ...
procstat, mag.graphics.style.Default(Title = "Messages in Queue", YLabel = "n [-]", Legend = ["FOB", "FIB"], Charts = [mag.graphics.chart.Plot(YVariables = "OBNQ_NUM_MSG"), mag.graphics.chart.Plot(YVariables = "IBNQ_NUM_MSG")]), ...
drt, mag.graphics.style.Default(Title = "Data Ready Time", YLabel = "\Delta Data Ready Time [ms]", Charts = mag.graphics.chart.Plot(YVariables = "DIFF")), ...
Name = "Processor Stats", ...
Arrangement = [2, 1], ...
LinkXAxes = true);
end
end
Expand Down
11 changes: 9 additions & 2 deletions src/visualize/+mag/+graphics/savePlots.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,22 @@ function savePlots(figures, location, options)
figures (1, :) matlab.ui.Figure
location (1, 1) string {mustBeFolder} = "results"
options.DotReplacement (1, 1) string = "_"
options.ColonReplacement (1, 1) string = ""
end

for f = figures

if isvalid(f)

name = fullfile(location, replace(f.Name, ".", options.DotReplacement));
name = replace(f.Name, [".", ":"], [options.DotReplacement, options.ColonReplacement]);
name = fullfile(location, name);

try
savefig(f, name);
catch exception
warning("Could not save figure ""%s"":\n%s", f.Name, exception.message);
end

savefig(f, name);
exportgraphics(f, fullfile(name + ".png"), Resolution = 300);
end
end
Expand Down