def _authorize(self, params): auth = text_(base64.b64encode(bytes_("%s:%s" % (self.client_id, self.api_key)))) headers = {"Authorization": "Basic %s" % auth} res = self._session.post("%s/token" % self._oauth_endpoint, params=params, headers=headers) if res.status_code != 200: raise APIException("Got unexpected status code from API: %i" % res.status_code) return res.json()
def _authorize(self, params): auth = text_( base64.b64encode(bytes_("%s:%s" % (self.client_id, self.api_key)))) headers = {"Authorization": "Basic %s" % auth} res = self._session.post("%s/token" % self._oauth_endpoint, params=params, headers=headers) if res.status_code != 200: raise APIException("Got unexpected status code from API: %i" % res.status_code) return res.json()
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 _authorize(self, params): auth = text_( base64.b64encode(bytes_("%s:%s" % (self.client_id, self.api_key)))) headers = {"Authorization": "Basic %s" % auth} try: res = self._session.post("%s/token" % self._oauth_endpoint, params=params, headers=headers, timeout=APIConnection.TIMEOUT) except requests.exceptions.RequestException: raise APIException("No response from server") if res.status_code != 200: raise APIException("Got unexpected status code from API: %i" % res.status_code) return res.json()
def _authorize(self, params): auth = text_(base64.b64encode(bytes_("%s:%s" % (self.client_id, self.api_key)))) headers = {"Authorization": "Basic %s" % auth} try: res = self._session.post( "%s/token" % self._oauth_endpoint, params=params, headers=headers, timeout=APIConnection.TIMEOUT ) except requests.exceptions.RequestException: raise APIException("No response from server") if res.status_code != 200: raise APIException("Got unexpected status code from API: %i" % res.status_code) return res.json()
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 band_names=l1b_h5['MODIS_SWATH_Type_L1B']['Data Fields']['EV_1KM_Emissive'].attrs['band_names'] try: band_names_ascii=band_names band_names_list=band_names.split(',') index31=band_names_list.index('31') print('success: type of band_names: {} -- value of index31: {}'.format(type(band_names),index31)) except TypeError as ex: ex_type, ex_val, tb = sys.exc_info() print('bummer: ',ex_val) print('\nhere is the traceback:\n') traceback.print_tb(tb) print("python3 reads band_names as bytes, won't split on comma") if is_py3: print('\nTry this again, decoding the byte string assuming an ascii encoding') band_names_ascii=band_names.decode('ascii','strict') print('\nbandnames was {}, now it is {}'.format(type(band_names),type(band_names_ascii))) band_names_list=band_names_ascii.split(',') index31=band_names_list.index('31') print('success: type of band_names: {} -- value of index31: {}\n\n'.format(type(band_names),index31)) print('\nFinally -- show how the text_ helper handles both python2 and python3\n') band_names=text_(l1b_h5['MODIS_SWATH_Type_L1B']['Data Fields']['EV_1KM_Emissive'].attrs['band_names']) band_names_list=band_names_ascii.split(',') index31=band_names_list.index('31') print('success: type of band_names: {} -- value of index31: {}\n\n'.format(type(band_names),index31))
keys=['l1b_file', 'geom_file', 'mask_file', 'm06_file'] l1b_file,geom_file,mask_file,mod06_file=\ [name_dict[key] for key in keys] plot_dir='plots' try: os.makedirs(plot_dir) except OSError as e: if e.errno == errno.EEXIST: pass #not a problem if file exists with h5py.File(geom_file) as geom_file,h5py.File(l1b_file) as l1b_file: #channel31 is emissive channel 10 band_names=text_(l1b_file['MODIS_SWATH_Type_L1B']['Data Fields']['EV_1KM_Emissive'].attrs['band_names']) band_names=band_names.split(',') index31=band_names.index('31') 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 index1=0 #channel 1 is first 250 meter reflective channel 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]