I am now working with VIIRS/NPP Active Fires by using python gdal. But I cannot read the data inside the files.
Filename = "NPP_AVAF_L2.A2012019.0600.P1_03110.2014057125956.hdf"
Here is some information that I can get by using gdal.
gdal.RasterCount = 0
And gdalinfo:
gdalinfo NPP_AVAF_L2.A2012019.0600.P1_03110.2014057125956.hdf
Driver: HDF4/Hierarchical Data Format Release 4
Files: NPP_AVAF_L2.A2012019.0600.P1_03110.2014057125956.hdf
Size is 512, 512
Coordinate System is `'
Metadata:
AlgorithmType=OPS
Beginning_Time_IET=[1.7056441e+15]
BeginningTime=060027.600000Z
DayNightFlag=Day
EastBoundingCoord=123.866
Ending_Time_IET=[1.7056444e+15]
EndingTime=060609.000000Z
EndTime=2012-01-19 06:06:09.000
HDFEOSVersion=HDFEOS_V2.17
InputPointer=NPP_GRCMAE_L1.A2012019.0555.P1_03110.2014057115525.hdf,NPP_GRCMAE_L1.A2012019.0600.P1_03110.2014057115623.hdf,NPP_GRCMAE_L1.A2012019.0605.P1_03110.2014057115525.hdf
InstrumentShortname=VIIRS
LocalGranuleID=NPP_AVAF_L2.A2012019.0600.P1_03110.2014057125956.hdf
LongName=VIIRS/NPP Active Fires 5-Min L2 Swath ARP 750m
LPEATE_AlgorithmVersion=NPP_PRVAF 1.5.07.01
LUTs_used=VIIRS-AF-EDR-AC-Int_v1.5.06.02_LP
NorthBoundingCoord=27.8258
Number_Fire_Pixels=256
NumSCEA_RDR_TimeSegments=[18]
NumSci_RDR_TimeSegments=[4]
PGE_EndTime=2012-01-19 06:05:00.000
PGE_Name=PGE330
PGE_StartTime=2012-01-19 06:00:00.000
PGEVersion=P2.3.0
Platform_Short_Name=NPP
ProcessingEnvironment=Linux minion5609 2.6.18-371.1.2.el5 #1 SMP Tue Oct 22 12:51:53 EDT 2013 x86_64 x86_64 x86_64 GNU/Linux
ProcessVersion=P1_03110
ProductionTime=2014-02-26 12:59:56.000
ProxyDataType=Operational Data
Resolution=Imagery
SatelliteInstrument=NPP_OPS
ShortName=NPP_AVAF_L2
SouthBoundingCoord=3.93342
StartTime=2012-01-19 06:00:27.600
Unagg_DayNightFlag=TS 0: Day; TS 1: Day; TS 2: Day; TS 3: Day
WestBoundingCoord=90.5542
Corner Coordinates:
Upper Left ( 0.0, 0.0)
Lower Left ( 0.0, 512.0)
Upper Right ( 512.0, 0.0)
Lower Right ( 512.0, 512.0)
Center ( 256.0, 256.0)
This is what I can see from HDFViewer on same file:
I know that the file carries information of active fire points, but I cannot read the data inside into an array.
From gdalinfo above, I can see Number_Fire_Pixels=256
, but how can I get lat,lon of these points?
How can I read the data by using python?
UPDATE: Here's the link to the file that I'm working with.
Answer
Your data are stored as tables rather than gridded (raster) data which could be interpreted by GDAL.
It might be easier in the end to work in HDF5 rather than HDF4. Given you're on a Windows box it's easy to download and install the h4toh5 tools from the HDF group which can be used from the command line with (using your example file):
h4toh5convert NPP_AVAF_L2.A2012019.0600.P1_03110.2014057125956.hdf NPP_AVAF_L2.A2012019.0600.P1_03110.2014057125956.h5
Once you've got the file in HDF5 (you should not lose any data here as HDF4 attributes translate directly to HDF5) you've got a number of options in Python for working with the data. Your best bet is to install PyTables and Pandas and use the inbuilt HDFStore
object to read in the data, which might look something like:
import pandas as pd
path = "NPP_AVAF_L2.A2012019.0600.P1_03110.2014057125956.h5"
store = pd.io.pytables.HDFStore(path)
print store
Printing the store gives you a list of the series and frames stored in the dataset:
File path: /TEMP/NPP_AVAF_L2.A2012019.0600.P1_03110.2014057125956.h5
/ActiveFires_ARR/Data Fields/ColIndex frame_table [0.0.0] (typ->generic,nrows->256,ncols->1,indexers->[index],dc->[ColIndex])
/ActiveFires_ARR/Data Fields/Latitude frame_table [0.0.0] (typ->generic,nrows->256,ncols->1,indexers->[index],dc->[Latitude])
/ActiveFires_ARR/Data Fields/Longitude frame_table [0.0.0] (typ->generic,nrows->256,ncols->1,indexers->[index],dc->[Longitude])
/ActiveFires_ARR/Data Fields/QF1_VIIRSAFARP frame_table [0.0.0] (typ->generic,nrows->256,ncols->1,indexers->[index],dc->[QF1_VIIRSAFARP])
/ActiveFires_ARR/Data Fields/QF2_VIIRSAFARP frame_table [0.0.0] (typ->generic,nrows->256,ncols->1,indexers->[index],dc->[QF2_VIIRSAFARP])
/ActiveFires_ARR/Data Fields/QF3_VIIRSAFARP frame_table [0.0.0] (typ->generic,nrows->256,ncols->1,indexers->[index],dc->[QF3_VIIRSAFARP])
/ActiveFires_ARR/Data Fields/QF4_VIIRSAFARP frame_table [0.0.0] (typ->generic,nrows->256,ncols->1,indexers->[index],dc->[QF4_VIIRSAFARP])
/ActiveFires_ARR/Data Fields/RowIndex frame_table [0.0.0] (typ->generic,nrows->256,ncols->1,indexers->[index],dc->[RowIndex])
Which you can then select out the data using the name as a key:
latitude = store["/ActiveFires_ARR/Data Fields/Latitude"]
longitude = store["/ActiveFires_ARR/Data Fields/Longitude"]
qf1 = store["/ActiveFires_ARR/Data Fields/QF1_VIIRSAFARP"]
qf2 = store["/ActiveFires_ARR/Data Fields/QF2_VIIRSAFARP"]
qf3 = store["/ActiveFires_ARR/Data Fields/QF3_VIIRSAFARP"]
qf4 = store["/ActiveFires_ARR/Data Fields/QF4_VIIRSAFARP"]
And then join into a single pandas dataframe object:
df = latitude.join([longitude, qf1, qf2, qf3, qf4])
And from there you've got a complete dataframe object where you can do what you like, eg:
import seaborn
df.plot(kind="scatter",
x="Longitude", y="Latitude",
s=df["QF4_VIIRSAFARP"] / df["QF4_VIIRSAFARP"].max() * 200,
alpha=0.5
)
And one last note, the store object can be used as a context manager so it's closed automatically:
with HDFStore(path) as store:
# do something...
No comments:
Post a Comment