Esempio n. 1
0
mask_file=glob.glob('MYD35*2010215*.hdf')[0]
my_parser=metaParse(filename=mask_file)
meta_data=my_parser.get_info()
mask=pyhdf.SD.SD(mask_file)

theDate=parse(meta_data['startdate'][:-3] + meta_data['starttime'])
theDate=theDate.replace(tzinfo=tz.tzutc())

maskVals=mask.select('Cloud_Mask')
maskVals=maskVals.get()
maskVals=maskVals[0,...] #get the first byte
#
# pass the byte to bitmap and get back the cloudmask
# and the landmask
#
maskout,landout=bitmap.getmask_zero(maskVals)
oceanvals=(landout==0)
cloudvals=np.logical_and(maskout==0,oceanvals)
cloudfrac=np.sum(cloudvals)/oceanvals.size
oceanfrac=np.sum(oceanvals)/landout.size
print "Cloud fraction is {0:8.4f}".format(cloudfrac)
print "fraction of scene surface that is ocean is {0:8.4f}".format(oceanfrac)

thinout,highout=bitmap.getmask_zero(maskVals)
clear_thin_frac=np.sum(thinout.flat)/thinout.size
clear_high_frac=np.sum(highout.flat)/highout.size

print "fraction of scene that is covered by thin clouds is {0:8.4f}".format(1. - clear_thin_frac)
print "fraction of scene that is covered by high clouds is {0:8.4f}".format(1. - clear_high_frac)

## fig=plt.figure(1)
Esempio n. 2
0
    fullLons_raw=sdgeom.select('Longitude')
    fullLons_raw=fullLons_raw.get()
    sdgeom.end()
    model2_file='*D021KM*{0:s}*hdf'.format(granule_info)
    model2_file=glob.glob(model2_file)[0]
    sdrad=pyhdf.SD.SD(model2_file)
    longWave=sdrad.select('EV_1KM_Emissive')
    allRadiances=longWave.get()

    model35_file='*D35*{0:s}*hdf'.format(granule_info)
    model35_file=glob.glob(model35_file)[0]
    mask=pyhdf.SD.SD(model35_file)
    maskVals=mask.select('Cloud_Mask')
    maskVals=maskVals.get()
    byte0=maskVals[0,...] #get the first byte
    maskout,landout=bitmap.getmask_zero(byte0)
    maskout=maskout.astype(np.float32)
    landout=landout.astype(np.float32)
    fullLats,fullLons,maskout=orient(fullLats_raw,fullLons_raw,maskout)
    fullLats,fullLons,landout=orient(fullLats_raw,fullLons_raw,landout)
    #
    # find the index for channel 31 (it's 10, i.e. channel 31 is
    # the 11th channel)
    #
    theChans=longWave.attributes()['band_names']
    band_names=theChans.split(',')
    index31=band_names.index('31')
    #
    #  get the radiances as 16 bit integers
    #
    chan31=allRadiances[index31,:,:]
Esempio n. 3
0
if not os.path.isdir(plot_dir):
    os.makedirs(plot_dir)


mask_name='MYD35_L2.A2008290.0740.005.2008290182115.hdf'

mask=pyhdf.SD.SD(mask_name)
theMeta=parseMeta(mask)
theDate=parse(theMeta['startdate'][:-3] + theMeta['starttime'])
theDate=theDate.replace(tzinfo=tz.tzutc())


maskVals=mask.select('Cloud_Mask')
maskVals=maskVals.get()
maskVals=maskVals[0,...] #get the first byte
maskout,landout=bitmap.getmask_zero(maskVals)
oceanvals=(landout==0)
cloudvals=np.logical_and(maskout==0,oceanvals)
cloudfrac=np.sum(cloudvals)/oceanvals.size
oceanfrac=np.sum(oceanvals)/landout.size

options={'fignum':1}
corner_plot=simplots(option_dict=options)
theMap=corner_plot.make_lambert()
x,y=theMap(theMeta['cornerlons'],theMeta['cornerlats'])
theMap.plot(x,y)
theFig=theMap.ax.figure
theFig.canvas.draw()
theTitle=theMap.ax.set_title('cloud frac: %5.3f, oceanfrac: %5.3f' % (cloudfrac,oceanfrac))
x,y=theTitle.get_position()
theSize=theTitle.get_fontsize()
Esempio n. 4
0
    parser = argparse.ArgumentParser(formatter_class=linebreaks,
                                     description=descrip)
    parser.add_argument('infile',
                        type=str,
                        help='MYD35_L2 input hdf5 file path')
    parser.add_argument('outfile',
                        type=str,
                        help='output hdf5 file for cloud/land mask')
    args = parser.parse_args()

    cloud_mask, = glob.glob(args.infile)
    with h5py.File(cloud_mask) as cloud_mask_h5:
        cloud_mask_byte0 = cloud_mask_h5['mod35']['Data Fields']['Cloud_Mask'][
            0, :, :]

    maskout, landout = bitmap.getmask_zero(cloud_mask_byte0)
    maskout = maskout.astype(np.float32)
    landout = landout.astype(np.float32)

    with h5py.File(args.outfile, "w") as f:
        dset = f.create_dataset('cloudmask',
                                maskout.shape,
                                dtype=maskout.dtype)
        dset[...] = maskout[...]
        dset.attrs['input_file'] = cloud_mask
        dset.attrs[
            'description'] = '0 = Cloud;1 = 66% prob. Clear;2 = 95% prob. Clear;3 = 99% prob. Clear'
        dset = f.create_dataset('landmask', landout.shape, dtype=landout.dtype)
        dset.attrs['input_file'] = cloud_mask
        dset.attrs['description'] = '0=Water;1=Coastal;2=Desert;3=Land'
        dset[...] = landout[...]
Esempio n. 5
0
from __future__ import division
import h5py
import bitmap
import numpy as np

mask_name = '../datasets/MYD35_L2.A2014125.2135.006.2014125184012.h5'

with h5py.File(mask_name, 'r') as infile:
    cloud_mask = infile['mod35/Data Fields/Cloud_Mask'][...]

maskVals = cloud_mask[0, ...]  #get the first byte
maskout, landout = bitmap.getmask_zero(maskVals)
oceanvals = (landout == 0)
cloudvals = np.logical_and(maskout == 0, oceanvals)
cloudfrac = np.sum(cloudvals) / oceanvals.size
oceanfrac = np.sum(oceanvals) / landout.size
print('cloud fraction: ', cloudfrac)
print('clear fraction: ', oceanfrac)
Esempio n. 6
0
if __name__ == "__main__":
    #
    # the following two lines help format the docstring at the top of the file
    # into a help text
    #
    linebreaks=argparse.RawTextHelpFormatter
    descrip=textwrap.dedent(globals()['__doc__'])
    parser = argparse.ArgumentParser(formatter_class=linebreaks,description=descrip)
    parser.add_argument('infile',type=str,help='MYD35_L2 input hdf5 file path')
    parser.add_argument('outfile',type=str,help='output hdf5 file for cloud/land mask')
    args=parser.parse_args()

    cloud_mask,=glob.glob(args.infile)
    with  h5py.File(cloud_mask) as cloud_mask_h5:
        cloud_mask_byte0=cloud_mask_h5['mod35']['Data Fields']['Cloud_Mask'][0,:,:]

    maskout,landout=bitmap.getmask_zero(cloud_mask_byte0)
    maskout=maskout.astype(np.float32)
    landout=landout.astype(np.float32)

    with h5py.File(args.outfile, "w") as f:
        dset=f.create_dataset('cloudmask',maskout.shape, dtype=maskout.dtype)
        dset[...]=maskout[...]
        dset.attrs['input_file']=cloud_mask
        dset.attrs['description']='0 = Cloud;1 = 66% prob. Clear;2 = 95% prob. Clear;3 = 99% prob. Clear'
        dset=f.create_dataset('landmask',landout.shape, dtype=landout.dtype)
        dset.attrs['input_file']=cloud_mask
        dset.attrs['description']='0=Water;1=Coastal;2=Desert;3=Land'
        dset[...]=landout[...]