def trigger_radio_processing(product):

    global PROCESSING_STATUS
    PROCESSING_STATUS = 'PASSED'  #to be pass in this interface (as parameter)

    infra = main_infra.mainInfra()
    stat_table = []
    stat_table_sort = []
    roi_list = [rec for rec in glob.glob(os.path.join(product, 'ROI*'))]
    for roi in roi_list:
        log.infog(' -- Processing of ' + roi + '  : ')
        mtl = metadata_extraction.LandsatMTL(roi)
        mtl.set_test_site_information(
            infra.configuration_site_description_file)
        log.info(' -- Convert to RAD / TOA')
        mtl.display_mtl_info()
        r = rad.radiometric_calibration(product, mtl)
        log.info(' -- Extract / store statistics : ')

        image_file_list = mtl.rhotoa_image_list
        output_txt_file = RADIOMETRIC_STABILITY_RHO_RESULTS

        #infra.result_radiometricStability
        roi_id = os.path.basename(roi)
        gainList = [str(rec) for rec in mtl.rescaling_gain]
        #print mtl.band_sequence
        for image_file in image_file_list:
            a = None
            a = Image.Statistics(image_file, roi_id)
            r = a.get_statistics()
            stat_table.append(r)

    stat_table_sort = sorted(stat_table,
                             key=lambda x: x[1])  #sort by  band_number
    infra.update_text_file(mtl, stat_table_sort)
예제 #2
0
def trigger_productSubview(product):

    global PROCESSING_STATUS
    PROCESSING_STATUS = 'PASSED'
    infra = main_infra.mainInfra()
    #infra.checkDirectoryPresence()
    mtl = metadata_extraction.LandsatMTL(product)
    if mtl.mtl_file_name == '':
        print ' -- Missing MTL File'
        return

    if mtl.missing_image_in_list == 'Missing_image':
        print ' -- Missing Image files'
        return

    mtl.set_test_site_information(infra.configuration_site_description_file)
    if str(len(mtl.test_site)) == '0':
        print ' -- No Test site Found'
        return

    print " -- site " + mtl.test_site[0]

    mtl.display_mtl_info()

    infra.makeProductSubview(mtl)
    return True
예제 #3
0
def trigger_radio_processing():
    infra = main_infra.mainInfra()
    product_id = 'LC81810402013218LGN00'
    #Hypothese : nous sommes dans le repertoire stabilityMonitoring
    interest = 'stabilityMonitoring'
    product_list = [
        rec for rec in glob.glob(
            os.path.join(infra.processing_location, interest, 'input',
                         product_id, 'ROI*'))
    ]
    for product in product_list:
        log.infog(' -- Processing of ' + product + '  : ')
        mtl = metadata_extraction.LandsatMTL(product)
        log.info(' -- Convert to RAD / TOA')
        #r=rad.radiometric_calibration(product,mtl)
        log.info(' -- Extract / store statistics ')
        mtl.update_image_file_list()
        #mtl.display_mtl_info()
        image_file_list = mtl.rhotoa_image_list
        output_txt_file = infra.result_radiometricStability
        roi_id = os.path.basename(product)
        gainList = [str(rec) for rec in mtl.rescaling_gain]
        #print mtl.band_sequence
        extract_reflectance_in_roy.reduction_on_roi(mtl, image_file_list,
                                                    output_txt_file, roi_id)
        print '\n'
        print output_txt_file
        #Move Product From input to done
    input_product = os.path.join(infra.processing_location, interest, 'input',
                                 product_id)
    output_rep = os.path.join(infra.processing_location, interest, 'done')
    cmd = ' '.join(['mv', input_product, output_rep])
    os.system(cmd)
예제 #4
0
def trigger_productSubview():

    infra = main_infra.mainInfra()
    infra.checkDirectoryPresence()
    product_id = 'LC81810402013218LGN00'
    product = os.path.join(infra.input_data_location, product_id)
    mtl = metadata_extraction.LandsatMTL(product)
    mtl.get_test_site_information(infra.configuration_site_description_file)
    infra.makeProductSubview(mtl)
예제 #5
0
def test_thresholdImage():
    infra = main_infra.mainInfra()
    infra.checkDirectoryPresence()
    #trigger_productSubview()

    #trigger_radio_processing()
    cor_product = os.path.join(
        infra.processing_location, 'interbandRegistration', 'wd_pan',
        'LC81960302017110MTI00_ROI_prism_roi_BD_REF8_BD_WORK10')

    land_sea_mask = os.path.join(infra.processing_location,
                                 'interbandRegistration', 'input',
                                 'LC81960302017110MTI00', 'ROI_prism_roi',
                                 'land_sea_mask.tif')
    cor_conf_image = os.path.join(
        cor_product, 'LC81960302017110MTI00_B10_dc-confidence.TIF')
    dst_file_name = os.path.join(
        cor_product, 'LC81960302017110MTI00_B10_dc-displacement.TIF')

    infra.threshold_confidence_image(land_sea_mask, cor_conf_image,
                                     dst_file_name)
    #threshold_displacement_image(self,cor_conf_image,d_image):
    dx_image = os.path.join(cor_product,
                            'LC81960302017110MTI00_B10_dx-displacement.TIF')
def trigger_directLocation_processing(product,interband):

   global PROCESSING_STATUS
   PROCESSING_STATUS='PASSED' #to be pass in this interface (as parameter)

   infra=main_infra.mainInfra()
   mtl = metadata_extraction.LandsatMTL(product)
   scene_id = mtl.landsat_scene_id

   mtl.set_test_site_information(infra.configuration_site_description_file)
   country_name=((mtl.test_site[0]).split())[0]
   site_name=((mtl.test_site[0]).split())[1]
   repo_ref=os.path.join(infra.reference_data_raster_file_location,country_name,site_name,'ROI');
#Access to assessment manager ? 
   band_list=assessmentManager_get_band_list(infra,mtl)   
   mtl=None
#http class : interface with web server 
   http = http_side.performance_report(product)

#-- MLAB output file initialisation
   file_label = interband.file_label
   band_type = interband.band_type

#-- Loop on all image roi, perform correlation and statistics


#LOOP OVER ROIs
   roi_list=[rec for rec in glob.glob(os.path.join(product,'ROI*'))]
   for roi in roi_list:
      roi_name=os.path.basename(roi).split('_')[1]
      print ' '
      print ' -------------------------'
      log.infog(' -- Processing of '+roi_name+'  : ')

      

      mtl = metadata_extraction.LandsatMTL(roi)
      mtl.set_test_site_information(infra.configuration_site_description_file)
      mtl.add_roi_name_information(roi_name)
      
#START Image Matching Loop
      wd_list = []
      interband.roi = roi
      for band_twin in band_combination[band_type]:

         interband.set_ref_channel(band_twin)
         ref_channel = interband.ref_channel
         work_channel = interband.work_channel
        

#Define the working directory        
         wd_name=mtl.landsat_scene_id+'_ROI_'+roi_name+'_BD_'+ref_channel

         productWorkingDirectory=os.path.join(infra.processing_location,interest,'wd',wd_name)

         ref_channel_reg = os.path.join(os.path.join(repo_ref,roi_name,'*B0'+ref_channel+'*.tiff'))
         work_channel_reg = os.path.join(os.path.join(product,'ROI_'+roi_name,'*B'+work_channel+'*.TIF'))

         if len(glob.glob(ref_channel_reg)) > 0 :
             interband.refImage = glob.glob(ref_channel_reg)[0]
             interband.refImageTrue = True
         else :
            log.err('Missing reference product ')
            return

         if len(glob.glob(work_channel_reg)) > 0 :
              interband.workImage = glob.glob(work_channel_reg)[0]
              interband.workImageTrue = True
         else :
            log.err('Missing one product as input ')
            log.err(work_channel_reg)
            return


 #CORREL
         log.infog(" -- Prepare Parameters")
         cor = correl_image(os.path.join(productWorkingDirectory,'grille.hdf'))

         log.infog(" -- Start Matching")
         
         productWorkingDirectory = image_matching(mtl,
                                                      infra,
                                                      interband,
                                                      cor)

         #productWorkingDirectory = '/home/saunier/DEV/LS08_ideas_cyclic_report__processing/PROCESSING/directLocation/wd/LC81980332017172MTI00_ROI_ibiza_BD_8'
         wd_list = (productWorkingDirectory)
         
         log.infog(" -- Processing of : "+productWorkingDirectory)

#         cor = correl_image(os.path.join(productWorkingDirectory,'grille.hdf'))
#GEOCODING
         log.infog(" -- Geocoded Medicis Results")
         inputImage = interband.workImage
         refimageName = interband.workImage  #?

#Size of input Full Image (correlation undersampled input images ...)
      
         src_filename = inputImage
         src_ds = gdal.Open(str(src_filename))
         image_width = src_ds.RasterXSize
         image_length = src_ds.RasterYSize
         src_ds = None

         cor.geocoded(inputImage,refimageName,productWorkingDirectory)
         if (cor.geocoded_valid) :
             dx = cor.dx
             dy = cor.dy
             dc = cor.dc
             mask =  cor.mask
         else :
            log.warning(" --  [ERROR ] No Correlation Results in ")          
            log.warning(" --  [ERROR ] No Correlation Results in ")          
            return
#FILTERING : IF MASK AVAILABLE - APPLIED
         log.infog(" -- Mask Confidence Image with land_sea mask \n")
         land_sea_mask  = os.path.join(product,roi,'land_sea_mask.tif') 
     
         if os.path.exists(land_sea_mask):
             log.infog(" --- Land Sea Mask Exist : "+land_sea_mask)
             input_image = dc
             mask = land_sea_mask
             log.infog(" --- Applied Land Sea Mask to confidence image")
             list_image = []
             list_image.append(input_image)
             im_st = im_p.image(list_image)
             im_st.maskImage(mask,productWorkingDirectory)
             log.info(" -- Create "+im_st.masked_image+' \n')
             cmd = ' '.join(['mv', im_st.masked_image,dc])
             os.system(cmd)
             im_st = None

#FILTERING : APPLIED CONFIDENCE THRESHOLD ON DC - can applied to DX,DY,DC
         list_image = []
         list_image.append(dc)
         im_st = im_p.image(list_image)
         im_st.histerysisThreshold(confidence,productWorkingDirectory)
         dc = im_st.masked_image
         dc_mask = im_st.mask_image #BINARY MASK
         im_st = None

#UPDATE DC / DC MASK WITH 3 SIGMA THRESHOLD ON DX , DY
         im_st = im_p.image([dc,dc_mask])

         n_value = 3.5          #SIGMA VALUE
         threshold = confidence     #CONFIDENCE VALUE - 
         im_st.sigma_threshold(dx,n_value,confidence)
         im_st.sigma_threshold(dy,n_value,confidence)
         dc = im_st.masked_image
         dc_mask = im_st.mask_image #BINARY MASK
         cmd = ' '.join(['mv', im_st.masked_image,cor.dc]) #Ecrase DC - original in "OLD"
         os.system(cmd) 
         im_st = None

#APPLIED DC BINARY MASK TO DX, DY
         mask = dc_mask
         list_image = []
         list_image.append(dx)
         im_st = im_p.image(list_image)
         im_st.maskImage(mask,productWorkingDirectory)
         log.info(" -- Create "+im_st.masked_image+' \n')
         dx = im_st.masked_image
         im_st = None

         list_image = []
         list_image.append(dy)
         im_st = im_p.image(list_image)
         im_st.maskImage(mask,productWorkingDirectory)
         log.info(" -- Create "+im_st.masked_image+' \n')
         dy = im_st.masked_image
         im_st = None

         log.infog(" -- Mask :"+dc_mask)
         log.infog(" -- DX   :"+dx)
         log.infog(" -- DY   :"+dy)
         log.infog(" -- DC   :"+dc+'\n')

#COMPUTE DX²+ DY² - RADIAL ERROR
         list_image = [dx,dy]
         
         dst_file_name = os.path.join(productWorkingDirectory,scene_id+
                                      '_B'+interband.ref_channel+
                                      '_B'+interband.work_channel+
                                      '_radialError_'+
                                       str(np.int(confidence*100))+'.tif',)
         im_st = im_p.image(list_image)
         if (im_st.computeRadialError(dst_file_name)):
            cor.radial_error = dst_file_name
            cor.radial_error_valid = True
         im_st = None

#STATISTICS DX

#STATISTICS DY

#STATISTICS DC

#--  QL Radial Error - Overlayed Image Band with B1 B2 B3 Image
#Rescale QL Radial Error to size of B1 , B2 , B3 
         list_image = [interband.workImage]
         im1 = cor.radial_error
         dst_filename = im1.replace('.tif','_rescale.tif')
         im_st = im_p.image(list_image)
         im_st.rescaleImage(im1,dst_filename)   
         cor.radial_error_rescaled = dst_filename

         im1 = dc_mask
         dst_filename = im1.replace('.TIF','_rescale.tif')

         im_st.rescaleImage(im1,dst_filename)   #Geometric Rescaling
         cor.dc_mask_rescaled = dst_filename

         im_st = None

#BURN TIF IMAGES WITH RADIAL ERRORS
         #Convert each image to 8 Bits
         list_image = []
	 list_image.append(glob.glob(os.path.join(product,roi,'*B8.TIF'))[0]) # QL Generation
	 list_image.append(glob.glob(os.path.join(product,roi,'*B8.TIF'))[0]) # QL Generation
	 list_image.append(glob.glob(os.path.join(product,roi,'*B8.TIF'))[0]) # QL Generation
         im_st = im_p.image(list_image)
         dst_repo = productWorkingDirectory
         output_list = im_st.byte_rescaling(dst_repo )
         im_st = None

 #Burn each one tif images
         list_image = output_list
         output_list = [] 

         for image in list_image:
              output_list.append(image.replace('.tif','_burn.tif'))

         im_st = im_p.image(list_image)
         im_filename = cor.radial_error_rescaled #Radial Error Value map to QL 
         mask_filename = cor.dc_mask_rescaled    #DC Mask to select pixel
         im_st.burn_image(output_list,im_filename,mask_filename)
         im_st = None

         #Create the quick look 
         image_data_list = output_list
         ql_name = os.path.join(productWorkingDirectory,scene_id+
                                      '_B'+interband.ref_channel+
                                      '_B'+interband.work_channel+
                                      '_Radial_Error_QL.jpg')
	  
	 outputdir =  productWorkingDirectory
	 quick_look_resolution = 30
	 im_st = im_p.image(image_data_list) # Create Object instance
	 im_st.createimageQuicklook(ql_name,outputdir,quick_look_resolution)

#-- MLAB Production

         #result file is matlab file (.mat)
         src_ds = gdal.Open(str(interband.refImage))
         pixelSpacing= (src_ds.GetGeoTransform())[1] #Pixel spacing of the orginal Image
         src_ds = None
        #-- Option 
        #createimageQuicklook(inputImage,productWorkingDirectory)
        #addDigitalElevationImage(inputImage,productWorkingDirectory,demReference)
         #-- End Option 

#   ext = '.mat'
#   result_mat_file= interband.get_output_filename(mtl,infra,ext)
#-- Summary Statistisque file_label - same level of mat file but
#   just list results in a CSV.
#   ext = '.txt'
#   result_sta_file= interband.get_output_filename(mtl,infra,ext)

   


         log.infog(" -- Update Multi Temporal MAT File  \n")




         metadataFile=mtl
#   Set Filename of ".mat" file
         filename = site_name+'_multiTemp.mat' 
         result_mat_file=os.path.join(infra.result_location,interest,filename)
         medicisDirectory=productWorkingDirectory


         #[NFO]       Mlab_run - attente des fichiers dx,dy,dc normés
         #            M=dir([obj.repName filesep '*_dx-displacement.TIF']); 
         #            M=dir([obj.repName filesep '*_dy-displacement.TIF']);            
         #            M=dir([obj.repName filesep '*_dc-confidence.TIF']);  

         Mlab_run(mtl,
                  result_mat_file,
                  productWorkingDirectory,
                  pixelSpacing)
         
         ##TEMPS MININIMUM A 30 BIEN ATTENDRE LA FIN DE TRAITEMENT
         print (' ')
         log.warn('TIME SLEEP ACTIVIATED - 30 s - Wait end of M LAB PROCESSING')
         log.warn('TIME SLEEP ACTIVIATED - 30 s - Important to let Completion')
         log.warn('TIME SLEEP ACTIVIATED - 30 s - of the mat file ')
         print (' ')
         time.sleep(30)


#--- 2. Repatriate BD2 BD3 BD4 Images
#--- 3. Open Images and Burn Values
#--- 4. Create QL

#-- CP to the HTTP
         src_directory = productWorkingDirectory
#-- Copy MLAB Results   (PNG) to repository
#-- Copy DC  mask image (PNG)to http repository
#-- Copy Radial Error  image (JPG)to http repository
         http.updateContent(productWorkingDirectory,interest,band_type)
#Generate A single stat/csv for all Report WD in this processing
         result_sta_file = os.path.join(productWorkingDirectory,'stat.txt')
         log.infog(" - [STA File] STA File : "+result_sta_file)     

#PARTIE EXPORT SUR HTTP A SEPARER DE CETTE FONCTION
         print ( ' ')
         log.infog(" - Populate HTTP \n")


#--  STA FILE :
         dst_file_name = ''.join([mtl.landsat_scene_id,'_','roi_',roi_name,'_multiTemp_',band_type,'.txt'])
         http.updateContentWith_FILE(result_sta_file,dst_file_name,interest,band_type)

   log.infog(" - CP Matlab File \n")
   
   http.updateWithDirectLocationMATFile(result_mat_file)

   input_product=product
   output_rep=os.path.join(product,'../../done')
   cmd = ' '.join(['mv',input_product,output_rep])
   log.info(' - [CMD     ] '+cmd)
   os.system(cmd)
   input_product=product
   output_rep=os.path.join(product,'../../done')
   cmd = ' '.join(['mv',input_product,output_rep])
   log.info(' - [CMD     ] '+cmd)
   os.system(cmd)



if __name__ == '__main__':

    band_type = 'pan' #MS OR PAN band_type to create specific WD.
                       #IF Directlocation the WD is 'WD'     
    interband = interband(band_type);

    if len(sys.argv) == 2 :
        infra=main_infra.mainInfra()
        infra.checkDirectoryPresence()
        interest='directLocation'
        product = sys.argv[1]
        log.info(" Processing of : "+product)
        mtl = metadata_extraction.LandsatMTL(product)
        dst_filename = os.path.join(product,'land_sea_mask.tif')
        if (mtl.bqa) :
            get_qa_land_sea_mask(mtl, dst_filename)
        #product = glob.glob(product)
        trigger_directLocation_processing(product,interb)


    else :

        infra=main_infra.mainInfra()
def trigger_interband_processing(product,interband):

#Recall Object
   infra=main_infra.mainInfra()
   mtl = metadata_extraction.LandsatMTL(product)
   scene_id = mtl.landsat_scene_id

   mtl.set_test_site_information(infra.configuration_site_description_file)
   country_name=((mtl.test_site[0]).split())[0]
   site_name=((mtl.test_site[0]).split())[1]
   repo_ref=os.path.join(infra.reference_data_raster_file_location,country_name,site_name,'ROI');
#Access to assessment manager ? 
   band_list=assessmentManager_get_band_list(infra,mtl)   
#   mtl=None ? cette commande
   roi_list=[rec for rec in glob.glob(os.path.join(product,'ROI*'))]
#http class : interface with web server 
   http = http_side.performance_report(product)

   band_type = interband.band_type
   interband.set_main_wd(infra,band_type)

#-- MLAB output file initialisation
   file_label = interband.file_label
   ext = '.mat'
   result_mat_file= interband.get_output_filename(mtl,infra,ext)

#-- Summary Statistisque file_label - same level of mat file but
#   just list results in a CSV.
   ext = '.txt'
   result_sta_file= interband.get_output_filename(mtl,infra,ext)

   

#-- Loop on all image roi, perform correlation and statistics
   for roi in roi_list:
      interband.roi = roi
      roi_name=os.path.basename(roi).split('_')[1]
      print ' '
      print ' -------------------------'
      log.infog(' -- Processing of '+roi_name+'  : ')
      mtl = metadata_extraction.LandsatMTL(roi)
      mtl.set_test_site_information(infra.configuration_site_description_file)
      mtl.add_roi_name_information(roi_name)

#START Image Matching Loop
      wd_list = []
      for band_twin in band_combination[band_type]:

         interband.set_ref_channel(band_twin)
         test1=interband.search_image_twin(product)
         if test1 :
	     if (interband.ref_channel == '8') : #Et mission Landsat alors rescaling a 30 m
                 if  interband.ref_pixel_size == 15 :
		      log.infog(' -- Input Image scale is '+str(interband.ref_pixel_size)+' m --')
		      log.infog(' -- Input Image is rescaled '+str(interband.work_pixel_size)+' m --')
		      px_size = str(interband.work_pixel_size)
		      i_file = interband.refImage
		      o_file = interband.refImage.replace('B8.TIF','B8_30.TIF')
		      if not os.path.exists(o_file) : 
                          cmd = ' '.join(['gdalwarp -tr ', px_size,px_size, i_file, o_file])                 
                          os.system(cmd)
                      interband.refImage = o_file
             src_ds = None


             band_type = interband.band_type
             roi = interband.roi
             ref_channel = interband.ref_channel
             work_channel = interband.work_channel
             wd_name = (mtl.landsat_scene_id+'_'+os.path.basename(roi)+'_BD_REF'+ref_channel+'_BD_WORK'+work_channel)
             productWorkingDirectory=os.path.join(infra.processing_location,interest,'wd_'+band_type,wd_name)
 
             cor = correl_image(os.path.join(productWorkingDirectory,'grille.hdf'))
             print cor.grille
             print interband.refImage
             productWorkingDirectory = image_matching(mtl,
                                                      infra,
                                                      interband,
                                                      cor)
         wd_list.append(productWorkingDirectory)
         cor = correl_image(os.path.join(productWorkingDirectory,'grille.hdf'))



#GEOCODING
         log.infog(" -- Geocoded Medicis Results")
         inputImage = interband.workImage
         refimageName = interband.workImage  #?

#Size of input Full Image (correlation undersampled input images ...)
      
         src_filename = inputImage
         src_ds = gdal.Open(str(src_filename))
         image_width = src_ds.RasterXSize
         image_length = src_ds.RasterYSize
         src_ds = None

         cor.geocoded(inputImage,refimageName,productWorkingDirectory)
         if (cor.geocoded_valid) :
             dx = cor.dx
             dy = cor.dy
             dc = cor.dc
             mask =  cor.mask
         else :
            log.warning(" --  [ERROR ] No Correlation Results in ")          
            log.warning(" --  [ERROR ] No Correlation Results in ")          
            return


#FILTERING : IF MASK AVAILABLE - APPLIED
         log.infog(" -- Mask Confidence Image with land_sea mask \n")
         land_sea_mask  = os.path.join(product,roi,'land_sea_mask.tif') 
     
         if os.path.exists(land_sea_mask):
             log.infog(" --- Land Sea Mask Exist : "+land_sea_mask)
             input_image = dc
             mask = land_sea_mask
             log.infog(" --- Applied Land Sea Mask to confidence image")
             list_image = []
             list_image.append(input_image)
             im_st = im_p.image(list_image)
             im_st.maskImage(mask,productWorkingDirectory)
             log.info(" -- Create "+im_st.masked_image+' \n')
             cmd = ' '.join(['mv', im_st.masked_image,dc])
             os.system(cmd)
             im_st = None


#FILTERING : APPLIED CONFIDENCE THRESHOLD ON DC - can applied to DX,DY,DC
         list_image = []
         list_image.append(dc)
         im_st = im_p.image(list_image)
         im_st.histerysisThreshold(confidence,productWorkingDirectory)
         dc = im_st.masked_image
         dc_mask = im_st.mask_image #BINARY MASK
         im_st = None

#UPDATE DC / DC MASK WITH 3 SIGMA THRESHOLD ON DX , DY
         im_st = im_p.image([dc,dc_mask])

         n_value = 3          #SIGMA VALUE
         threshold = confidence     #CONFIDENCE VALUE - 
         log.infog(" --- Applied Sigma Threshold to DX ")
         DX_proc_flag = im_st.sigma_threshold(dx,n_value,confidence)
         log.infog(" --- Applied Sigma Threshold to DY ")
         DY_proc_flag = im_st.sigma_threshold(dy,n_value,confidence)
         dc = im_st.masked_image
         dc_mask = im_st.mask_image #BINARY MASK
         cmd = ' '.join(['mv', im_st.masked_image,cor.dc]) #Ecrase DC - original in "OLD"
         os.system(cmd) 
         im_st = None

	 print "Exit Processing if cannot applied 3 sigma threshold "

         if ((not DX_proc_flag) or (not DY_proc_flag)) :
            log.err(" -- Correlation is NOT successfull")
	    log.err(" --             After 3 Sigma threshold ")
	    log.err(" --             There is no sufficient point above the confidence threshold ")
            log.err(" --             Processing Abort and record not added to the m lab structure ")
         
	    return
	


#APPLIED DC BINARY MASK TO DX, DY
         mask = dc_mask
         list_image = []
         list_image.append(dx)
         im_st = im_p.image(list_image)
         im_st.maskImage(mask,productWorkingDirectory)
         log.info(" -- Create "+im_st.masked_image+' \n')
         dx = im_st.masked_image
         im_st = None

         list_image = []
         list_image.append(dy)
         im_st = im_p.image(list_image)
         im_st.maskImage(mask,productWorkingDirectory)
         log.info(" -- Create "+im_st.masked_image+' \n')
         dy = im_st.masked_image
         im_st = None

         log.infog(" -- Mask :"+dc_mask)
         log.infog(" -- DX   :"+dx)
         log.infog(" -- DY   :"+dy)
         log.infog(" -- DC   :"+dc+'\n')

#COMPUTE DX²+ DY² - RADIAL ERROR
         list_image = [dx,dy]
         
         dst_file_name = os.path.join(productWorkingDirectory,scene_id+
                                      '_B'+interband.ref_channel+
                                      '_B'+interband.work_channel+
                                      '_radialError_'+
                                       str(np.int(confidence*100))+'.tif',)
         im_st = im_p.image(list_image)
         if (im_st.computeRadialError(dst_file_name)):
            cor.radial_error = dst_file_name
            cor.radial_error_valid = True
         im_st = None

#STATISTICS DX

#STATISTICS DY

#STATISTICS DC

#--  QL Radial Error - Overlayed Image Band with B1 B2 B3 Image
#Rescale QL Radial Error to size of B1 , B2 , B3 
         list_image = [interband.workImage]
         im1 = cor.radial_error
         dst_filename = im1.replace('.tif','_rescale.tif')
         im_st = im_p.image(list_image)
         im_st.rescaleImage(im1,dst_filename)   
         cor.radial_error_rescaled = dst_filename

         im1 = dc_mask
         dst_filename = im1.replace('.TIF','_rescale.tif')

         im_st.rescaleImage(im1,dst_filename)   #Geometric Rescaling
         cor.dc_mask_rescaled = dst_filename

         im_st = None

#BURN TIF IMAGES WITH RADIAL ERRORS
         #Convert each image to 8 Bits
         list_image = []
	 list_image.append(glob.glob(os.path.join(product,roi,'*B2.TIF'))[0]) # QL Generation
	 list_image.append(glob.glob(os.path.join(product,roi,'*B3.TIF'))[0]) # QL Generation
	 list_image.append(glob.glob(os.path.join(product,roi,'*B4.TIF'))[0]) # QL Generation
         im_st = im_p.image(list_image)
         dst_repo = productWorkingDirectory
         output_list = im_st.byte_rescaling(dst_repo )
         im_st = None

         #Burn each one tif images
         list_image = output_list
         output_list = []

         for image in list_image:
              output_list.append(image.replace('.tif','_burn.tif'))

         im_st = im_p.image(list_image)
         im_filename = cor.radial_error_rescaled #Radial Error Value map to QL 
         mask_filename = cor.dc_mask_rescaled    #DC Mask to select pixel
         im_st.burn_image(output_list,im_filename,mask_filename)
         im_st = None

         #Create the quick look 
         image_data_list = output_list
         ql_name = os.path.join(productWorkingDirectory,scene_id+
                                      '_B'+interband.ref_channel+
                                      '_B'+interband.work_channel+
                                      '_Radial_Error_QL.jpg')
	  
	 outputdir =  productWorkingDirectory
	 quick_look_resolution = 30
	 im_st = im_p.image(image_data_list) # Create Object instance
	 im_st.createimageQuicklook(ql_name,outputdir,quick_look_resolution)




#-- MLAB Production

         #result file is matlab file (.mat)

         pixelSpacing=interband.ref_pixel_size  #Pixel spacing of the orginal Image

         #[NFO]       Mlab_run - attente des fichiers dx,dy,dc normés
         #            M=dir([obj.repName filesep '*_dx-displacement.TIF']); 
         #            M=dir([obj.repName filesep '*_dy-displacement.TIF']);            
         #            M=dir([obj.repName filesep '*_dc-confidence.TIF']);  

         Mlab_run(mtl,
                  result_mat_file,
                  productWorkingDirectory,
                  pixelSpacing)
         
         ##TEMPS MININIMUM A 30 BIEN ATTENDRE LA FIN DE TRAITEMENT
         print (' ')
         log.warn('TIME SLEEP ACTIVIATED - 30 s - Wait end of M LAB PROCESSING')
         log.warn('TIME SLEEP ACTIVIATED - 30 s - Important to let Completion')
         log.warn('TIME SLEEP ACTIVIATED - 30 s - of the mat file ')
         print (' ')

         time.sleep(30)

#--- 2. Repatriate BD2 BD3 BD4 Images
#--- 3. Open Images and Burn Values
#--- 4. Create QL

#-- CP to the HTTP
         src_directory = productWorkingDirectory
#-- Copy MLAB Results   (PNG) to repository
#-- Copy DC  mask image (PNG)to http repository
#-- Copy Radial Error  image (JPG)to http repository

         http.updateContent(productWorkingDirectory,interest,band_type)

#Remove the hdf file as output from medicis
         hdf_grille = os.path.join(productWorkingDirectory,'grille.hdf')
         if os.path.exists(hdf_grille):
            cmd = ' '.join(['rm -f ',hdf_grille])
            os.system(cmd)

#[END] of processing the band twin LOOP
      log.infog(" - End Loop on WD LIST \n")

#Generate A single stat/csv for all Report WD in this processing
      log.infog(" - [STA File] Create STA File : "+result_sta_file)     
      create_statistics_report(wd_list,result_sta_file)

#PARTIE EXPORT SUR HTTP A SEPARER DE CETTE FONCTION


      print ( ' ')
      log.infog(" - Populate HTTP \n")

# POPULATE HTTP WITH ALL RESULTS :
#--  MAT FILE :
      dst_file_name = ''.join([mtl.landsat_scene_id,'_','roi_',roi_name,'_inter_',band_type,'.mat'])
      if not (http.updateContentWith_FILE(result_mat_file,dst_file_name,interest,band_type)):
#          log.info(" -- [MAT File] Copy From : "+result_mat_file)
#          log.info(" -- [MAT File] to   : "+dst_file_name)
#      else :
          log.err(" -- [ERROR   ] Input / Output MAT FILE Missing+'\n' ")

#--  STA FILE :
      dst_file_name = ''.join([mtl.landsat_scene_id,'_','roi_',roi_name,'_inter_',band_type,'.txt'])
      if not (http.updateContentWith_FILE(result_sta_file,dst_file_name,interest,band_type)):
#          log.info(" -- [MAT File] Copy From : "+result_sta_file)
#          log.info(" -- [MAT File] to   : "+dst_file_name)
#      else :
          log.err(" - [ERROR   ] Input / Output TXT-STA FILE Missing+'\n' ")


#--  QL
      listql=[]
      listql.append(glob.glob(os.path.join(product,roi,'*B2.TIF'))[0]) # QL Generation
      listql.append(glob.glob(os.path.join(product,roi,'*B3.TIF'))[0]) # QL Generation
      listql.append(glob.glob(os.path.join(product,roi,'*B4.TIF'))[0]) # QL Generation

      image_data_list = listql
      ql_file_name = ''.join([mtl.landsat_scene_id,'_','roi_',roi_name,'_bd234.jpg'])
      ql_name = os.path.join(interband.main_wd,ql_file_name)
      log.info(" -- [QL      ] Create ROI QL : "+ql_name)
      
      dst_dir = productWorkingDirectory
      quick_look_resolution = 30
      outputdir = interband.main_wd
      im_st = im_p.image(listql) # Create Object instance
      im_st.createimageQuicklook(ql_name,outputdir,quick_look_resolution)
      http.updateContentWitQL(infra,interest,band_type,ql_name)



      #End of processing each ROI
      log.infog(" - [PROC     ] End ")
예제 #9
0
def trigger_interband_processing_with_ms(product, interband):

    #Recall Object
    infra = main_infra.mainInfra()
    mtl = metadata_extraction.LandsatMTL(product)
    scene_id = mtl.landsat_scene_id

    mtl.set_test_site_information(infra.configuration_site_description_file)
    country_name = ((mtl.test_site[0]).split())[0]
    site_name = ((mtl.test_site[0]).split())[1]
    repo_ref = os.path.join(infra.reference_data_raster_file_location,
                            country_name, site_name, 'ROI')
    #Access to assessment manager ?
    band_list = assessmentManager_get_band_list(infra, mtl)
    #   mtl=None ? cette commande
    roi_list = [rec for rec in glob.glob(os.path.join(product, 'ROI*'))]
    #http class : interface with web server
    http = http_side.performance_report(product)

    band_type = interband.band_type
    interband.set_main_wd(infra, band_type)

    #-- MLAB output file initialisation
    file_label = interband.file_label
    ext = '.mat'
    result_mat_file = interband.get_output_filename(mtl, infra, ext)

    #-- Summary Statistisque file_label - same level of mat file but
    #   just list results in a CSV.
    ext = '.txt'
    result_sta_file = interband.get_output_filename(mtl, infra, ext)

    #-- Loop on all image roi, perform correlation and statistics
    for roi in roi_list:
        print 'roi ' + roi
        interband.roi = roi
        roi_name = os.path.basename(roi).split('_')[1]
        print ' '
        log.infog(' -------------------------')
        log.infog(' -- Processing of ' + roi_name + ' -- ')
        log.infog(' -------------------------')

        mtl = metadata_extraction.LandsatMTL(roi)
        mtl.set_test_site_information(
            infra.configuration_site_description_file)
        mtl.add_roi_name_information(roi_name)

        #START Image Matching Loop
        wd_list = []
        for band_twin in band_combination[band_type]:
            interband.set_ref_channel(band_twin)

            test1 = interband.search_image_twin(product)

            if (interband.ref_channel == '8'
                ):  #Et mission Landsat alors rescaling a 30 m

                if interband.ref_pixel_size == 15:
                    log.infog(' -- Input Image scale is ' +
                              str(interband.ref_pixel_size) + ' m --')
                    log.infog(' -- Input Image is rescaled ' +
                              str(interband.work_pixel_size) + ' m --')
                    px_size = str(interband.work_pixel_size)
                    i_file = interband.refImage
                    o_file = interband.refImage.replace('B8.TIF', 'B8_30.TIF')
                    if not os.path.exists(o_file):
                        cmd = ' '.join([
                            'gdalwarp -tr ', px_size, px_size, i_file, o_file
                        ])
                        os.system(cmd)
                    interband.refImage = o_file
                src_ds = None