Skip to content

Commit

Permalink
Fix WQM global attribute instrument_burst_duration value, was wrong b…
Browse files Browse the repository at this point in the history
…y 1 sample. Add global attributes instrument_burst_duration/interval to NXIC parser.
  • Loading branch information
ggalibert committed Oct 4, 2016
1 parent 891a219 commit fb223a2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
26 changes: 22 additions & 4 deletions Parser/NXICBinaryParse.m
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,30 @@
sample_data.meta.instrument_model = header.instrument_model;
sample_data.meta.instrument_serial_no = header.instrument_serial_no;
sample_data.meta.featureType = mode;
if header.sampleRate > 0
sample_data.meta.instrument_sample_interval = 1/header.sampleRate;
else
sample_data.meta.instrument_sample_interval = median(diff(samples.time*24*3600));

% Let's find each start of bursts
dt = [0; diff(samples.time)];
iBurst = [1; find(dt>(1/24/60)); length(samples.time)+1];

% let's read data burst by burst
nBurst = length(iBurst)-1;
firstTimeBurst = zeros(nBurst, 1);
sampleIntervalInBurst = zeros(nBurst, 1);
durationBurst = zeros(nBurst, 1);
for i=1:nBurst
timeBurst = samples.time(iBurst(i):iBurst(i+1)-1);
if numel(timeBurst)>1 % deals with the case of a file with a single sample in a single burst
sampleIntervalInBurst(i) = median(diff(timeBurst*24*3600));
firstTimeBurst(i) = timeBurst(1);
durationBurst(i) = (timeBurst(end) - timeBurst(1))*24*3600 + sampleIntervalInBurst(i);
end
end

sample_data.meta.instrument_sample_interval = round(median(sampleIntervalInBurst));
sample_data.meta.instrument_burst_interval = round(median(diff(firstTimeBurst*24*3600)));
sample_data.meta.instrument_burst_duration = round(median(durationBurst));


sample_data.dimensions = {};
sample_data.variables = {};

Expand Down
2 changes: 1 addition & 1 deletion Parser/readWQMdat.m
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@
if numel(timeBurst)>1 % deals with the case of a file with a single sample in a single burst
sampleIntervalInBurst(i) = median(diff(timeBurst*24*3600));
firstTimeBurst(i) = timeBurst(1);
durationBurst(i) = (timeBurst(end) - timeBurst(1))*24*3600;
durationBurst(i) = (timeBurst(end) - timeBurst(1))*24*3600 + sampleIntervalInBurst(i);
end
end

Expand Down
2 changes: 1 addition & 1 deletion Parser/readWQMraw.m
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@
timeBurst = time(iBurst(i):iBurst(i+1)-1);
sampleIntervalInBurst(i) = median(diff(timeBurst*24*3600));
firstTimeBurst(i) = timeBurst(1);
durationBurst(i) = (timeBurst(end) - timeBurst(1))*24*3600;
durationBurst(i) = (timeBurst(end) - timeBurst(1))*24*3600 + sampleIntervalInBurst(i);
end

sample_data.meta.instrument_sample_interval = round(median(sampleIntervalInBurst));
Expand Down

0 comments on commit fb223a2

Please sign in to comment.