Skip to content

Commit

Permalink
Fix Sort by Region with X-Y changes by year.
Browse files Browse the repository at this point in the history
  • Loading branch information
TCallaghan2 committed Jan 21, 2025
1 parent 7cd055a commit b4f4a4b
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 15 deletions.
26 changes: 24 additions & 2 deletions PythonScripts/GUI/GeoSAM/GeoSams.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,9 +502,9 @@ def InterpAndPlotResults(self):

print( 'Interpolation exec time: {}'.format(end-start))

#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# PLOTTING
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# We have the needed output paramters so lets plot data and save to pdf files
for pStr in self.paramStr:
if self.frame2.usingMatlab.get():
Expand All @@ -520,6 +520,28 @@ def InterpAndPlotResults(self):
procID += 1
retDict[procID] = result.returncode

#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# Combine results by year
# modeling region could change from one year to another so it is difficult to concatenate all
# files as X-Y positions may differ.
# Thus to aid in post processing combine the MA|GB files into a single file for each year
# Lat_Lon_Grid_ABUN_ALyyyy_GB_REGION_KRIGE \
# Lat_Lon_Grid_ABUN_ALyyyy_GB_REGION_KRIGE / BIOM_yyyy_KRIGE.csv
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
pfix = os.join.path('Results', 'Lat_Lon_Grid_')
for pStr in self.paramStr:
for year in years:
flout = os.path.join('Results', pStr + str(year) + '_KRIGE.csv')
for r in region:
flin = pfix + pStr + self.domainName + str(year) + r + '_REGION_KRIGE.csv'

df = pd.read_csv(flin, usecols=['UTM_X', 'UTM_Y', 'LAT','LON', 'DEPTH', 'STRATUM', 'ZONE', 'FINALPREDICT'])

if r == region[0]:
df.to_csv(flout, index=False)
else:
df.to_csv(flout, mode='a', index=False,header=False)

return (retDict, procID)

##
Expand Down
31 changes: 18 additions & 13 deletions PythonScripts/GUI/GeoSAM/SortByRegionFrame.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,28 +236,33 @@ def RunSort(self, showMsg=True):
countNonZeroData = [[0.0 for _ in range(cols)] for _ in range(rows)] # data read in from file
countData = [[0.0 for _ in range(cols)] for _ in range(rows)] # data read in from file
desiredParam = self.comboParameter.get()
# typical name: Lat_Lon_Grid_EBMS_MA_2015_2017
# Lat_Lon_Grid_ABUN_AL_2015_2017
fileName = os.path.join('Results', 'Lat_Lon_Grid_' +
desiredParam + self.domainName + '_' + str(self.yearStart) + '_' + str(self.yearStop) + '.csv')
paramFName = os.path.join(self.root, fileName)

years = range(self.yearStart, self.yearStop + 1) # year_start is initial state
if os.path.isfile(paramFName):
df = pd.read_csv(paramFName)
dfAgg = pd.DataFrame()
for year in years:
dfAgg[str(year)] = df.groupby('ZONE').agg({str(year):'sum'})

# typical name: BIOM_2022_KRIGE - BIOM_2026_KRIGE Lat_Lon_Grid_EBMS_MA_2015_2017

# build list of files to consider
fileList = []
dfAgg = pd.DataFrame()
for year in years:
fileName = os.path.join('Results', desiredParam + str(year) + '_KRIGE.csv')
fileList.append(fileName)
if os.path.isfile(fileName):
df = pd.read_csv(fileName)
dfAgg[str(year)] = df.groupby('ZONE').agg({'FINALPREDICT':'sum'})
else:
messagebox.showerror("Reading Parameter File", f'No data for '+fileName+'\nHas Simulation been run?\nAre years correct?')
runSortErrors = 1

if runSortErrors == 0:
# For each area
for row in range(self.numAreas):
for col in range(self.numYears):
df = pd.read_csv(fileList[col])
accumParamData[row][col] = dfAgg[str(col+self.yearStart)][self.zones[row]]
countData[row][col] = len(df[df['ZONE']==self.zones[row]])

# Determine number of non-zero data by first counting the number of data counts
# then subracting the number of zero counts
counts = df[df['ZONE']==self.zones[row]][str(col+self.yearStart)].value_counts()
counts = df[df['ZONE']==self.zones[row]]['FINALPREDICT'].value_counts()
try:
countNonZeroData[row][col] = countData[row][col] - counts[0]
except:
Expand Down

0 comments on commit b4f4a4b

Please sign in to comment.