zia207

HDF to tiff : Extract in folders based on HDF file names

Discussion created by zia207 on Nov 17, 2015
Latest reply on Nov 18, 2015 by rastrauch

Hi,

I am processing  190s HDF files  from a Folder (J:\RapidEyr_Atcor\HDF).  Here is the example of file name:

 

AtmosCorrected_4549227_2014-12-23_RE1_3A_278182.hdf

AtmosCorrected_4549227_2015-02-15_RE1_3A_278163.hdf

AtmosCorrected_4549227_2015-01-13_RE1_3A_278182.hdf

AtmosCorrected_4549227_2015-03-23_RE1_3A_278102.hdf

 

Each HDF  file contains 13 bands. But I want to extract the first  5 bands from each of  HDF file and   save as TIFF files in a folder created with [16:46] characters of  corresponding HDF file.

 

Folder and files arrangement as like as below:

 

J:\RapidEyr_Atcor\TIF \4549227_2015-02-15_RE1_3A_278163

          4549227_2015-02-15_RE1_3A_278163_b1. tif,

          4549227_2015-02-15_RE1_3A_278163_b2.tif,

          4549227_2015-02-15_RE1_3A_278163_b3.tif,

          4549227_2015-02-15_RE1_3A_278163_b4.tif,

          4549227_2015-02-15_RE1_3A_278163_b5.tif

 

J:\RapidEyr_Atcor\TIF \4549227_2015-01-13_RE1_3A_278182

          4549227_2015-01-13_RE1_3A_278182_b1.tif

          4549227_2015-01-13_RE1_3A_278182_b2.tif

           4549227_2015-01-13_RE1_3A_278182_b3.tif

          4549227_2015-01-13_RE1_3A_278182_b4.tif

          4549227_2015-01-13_RE1_3A_278182_b4.tif

 

 

I think, first I have to create a output folder and name it with [16:46] characters of  one  HDF file, then apply arcpy.ExtractSubDataset for selecting the first five bands (0:4) from the corresponding HDF file.  And I have to run this process in a loop for all HDF files.

 

If anyone help me to modify following codes to process all HDF files with batch mode. 

 

Thanks

Zia

 

import arcpy  
try:  
 arcpy.env.workspace = r"J:\RapidEyr_Atcor\HDF"  
 rasterListA = arcpy.ListRasters()  
for raster in rasterListA:  
tifOutA="J:\\RapidEyr_Atcor\\TIFF"+raster[16:46]  
 arcpy.ExtractSubDataset_management(raster,tifOutA+"_B1"+".tif", "0")  
 arcpy.ExtractSubDataset_management(raster,tifOutA+"_B2"+".tif", "1")  
 arcpy.ExtractSubDataset_management(raster,tifOutA+"_B3"+".tif", "2")  
 arcpy.ExtractSubDataset_management(raster,tifOutA+"_B4"+".tif", "3")  
 arcpy.ExtractSubDataset_management(raster,tifOutA+"_B5"+".tif", "4")  
except:  
print "Extract Subdataset example failed."  
print arcpy.GetMessages()  

Outcomes