Skip to content

Commit

Permalink
Update prediction map workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
CameronBodine committed Jan 5, 2024
1 parent 8e9a228 commit 325fc62
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions src/class_portstarObj.py
Original file line number Diff line number Diff line change
Expand Up @@ -1804,8 +1804,13 @@ def _mapSubstrate(self, map_class_method, chunk, npzs):
def _mapPredictions(self, map_predict, imgOutPrefix, chunk, npzs):
'''
'''
# Set pixel down/upscale factor
pix_res_factor=self.port.pix_res
# Don't do this because it will create gaps between chunks
# Do rescale when mosaicing
# # Set pixel size [m]
# pix_res = self.port.pix_res

# if pix_res == 0:
# pix_res = 0.25

# Set output directory
self.outDir = self.port.outDir
Expand Down Expand Up @@ -1968,15 +1973,15 @@ def _mapPredictions(self, map_predict, imgOutPrefix, chunk, npzs):
imgName = projName+'_'+imgOutPrefix+'_'+addZero+str(int(chunk))+'.tif'
gtiff = os.path.join(self.outDir, imgName)

# Export georectified image
# Export georectified image at raw resolution
with rasterio.open(
gtiff,
'w',
driver='GTiff',
height=out.shape[1] * pix_res_factor,
width=out.shape[2] * pix_res_factor,
# height=out.shape[1],
# width=out.shape[2],
# height=out.shape[1] * pix_res_factor,
# width=out.shape[2] * pix_res_factor,
height=out.shape[1],
width=out.shape[2],
count=classes,
dtype=out.dtype,
crs=epsg,
Expand All @@ -1987,6 +1992,12 @@ def _mapPredictions(self, map_predict, imgOutPrefix, chunk, npzs):
dst.write(out)
dst=None

# # Reopen and warp to xres
# gtiff = gtiff_temp.replace('temp', '')
# gdal.Warp(gtiff, gtiff_temp, xRes = pix_res, yRes = pix_res)

# os.remove(gtiff_temp)

return


Expand Down Expand Up @@ -2132,6 +2143,8 @@ def _rectify(self, dat, chunk, imgOutPrefix, filt=50, wgs=False, return_rect=Fal
## of upper left corner of the image and the pixel size
transform = from_origin(xMin - xres/2, yMax - yres/2, xres, yres)

# Potential for warp speedup
# https://stackoverflow.com/a/49901710
# Warp image from the input shape to output shape
out = warp(dat.T,
tform.inverse,
Expand Down

0 comments on commit 325fc62

Please sign in to comment.