# 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 sys
import os
import ee
import functools
import threading
import cmt.domain
import cmt.util.evaluation
import cmt.util.gui_util
from cmt.modis.flood_algorithms import *
from cmt.mapclient_qt import centerMap, addToMap
  # Fetch data set information
  domain = cmt.domain.Domain()
  domain.load_xml(sys.argv[1])
  
  # Display the Landsat and MODIS data for the data set
  cmt.util.gui_util.visualizeDomain(domain)
  
  #
  # import cmt.modis.adaboost
  # cmt.modis.adaboost.adaboost_learn()         # Adaboost training
  # #cmt.modis.adaboost.adaboost_dem_learn(None) # Adaboost DEM stats collection
  # raise Exception('DEBUG')
  
  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)
  
  # For each of the algorithms
  for a in range(len(ALGORITHMS)):
      # Run the algorithm on the data and get the results
      try:
          (alg, result) = detect_flood(domain, ALGORITHMS[a])
          if result is None:
              continue
  
          # These lines are needed for certain data sets which EE is not properly masking!!!
          # result = result.mask(domain.skybox_nir.image.reduce(ee.Reducer.allNonZero()))
          # result = result.mask(domain.skybox.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_modis.py
import logging
    import cmt.ee_authenticate
    import sys
    import os.path
    import cmt.ee_authenticate
import matplotlib
import sys
import os
import ee
import functools
import threading
import cmt.domain
import cmt.util.evaluation
import cmt.util.gui_util
from cmt.modis.flood_algorithms import *
from cmt.mapclient_qt import centerMap, addToMap

  # Fetch data set information
  domain = cmt.domain.Domain()
  domain.load_xml(sys.argv[1])
  
  # Display the Landsat and MODIS data for the data set
  cmt.util.gui_util.visualizeDomain(domain)
  
  #
  # import cmt.modis.adaboost
  # cmt.modis.adaboost.adaboost_learn()         # Adaboost training
  # #cmt.modis.adaboost.adaboost_dem_learn(None) # Adaboost DEM stats collection
  # raise Exception('DEBUG')
  
  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)
  
  # For each of the algorithms
  for a in range(len(ALGORITHMS)):
      # Run the algorithm on the data and get the results
      try:
          (alg, result) = detect_flood(domain, ALGORITHMS[a])
          if result is None:
              continue
  
          # These lines are needed for certain data sets which EE is not properly masking!!!
          # result = result.mask(domain.skybox_nir.image.reduce(ee.Reducer.allNonZero()))
          # result = result.mask(domain.skybox.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},