# Path: cmt/mapclient_qt.py
# def centerMap(lng, lat, zoom):  # pylint: disable=g-bad-name
#     """Center the default map instance at the given lat, lon and zoom values."""
#     addEmptyGui()
#     map_instance.CenterMap(lng, lat, zoom)
# 
# def addToMap(self, eeobject, vis_params=None, name="", show=True):
#     '''Ads an EE object to the map'''
#         
#     # Flatten any lists to comma separated strings - needed for eeobject.getMapId() call below!
#     if vis_params:
#         vis_params = dict(vis_params)
#         for key in vis_params.keys():
#             item = vis_params.get(key)
#             if (isinstance(item, collections.Iterable) and (not isinstance(item, basestring))):
#                  vis_params[key] = ','.join([str(x) for x in item])
# 
#     def execute_thread(waiting_threads):
#         # get thread before starting
#         with self.thread_lock:
#             pass
#         result = eeobject.getMapId(vis_params)
#         for t in waiting_threads:
#             t.join()
#         with self.thread_lock:
#             self.executing_threads.pop(0)
#         return result
# 
#     with self.thread_lock:
#         self.executing_threads.append(cmt.util.miscUtilities.waitForEeResult(functools.partial(execute_thread, list(self.executing_threads)),
#                     lambda a : self.addOverlay(MakeTileManager(a), eeobject, name, show, vis_params)))


import logging
    import cmt.ee_authenticate
    import sys
    import os.path
    import cmt.ee_authenticate
import matplotlib
import os
import sys
import ee
import functools
import threading
import cmt.domain
import cmt.util.evaluation
import cmt.util.gui_util
from cmt.radar.flood_algorithms import *
from cmt.mapclient_qt import centerMap, addToMap
    # Get the domain XML file from the command line arguments
    if len(sys.argv) < 2:
        print 'Usage: detect_flood_radar.py domain.xml'
        sys.exit(0)
    
    cmt.ee_authenticate.initialize()
    
    # Fetch data set information
    domain = cmt.domain.Domain()
    domain.load_xml(sys.argv[1])
    
    # Display radar and ground truth
    cmt.util.gui_util.visualizeDomain(domain)
    
    waterMask = ee.Image("MODIS/MOD44W/MOD44W_005_2000_02_24").select(['water_mask'], ['b1'])
    addToMap(waterMask.mask(waterMask), {'min': 0, 'max': 1}, 'Permanent Water Mask', False)
    
    # print im.image.getDownloadUrl({'name' : 'sar', 'region':ee.Geometry.Rectangle(-91.23, 32.88, -91.02, 33.166).toGeoJSONString(), 'scale': 6.174})
    
    # For each of the algorithms
    for a in range(len(ALGORITHMS)):
        #try:
        # Run the algorithm on the data and get the results
        (alg, result) = detect_flood(domain, ALGORITHMS[a])

        # Needed for certain images which did not mask properly from maps engine
        # result = result.mask(domain.get_radar().image.reduce(ee.Reducer.allNonZero()))

        # Get a color pre-associated with the algorithm, then draw it on the map
        color = get_algorithm_color(ALGORITHMS[a])

# Path: cmt/mapclient_qt.py
# def centerMap(lng, lat, zoom):  # pylint: disable=g-bad-name
#     """Center the default map instance at the given lat, lon and zoom values."""
#     addEmptyGui()
#     map_instance.CenterMap(lng, lat, zoom)
# 
# def addToMap(self, eeobject, vis_params=None, name="", show=True):
#     '''Ads an EE object to the map'''
#         
#     # Flatten any lists to comma separated strings - needed for eeobject.getMapId() call below!
#     if vis_params:
#         vis_params = dict(vis_params)
#         for key in vis_params.keys():
#             item = vis_params.get(key)
#             if (isinstance(item, collections.Iterable) and (not isinstance(item, basestring))):
#                  vis_params[key] = ','.join([str(x) for x in item])
# 
#     def execute_thread(waiting_threads):
#         # get thread before starting
#         with self.thread_lock:
#             pass
#         result = eeobject.getMapId(vis_params)
#         for t in waiting_threads:
#             t.join()
#         with self.thread_lock:
#             self.executing_threads.pop(0)
#         return result
# 
#     with self.thread_lock:
#         self.executing_threads.append(cmt.util.miscUtilities.waitForEeResult(functools.partial(execute_thread, list(self.executing_threads)),
#                     lambda a : self.addOverlay(MakeTileManager(a), eeobject, name, show, vis_params)))


# Path: bin/detect_flood_radar.py
import logging
    import cmt.ee_authenticate
    import sys
    import os.path
    import cmt.ee_authenticate
import matplotlib
import os
import sys
import ee
import functools
import threading
import cmt.domain
import cmt.util.evaluation
import cmt.util.gui_util
from cmt.radar.flood_algorithms import *
from cmt.mapclient_qt import centerMap, addToMap

    # Get the domain XML file from the command line arguments
    if len(sys.argv) < 2:
        print 'Usage: detect_flood_radar.py domain.xml'
        sys.exit(0)
    
    cmt.ee_authenticate.initialize()
    
    # Fetch data set information
    domain = cmt.domain.Domain()
    domain.load_xml(sys.argv[1])
    
    # Display radar and ground truth
    cmt.util.gui_util.visualizeDomain(domain)
    
    waterMask = ee.Image("MODIS/MOD44W/MOD44W_005_2000_02_24").select(['water_mask'], ['b1'])
    addToMap(waterMask.mask(waterMask), {'min': 0, 'max': 1}, 'Permanent Water Mask', False)
    
    # print im.image.getDownloadUrl({'name' : 'sar', 'region':ee.Geometry.Rectangle(-91.23, 32.88, -91.02, 33.166).toGeoJSONString(), 'scale': 6.174})
    
    # For each of the algorithms
    for a in range(len(ALGORITHMS)):
        #try:
        # Run the algorithm on the data and get the results
        (alg, result) = detect_flood(domain, ALGORITHMS[a])

        # Needed for certain images which did not mask properly from maps engine
        # result = result.mask(domain.get_radar().image.reduce(ee.Reducer.allNonZero()))

        # Get a color pre-associated with the algorithm, then draw it on the map
        color = get_algorithm_color(ALGORITHMS[a])

        addToMap(result.mask(result), {'min': 0, 'max': 1, 'opacity': 0.5, 'palette': '000000, ' + color},