calipso

作者: 榴莲气象 | 来源:发表于2019-01-17 17:42 被阅读8次

    https://hdfeos.org/forums/showthread.php?t=796

    """
    Copyright (C) 2018 The HDF Group
    
    This example code illustrates how to access and visualize a LaRC CALIPSO file 
    in file in Python.
    
    If you have any questions, suggestions, or comments on this example, please use
    the HDF-EOS Forum (http://hdfeos.org/forums).  If you would like to see an
    example of any other NASA HDF/HDF-EOS data product that is not listed in the
    HDF-EOS Comprehensive Examples page (http://hdfeos.org/zoo), feel free to
    contact us at eoshelp@hdfgroup.org or post it at the HDF-EOS Forum
    (http://hdfeos.org/forums).
    
    Usage:  save this script and run
    
        python CAL_LID_L2_05kmAPro-Standard-V4-10.2007-03-06T09-29-19ZD.hdf.py
    
    The HDF file must be in your current working directory.
    
    Last Update: 2018-02-15
    """
    import os
    import matplotlib as mpl
    import matplotlib.pyplot as plt
    import numpy as np
    from mpl_toolkits.basemap import Basemap
    from matplotlib import colors
    from pyhdf.SD import SD, SDC
    
    DATAFIELD_NAME = 'Column_Optical_Depth_Cloud_532'
    FILE_NAME = 'CAL_LID_L2_05kmAPro-Standard-V4-10.2007-03-06T09-29-19ZD.hdf'
    hdf = SD(FILE_NAME, SDC.READ)
            
    # Read dataset.
    data2D = hdf.select(DATAFIELD_NAME)
    data = data2D[:,0]
    
    # Read attributes.
    attrs = data2D.attributes(full=1)
    fva=attrs["fillvalue"]
    _FillValue = fva[0]
    ua=attrs["units"]
    units = ua[0]
    
    vra=attrs["valid_range"]
    vra_str = vra[0]
    
    # Valid attribute is string '0.0...25.0'.
    smin, smax = vra_str.split("...")
    valid_min = float(smin)
    valid_max = float(smax)
    
    invalid = np.logical_or(data > valid_max,
                            data < valid_min)
    invalid = np.logical_or(invalid, data == _FillValue)
    data[invalid] = np.nan
    
    # Read geolocation datasets.
    latitude = hdf.select('Latitude')
    lat = latitude[:,0]
    
    longitude = hdf.select('Longitude')
    lon = longitude[:,0]
    
    m = Basemap(projection='cyl', resolution='l',
                llcrnrlat=-90, urcrnrlat=90,
                llcrnrlon=-180, urcrnrlon=180)
    m.drawcoastlines(linewidth=0.5)
    m.drawparallels(np.arange(-90, 91, 45))
    m.drawmeridians(np.arange(-180, 180, 45), labels=[True,False,False,True])
    m.scatter(lon, lat, c=data, s=1, cmap=plt.cm.jet,
              edgecolors=None, linewidth=0)
    cb = m.colorbar()
    cb.set_label(units)
    
    basename = os.path.basename(FILE_NAME)
    # There is no long_name attribute on dataset.
    longname = DATAFIELD_NAME
    plt.title('{0}\n{1}'.format(basename, longname))
    fig = plt.gcf()
    
    pngfile = "{0}.py.png".format(basename)
    fig.savefig(pngfile)
    

    https://github.com/vnoel/pycode

    相关文章

      网友评论

          本文标题:calipso

          本文链接:https://www.haomeiwen.com/subject/fwzidqtx.html