Skip to content

Commit

Permalink
Removing Use HabCam
Browse files Browse the repository at this point in the history
  • Loading branch information
TCallaghan2 committed Aug 1, 2024
1 parent 459f227 commit f0a390d
Show file tree
Hide file tree
Showing 14 changed files with 164 additions and 215 deletions.
1 change: 1 addition & 0 deletions .octaverc
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
warning('off', 'Octave:shadowed-function');
addpath mfiles/
addpath mfiles/latlonutm/
addpath PreProcess/
Expand Down
1 change: 0 additions & 1 deletion Configuration/Simulation/Scallop.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# input file for Scallops
Time steps per Year = 13
Use HabCam Data = T
# Configuration files are expected to be in the Configuration directory
Mortality Config File = Growth.cfg
Recruit Config File = Recruitment.cfg
Expand Down
Binary file modified OriginalData/dredgetowbysize7917.zip
Binary file not shown.
23 changes: 23 additions & 0 deletions PreProcess/AddXY.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
function AddXY()

M=dlmread('OriginalData/dredgetowbysize7917.csv');
lat=M(:,18);
lon=-M(:,19);
% preallocate
xx=lon;
yy=lat;
n = size(lon,1);
for i = 1:n
if lon(i)>-70.5
zone=19;
else
zone=18;
end
if mod(i,10000) == 0; fprintf('i : %d of %d\n', i, n); end
[xx(i),yy(i)]=ll2utm(lat(i),lon(i),zone);
end

M = [M, xx, yy];
dlmwrite('OriginalData/dredgetowbysizeXY.csv', M);
end

17 changes: 13 additions & 4 deletions PreProcess/HabCamData5mmbin.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function HabCamData5mmbin(yrStart, yrEnd, domain)
function HabCamData5mmbin(yrStart, yrEnd, domain, appendResults)

dataFile = 'OriginalData/Habcam_BySegment_2000_2014-2020.csv';

Expand Down Expand Up @@ -29,6 +29,7 @@ function HabCamData5mmbin(yrStart, yrEnd, domain)
yrStart = str2num(cell2mat(arg_list(1)));
yrEnd = str2num(cell2mat(arg_list(2)));
domain = cell2mat(arg_list(3));
appendResults = cell2mat(arg_list(4));
else
yrStart = str2num(yrStart);
yrEnd = str2num(yrEnd);
Expand Down Expand Up @@ -147,12 +148,20 @@ function HabCamData5mmbin(yrStart, yrEnd, domain)
end
end
end
flnm=strcat('Data/HCbin5mm',int2str(yr),domain,'.csv');
flnm=strcat('Data/bin5mm',int2str(yr),domain,'.csv');
fprintf('Size of grid %d\n', size(X,1))
if isOctave
csvwrite(flnm,X);
if strcmp(appendResults(1), 'T')
dlmwrite(flnm, X, "-append")
else
dlmwrite(flnm,X);
endif
else
writetable(X,flnm,'WriteVariableNames',0);
if strcmp(appendResults(1), 'T')
writematrix(X,flnm,'WriteMode','append')
else
writematrix(X,flnm);
endif
end
end % if sum(j) == 0
end % for yr=yrStart:yrEnd
Expand Down
44 changes: 17 additions & 27 deletions PreProcess/PullOutRecruitData.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
% VIMSRSA ==> 4444
% NMFSSHRP ==> 5555
% ALL ==> 0
function PullOutRecruitData(src, useHabCam)
function PullOutRecruitData(src, useHabCam, appendResults)

isOctave = (exist('OCTAVE_VERSION', 'builtin') ~= 0);

Expand All @@ -17,7 +17,8 @@ function PullOutRecruitData(src, useHabCam)
arg_list=argv();
if ~strcmp(arg_list(1), '--gui');
src = str2num(cell2mat(arg_list(1)));
useHabCam = cell2mat(arg_list(2))
useHabCam = cell2mat(arg_list(2));
appendResults = cell2mat(arg_list(3));
else
src = str2num(src);
end
Expand Down Expand Up @@ -49,12 +50,14 @@ function PullOutRecruitData(src, useHabCam)
"statype","SVGEAR","haul","gearcon","sdefid","newstra","clop","lat","lon","tnms",...
"setdpth","bottemp","dopdisb","distused","towadj","towdur","sizegrp","catchnu",...
"catchwt","surv_n","partrecn","fullrecn","surv_b","partrecb","fullrecb","postow",...
"datasource","lwarea","SETLW","SVSPP","PropChains","AREAKIND","STRATMAP","SQNM"};
"datasource","lwarea","SETLW","SVSPP","PropChains","AREAKIND","STRATMAP","SQNM", "UTM X", "UTM Y"};
yearCol = find(strcmpi("year", header), 1);
monCol = find(strcmpi("month", header), 1);
dayCol = find(strcmpi("day", header), 1);
latCol = find(strcmpi("lat" , header), 1);
lonCol = find(strcmpi("lon" , header), 1);
utmxCol = find(strcmpi("UTM X" , header), 1);
utmyCol = find(strcmpi("UTM Y" , header), 1);
zCol = find(strcmpi("setdpth", header), 1);
sgCol = find(strcmpi("sizegrp", header), 1);
svCol = find(strcmpi("surv_n" , header), 1);
Expand Down Expand Up @@ -125,34 +128,21 @@ function PullOutRecruitData(src, useHabCam)
else
j=size_grp==4 & dataSrc==srcText;
end
if useHC
utmX = F(j, utmxCol);
utmY = F(j, utmyCol);
else
% Correct sign of longitude
F(j,lonCol) = -F(j,lonCol);
lon = F(j,lonCol);
lat = F(j,latCol);

utmX = zeros(size(lon,1),1);
utmY = zeros(size(lon,1),1);

for i = 1:size(lon,1)
if lon(i)>-70.5
zone=19;
else
zone=18;
end
[utmX(i),utmY(i)]=ll2utm(lat(i),lon(i),zone);
end
end

M = [F(j,yearCol) F(j,monCol) F(j,dayCol) F(j,latCol) F(j,lonCol) utmX utmY F(j,zCol) recr_t];
M = [F(j,yearCol) F(j,monCol) F(j,dayCol) F(j,latCol) F(j,lonCol) F(j, utmxCol) F(j, utmyCol) F(j,zCol) recr_t];

flnm = 'OriginalData/NewRecruits.csv';

if isOctave
csvwrite(flnm, M);
if strcmp(appendResults(1), 'T') && useHC
dlmwrite(flnm, M, "-append")
else
dlmwrite(flnm,M);
endif
else
writetable(M,flnm);
if strcmp(appendResults(1), 'T') && useHC
writematrix(M,flnm,'WriteMode','append')
else
writematrix(M,flnm);
endif
end
65 changes: 12 additions & 53 deletions PreProcess/TrawlData5mmbin.m
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,14 @@ function TrawlData5mmbin(yrStart, yrEnd, src, domain)
end

if isOctave

M=csvreadK('OriginalData/dredgetowbysize7917.csv');
mon=M(:,5);
j=find(mon>0);
M=M(j,:);
%------- new M table ----------------------

%------- new M table ----------------------
if ~strcmp(domain, 'AL')
lon=-M(:,19);
lon=M(:,19);
if strcmp(domain, 'GB')
j = lon>-70.5;%GB
zone=19;
Expand All @@ -53,41 +52,20 @@ function TrawlData5mmbin(yrStart, yrEnd, src, domain)

%------- new M with just MA or GB ----------------------
M = M(j,:);
lat=table2array(M(:,18));
lon=-table2array(M(:,19));
[xx,yy]=ll2utm(lat,lon,zone);

else % working with AL
lat=M(:,18);
lon=-M(:,19);
% preallocate
xx=lon;
yy=lat;
n = size(lon,1);
for i = 1:n
if lon(i)>-70.5
zone=19;
else
zone=18;
end
if mod(i,10000) == 0; fprintf('i : %d of %d\n', i, n); end
[xx(i),yy(i)]=ll2utm(lat(i),lon(i),zone);
end
end

year = M(:,4);
sg = M(:,27);
dataSrc = M(:,37);
else % NOT Octave
M = readtable('OriginalData/dredgetowbysize7917.csv',"FileType","text");

mon=table2array(M(:,5));
j=mon>0;
M=M(j,:);
%------- new M table ----------------------

%------- new M table ----------------------
if ~strcmp(domain, 'AL')
lon = -table2array(M(:,19));
lon = table2array(M(:,19));
if strcmp(domain, 'GB')
j = lon>-70.5;
zone=19;
Expand All @@ -98,24 +76,6 @@ function TrawlData5mmbin(yrStart, yrEnd, src, domain)

%------- new M with just MA or GB ----------------------
M = M(j,:);
lat=table2array(M(:,18));
lon=-table2array(M(:,19));
[xx,yy]=ll2utm(lat,lon,zone);

else % working with AL
lat=table2array(M(:,18));
lon=-table2array(M(:,19));
% preallocate
xx=lon;
yy=lat;
for i = 1:size(lon,1)
if lon(i)>-70.5
zone=19;
else
zone=18;
end
[xx(i),yy(i)]=ll2utm(lat(i),lon(i),zone);
end
end

year = table2array(M(:,4));
Expand All @@ -130,7 +90,6 @@ function TrawlData5mmbin(yrStart, yrEnd, src, domain)
countPerSqm = detect / towArea_sqm;

for yr=yrStart:yrEnd
yr
X=[];
%j=and(year==yr,sg==3.);
if srcText == 0
Expand All @@ -153,7 +112,7 @@ function TrawlData5mmbin(yrStart, yrEnd, src, domain)
stratum_t = M(j,8);
is_closed_t = double(M(j,17)>0);
lat_t = M(j,18);
lon_t = -(M(j,19));
lon_t = M(j,19);
mon = M(j,5);
day = M(j,6);
yd = 0 * day;
Expand All @@ -162,23 +121,23 @@ function TrawlData5mmbin(yrStart, yrEnd, src, domain)
end
DecYr_t = year(j) + yd/365.25;
z_t = cast(M(j,21),"double");
x_t = xx(j);
y_t = yy(j);
x_t = M(j,45);
y_t = M(j,46);
else
stratum_t = M(j,8);
is_closed_t = array2table(int8(table2array(M(j,17)>0)),'VariableNames',{'isClosed'});
lat_t = M(j,18);
lon_t = array2table(-table2array(M(j,19)),'VariableNames',{'lon'});
lat_t = table2array(M(j,18));
lon_t = table2array(M(j,19));
mon = table2array(M(j,5));
day = table2array(M(j,6));
yd = 0 * day;
for k=1:length(day)
yd(k) = yearday(mon(k),day(k),0);
end
DecYr_t = array2table(year(j) + yd/365.25,'VariableNames',{'DecYr'});
z_t = M(j,21);
x_t = array2table(xx(j),'VariableNames',{'x'});
y_t = array2table(yy(j),'VariableNames',{'y'});
z_t = table2array(M(j,21));
x_t = table2array(M(j,45));
y_t = table2array(M(j,46));
end

n=find(and(year==yr,sg==3.));
Expand Down
15 changes: 3 additions & 12 deletions PythonScripts/GUI/GeoSAM/GeoSams.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,14 +186,8 @@ def Run_Sim(self):
# Ensure data is available, by first checking if data files have been created.
# Typical data file name: Data/bin5mm2015AL.csv
filesExist = True
if self.frame1.usingHabCam.get():
prefix = 'HCbin5mm'
dataSrcArg = 'H'
else:
prefix = 'bin5mm'
dataSrcArg = 'D'
for yr in range(self.yearStart, self.yearStop+1):
dataFName = os.path.join(self.root, 'Data', prefix+str(yr)+self.domainName+'.csv')
dataFName = os.path.join(self.root, 'Data', 'bin5mm'+str(yr)+self.domainName+'.csv')
if not os.path.isfile(dataFName):
filesExist = False
break
Expand All @@ -206,9 +200,9 @@ def Run_Sim(self):
mathArg = 'O'

if platform.system() == 'Windows':
cmd = [os.path.join(self.root, 'Unpack.bat'), startYear, stopYear, '0', self.domainName, mathArg, dataSrcArg]
cmd = [os.path.join(self.root, 'Unpack.bat'), startYear, stopYear, '0', self.domainName, mathArg]
else:
cmd = [os.path.join(self.root, 'Unpack.sh'), startYear, stopYear, '0', self.domainName, mathArg, dataSrcArg]
cmd = [os.path.join(self.root, 'Unpack.sh'), startYear, stopYear, '0', self.domainName, mathArg]
subprocess.run(['chmod','744','Unpack.sh']) # make file executable
messagebox.showinfo("Unpack", f'Starting Unpack.\nThis could take several minutes, longer if using Octave.\nPlease be patient.')
result = subprocess.run(cmd)
Expand Down Expand Up @@ -458,7 +452,6 @@ def WriteScallopConfig(self):
with open(simCfgFile, 'w') as f:
f.write('# input file for Scallops \n')
f.write('Time steps per Year = ' + str(self.frame1.tsPerYear.myEntry.get())+'\n')
f.write('Use HabCam Data = ' + str(self.frame1.usingHabCam.get())[0]+'\n')
f.write('# Configuration files are expected to be in the Configuration directory\n')
f.write('Mortality Config File = ' + self.frame1.mortCfgFile.myEntry.get() + '\n')
f.write('Recruit Config File = ' + self.frame1.recrCfgFile.myEntry.get() + '\n')
Expand Down Expand Up @@ -712,8 +705,6 @@ def ReadSimConfigFile(self):
self.paramVal += 256
elif (tag == 'Time steps per Year'):
self.tsPerYear = int(value)
elif (tag == 'Use HabCam Data'):
self.useHabCamData = value[0] == 'T'

##
# Read in the (tag, value) parameters from the UK configuration file.
Expand Down
9 changes: 0 additions & 9 deletions PythonScripts/GUI/GeoSAM/MainInputFrame.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,6 @@ def __init__(self, container, friend, tsPerYear, selectedOutputs, maxYears):
self.domainNameCombo.current(2)
self.domainNameCombo.grid(row=3, column=1, sticky='w', pady=5)
#-------------------------------------------------------------------------------------------
self.usingHabCamLabel = ttk.Label(durationFrame, text='Domain Name')
self.usingHabCam = tk.BooleanVar(durationFrame, self.friend.useHabCamData)
self.usingHabCamLabel = ttk.Label(durationFrame, text='Data Source')
self.usingHabCamLabel.grid(row=4, column=0)
self.useHabCamRB = ttk.Radiobutton(durationFrame, text='Habcam', value=True, variable=self.usingHabCam, command=None)
self.useHabCamRB.grid(row=4, column=1,sticky='w')
self.useDredgeRB = ttk.Radiobutton(durationFrame, text='Dredge', value=False, variable=self.usingHabCam, command=None)
self.useDredgeRB.grid(row=5, column=1,sticky='w')
#-------------------------------------------------------------------------------------------
durationFrame.grid(row=2, column=1, padx=5, sticky='w')
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
outputSelFrame = ttk.LabelFrame(self, text='Output Selection', style='SAMS.TFrame')
Expand Down
5 changes: 1 addition & 4 deletions SRC/GridManager.f90
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ module Grid_Manager_Mod
integer, PRIVATE :: num_areas ! number of special access areas
integer, PRIVATE :: num_grids
logical, PRIVATE :: use_spec_access_data
logical, PRIVATE :: use_habcam_data
character(domain_len), PRIVATE :: domain_name
character(fname_len), PRIVATE :: config_file_name
character(fname_len), PRIVATE :: init_cond_fname
Expand Down Expand Up @@ -139,19 +138,17 @@ integer function Set_Num_Grids()
!> Initializes growth for startup
!>
!==================================================================================================================
subroutine Set_Grid_Manager(state_mat, grid, ngrids, dom_name, use_hc)
subroutine Set_Grid_Manager(state_mat, grid, ngrids, dom_name)
integer, intent(inout) :: ngrids
real(dp), intent(out):: state_mat(1:ngrids, 1:num_size_classes)
type(Grid_Data_Class), intent(out) :: grid(*)
character(domain_len), intent(in) :: dom_name
logical, intent(in) :: use_hc

integer n, j, k
character(fname_len) fname

! set private variables
domain_name = dom_name
use_habcam_data = use_hc

! Used to verify grid in special access area
fname = 'Results/SurveyLoc.txt'
Expand Down
Loading

0 comments on commit f0a390d

Please sign in to comment.