Difference between revisions of "COPSradQC"
Jump to navigation
Jump to search
(Created page with "back to C-OPS/CERBERUS Mfiles") |
|||
| Line 1: | Line 1: | ||
| + | <pre> | ||
| + | function COPSradQC(infile,path)%,channel,threshold) | ||
| + | %This is a quality control function for PRR radiometer processing | ||
| + | %check and flag data of spectral channels by comparing each value to a | ||
| + | %threshold | ||
| + | %created by Erik Stassinos 4/27/2011 | ||
| + | %This function will process the infile(assume LCD format) | ||
| + | %for now file processing will always be of type 'a' which is a simple | ||
| + | %comparison function between channel values and the threshold | ||
| + | %This script has been modified to work with a list file now 7/1/2011 | ||
| + | %====> made a procfile loop and changed added filters loop | ||
| + | |||
| + | intype = 'a'; %hardcoding | ||
| + | type = lower(intype); | ||
| + | chanind =0; | ||
| + | flag = -9.9E35; | ||
| + | ct = 1; %arbitrary counter | ||
| + | infile = strtrim(infile); | ||
| + | |||
| + | |||
| + | if strncmp(type,'a',1) ==1 | ||
| + | disp('you are doing a comparison') | ||
| + | %load rcq list | ||
| + | %proclist = load('/home/data65/pb/REPROCESS_2010/PRR/rqclist.txt'); | ||
| + | procfile = fopen(path);% modified to tak in path'/home/data65/pb/REPROCESS_2010/PRR/rqclist.txt'); | ||
| + | |||
| + | end | ||
| + | while ~feof(procfile) | ||
| + | line = fgets(procfile); | ||
| + | line = strsplit(line); | ||
| + | chan = line{1}; | ||
| + | thresh = str2num(line{2}); | ||
| + | %[chan, thresh] = textread(path,'%s %f'); %modified to put in path 1-10-2013 | ||
| + | |||
| + | |||
| + | if ct ==54 | ||
| + | break | ||
| + | end | ||
| + | |||
| + | channel = chan;%{ct} | ||
| + | threshold = thresh;%(ct) | ||
| + | infid = fopen(infile); | ||
| + | %===READ LCD FILE AND GET INDEX OF CHANNEL=== | ||
| + | lineind =0; | ||
| + | %frewind(infid) | ||
| + | while ~feof(infid) | ||
| + | line = fgets(infid); | ||
| + | if strncmp(line,'<sampled_parameters>',20) ==1 | ||
| + | while strncmp(line,'<data>',6) ~= 1 | ||
| + | lineind = lineind +1; | ||
| + | line = fgets(infid); | ||
| + | if strncmp(line,'<derived_parameters>',20) == 1 | ||
| + | lineind = lineind -1; | ||
| + | end | ||
| + | if strncmp(channel,line,5) ==1 | ||
| + | chanind = lineind; | ||
| + | end | ||
| + | end | ||
| + | end | ||
| + | end | ||
| + | |||
| + | |||
| + | |||
| + | %===RESET READ LCD AND LOAD ONLY DATA INTO DATA FILE=== | ||
| + | frewind(infid) | ||
| + | dataname = strcat('radQCmat',infile); | ||
| + | dataname = strrep(dataname,'.lcd',''); | ||
| + | datafid = fopen(dataname,'r+'); | ||
| + | |||
| + | |||
| + | if datafid == -1 | ||
| + | disp('cant open dataname, creating file') | ||
| + | datafid = fopen(dataname,'w+'); | ||
| + | end | ||
| + | if ct ==1; | ||
| + | while ~feof(infid) | ||
| + | testline = fgets(infid); | ||
| + | if strncmp(testline,'<data>',6) ==1 %start of data section | ||
| + | while strncmp(testline,'<filters_used>',14) ~=1 | ||
| + | testline = fgets(infid); | ||
| + | if strncmp(testline,'<filters_used>',14) ==1 | ||
| + | % fprintf(datafid,testline); | ||
| + | % testline | ||
| + | % pause | ||
| + | break | ||
| + | end | ||
| + | fprintf(datafid,testline); | ||
| + | end | ||
| + | end | ||
| + | end | ||
| + | fclose(datafid); | ||
| + | frewind(infid); | ||
| + | end | ||
| + | |||
| + | |||
| + | |||
| + | |||
| + | %===DO QUALITY CONTROL AND REPLACE DATA WITH FLAG IF NEEDED=== | ||
| + | |||
| + | QCdata = load(dataname); | ||
| + | checkcol = QCdata(:,chanind); | ||
| + | badloc = find(checkcol < threshold); | ||
| + | checkcol(badloc) = flag; | ||
| + | QCdata_new = QCdata; | ||
| + | %QCdata_new(:,chanind) | ||
| + | QCdata_new(:,chanind) = checkcol; | ||
| + | %QCdata_new(:,chanind) | ||
| + | |||
| + | dlmwrite(dataname,QCdata_new,'delimiter',' ','precision',6); %overwrite old matrix file | ||
| + | |||
| + | %===INSERT NEW DATA INTO NEW LCD=== | ||
| + | |||
| + | frewind(infid); | ||
| + | %if ct ==1 | ||
| + | qclcd = fopen(strcat('rqc',infile),'w+'); | ||
| + | %else | ||
| + | % qclcd = fopen(strcat('rqc',infile),'r+'); | ||
| + | %end | ||
| + | while ~feof(infid) | ||
| + | pos = fgets(infid); | ||
| + | fprintf(qclcd,pos); | ||
| + | if strncmp(pos,'<data>',6) ==1 %start of data section | ||
| + | break | ||
| + | end | ||
| + | end | ||
| + | |||
| + | datafile = fopen(dataname); | ||
| + | while ~feof(datafile) | ||
| + | %for loop = 1:length(QCdata_new) | ||
| + | datln = fgets(datafile); | ||
| + | fprintf(qclcd,datln); | ||
| + | end | ||
| + | |||
| + | |||
| + | %===ADD TO FILTERS USED ON NEW LCD=== | ||
| + | %if ct ==1 %%%new for list file | ||
| + | while ~feof(infid) | ||
| + | lcdline = fgets(infid); | ||
| + | if strncmp(lcdline,'<filters_used>',14) ==1 | ||
| + | %fseek(qclcd,0,'eof') | ||
| + | fprintf(qclcd,'%s\n','<filters_used>'); | ||
| + | while ~feof(infid) | ||
| + | filter = fgets(infid); | ||
| + | fprintf(qclcd,'%s',filter); | ||
| + | end | ||
| + | end | ||
| + | end | ||
| + | |||
| + | |||
| + | clear channel | ||
| + | clear threshold | ||
| + | ct = ct +1; | ||
| + | fclose(infid); | ||
| + | %keyboard | ||
| + | end | ||
| + | fclose('all'); | ||
| + | |||
| + | |||
| + | %===loop to add list of filters | ||
| + | procfile = fopen('/home/oceancolor/Plumes_and_Blooms/workspace/eriks/C-OPS/Copsrqclist.txt'); | ||
| + | qclcd = fopen(strcat('rqc',infile),'r+'); | ||
| + | fseek(qclcd,0,'eof'); | ||
| + | fgets(qclcd); | ||
| + | |||
| + | %[chan,threshold] = textread('/home/oceancolor/Plumes_and_Blooms/workspace/eriks/C-OPS/Copsrqclist.txt','%s '); | ||
| + | chanfid = fopen('/home/oceancolor/Plumes_and_Blooms/workspace/eriks/C-OPS/Copsrqclist.txt'); | ||
| + | while ~feof(chanfid) | ||
| + | channelII = fgets(chanfid); | ||
| + | if isempty(strtrim(channelII)) | ||
| + | break | ||
| + | end | ||
| + | |||
| + | fprintf(qclcd,'%s','radQC '); | ||
| + | fprintf(qclcd,'%s',intype); | ||
| + | fprintf(qclcd,'%s',' '); | ||
| + | fprintf(qclcd,'%s',channelII); | ||
| + | |||
| + | end | ||
| + | |||
| + | </pre> | ||
| + | |||
| + | |||
| + | |||
back to [[C-OPS/CERBERUS Mfiles]] | back to [[C-OPS/CERBERUS Mfiles]] | ||
Latest revision as of 14:22, 13 February 2014
function COPSradQC(infile,path)%,channel,threshold)
%This is a quality control function for PRR radiometer processing
%check and flag data of spectral channels by comparing each value to a
%threshold
%created by Erik Stassinos 4/27/2011
%This function will process the infile(assume LCD format)
%for now file processing will always be of type 'a' which is a simple
%comparison function between channel values and the threshold
%This script has been modified to work with a list file now 7/1/2011
%====> made a procfile loop and changed added filters loop
intype = 'a'; %hardcoding
type = lower(intype);
chanind =0;
flag = -9.9E35;
ct = 1; %arbitrary counter
infile = strtrim(infile);
if strncmp(type,'a',1) ==1
disp('you are doing a comparison')
%load rcq list
%proclist = load('/home/data65/pb/REPROCESS_2010/PRR/rqclist.txt');
procfile = fopen(path);% modified to tak in path'/home/data65/pb/REPROCESS_2010/PRR/rqclist.txt');
end
while ~feof(procfile)
line = fgets(procfile);
line = strsplit(line);
chan = line{1};
thresh = str2num(line{2});
%[chan, thresh] = textread(path,'%s %f'); %modified to put in path 1-10-2013
if ct ==54
break
end
channel = chan;%{ct}
threshold = thresh;%(ct)
infid = fopen(infile);
%===READ LCD FILE AND GET INDEX OF CHANNEL===
lineind =0;
%frewind(infid)
while ~feof(infid)
line = fgets(infid);
if strncmp(line,'<sampled_parameters>',20) ==1
while strncmp(line,'<data>',6) ~= 1
lineind = lineind +1;
line = fgets(infid);
if strncmp(line,'<derived_parameters>',20) == 1
lineind = lineind -1;
end
if strncmp(channel,line,5) ==1
chanind = lineind;
end
end
end
end
%===RESET READ LCD AND LOAD ONLY DATA INTO DATA FILE===
frewind(infid)
dataname = strcat('radQCmat',infile);
dataname = strrep(dataname,'.lcd','');
datafid = fopen(dataname,'r+');
if datafid == -1
disp('cant open dataname, creating file')
datafid = fopen(dataname,'w+');
end
if ct ==1;
while ~feof(infid)
testline = fgets(infid);
if strncmp(testline,'<data>',6) ==1 %start of data section
while strncmp(testline,'<filters_used>',14) ~=1
testline = fgets(infid);
if strncmp(testline,'<filters_used>',14) ==1
% fprintf(datafid,testline);
% testline
% pause
break
end
fprintf(datafid,testline);
end
end
end
fclose(datafid);
frewind(infid);
end
%===DO QUALITY CONTROL AND REPLACE DATA WITH FLAG IF NEEDED===
QCdata = load(dataname);
checkcol = QCdata(:,chanind);
badloc = find(checkcol < threshold);
checkcol(badloc) = flag;
QCdata_new = QCdata;
%QCdata_new(:,chanind)
QCdata_new(:,chanind) = checkcol;
%QCdata_new(:,chanind)
dlmwrite(dataname,QCdata_new,'delimiter',' ','precision',6); %overwrite old matrix file
%===INSERT NEW DATA INTO NEW LCD===
frewind(infid);
%if ct ==1
qclcd = fopen(strcat('rqc',infile),'w+');
%else
% qclcd = fopen(strcat('rqc',infile),'r+');
%end
while ~feof(infid)
pos = fgets(infid);
fprintf(qclcd,pos);
if strncmp(pos,'<data>',6) ==1 %start of data section
break
end
end
datafile = fopen(dataname);
while ~feof(datafile)
%for loop = 1:length(QCdata_new)
datln = fgets(datafile);
fprintf(qclcd,datln);
end
%===ADD TO FILTERS USED ON NEW LCD===
%if ct ==1 %%%new for list file
while ~feof(infid)
lcdline = fgets(infid);
if strncmp(lcdline,'<filters_used>',14) ==1
%fseek(qclcd,0,'eof')
fprintf(qclcd,'%s\n','<filters_used>');
while ~feof(infid)
filter = fgets(infid);
fprintf(qclcd,'%s',filter);
end
end
end
clear channel
clear threshold
ct = ct +1;
fclose(infid);
%keyboard
end
fclose('all');
%===loop to add list of filters
procfile = fopen('/home/oceancolor/Plumes_and_Blooms/workspace/eriks/C-OPS/Copsrqclist.txt');
qclcd = fopen(strcat('rqc',infile),'r+');
fseek(qclcd,0,'eof');
fgets(qclcd);
%[chan,threshold] = textread('/home/oceancolor/Plumes_and_Blooms/workspace/eriks/C-OPS/Copsrqclist.txt','%s ');
chanfid = fopen('/home/oceancolor/Plumes_and_Blooms/workspace/eriks/C-OPS/Copsrqclist.txt');
while ~feof(chanfid)
channelII = fgets(chanfid);
if isempty(strtrim(channelII))
break
end
fprintf(qclcd,'%s','radQC ');
fprintf(qclcd,'%s',intype);
fprintf(qclcd,'%s',' ');
fprintf(qclcd,'%s',channelII);
end
back to C-OPS/CERBERUS Mfiles