Skip to content

Commit 7d3223e

Browse files
committed
Merge branch 'integration' into calvin
2 parents 6823ed9 + 1eb3d5e commit 7d3223e

File tree

4 files changed

+25
-14
lines changed

4 files changed

+25
-14
lines changed

CoralLabeler/LoadFunctions.qml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@ Rectangle{
3131
console.log("temp not initialized")
3232
}
3333

34+
3435
else{
3536
//load in csv from python function
36-
var everything = tbox.readCSV(tbox.fixTempUrl(tbox.getTempUrl()) + "/" + imgLoad + ".csv");
37+
var everything = tbox.readCSV(tbox.trimFileUrl(tbox.getTempUrl())+ "/" + imgLoad + ".csv");
3738
//holding dictionaries, arrays, and variables
3839

3940
//holds everything
@@ -171,8 +172,8 @@ Rectangle{
171172

172173
//function to check if current image has a label file
173174
function hasLabels(imgsource){
174-
console.log(tbox.fileExists("C:/Users/kevin/AppData/Roaming/CoralLabeler"))
175-
return tbox.fileExists(tbox.fixTempUrl(tbox.getTempUrl()) + "/" + imgsource + ".csv")
175+
//console.log((tbox.trimFileUrl(tbox.getTempUrl()) + imgsource + ".csv"))
176+
return tbox.fileExists(tbox.trimFileUrl(tbox.getTempUrl()) + "/" + imgsource + ".csv")
176177
}
177178

178179
//a function to loop through the current label's shapes and create shapes from coordinates

CoralLabeler/SaveLocationsPopup.qml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ import QtQuick.Dialogs
9393
}
9494

9595
onRejected: {
96-
if (!tbox.fileExists("file_config")) {
96+
if (!tbox.fileExists(tbox.getFileLocation()+"/file_config")) {
9797
//if user cancelled but no value exists, choose defaults
9898
tbox.saveFilePreference(StandardPaths.writableLocation(StandardPaths.AppDataLocation), StandardPaths.writableLocation(StandardPaths.DocumentsLocation) + "/CoralLabeler")
9999
var result = tbox.initFilePreference(StandardPaths.writableLocation(StandardPaths.AppDataLocation), StandardPaths.writableLocation(StandardPaths.DocumentsLocation) + "/CoralLabeler")

CoralLabeler/main.qml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1789,7 +1789,7 @@ ApplicationWindow {
17891789
}
17901790
////Check if file preferences exist. If not, ask user
17911791
Component.onCompleted: {
1792-
if (tbox.fileExists("file_config")) {
1792+
if (tbox.fileExists(tbox.getFileLocation()+"/file_config")) {
17931793
tbox.loadFilePreference()
17941794
saveLocationsPopup.updateText()
17951795
} else {

CoralLabeler/toolbox.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,13 @@ def initFilePreference(self, temp_url, out_url):
9292
else:
9393
if not os.path.isdir(fp):
9494
return 1 #a non directory file exists with that name
95+
try:
96+
os.makedirs(os.path.join(out_fp,'raster_labels'))
97+
os.makedirs(os.path.join(out_fp,'statistics'))
98+
except PermissionError:
99+
return 2
100+
except OSError:
101+
return 3
95102
return 0
96103

97104
@QtCore.Slot()
@@ -201,8 +208,8 @@ def readCSV(self, fileName):
201208
@QtCore.Slot(dict, str, list, result="QVariantList")
202209
def saveLabels(self, data, fileName, paintshapes):
203210
name = ""
204-
205-
filename = os.path.join(self.temp_url[8:], fileName+'.csv')
211+
external_dir = self.trimFileUrl(self.getTempUrl())
212+
filename = os.path.join(external_dir, fileName+'.csv')
206213
check = False
207214
paintSize = ''
208215
paintFirstCoords = []
@@ -261,7 +268,7 @@ def saveLabels(self, data, fileName, paintshapes):
261268

262269
@QtCore.Slot(str, result = bool)
263270
def fileExists(self, fileName):
264-
return os.path.exists(os.path.join(dirname,fileName))
271+
return os.path.exists(fileName)
265272

266273
@QtCore.Slot(str, result="QString")
267274
def splited(self, fileName):
@@ -274,7 +281,7 @@ def printString(self, s):
274281

275282
@QtCore.Slot(str, str, str, result="QVariantList")
276283
def addToCSV(self, data, name, fileName):
277-
fileName = os.path.join(dirname,fileName)
284+
fileName = os.path.join(dirname,fileName) #hardcoded to internal file. fine bc only used to operate on SpeciesList.csv which is internal
278285
with open(fileName, 'a') as file:
279286

280287
# write row
@@ -301,8 +308,8 @@ def toPixels(self, coords, x_coord, y_coord, x_factor, y_factor):
301308
for shape_num, shape_coords in coords_dict.items():
302309
numpy_shapes[label_num][shape_num] = []
303310
for coord in shape_coords:
304-
x = math.floor((coord[0] - x_coord) / x_factor)
305-
y = math.floor((coord[1] - y_coord) / y_factor)
311+
x = math.floor((coord[0] - x_coord) / x_factor) - 1
312+
y = math.floor((coord[1] - y_coord) / y_factor) - 1
306313

307314
numpy_coord = [x, y]
308315
numpy_shapes[label_num][shape_num].append(numpy_coord)
@@ -356,7 +363,9 @@ def saveRasters(self, coords, x_coord, y_coord, x_factor, y_factor, img_width, i
356363
final_array[rr, cc] = n_label_id
357364

358365
# save to csv file
359-
np.savetxt('./raster_labels/' + filename + '.csv', final_array, fmt='%d', delimiter=',')
366+
external_dir = self.trimFileUrl(self.getOutUrl())
367+
save_to = os.path.join(external_dir,'raster_labels',filename+".csv")
368+
np.savetxt(save_to, final_array, fmt='%d', delimiter=',')
360369

361370

362371
@QtCore.Slot(dict, list, int, int, float, float, int, int, str, str, str)
@@ -389,8 +398,9 @@ def saveStats(self, coords, specs_list, x_coord, y_coord, x_factor, y_factor, im
389398
'area (cm2)': img_area}
390399

391400
stats_list.append(shape_stats)
392-
393-
with open('./statistics/' + filename + '.csv', 'w') as csvfile:
401+
external_dir = self.trimFileUrl(self.getOutUrl())
402+
save_to = os.path.join(external_dir,'statistics',filename+".csv")
403+
with open(save_to, 'w') as csvfile:
394404
writer = csv.DictWriter(csvfile, fieldnames=headers)
395405
writer.writeheader()
396406
writer.writerows(stats_list)

0 commit comments

Comments
 (0)