def get_channels(l1b_file, geom_file, cloud_mask, mod06_file): with h5py.File(geom_file) as geom_h5, h5py.File(l1b_file) as l1b_h5: #channel31 is emissive channel 10 #pdb.set_trace() band_names = text_(l1b_h5['MODIS_SWATH_Type_L1B']['Data Fields'] ['EV_1KM_Emissive'].attrs['band_names']) band_names = band_names.split(',') index31 = band_names.index('31') chan31 = l1b_h5['MODIS_SWATH_Type_L1B']['Data Fields'][ 'EV_1KM_Emissive'][index31, :, :] scale = l1b_h5['MODIS_SWATH_Type_L1B']['Data Fields'][ 'EV_1KM_Emissive'].attrs['radiance_scales'][index31] offset = l1b_h5['MODIS_SWATH_Type_L1B']['Data Fields'][ 'EV_1KM_Emissive'].attrs['radiance_offsets'][index31] chan31 = (chan31 - offset) * scale index1 = 0 #channel 1 is first 250 meter reflective channel reflective = l1b_h5['MODIS_SWATH_Type_L1B']['Data Fields'][ 'EV_250_Aggr1km_RefSB'][0, :, :] scale = l1b_h5['MODIS_SWATH_Type_L1B']['Data Fields'][ 'EV_250_Aggr1km_RefSB'].attrs['reflectance_scales'] offset = l1b_h5['MODIS_SWATH_Type_L1B']['Data Fields'][ 'EV_250_Aggr1km_RefSB'].attrs['reflectance_offsets'] chan1 = (reflective - offset[0]) * scale[0] index29 = band_names.index('29') chan29 = l1b_h5['MODIS_SWATH_Type_L1B']['Data Fields'][ 'EV_1KM_Emissive'][index29, :, :] scale = l1b_h5['MODIS_SWATH_Type_L1B']['Data Fields'][ 'EV_1KM_Emissive'].attrs['radiance_scales'][index29] offset = l1b_h5['MODIS_SWATH_Type_L1B']['Data Fields'][ 'EV_1KM_Emissive'].attrs['radiance_offsets'][index29] chan29 = (chan29 - offset) * scale the_lon = geom_h5['MODIS_Swath_Type_GEO']['Geolocation Fields'][ 'Longitude'][...] the_lat = geom_h5['MODIS_Swath_Type_GEO']['Geolocation Fields'][ 'Latitude'][...] c31_bright = planckInvert(11.03, chan31) c29_bright = planckInvert(8.55, chan29) with h5py.File(cloud_mask) as cm_h5: maskout = cm_h5['cloudmask'][...] landout = cm_h5['landmask'][...] with h5py.File(mod06_file) as m06_h5: phase = m06_h5['mod06']['Data Fields']['Cloud_Phase_Infrared_1km'][...] phase = phase.astype(np.int32) return c31_bright, c29_bright, maskout, landout, phase, the_lon, the_lat
def get_channels(l1b_file,geom_file,cloud_mask,mod06_file): with h5py.File(geom_file) as geom_h5,h5py.File(l1b_file) as l1b_h5: #channel31 is emissive channel 10 #pdb.set_trace() band_names=text_(l1b_h5['MODIS_SWATH_Type_L1B']['Data Fields']['EV_1KM_Emissive'].attrs['band_names']) band_names=band_names.split(',') index31=band_names.index('31') chan31=l1b_h5['MODIS_SWATH_Type_L1B']['Data Fields']['EV_1KM_Emissive'][index31,:,:] scale=l1b_h5['MODIS_SWATH_Type_L1B']['Data Fields']['EV_1KM_Emissive'].attrs['radiance_scales'][index31] offset=l1b_h5['MODIS_SWATH_Type_L1B']['Data Fields']['EV_1KM_Emissive'].attrs['radiance_offsets'][index31] chan31=(chan31 - offset)*scale index1=0 #channel 1 is first 250 meter reflective channel reflective=l1b_h5['MODIS_SWATH_Type_L1B']['Data Fields']['EV_250_Aggr1km_RefSB'][0,:,:] scale=l1b_h5['MODIS_SWATH_Type_L1B']['Data Fields']['EV_250_Aggr1km_RefSB'].attrs['reflectance_scales'] offset=l1b_h5['MODIS_SWATH_Type_L1B']['Data Fields']['EV_250_Aggr1km_RefSB'].attrs['reflectance_offsets'] chan1=(reflective - offset[0])*scale[0] index29=band_names.index('29') chan29=l1b_h5['MODIS_SWATH_Type_L1B']['Data Fields']['EV_1KM_Emissive'][index29,:,:] scale=l1b_h5['MODIS_SWATH_Type_L1B']['Data Fields']['EV_1KM_Emissive'].attrs['radiance_scales'][index29] offset=l1b_h5['MODIS_SWATH_Type_L1B']['Data Fields']['EV_1KM_Emissive'].attrs['radiance_offsets'][index29] chan29=(chan29 - offset)*scale the_lon=geom_h5['MODIS_Swath_Type_GEO']['Geolocation Fields']['Longitude'][...] the_lat=geom_h5['MODIS_Swath_Type_GEO']['Geolocation Fields']['Latitude'][...] c31_bright=planckInvert(11.03,chan31) c29_bright=planckInvert(8.55,chan29) with h5py.File(cloud_mask) as cm_h5: maskout=cm_h5['cloudmask'][...] landout=cm_h5['landmask'][...] with h5py.File(mod06_file) as m06_h5: phase=m06_h5['mod06']['Data Fields']['Cloud_Phase_Infrared_1km'][...] phase=phase.astype(np.int32) return c31_bright,c29_bright,maskout,landout,phase,the_lon,the_lat
#channel31 is emissive channel 10 index31=10 chan31=l1b_file['MODIS_SWATH_Type_L1B']['Data Fields']['EV_1KM_Emissive'][index31,:,:] scale=l1b_file['MODIS_SWATH_Type_L1B']['Data Fields']['EV_1KM_Emissive'].attrs['radiance_scales'][index31] offset=l1b_file['MODIS_SWATH_Type_L1B']['Data Fields']['EV_1KM_Emissive'].attrs['radiance_offsets'][index31] chan31=(chan31 - offset)*scale #channel29 is emissive channel 8 index29=8 chan29=l1b_file['MODIS_SWATH_Type_L1B']['Data Fields']['EV_1KM_Emissive'][index29,:,:] scale=l1b_file['MODIS_SWATH_Type_L1B']['Data Fields']['EV_1KM_Emissive'].attrs['radiance_scales'][index29] offset=l1b_file['MODIS_SWATH_Type_L1B']['Data Fields']['EV_1KM_Emissive'].attrs['radiance_offsets'][index29] chan29=(chan29 - offset)*scale the_lon=geom_file['MODIS_Swath_Type_GEO']['Geolocation Fields']['Longitude'][...] the_lat=geom_file['MODIS_Swath_Type_GEO']['Geolocation Fields']['Latitude'][...] ch31_bright=planckInvert(11.03,chan31) ch29_bright=planckInvert(8.6,chan29) lim= None the_slice=slice(0,lim) small_lons=the_lon[the_slice,:] small_lats=the_lat[the_slice,:] chan31_small=chan31[the_slice,:] chan29_small=chan29[the_slice,:] lcc_values,lon_res,lat_res=find_corners(small_lons,small_lats) lcc_values['fix_aspect']=True lcc_values['resolution']='c' lcc_values['projection']='lcc' with h5py.File(mod06_file) as m06_h5:
with h5py.File(geom_file) as geom_file, h5py.File(l1b_file) as l1b_file: #channel31 is emissive channel 10 index31 = 10 chan31 = l1b_file['MODIS_SWATH_Type_L1B']['Data Fields'][ 'EV_1KM_Emissive'][index31, :, :] scale = l1b_file['MODIS_SWATH_Type_L1B']['Data Fields'][ 'EV_1KM_Emissive'].attrs['radiance_scales'][index31] offset = l1b_file['MODIS_SWATH_Type_L1B']['Data Fields'][ 'EV_1KM_Emissive'].attrs['radiance_offsets'][index31] chan31 = (chan31 - offset) * scale the_lon = geom_file['MODIS_Swath_Type_GEO']['Geolocation Fields'][ 'Longitude'][...] the_lat = geom_file['MODIS_Swath_Type_GEO']['Geolocation Fields'][ 'Latitude'][...] ch31_bright = planckInvert(11.03, chan31) lim = None the_slice = slice(0, lim) small_lons = the_lon[the_slice, :] small_lats = the_lat[the_slice, :] chan31_small = chan31[the_slice, :] lcc_values, lon_res, lat_res = find_corners(small_lons, small_lats) lcc_values['fix_aspect'] = True lcc_values['resolution'] = 'c' lcc_values['projection'] = 'lcc' plt.close('all') missing_val = -999.
#channel31 is emissive channel 10 index31=10 chan31=l1b_file['MODIS_SWATH_Type_L1B']['Data Fields']['EV_1KM_Emissive'][index31,:,:] scale=l1b_file['MODIS_SWATH_Type_L1B']['Data Fields']['EV_1KM_Emissive'].attrs['radiance_scales'][index31] offset=l1b_file['MODIS_SWATH_Type_L1B']['Data Fields']['EV_1KM_Emissive'].attrs['radiance_offsets'][index31] chan31=(chan31 - offset)*scale #channel32 is emissive channel 8 index32=11 chan32=l1b_file['MODIS_SWATH_Type_L1B']['Data Fields']['EV_1KM_Emissive'][index32,:,:] scale=l1b_file['MODIS_SWATH_Type_L1B']['Data Fields']['EV_1KM_Emissive'].attrs['radiance_scales'][index32] offset=l1b_file['MODIS_SWATH_Type_L1B']['Data Fields']['EV_1KM_Emissive'].attrs['radiance_offsets'][index32] chan32=(chan32 - offset)*scale the_lon=geom_file['MODIS_Swath_Type_GEO']['Geolocation Fields']['Longitude'][...] the_lat=geom_file['MODIS_Swath_Type_GEO']['Geolocation Fields']['Latitude'][...] ch31_bright=planckInvert(11.03,chan31) ch32_bright=planckInvert(12.02,chan32) lim= None the_slice=slice(0,lim) small_lons=the_lon[the_slice,:] small_lats=the_lat[the_slice,:] chan31_small=chan31[the_slice,:] chan32_small=chan32[the_slice,:] lcc_values,lon_res,lat_res=find_corners(small_lons,small_lats) lcc_values['fix_aspect']=True lcc_values['resolution']='c' lcc_values['projection']='lcc' plt.close('all')
print "looping: " Temp,press,rho,height=hydrostat(T_surf,p_surf,the_lapse_rate,delta_z,num_levels) # # I played around with the magnitude of k_lambda until the weighting functions # peaked at a range of heights # k_lambda=np.array([0.002,0.003,0.006,0.010,0.012,0.016,0.020])*5. wavel_k_tup=zip(wavelengths,k_lambda) rad_dict=OrderedDict() bright_dict=OrderedDict() for wavel,k_lambda in wavel_k_tup: tau=find_tau(r_gas,k_lambda,rho,height) #convert wavel to meters rad_value=top_radiance(tau,Temp,height,T_surf,wavel*1.e-6,k_lambda) rad_dict[wavel]=rad_value bright_dict[wavel]=planckInvert(wavel*1.e-6,rad_value) rad_profs.append(rad_dict) bright_profs.append(bright_dict) plt.close('all') fig1,axis1=plt.subplots(1,1) for index,the_profile in enumerate(rad_profs): wavelengths=the_profile.keys() radiances=np.array(the_profile.values()) radiances=radiances/radiances.mean() # # convert dT_dz to K/km # axis1.plot(wavelengths,radiances,label=str(dT_dz[index]*1.e3)) axis1.set_title('normalized radiances at top of atmosphere for {} values of dT/dz (K/km)'.format(len(dT_dz))) axis1.set_ylabel('normalized radiances (no units)')
chan1=chan1[hit] chan31=chan31[hit] lim= None the_slice=slice(0,lim) with h5py.File(mask_fileA) as cm_h5A,h5py.File(mask_fileB) as cm_h5B: maskoutA=cm_h5A['cloudmask'][the_slice,:] landoutA=cm_h5A['landmask'][the_slice,:] maskoutB=cm_h5B['cloudmask'][the_slice,:] landoutB=cm_h5B['landmask'][the_slice,:] landout=np.concatenate([landoutA.ravel(),landoutB.ravel()]) maskout=np.concatenate([maskoutA.ravel(),maskoutB.ravel()]) landout=landout[hit] maskout=maskout[hit] c31_bright=planckInvert(11.03,chan31) lcc_values,lon_res,lat_res=find_corners(the_lons,the_lats) lcc_values['fix_aspect']=True lcc_values['lat_0']=49.5 lcc_values['lat_1']=47.5 lcc_values['lat_2']=51 lcc_values['llcrnrlat']=48. lcc_values['urcrnrlat']=50.5 lcc_values['llcrnrlon']= -126.5 lcc_values['urcrnrlon']= -121.5 ## lcc_values['width']=500.e3 ## lcc_values['height']=200.e3 lcc_values['resolution']='h' lcc_values['projection']='lcc'
chan31 = (chan31 - offset) * scale #channel22 is emissive channel 2 index22 = 11 chan22 = l1b_file['MODIS_SWATH_Type_L1B']['Data Fields'][ 'EV_1KM_Emissive'][index22, :, :] scale = l1b_file['MODIS_SWATH_Type_L1B']['Data Fields'][ 'EV_1KM_Emissive'].attrs['radiance_scales'][index22] offset = l1b_file['MODIS_SWATH_Type_L1B']['Data Fields'][ 'EV_1KM_Emissive'].attrs['radiance_offsets'][index22] chan22 = (chan22 - offset) * scale the_lon = geom_file['MODIS_Swath_Type_GEO']['Geolocation Fields'][ 'Longitude'][...] the_lat = geom_file['MODIS_Swath_Type_GEO']['Geolocation Fields'][ 'Latitude'][...] ch31_bright = planckInvert(11.03, chan31) ch22_bright = planckInvert(3.96, chan22) max22bright = np.nanmax(ch22_bright) min22bright = np.nanmax(ch22_bright) lim = None the_slice = slice(0, lim) small_lons = the_lon[the_slice, :] small_lats = the_lat[the_slice, :] chan31_small = chan31[the_slice, :] chan22_small = chan22[the_slice, :] lcc_values, lon_res, lat_res = find_corners(small_lons, small_lats) lcc_values['fix_aspect'] = True lcc_values['resolution'] = 'c'
reflective=l1b_file['MODIS_SWATH_Type_L1B']['Data Fields']['EV_250_Aggr1km_RefSB'][0,:,:] scale=l1b_file['MODIS_SWATH_Type_L1B']['Data Fields']['EV_250_Aggr1km_RefSB'].attrs['reflectance_scales'] offset=l1b_file['MODIS_SWATH_Type_L1B']['Data Fields']['EV_250_Aggr1km_RefSB'].attrs['reflectance_offsets'] chan1=(reflective - offset[0])*scale[0] index29=band_names.index('29') chan29=l1b_file['MODIS_SWATH_Type_L1B']['Data Fields']['EV_1KM_Emissive'][index29,:,:] scale=l1b_file['MODIS_SWATH_Type_L1B']['Data Fields']['EV_1KM_Emissive'].attrs['radiance_scales'][index29] offset=l1b_file['MODIS_SWATH_Type_L1B']['Data Fields']['EV_1KM_Emissive'].attrs['radiance_offsets'][index29] chan29=(chan29 - offset)*scale the_lon=geom_file['MODIS_Swath_Type_GEO']['Geolocation Fields']['Longitude'][...] the_lat=geom_file['MODIS_Swath_Type_GEO']['Geolocation Fields']['Latitude'][...] c31_bright=planckInvert(11.03,chan31) c29_bright=planckInvert(8.55,chan29) lim= None the_slice=slice(0,lim) small_lons=the_lon[the_slice,:] small_lats=the_lat[the_slice,:] chan31_small=chan31[the_slice,:] chan1_small=chan1[the_slice,:] cloud_mask,=glob.glob(mask_file) with h5py.File(cloud_mask) as cm_h5: maskout=cm_h5['cloudmask'][the_slice,:] landout=cm_h5['landmask'][the_slice,:] with h5py.File(mod06_file) as m06_h5: phase=m06_h5['mod06']['Data Fields']['Cloud_Phase_Infrared_1km'][the_slice,:]