# 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 ee
from cmt.mapclient_qt import centerMap, addToMap
from histogram import RadarHistogram
# -----------------------------------------------------------------------------
# Copyright * 2014, United States Government, as represented by the
# Administrator of the National Aeronautics and Space Administration. All
# rights reserved.
#
# The Crisis Mapping Toolkit (CMT) v1 platform is licensed under the Apache
# License, Version 2.0 (the "License"); you may not use this file except in
# compliance with the License. You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0.
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
# -----------------------------------------------------------------------------





def grow_regions(sensor, thresholded, thresholds):
    '''???????'''
    REGION_GROWTH_RANGE = 20
    neighborhood_kernel = ee.Kernel.square(1, 'pixels', False)
    loose_thresholded   = sensor.image.select([sensor.band_names[0]]).lte(thresholds[0])
    for i in range(1, len(sensor.band_names)):
        loose_thresholded = loose_thresholded.And(sensor.image.select([sensor.band_names[i]]).lte(thresholds[i]))

# 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: cmt/radar/matgen.py
import ee
from cmt.mapclient_qt import centerMap, addToMap
from histogram import RadarHistogram

# -----------------------------------------------------------------------------
# Copyright * 2014, United States Government, as represented by the
# Administrator of the National Aeronautics and Space Administration. All
# rights reserved.
#
# The Crisis Mapping Toolkit (CMT) v1 platform is licensed under the Apache
# License, Version 2.0 (the "License"); you may not use this file except in
# compliance with the License. You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0.
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
# -----------------------------------------------------------------------------





def grow_regions(sensor, thresholded, thresholds):
    '''???????'''
    REGION_GROWTH_RANGE = 20
    neighborhood_kernel = ee.Kernel.square(1, 'pixels', False)
    loose_thresholded   = sensor.image.select([sensor.band_names[0]]).lte(thresholds[0])
    for i in range(1, len(sensor.band_names)):
        loose_thresholded = loose_thresholded.And(sensor.image.select([sensor.band_names[i]]).lte(thresholds[i]))

    addToMap(loose_thresholded, {'min': 0, 'max': 1}, 'Loose', False)