Plotting CALIPSO using Python

Use this Forum to find information on, or ask a question about, NASA Earth Science data.
Post Reply
shravu
Posts: 11
Joined: Thu May 04, 2023 6:29 am America/New_York
Answers: 0

Plotting CALIPSO using Python

by shravu » Tue May 09, 2023 3:44 am America/New_York

Hello everyone,

I'm trying to plot CALIPSO hdf L2 files and analyze the Backscattering coefficient from them, and to do this I want to plot (via Python) a vertical profile of the data (elevation vs Backscattering coefficient). I found an example from the Comprehensive Examples site below:

https://hdfeos.org/zoo/MORE/LaRC/CALIPSO/CAL_LID_L2_05kmAPro-Standard-V4-21.2021-01-10T21-34-11ZN.hdf.py

But with the Python script from there, I can only plot the vertical profile of the Backscattering coefficient for the whole data. While I need to plot them for a specific latitude.

How can I plot them for a specific latitude suppose 5-10 degrees N only? I'm trying to do it, but it has been difficult. I have a number of such files of different dates. Thank you very much!

(Filename example- CAL_LID_L2_05kmAPro-Standard-V4-20.2015-05-15T07-58-31ZD_Subset.hdf)

Tags:

ASDC - cheyenne.e.land
Subject Matter Expert
Subject Matter Expert
Posts: 129
Joined: Mon Mar 22, 2021 3:55 pm America/New_York
Answers: 1
Has thanked: 1 time
Been thanked: 8 times

Re: Plotting CALIPSO using Python

by ASDC - cheyenne.e.land » Fri May 12, 2023 11:45 am America/New_York

Hello,

Thank you for your interest in CALIPSO data.

From the filename example that you gave it looks like you are using ASDC's CALIPSO Subsetter. By using this application you can select a geospatial range (Step 3) and decide what specific latitude and/or longitude to analyze. Once you order the data you have subsetted and receive it through email, you will not have to extract any specific latitude and longitude values using the Python script because you already did it through the ASDC's CALIPSO Subsetter. All you have to do is tell the Python script which HDF file you want it to plot.

Please let us know if you have any other questions.

Regards,
ASDC User Services

shravu
Posts: 11
Joined: Thu May 04, 2023 6:29 am America/New_York
Answers: 0

Re: Plotting CALIPSO using Python

by shravu » Sat May 13, 2023 2:05 pm America/New_York

Thank you for your response. I have already taken subsetted data using the ASDC's CALIPSO Subsetter. But, now I have to further subset it based on different latitude ranges like 10-20N, 20-30N etc. So, how to modify the https://hdfeos.org/zoo/MORE/LaRC/CALIPSO/CAL_LID_L2_05kmAPro-Standard-V4-21.2021-01-10T21-34-11ZN.hdf.py code using Python? Please help me out.

ASDC - cheyenne.e.land
Subject Matter Expert
Subject Matter Expert
Posts: 129
Joined: Mon Mar 22, 2021 3:55 pm America/New_York
Answers: 1
Has thanked: 1 time
Been thanked: 8 times

Re: Plotting CALIPSO using Python

by ASDC - cheyenne.e.land » Tue May 16, 2023 7:52 am America/New_York

Hello,

Here is code to subset for latitude

Code: Select all

import os
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
from pyhdf import HDF, SD, VS
from pyhdf.SD import SD, SDC

FILE_NAME = 'CAL_LID_L2_05kmAPro-Standard-V4-20.2015-05-14T23-44-05ZD.hdf'
DATAFIELD_NAME = 'Extinction_Coefficient_532'
sd = SD(FILE_NAME, SDC.READ)
hdf = HDF.HDF(FILE_NAME)
vs = hdf.vstart()
hdf = SD(FILE_NAME, SDC.READ)

#get altitude
xid = vs.find('metadata')
altid = vs.attach(xid)
altid.setfields('Lidar_Data_Altitudes')
nrecs, _, _, _, _ = altid.inquire()
altitude = altid.read(nRec=nrecs)
altid.detach()
alti = np.array(altitude[0][0])
alt = np.flip(alti)

# Read geolocation datasets.
# They are all same for every file so we read only once.
lat = hdf.select("Latitude")
latitude = np.squeeze(lat[:,0])

#subset for latitude (10-20N)
idx_lat = np.where((latitude >= 10) & (latitude <= 20))
idx_subset_lat = idx_lat[0]
subset_lat = np.array([latitude[i] for i in idx_subset_lat])

# Read dataset.
data2D = hdf.select(DATAFIELD_NAME)
data = data2D[:,:].astype(np.float64)
# Retrieve the attributes.
attrs = data2D.attributes(full=1)
# print(attrs)

fva=attrs["fillvalue"]
fill_value = fva[0]
ua=attrs["units"]
units = ua[0]

# Replace the missing values with NaN.        
data[data == float(fill_value)] = np.nan

#subset data to accomodate the subsetting of latitude
data_arrays = []
for x in range(len(data.T)):
   subset = np.take(data[:,x], idx_subset_lat)
   data_arrays.append(subset)
   if x >= len(data.T):
       break
subset_data = np.stack(data_arrays)


# Contour the data on a grid of latitude vs. altitude
lats, alts = np.meshgrid(subset_lat, alt)

#plot data
plt.figure(figsize=(7.20,3.60))
plt.contourf(lats, alts, subset_data, cmap=plt.get_cmap('jet'))
cb = plt.colorbar()
cb.set_label(units)
long_name = DATAFIELD_NAME 
plt.title("{0}\n{1}".format(FILE_NAME, long_name), fontsize=8)
plt.xlabel('Latitude (degrees north)')
plt.ylabel('Altitude (km)')
fig = plt.gcf()
pngfile = "{0}.v.py.png".format(FILE_NAME)
fig.savefig(pngfile, dpi=200)

shravu
Posts: 11
Joined: Thu May 04, 2023 6:29 am America/New_York
Answers: 0

Re: Plotting CALIPSO using Python

by shravu » Wed May 17, 2023 1:25 am America/New_York

Hello,
Thank You for helping me out. As mentioned earlier I wanted to plot backscatter coeff vs altitude for a specific range of latitude, not a contour plot. But, my problem is solved now. I got an idea of how to subset the latitude from the code.

Thank You once again!

dishipthomas
Posts: 2
Joined: Sun Nov 26, 2023 3:29 am America/New_York
Answers: 0

Re: Plotting CALIPSO using Python

by dishipthomas » Fri Dec 08, 2023 3:19 am America/New_York

My name is Dishi P Thomas, PhD student at University of Alaska Fairbanks. I am not able to understand calipso data properly . I am using CAL_LID_L2_01kmCLay-ValStage1-V3-41.2022-02-28T23-12-48ZD.hdf data . I need to take latitude and longitude values as one degree by one degree around fairbanks, alaska which its latitude and longitude values is 64.8, -147.8. I need to plot attenuated_backscatter_532 v/s altitude to see surface based inversion layer. when considering backscatter data Im getting (21200, 60). what is this 60 columns. and also i have altitude top and altitude base each shape is (21200, 10). I need to plot I need to plot attenuated_backscatter_532 v/s altitude, altitude is upto 3km . I am using python program . Can you help me. It is urgent as we need some results.

Thank you for your time.

ASDC - cheyenne.e.land
Subject Matter Expert
Subject Matter Expert
Posts: 129
Joined: Mon Mar 22, 2021 3:55 pm America/New_York
Answers: 1
Has thanked: 1 time
Been thanked: 8 times

Re: Plotting CALIPSO using Python

by ASDC - cheyenne.e.land » Fri Dec 08, 2023 2:00 pm America/New_York

Hello Dishi,

Thank you for your interest in CALIPSO data.

Just as an oberservation, you are using an older version of the product CAL_LID_L2_01kmCLay. Would recommend using the latest version, V4-51.

To help get you started here is the link to CALIPSO's nominal browse images for 2022-02-28T23-12-48ZD that includes plots for attenuated backscatter at 532nm: https://www-calipso.larc.nasa.gov/products/lidar/browse_images/show_v451_detail.php?s=production&v=V4-51&browse_date=2022-02-28&orbit_time=23-12-48&page=4&granule_name=CAL_LID_L1-Standard-V4-51.2022-02-28T23-12-48ZD.hdf

There were three variables that you had question in regards to the dimensions, the Attenuated_Backscatter_Statistics_532 (21200, 60), Layer_Top_Altitude (21200, 10) and Layer_Base_Altitude (21200, 10). The first number, 21200, is the time dimension, for the values 60 and 10, I will need to get in contact with a member of the CALIPSO Science Team. It's not clear what the values represent when looking at the documentation.

Apologies for the inconvenience. Hope this helps.

Regards,
ASDC

dishithomas
Posts: 1
Joined: Wed Aug 18, 2021 6:01 am America/New_York
Answers: 0

Re: Plotting CALIPSO using Python

by dishithomas » Fri Dec 08, 2023 8:23 pm America/New_York

CAL_LID_L2_01kmCLay-ValStage1-V3-41.2022-02-28T23-12-48ZD.hdf not able to download this data
and not able to find any documentation regarding this data

ASDC - cheyenne.e.land
Subject Matter Expert
Subject Matter Expert
Posts: 129
Joined: Mon Mar 22, 2021 3:55 pm America/New_York
Answers: 1
Has thanked: 1 time
Been thanked: 8 times

Re: Plotting CALIPSO using Python

by ASDC - cheyenne.e.land » Mon Dec 11, 2023 11:59 am America/New_York

Hello,

Yes, CAL_LID_L2_01kmCLay-ValStage1-V3-41, is a Legacy product so you will not be able to download any data. We recommend using a current version of this product, CAL_LID_L2_01kmCLay-Standard-V4-51_V4-51 where you can download this data via Direct Data Download. I have also provided the link to download the file that you want but with the current product:
CAL_LID_L2_01kmCLay-Standard-V4-51.2022-02-28T23-12-48ZD.hdf.

Here is the documentation for this product as well:
https://www-calipso.larc.nasa.gov/resources/calipso_users_guide/data_desc/cal_lid_l2_layer_v4-51_desc.php

For the variables that you initially asked about, Layer_Top_Altitude (21200, 10), Layer_Base_Altitude (21200, 10), the dimenson 21200 represents a 1-km resolution column which describe the temporal and spatial location of the vertical column. The 10 represents the layer and for the 1km cloud layer product there can be upwards of 10 potential layers. For the 60 in the variable Attenuated_Backscatter_Statistics_532 (21200, 60), reports the minimum, maximum, mean, standard deviation, centroid, and skewness coefficient. More information for this variable found here.

Regards,
ASDC

Post Reply