Skip to content

Commit

Permalink
bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveCoss committed Jan 22, 2021
1 parent d2a3e2a commit 12e944c
Show file tree
Hide file tree
Showing 38 changed files with 1,404 additions and 183 deletions.
40 changes: 40 additions & 0 deletions ADDfd2gage.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
function [Gout] = ADDfd2gage(Gin,Riv,ST,svnm);
CL=shaperead(fullfile('C:\Users\coss.31\Documents\MATH\OSU_RA_Toolbox2018\CenterLines',strcat(Riv,'_centerline.shp')));
%unpack CL
Xline = [CL.X];
Yline = [CL.Y];
Xg=Gin.Lon;Yg=Gin.Lat;
FD = CL.Flow_Dist;
%reproject center;ine
ZONE = utmzone(Yline, Xline);
mstruct = defaultm('utm');
mstruct.zone = ZONE;
mstruct.geoid = almanac('earth','wgs84','meters');
mstruct = defaultm(mstruct);
[Xline,Yline]=mfwdtran(mstruct,Yline,Xline);
Xline = smooth(Xline);
Yline = smooth (Yline);
[Xg,Yg]=mfwdtran(mstruct,Yg,Xg);
[blork DX]= min(abs(sqrt(( Xg-Xline).^2 + ( Yg- Yline).^2 )));
Gout=Gin;
Gout.GageFLdist=CL(DX).Flow_Dist;
Gout.RIVER=Riv;
Cut1=ST(length(Riv)+1:end);
Cut2=Cut1(1:end-6);
Gout.Station=Cut2;
DATE=Gout.DATE;
Lat=Gout.Lat;
Lon=Gout.Lon;
stage=Gout.stage;
GageFLdist=Gout.GageFLdist;
RIVER=Gout.RIVER;
Station=Gout.Station;
if isfield(Gout,'flags')
flags=Gout.flags;
ice=Gout.ice;
save(svnm,'DATE','Lat','Lon','flags','ice','stage','GageFLdist','RIVER','Station');
else
save(svnm,'DATE','Lat','Lon','stage','GageFLdist','RIVER','Station');
end

end
13 changes: 13 additions & 0 deletions AltimeterFootprint.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
clear all

R0e=785e3; %Envisat = 785; jason-2 = 1336
R0j=1336e3;
Re=6371*1000; % km x 1000 = m
c=3e8; %m/s
tau=3.125e-9; %pulse length
Hw=0:15;

re=((c.*tau + 2.*Hw).*R0e./(1+R0e./Re)).^.5;
rj=((c.*tau + 2.*Hw).*R0j./(1+R0j./Re)).^.5;

plot(Hw,re./1000,Hw,rj./1000)
12 changes: 11 additions & 1 deletion CalcAvgHeights2.m
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,16 @@


end

if Altimetry.cmax> length(Altimetry.call)
if Altimetry.nGood/length(Altimetry.call)<=0.50 && isempty(IceData)
Altimetry.Write=0;
else if Altimetry.nGood/length(Altimetry.call)<=0.25 && ~isempty(IceData)
Altimetry.Write=0;
else
Altimetry.Write=1;
end
end
else
if Altimetry.nGood/Altimetry.cmax<=0.50 && isempty(IceData)
Altimetry.Write=0;
else if Altimetry.nGood/Altimetry.cmax<=0.25 && ~isempty(IceData)
Expand All @@ -78,5 +87,6 @@
Altimetry.Write=1;
end
end
end

end
33 changes: 21 additions & 12 deletions Cycle_Rate.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,44 @@
Ncyc.ct=88;
VS(i).Rate=18; %Hz

else if satellite(1)=='J'
Ncyc.max=303;
Ncyc.ct=303;
else if satellite(end-1:end)=='n2'
Ncyc.max=303;%going with max on the sheet
Ncyc.ct=303;
VS(i).Rate=20; %Hz
else if satellite(1:4)=='ERS2'%need to correct these cycle numbers
Ncyc.max=85;
Ncyc.ct=85;
Ncyc.ct=85;
VS(i).Rate=20; %Hz
else if satellite(1:2)=='To'
Ncyc.max=481;
Ncyc.ct=482;
Ncyc.ct=482;
VS(i).Rate=10; %Hz
else if satellite(1:5)=='ERS1g'%need to correct these cycle numbers
Ncyc.max=156;
Ncyc.ct=12;
VS(i).Rate=20; %Hz
else if satellite(1:5)=='ERS1c'%need to correct these cycle numbers
Ncyc.max=101;
Ncyc.ct=19;
Ncyc.ct=19;
VS(i).Rate=20; %Hz
else if satellite(1:5)=='SARAL'%need to correct these cycle numbers
Ncyc.max=35;
Ncyc.ct=35;
VS(i).Rate=40; %Hz
else if satellite(1:5)=='SARAL'%need to correct these cycle numbers
Ncyc.max=35;
Ncyc.ct=35;
VS(i).Rate=40; %Hz
else if satellite(end-1:end)=='n1'
Ncyc.max=258;%going with max on the sheet
Ncyc.ct=258;
VS(i).Rate=20; %Hz
else if satellite(end-1:end)=='n3'
Ncyc.max=80;%going with max on the sheet
Ncyc.ct=57;
VS(i).Rate=20; %Hz
end
end
end
end
end
end
end
end
end
end
end
21 changes: 16 additions & 5 deletions FINDdateCAPS.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
%finddatecpas is a sub function of validate 2.0 that scrubs data for
%comparison
function [LIMITS]=FINDdateCAPS(VS,gagedata,vsnum);
function [LIMITS]=FINDdateCAPS(VS,gagedata,vsnum,Toggle);
DATE=gagedata.DATE;
stage=gagedata.stage;

Expand Down Expand Up @@ -40,19 +40,30 @@
%VS
LIMITS.VST= VS(vsnum).AltDat.t(intersect(VSdatedexst,VSdatedexend));%plot time VS
LIMITS.VSH=VS(vsnum).AltDat.hbar(intersect(VSdatedexst,VSdatedexend));%plot elevation VS
LIMITS.VSHst=VS(vsnum).AltDat.V3hbar(intersect(VSdatedexst,VSdatedexend));%plot elevation VS
if Toggle.SF
LIMITS.VSHst=VS(vsnum).AltDat.V3hbar(intersect(VSdatedexst,VSdatedexend));%plot elevation VS
end
if ~isnan(nansum( LIMITS.VSH));
%need to remove ice flags
icedex= LIMITS.VSH>-9998;
LIMITS.VSTslim= LIMITS.VST(icedex);
LIMITS.VSHslim= LIMITS.VSH(icedex);
LIMITS.VSHstslim= LIMITS.VSHst(icedex);
if Toggle.SF
LIMITS.VSHstslim= LIMITS.VSHst(icedex);
end
end
end

end
if ~isfield(LIMITS,'VST') || isempty(LIMITS.VST)||isempty(LIMITS.VSTslim)
LIMITS=[];
if Toggle.SF
if ~isfield(LIMITS,'VST') || isempty(LIMITS.VST)||isempty(LIMITS.VSTslim)
LIMITS=[];
end
else
if ~isfield(LIMITS,'VST') || isempty(LIMITS.VST)
LIMITS=[];

end
end


Expand Down
9 changes: 7 additions & 2 deletions GP.m
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
function [VS] = GP(VS,Grades)
if ~isempty(Grades)
G={Grades.grades};
Grades=(Grades(find(~cellfun(@isempty,G))));
Grades=(Grades(find(~cellfun(@isempty,G))));
gdex=find(strcmp([Grades.Sat],VS(1).Satellite)==1);

if ~isempty(gdex) && ~isempty(Grades(gdex).grades)
gradecells=string([Grades(gdex).grades.name]);
for j = 1:length(VS)
Expand All @@ -18,6 +18,11 @@
VS(j).stats = 'z';
end
end
else
for j = 1:length(VS)
VS(j).grade = 'z';
VS(j).stats = 'z';
end
end
else
for j = 1:length(VS)
Expand Down
7 changes: 4 additions & 3 deletions GetAltimetry2.m
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@

%% read DEM data
%ers DEM info is in a different format
if strcmp(VS.Satellite,'Envisat') || strcmp(VS.Satellite,'Jason2')
if strcmp(VS.Satellite,'Envisat') || strcmp(VS.Satellite,'Jason2') || strcmp(VS.Satellite,'Jason1') || strcmp(VS.Satellite,'Jason3')

delimiter = {' ',' ',' ',' '};
endRow = 3;
Expand All @@ -66,9 +66,9 @@
Altimetry.demDat=textscan(fid,formatSpec, endRow,...
'Delimiter',delimiter,'EmptyValue',NaN,'ReturnOnError', false);
fclose(fid);
if ~strcmp(VS.Satellite,'Envisat') && ~strcmp(VS.Satellite,'Jason2')
if ~strcmp(VS.Satellite,'Envisat') && ~strcmp(VS.Satellite,'Jason2')&& ~strcmp(VS.Satellite,'Jason1') && ~strcmp(VS.Satellite,'Jason3')
for k = 1:3;
for m=1:3;
for m=1:length( Altimetry.demDat{1,k});
delimiter = {'='};
formatSpec = '%*s%f';
Altimetry.demDat{1,k}(m)= textscan(Altimetry.demDat{1,k}{m},...
Expand All @@ -86,6 +86,7 @@
else
GDat=-1;
Altimetry.c=[];
DEM=[-9999,-9999,-9999];
end
end

Expand Down
4 changes: 4 additions & 0 deletions GradeUpdate.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
end
if ~isempty(gradefile)
[NUMj TXTj RAWj]=xlsread(gradefile,'A1:L800');
if isempty(TXTj)%file has never been written in
RAWj=Jdata;
else
Sj = size(Jdata);
k=1;
Jins ={};
Expand All @@ -51,6 +54,7 @@
RAWj=Fill;
end
RAWj=cat(1,RAWj,Jins);
end
OUTj={};
K=1;
for i=1:length(RAWj(:,1));
Expand Down
10 changes: 8 additions & 2 deletions IceCheck2.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,21 @@
|| strcmp(rivername,'Lena') || strcmp(rivername,'Menzen')...
||strcmp(rivername,'Ob') || strcmp(rivername,'Olenyok')...
|| strcmp(rivername,'Pechora')|| strcmp(rivername,'StLawrence')...
|| strcmp(rivername,'Yenisei');
|| strcmp(rivername,'Yenisei') || strcmp(rivername,'Kuloy')...
|| strcmp(rivername,'Pyasina') || strcmp(rivername,'Anadyr')...
|| strcmp(rivername,'Khatanga') || strcmp(rivername,'Amur');

DoIce=true;
else
DoIce=false;
end
icefile = fullfile(Toggle.Icedir,['icebreak_' rivername]);
if DoIce
[IceData] = ReadIceFile2(icefile); %read in ice file for freeze/thaw dates
[IceData] = ReadIceFile2(icefile,Toggle.MODICE); %read in ice file for freeze/thaw dates
else IceData=[];
end
if Toggle.IceCheck==0 %override ice removal
DoIce=false;
IceData=[];
end
end
56 changes: 56 additions & 0 deletions NewAltShapes.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
%read in shapefile and change field names for new alt
clc; clear all; close all;
Newdir=0
ONEriv='Ayeyarwada'
INalt='Jason3'
INorbit='Jason'
INdr='C:\Users\coss.31\Documents\MATH\OSU_RA_Toolbox2018\INshapes'
RIVdir='C:\Users\coss.31\Documents\MATH\OSU_RA_Toolbox2018\INDB'
EULERdir='C:\Users\coss.31\Documents\MATH\EULER_OUT'
Rivers=load(fullfile(RIVdir,'Rivlist.mat'));
%rate!
RATE(1).N = 'Topex';
RATE(1).R = '10hz';
RATE(2).N = 'Jason1';
RATE(2).R='20hz';

if isempty(ONEriv)
R=Rivers.World;
else
R={ONEriv};
end

for i=1:length(R)
if strcmp(INorbit,'Jason')
if isfile(fullfile(INdr,strcat(R{i},'_','Jason2V2.shp')));
BaseFile=shaperead(fullfile(INdr,strcat(R{i},'_','Jason2V2.shp')))
Ofile=BaseFile;
for j=1:length(BaseFile)
%id
Ofile(j).Station_ID=strcat(R{i},'_',INalt,'_',num2str(BaseFile(j).Id));
%rate
% NRD=strfind([RATE.N],INalt);
% NEWrate=RATE(NRD).R;
% Ofile(j).rate= NEWrate;
end
if Newdir
mkdir(EULERdir,strcat(R{i},'_',INalt))
shapewrite(Ofile,fullfile(EULERdir,strcat(R{i},'_',INalt),strcat(R{i},'_',INalt,'.shp')));
else
shapewrite(Ofile,fullfile(INdr,strcat(R{i},'_',INalt,'.shp')));
end
%shapeinfo(fullfile(INdr,strcat(R{i},'_',INalt,'.shp')));
end
end
if strcmp(INorbit,'Envisat')
if isfile(fullfile(INdr,strcat(R{i},'_','EnvisatV2.shp')));
BaseFile=shaperead(fullfile(INdr,strcat(R{i},'_','EnvisatV2.shp')))
Ofile=BaseFile;
for j=1:length(BaseFile)
Ofile(j).Station_ID=strcat(R{i},'_',INalt,'_',num2str(BaseFile(j).Id));
end
shapewrite(Ofile,fullfile(INdr,strcat(R{i},'_',INalt,'.shp')));
%shapeinfo(fullfile(INdr,strcat(R{i},'_',INalt,'.shp')));
end
end
end
21 changes: 21 additions & 0 deletions RUNgh.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
%run Chan's USGS reader here on the rivers in Toggle
function RUNgh(Toggle)
%identify relevant gages by river name
[NUM,TXT,RAW]=xlsread(fullfile(Toggle.USGSlistdir,'USGS_Selected_Site.xlsx'),1);
k=1;
for i = 1:length(Toggle.Curriv)
for j = 1:length(TXT)
if strcmp(Toggle.Curriv(i),cell2mat(TXT(j,6)))
check(k)=j;
k=k+1;
end
end
end
if exist('check','var');
CHKdb=RAW(check,:);
for i = 1:length(CHKdb)
RIV=cell2mat(CHKdb(i,6));
gh(strcat(num2str(cell2mat(CHKdb(i,1))),'.xml'),Toggle,RIV);
end
end
end
18 changes: 17 additions & 1 deletion ReadIceFile2.m
Original file line number Diff line number Diff line change
@@ -1,7 +1,23 @@
function [IceData] = ReadIceFile2(fname)
function [IceData] = ReadIceFile2(fname,MODICE)
[d f] =xlsread(fname);
S=size(f);
if MODICE && S(2)==4
for i = 1:length(f)
if ~isempty(f{i,3})
thaw(i)=datenum(f(i,3));
else
thaw(i)=datenum(f(i,1));
end
if ~isempty(f{i,4})
freeze(i)=datenum(f(i,4));
else
freeze(i)=datenum(f(i,2));
end
end
else
thaw=datenum(f(:,1));
freeze=datenum(f(:,2));
end

IceData(:,1)=str2num(datestr(thaw,10));
IceData(:,2)=thaw;
Expand Down
Loading

0 comments on commit 12e944c

Please sign in to comment.