def _extract_HDF_datatype(hdf, layer_indexs, outdir=None, datatype=None, force_custom=False, nodata_value=None): """ This function wraps "_extract_HDF_layer_data" and "_gdal_dataset_to_tif" It only works for datatypes listed in the datatype_library.csv :param hdf: a single hdf filepath :param layer_indexs: list of int index values of layers to extract :param outdir: filepath to output directory to place tifs. If left as "None" output geotiffs will be placed right next to input HDF. :param datatype: a dnppy.convert.datatype object created from an entry in the datatype_library.csv :param force_custom: if True, this will force the data to take on the projection and geotransform attributes from the datatype object, even if valid projection and geotransform info can be pulled from the gdal dataset. Should almost never be True. :param nodata_value: the value to set to Nodata :return: list of filepaths to output files """ output_filelist = [] if outdir is None: outdir = os.path.dirname(hdf) data = _extract_HDF_layer_data(hdf, layer_indexs) layer_indexs = core.enf_list(layer_indexs) for layer_index in layer_indexs: dataset = data[layer_index] outpath = core.create_outname(outdir, hdf, str(layer_index), "tif") print("creating dataset at {0}".format(outpath)) _gdal_dataset_to_tif(dataset, outpath, cust_projection=datatype.projectionTXT, cust_geotransform=datatype.geotransform, force_custom=force_custom, nodata_value=nodata_value) output_filelist.append(outpath) return output_filelist
def _extract_HDF_datatype(hdf, layer_indexs, outdir = None, datatype = None, force_custom = False, nodata_value = None): """ This function wraps "_extract_HDF_layer_data" and "_gdal_dataset_to_tif" It only works for datatypes listed in the datatype_library.csv :param hdf: a single hdf filepath :param layer_indexs: list of int index values of layers to extract :param outdir: filepath to output directory to place tifs. If left as "None" output geotiffs will be placed right next to input HDF. :param datatype: a dnppy.convert.datatype object created from an entry in the datatype_library.csv :param force_custom: if True, this will force the data to take on the projection and geotransform attributes from the datatype object, even if valid projection and geotransform info can be pulled from the gdal dataset. Should almost never be True. :param nodata_value: the value to set to Nodata :return: list of filepaths to output files """ output_filelist = [] if outdir is None: outdir = os.path.dirname(hdf) data = _extract_HDF_layer_data(hdf, layer_indexs) layer_indexs = core.enf_list(layer_indexs) for layer_index in layer_indexs: dataset = data[layer_index] outpath = core.create_outname(outdir, hdf, str(layer_index), "tif") print("creating dataset at {0}".format(outpath)) _gdal_dataset_to_tif(dataset, outpath, cust_projection = datatype.projectionTXT, cust_geotransform = datatype.geotransform, force_custom = force_custom, nodata_value = nodata_value) output_filelist.append(outpath) return output_filelist
print("processing chunk {0},{1}".format(aslice + 1, chunk + 1)) chunkrange = slice(int(chunk * chunk_height),int((chunk + 1) * chunk_height)) slicerange = slice(int(aslice * slice_width),int((aslice + 1) * slice_width)) slice_x_mesh = x_mesh[chunkrange, slicerange] slice_y_mesh = y_mesh[chunkrange, slicerange] outslice = self._sample_by_location(slice_x_mesh, slice_y_mesh, resolution) outgrid[chunkrange, slicerange] = outslice print("100%") return outgrid # testing area if __name__ == "__main__": from _extract_HDF_layer_data import * start = datetime.datetime.now() rasterpath = r"C:\Users\jwely\Desktop\troubleshooting\HDF_tests\GDNBO-SVDNB_npp_d20150626_t0132557_e0138361_b18964_c20150626174428799822_noaa_ops.h5" layer_data = _extract_HDF_layer_data(rasterpath, [2, 4, 19]) ngd = nongrid_data(layer_data[2].ReadAsArray(), layer_data[4].ReadAsArray(), layer_data[19].ReadAsArray(), "S") ngd.sample_by_grid(resolution = 1000) end = datetime.datetime.now() print end - start
chunkrange = slice(int(chunk * chunk_height), int((chunk + 1) * chunk_height)) slicerange = slice(int(aslice * slice_width), int((aslice + 1) * slice_width)) slice_x_mesh = x_mesh[chunkrange, slicerange] slice_y_mesh = y_mesh[chunkrange, slicerange] outslice = self._sample_by_location(slice_x_mesh, slice_y_mesh, resolution) outgrid[chunkrange, slicerange] = outslice print("100%") return outgrid # testing area if __name__ == "__main__": from _extract_HDF_layer_data import * start = datetime.datetime.now() rasterpath = r"C:\Users\jwely\Desktop\troubleshooting\HDF_tests\GDNBO-SVDNB_npp_d20150626_t0132557_e0138361_b18964_c20150626174428799822_noaa_ops.h5" layer_data = _extract_HDF_layer_data(rasterpath, [2, 4, 19]) ngd = nongrid_data(layer_data[2].ReadAsArray(), layer_data[4].ReadAsArray(), layer_data[19].ReadAsArray(), "S") ngd.sample_by_grid(resolution=1000) end = datetime.datetime.now() print end - start