def main(nom): # lecture de l'interpretation if nom == "": tkinter.Tk().withdraw() nom = filedialog.askopenfilename( title="Fichier contenant l'interpretation ?" ) # ,filetypes=(("fichiers shape","*.shp"))) interp, larg, haut = lecture_inter(nom) # lecture de l'image tif georeferencee nom_se = nom[:nom.rfind(".")] nom_image = nom_se + ".tif" # creation de l'image interpretee georeferencee info_geo = gr.MultiBandRaster(nom_image, load_data=False) im_gen = gr.SingleBandRaster.from_array(interp, info_geo.trans, info_geo.proj.srs, gdal.GDT_Int16) im_gen.save_geotiff(nom_se + "_int.tif", dtype=gdal.GDT_Int16)
def load(filename, grid): """ Load a MAR NetCDF file with the specified grid type using GeoRaster. DEPRECATED Parameters: filename : string, the path to the file with the relevant sub-dataset referencing, e.g. 'NETCDF:"MARv3.5.2-10km-monthly-ERA-Interim-1979.nc":AL' grid : string, corresponding to entry in grids dictionary. Returns: MultiBandRaster instance, over full domain, all bands loaded """ if gr_avail: spatial_ref = osr.SpatialReference() spatial_ref.ImportFromProj4(grids[grid]['spatial_ref']) rast = georaster.MultiBandRaster( filename, spatial_ref=spatial_ref, geo_transform=grids[grid]['geo_transform']) # Flip the raster bands to restore correct orientation for i in rast.bands: rast.r[:, :, i - 1] = np.flipud(rast.r[:, :, i - 1]) return rast else: print('GeoRaster dependency not available.') raise ImportError
final = np.asarray((np.reshape(pred_acc, (Y, X))), np.float32) # # write file to output directory # /output/filename.tif file_name = PATH_OUTPUT + 'pred_' + list_Filenames[i] border = (16, 16, 15, 15) image_temp = Image.fromarray(final) image_temp1 = np.asarray( ImageOps.expand(image_temp, border) ) # add border to resize to original value,convert to array, again # print('final.shape', image_temp1.size) # image_temp1.save(file_name) # Insert GEOTIFF information back into image before saving info_geo = gr.MultiBandRaster(imagePath[i], load_data=False) im_gen = gr.SingleBandRaster.from_array(image_temp1, info_geo.trans, info_geo.proj.srs, gdal.GDT_Int16) im_gen.save_geotiff(PATH_OUTPUT + 'geo_pred_' + list_Filenames[i]) print('processing', list_Filenames[i]) count = 1 #pred_acc.clear() time_elapsed = (time.perf_counter() - time_start) HMS_time = time.strftime("%H:%M:%S", time.gmtime(time_elapsed)) memMb = resource.getrusage( resource.RUSAGE_SELF).ru_maxrss / 1024.0 / 1024.0 print("[INFO] TIME USED: ", HMS_time) print("[INFO] MEMORY USAGE: {:.1f} MByte".format(memMb)) # print('pred',predictions) # TEST SLIDING WINDOW WITH OVERLAY..... # clone = image.copy()
parser.add_argument('-vmax', dest='vmax', type=str, default='default', help='float, the maximum value for colorscale, or can be expressed as a percentile e.g. 95% (default is calculated max value).') parser.add_argument('-band', dest='band', type=int, default=0, help='int, which band to display (start at 0) for multiband images (Default is 0).') parser.add_argument('-nocb', dest='nocb', help='If set, will not display a colorbar (Default is to display the colorbar).',action='store_true') parser.add_argument('-clabel', dest='clabel', type=str, default='', help='str, the label for the colorscale (Default is empty).') parser.add_argument('-title', dest='title', type=str, default='', help='str, figure title (Default is empty).') parser.add_argument('-figsize', dest='figsize', type=str, default='default', help='str, figure size, must be a tuple of size 2, either written with quotes, or two numbers seperated by coma, no space (Default is from rcParams).') parser.add_argument('-max_size', dest='max_size', type=int, default=2000, help='int, image size is limited to max_size**2 for faster reading/displaying (Default is 2000).') parser.add_argument('-save', dest='save', type=str, default='', help='str, filename to the output filename to save to disk (Default is displayed on screen).') parser.add_argument('-dpi', dest='dpi', type=str, default='default', help='int, dpi value to use when saving figure (Default is from rcParams).') parser.add_argument('-nodata', dest='nodata', type=str, default='default', help='float, no data value (Default is read from file metadata).') parser.add_argument('-noresampl', dest='noresampl', default=False, action='store_true', help='True or False, if False then allow dynamic image downscaling, if True, prevent it.') args = parser.parse_args() ## Load image metadata ## img = raster.MultiBandRaster(args.filename,load_data=False) xmin, xmax, ymin, ymax = img.extent if args.nodata=='default': nodata = img.ds.GetRasterBand(1).GetNoDataValue() else: try: nodata = float(args.nodata) except ValueError: print("ERROR: nodata must be a float, currently set to %s" %args.nodata) sys.exit(1) ## Resample if image is too large ## if (img.nx*img.ny>args.max_size**2) & (not args.noresampl): step = max(int(img.nx/args.max_size),int(img.ny/args.max_size))