-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
task: add first iteration of
mag.bart.Analysis
for loading Bartingt…
…on measurements
- Loading branch information
1 parent
bb32524
commit 3577d9c
Showing
2 changed files
with
123 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
classdef (Sealed) Analysis < mag.Analysis | ||
% ANALYSIS Automate analysis of Bartington data. | ||
|
||
properties | ||
% LOCATION Location of data to load. | ||
Location (1, 1) string {mustBeFolder} = pwd() | ||
% SCIENCEPATTERN Pattern of science data files. | ||
SciencePattern (1, 1) string = fullfile("*.Dat") | ||
% SCIENCEPROCESSING Steps needed to process science data. | ||
ScienceProcessing (1, :) mag.process.Step = mag.process.Step.empty() | ||
end | ||
|
||
properties (Dependent) | ||
% SCIENCEFILENAMES Files containing science data. | ||
ScienceFileNames (1, :) string | ||
end | ||
|
||
properties (SetAccess = private) | ||
% RESULTS Results collected during analysis. | ||
Results mag.Instrument {mustBeScalarOrEmpty} | ||
end | ||
|
||
properties (Access = private) | ||
% SCIENCEFILES Information about files containing science data. | ||
ScienceFiles (:, 1) struct | ||
end | ||
|
||
methods (Static) | ||
|
||
function analysis = start(options) | ||
% START Start automated analysis with options. | ||
|
||
arguments | ||
options.?mag.bart.Analysis | ||
end | ||
|
||
args = namedargs2cell(options); | ||
analysis = mag.bart.Analysis(args{:}); | ||
|
||
analysis.detect(); | ||
analysis.load(); | ||
end | ||
end | ||
|
||
methods | ||
|
||
function this = Analysis(options) | ||
|
||
arguments | ||
options.?mag.bart.Analysis | ||
end | ||
|
||
this.assignProperties(options); | ||
end | ||
|
||
function value = get.ScienceFileNames(this) | ||
value = string(fullfile({this.ScienceFiles.folder}, {this.ScienceFiles.name})); | ||
end | ||
|
||
function detect(this) | ||
this.ScienceFiles = dir(fullfile(this.Location, this.SciencePattern)); | ||
end | ||
|
||
function load(this) | ||
|
||
this.Results = mag.Instrument(); | ||
|
||
this.loadScienceData(); | ||
end | ||
|
||
function export(this, exportType, options) | ||
|
||
arguments | ||
this (1, 1) mag.bart.Analysis | ||
exportType (1, 1) string {mustBeMember(exportType, "MAT")} | ||
options.Location (1, 1) string {mustBeFolder} = "results" | ||
options.StartTime (1, 1) datetime = NaT(TimeZone = "UTC") | ||
options.EndTime (1, 1) datetime = NaT(TimeZone = "UTC") | ||
end | ||
|
||
% Determine export classes. | ||
format = mag.bart.out.("Science" + exportType); | ||
|
||
% Determine export window. | ||
if ismissing(options.StartTime) | ||
options.StartTime = datetime("-Inf", TimeZone = "UTC"); | ||
end | ||
|
||
if ismissing(options.EndTime) | ||
options.EndTime = datetime("Inf", TimeZone = "UTC"); | ||
end | ||
|
||
period = timerange(options.StartTime, options.EndTime, "closed"); | ||
|
||
% Export full science. | ||
if this.Results.HasScience | ||
|
||
results = this.Results.copy(); | ||
results.crop(period); | ||
|
||
mag.io.export(results, Location = options.Location, Format = format); | ||
end | ||
end | ||
end | ||
|
||
methods (Access = private) | ||
|
||
function loadScienceData(this) | ||
|
||
if isempty(this.ScienceFileNames) | ||
return; | ||
end | ||
|
||
this.Results.Science = mag.io.import( ... | ||
FileNames = this.ScienceFileNames, ... | ||
Format = mag.bart.in.ScienceDAT(), ... | ||
ProcessingSteps = this.ScienceProcessing); | ||
end | ||
end | ||
end |