Skip to content

Commit

Permalink
File renaming, dropping '_0'
Browse files Browse the repository at this point in the history
  • Loading branch information
TCallaghan2 committed Jul 11, 2024
1 parent ad8ec3e commit 2fbeaed
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 86 deletions.
23 changes: 2 additions & 21 deletions PythonScripts/GUI/GeoSAM/GeoSams.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ def Run_Sim(self):
#
def InterpAndPlotResults(self):
dataDir = 'Data'
years = range(self.yearStart, self.yearStop+1)
years = range(self.yearStart-1, self.yearStop+1) # year_start-1 is initial state

# set configuration file name for UK.exe
ukCfgFile = self.ukCfgFile # This may be overwritten depending on domain
Expand Down Expand Up @@ -328,7 +328,6 @@ def InterpAndPlotResults(self):
# .\UKsrc\UK UK.cfg GB X_Y_EBMS_GB2005_0_SW.csv GBxyzLatLon_SW.csv 0.0 | 70.0
# arg# 1 2 3 4 5
for r in rgn:
obsFile = 'X_Y_' + pStr + self.domainName + str(self.yearStart) + '_0' + r + '.csv'
if self.domainName == 'AL':
# ALxyzLatLon_MA uses the same grid file as MA,
# and did not want to configuration manage multiple identical files
Expand All @@ -350,15 +349,6 @@ def InterpAndPlotResults(self):
# DEPRECATE: if we no longer need to separate GB into sub regions
#gridFile = self.domainName+'xyzLatLon' + r + '.csv'
gridFile = self.domainName+'xyzLatLon.csv'
cmd = [ex, ukCfgFile, self.domainName, obsFile, gridFile, zArg]
result = subprocess.run(cmd)
if (result.returncode != 0):
errorStr = '' + ''.join(str(e)+' ' for e in cmd) + ' error: ' + hex(result.returncode) + ''
print(errorStr)
return (result.returncode, result.args)
print( 'Just Finished: ', cmd)
# Cleanup dataDir
os.remove(os.path.join(dataDir, obsFile))

for year in years:
obsFile = 'X_Y_' + pStr + self.domainName + str(year) + r + '.csv'
Expand All @@ -381,18 +371,8 @@ def InterpAndPlotResults(self):
col = [defaultdict(list) for _ in range(nyears)]
k = 0

flin = pfix + pStr + self.domainName + str(self.yearStart) + '_0' + r + '.csv'
with open(flin) as f:
reader = csv.reader(f)
for row in reader:
for (i,v) in enumerate(row):
col[k][i].append(v)
f.close()
os.remove(flin)

# append remaining years as additional columns to first data set
for year in years:
k += 1
flin = pfix + pStr + self.domainName + str(year) + r + '.csv'
with open(flin) as f:
reader = csv.reader(f)
Expand All @@ -404,6 +384,7 @@ def InterpAndPlotResults(self):

for i in range (len(col[0][0])):
col[0][k + 2].append(col[k][2][i])
k += 1

# brute force write out results
if self.savedByStratum:
Expand Down
25 changes: 4 additions & 21 deletions PythonScripts/ProcessResults.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
year_end = int(sys.argv[3])
simCfgFile = sys.argv[4]
ukCfgFile = sys.argv[5]
years = range(year_start, year_end + 1)
years = range(year_start-1, year_end + 1) # year_start-1 is initial state

# Used while concatenating files
# number of colums in csv file, starting at 0
Expand Down Expand Up @@ -68,7 +68,6 @@
# .\UKsrc\UK UK.cfg GB X_Y_EBMS_GB2005_0_SW.csv GBxyzLatLonSW.csv 0.0 | 70.0
# arg# 1 2 3 4 5
for r in rgn:
obsFile = 'X_Y_' + pStr + dn + str(year_start) + '_0' + r + '.csv'
if dn == 'AL':
# ALxyzLatLon_MA uses the same grid file as MA
# 'MA'+'xyzLatLon' + '' + '.csv'
Expand All @@ -88,13 +87,6 @@
# DEPRECATE: if we no longer need to separate GB into sub regions
#gridFile = self.domainName+'xyzLatLon' + r + '.csv'
gridFile = dn+'xyzLatLon.csv'
cmd = [ex, ukCfgFile, dn, obsFile, gridFile, zArg]
result = subprocess.run(cmd)
if (result.returncode != 0):
print('' + ''.join(str(e)+' ' for e in cmd) + ' error: ' + hex(result.returncode) + '')
sys.exit(result.returncode)
print( 'Just Finished: ', cmd)
### os.remove(dataDir + obsFile)

for year in years:
obsFile = 'X_Y_' + pStr + dn + str(year) + r + '.csv'
Expand All @@ -116,29 +108,20 @@
col = [defaultdict(list) for _ in range(nyears)]
k = 0

flin = pfix + pStr + dn + str(year_start) + '_0' + r + '.csv'
with open(flin) as f:
reader = csv.reader(f)
for row in reader:
for (i,v) in enumerate(row):
col[k][i].append(v)
f.close()
### os.remove(flin)

# append remaining years as additional columns to first data set
for year in years:
k += 1
flin = pfix + pStr + dn + str(year) + r + '.csv'
with open(flin) as f:
reader = csv.reader(f)
for row in reader:
for (i,v) in enumerate(row):
col[k][i].append(v)
f.close()
### os.remove(flin)
os.remove(flin)

for i in range (len(col[0][0])):
col[0][k + 2].append(col[k][2][i])
k += 1

# brute force write out results
if savedByStratum:
Expand Down Expand Up @@ -166,7 +149,7 @@
lines = rdFile.readlines()
wrFile.writelines(lines)
rdFile.close()
### os.remove(flin)
os.remove(flin)
wrFile.close()
print('Files concatenated to: ',flout)
# end for pfix
Expand Down
2 changes: 1 addition & 1 deletion SRC/ScallopMortality.f90
Original file line number Diff line number Diff line change
Expand Up @@ -973,7 +973,7 @@ subroutine Mortality_Write_At_Timestep(year, ts, state_mat, weight_grams, mortal
! This data is later interpolated to MA or GB Grid
if (mod(ts, ts_per_year) .eq. 1) then
if (ts .eq. 1) then
write(buf,'(I4,A2)') year, '_0'
write(buf,'(I4,A2)') year-1 ! this is the intial state
else
write(buf,'(I4)') year
endif
Expand Down
52 changes: 9 additions & 43 deletions SRC/ScallopPopDensity.f90
Original file line number Diff line number Diff line change
Expand Up @@ -716,36 +716,9 @@ subroutine Setup_Data_Files(plot_data_sel, num_grids, grid, domain_name, save_by
if (plot_data_sel%plot_RECR) call Write_Lat_Lon_Preamble(num_grids, grid, output_dir//'Lat_Lon_Surv_RECR_'//domain_name//'.csv')

! Write similar data for later interpolation by UK (Universal Kriging)
write(buf,'(I4)') start_year
yr_offset = 0.
if (plot_data_sel%plot_ABUN) &
& call Write_X_Y_Preamble(num_grids, grid, yr_offset, data_dir//'X_Y_ABUN_'//domain_name//buf//'_0.csv', save_by_stratum)

if (plot_data_sel%plot_BMMT) &
& call Write_X_Y_Preamble(num_grids, grid, yr_offset, data_dir//'X_Y_BMMT_'//domain_name//buf//'_0.csv', save_by_stratum)

if (plot_data_sel%plot_EBMS) &
& call Write_X_Y_Preamble(num_grids, grid, yr_offset, data_dir//'X_Y_EBMS_'//domain_name//buf//'_0.csv', save_by_stratum)

if (plot_data_sel%plot_FEFF) &
& call Write_X_Y_Preamble(num_grids, grid, yr_offset, data_dir//'X_Y_FEFF_'//domain_name//buf//'_0.csv', save_by_stratum)

if (plot_data_sel%plot_FMOR) &
& call Write_X_Y_Preamble(num_grids, grid, yr_offset, data_dir//'X_Y_FMOR_'//domain_name//buf//'_0.csv', save_by_stratum)

if (plot_data_sel%plot_LAND) &
& call Write_X_Y_Preamble(num_grids, grid, yr_offset, data_dir//'X_Y_LAND_'//domain_name//buf//'_0.csv', save_by_stratum)

if (plot_data_sel%plot_LNDW) &
& call Write_X_Y_Preamble(num_grids, grid, yr_offset, data_dir//'X_Y_LNDW_'//domain_name//buf//'_0.csv', save_by_stratum)

if (plot_data_sel%plot_LPUE) &
& call Write_X_Y_Preamble(num_grids, grid, yr_offset, data_dir//'X_Y_LPUE_'//domain_name//buf//'_0.csv', save_by_stratum)

if (plot_data_sel%plot_RECR) &
& call Write_X_Y_Preamble(num_grids, grid, yr_offset, data_dir//'X_Y_RECR_'//domain_name//buf//'_0.csv', save_by_stratum)

do n = start_year, stop_year
! Year-1 is the initial state
yr_offset = -1.
do n = start_year-1, stop_year
write(buf,'(I4)') n
if (plot_data_sel%plot_ABUN) &
& call Write_X_Y_Preamble(num_grids, grid, yr_offset, data_dir//'X_Y_ABUN_'//domain_name//buf//'.csv', save_by_stratum)
Expand Down Expand Up @@ -795,29 +768,22 @@ subroutine Write_Recruit_Estimates(ts, ts_per_year, num_grids, grid, domain_name
type(Recruitment_Class), intent(in) :: recruit(*)

character(4) buf
character(6) buf_0
integer recr_idx
character(fname_len) file_name

recr_idx = year - start_year + 1

if (mod(ts, ts_per_year) .eq. 1) then
write(buf,'(I4)') year
if (ts .eq. 1) then
write(buf,'(I4)') year-1
else
write(buf,'(I4)') year
endif
if (save_by_stratum) then
if (ts .eq. 1) then
write(buf_0,'(I4,A2)') year, '_0'
else
write(buf_0,'(I4)') year
endif
call Write_Column_CSV_By_Stratum(num_grids, recruit(1:num_grids)%recruitment(recr_idx), &
& grid(1:num_grids)%lat, grid(1:num_grids)%lon, grid(1:num_grids)%stratum, &
& 'RECR', data_dir//'X_Y_RECR_'//domain_name//trim(buf_0), .true.)
& 'RECR', data_dir//'X_Y_RECR_'//domain_name//trim(buf), .true.)
else
if (ts .eq. 1) then
file_name = data_dir//'X_Y_RECR_'//domain_name//buf//'_0.csv'
else
file_name = data_dir//'X_Y_RECR_'//domain_name//buf//'.csv'
endif
call Write_Column_CSV(num_grids, recruit(1:num_grids)%recruitment(recr_idx), 'Recruitment', file_name, .true.)
endif
endif
Expand Down

0 comments on commit 2fbeaed

Please sign in to comment.