Accessing CALIPSO metadata with Python

Use this Forum to find information on, or ask a question about, NASA Earth Science data.
Post Reply
rmooers
Posts: 1
Joined: Wed Jul 14, 2021 10:25 am America/New_York
Answers: 0

Accessing CALIPSO metadata with Python

by rmooers » Wed Jul 14, 2021 10:33 am America/New_York

Hello,

I am trying to plot a vertical profile of total backscatter from the CALIOP LiDAR on CALIPSO. However, I have been unable to access the “Lidar_Data_Altitudes” in the metadata group for the level 1B profile data product in Python using pyhdf.

I can view datasets in the root group with pyhdf’s SD module, but have not been able to read the metadata group with the vgroup module. I followed the example here (http://fhs.github.io/pyhdf/modules/V.ht ... g-a-vgroup) but did not see the metadata group in the output. Likewise, I am unable to view the altitude data in Panoply.

Is there a way to access the “Lidar_Data_Altitudes” using Python?

Thank you!
by robert.ryan » Thu Jul 22, 2021 1:27 pm America/New_York
Greetings,

I am able to access the "Lidar_Data_Altitudes" in the following way.

First, I initialize the HDF interface.

>>> hdf_interface = HDF(os.path.join(file_path, file_name))

Then, I initialize the VS API over the file and return a VS instance using the vstart() function of the HDF interface.

>>> vs_interface = hdf_interface.vstart()

Next, I use attach() to retrieve the "metadata" VD instance.

>>> meta = vs_interface.attach("metadata")

Finally, to access all of the fields of the metadata, there are a couple of methods but my preferred method is the following. Retrieve info about all vdata fields.

>>> field_infos = meta.fieldinfo()

Retrieve the values of the records...

>>> all_data = meta.read(meta._nrecs)[0]

Terminate access to the vdata. """

>>> meta.detach()

Create a more pythonic dictionary to easily access the data.

>>> data_dictionary = {}
>>> field_name_index = 0
>>> for field_info, data in zip(field_infos, all_data):
>>> data_dictionary[field_info[field_name_index]] = data
>>> lidar_altitudes = data_dictionary["Lidar_Data_Altitudes"]

Clean up access

>>> vs_interface.end()
>>> hdf_interface.close()

The variable lidar_altitudes should now hold a list of the lidar altitudes. The attached screenshots are of a full script that does what I believe you want to do.

Good luck and have a great day.
Go to full post

Tags:

ASDC - ingridgs
Subject Matter Expert
Subject Matter Expert
Posts: 142
Joined: Fri Apr 23, 2021 9:14 am America/New_York
Answers: 1
Has thanked: 17 times
Been thanked: 7 times

Re: Accessing CALIPSO metadata with Python

by ASDC - ingridgs » Thu Jul 15, 2021 1:19 pm America/New_York

Thank you for your question. A Subject Matter Expert has been notified and will answer your question shortly. Please stand by!

robert.ryan
Posts: 1
Joined: Thu Jul 22, 2021 1:05 pm America/New_York
Answers: 1

Re: Accessing CALIPSO metadata with Python

by robert.ryan » Thu Jul 22, 2021 1:27 pm America/New_York

Greetings,

I am able to access the "Lidar_Data_Altitudes" in the following way.

First, I initialize the HDF interface.

>>> hdf_interface = HDF(os.path.join(file_path, file_name))

Then, I initialize the VS API over the file and return a VS instance using the vstart() function of the HDF interface.

>>> vs_interface = hdf_interface.vstart()

Next, I use attach() to retrieve the "metadata" VD instance.

>>> meta = vs_interface.attach("metadata")

Finally, to access all of the fields of the metadata, there are a couple of methods but my preferred method is the following. Retrieve info about all vdata fields.

>>> field_infos = meta.fieldinfo()

Retrieve the values of the records...

>>> all_data = meta.read(meta._nrecs)[0]

Terminate access to the vdata. """

>>> meta.detach()

Create a more pythonic dictionary to easily access the data.

>>> data_dictionary = {}
>>> field_name_index = 0
>>> for field_info, data in zip(field_infos, all_data):
>>> data_dictionary[field_info[field_name_index]] = data
>>> lidar_altitudes = data_dictionary["Lidar_Data_Altitudes"]

Clean up access

>>> vs_interface.end()
>>> hdf_interface.close()

The variable lidar_altitudes should now hold a list of the lidar altitudes. The attached screenshots are of a full script that does what I believe you want to do.

Good luck and have a great day.
Attachments
Sample script pg3
Sample script pg3
ScriptScreenShot3.png (75.72 KiB) Not viewed yet
Sample script pg2
Sample script pg2
ScriptScreenShot2.png (142.2 KiB) Not viewed yet
Sample script pg1
Sample script pg1
ScriptScreenShot1.png (130.74 KiB) Not viewed yet

Post Reply