@@ -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