The HDF to GeoTIFF tool provides Python scripts to help users read NASA's Black Marble VNP46 files, convert them to GeoTIFF, and display them in QGIS. For those who do not have Geospatial Data Abstraction Library (GDAL) installed, the QGIS python console (Plugins -> Python Console) can be used to run the script.
Download the source code to convert NASA's Black Marble HDF5 product to GeoTIFF or HDF4 product to GeoTIFF.
Location of the Input Folder Containing HDF Images
os.chdir('C:\\InputFolder')
The current script only reads the first file (if there are multiple files in the input folder). The rasterFiles[ ] index can be modified to select one specific file or iterate through all files within the input folder.
hdflayer = gdal.Open(rasterFiles[0], gdal.GA_ReadOnly)
Reading a specific raster layer: GetSubDatasets()[0][0] for first layer, GetSubDatasets()[1][0] for second layer, and so on.
hdflayer.GetSubDatasets()[0][0]
Location of the Folder for Output Images
outputFolder = "C:\\OutputFolder\\"
Display Output GeoTiff Image in QGIS
This command works only if the script is executed within QGIS Python Console.
iface.addRasterLayer(outputRaster, outputNameFinal)