lakes = lakes.flatten().astype(int)
rivers = rivers.flatten().astype(int)
small_rivers = small_rivers.flatten().astype(int)
marshes = marshes.flatten().astype(int)

lakes = np.where(lakes == 1)[0]
rivers = np.where(rivers == 1)[0]
small_rivers = np.where(small_rivers == 1)[0]
marshes = np.where(marshes == 1)[0]
ds = 1"""
#new_watersheds = cPickle.load(open(saved_files + 'watershedsAfterMergingSubTraps.pkl', 'rb'))
# plot.plot_watersheds_and_lakes_rivers_marshes(landscape, new_watersheds, ds,
#                                              lakes, rivers, small_rivers, marshes)
#cPickle.dump(new_watersheds, open('watershedsAfterMergingSubTraps.pkl', 'wb'))

plot.plot_watersheds_2d(new_watersheds, landscape, 1)

#new_watersheds_second_iteration = trap_analysis.merge_sub_traps(
#    new_watersheds_first_iteration, landscape.coordinates[:, 2], landscape.num_of_nodes_x, landscape.num_of_nodes_y)
#print len(new_watersheds_second_iteration)
#
#new_watersheds_third_iteration = trap_analysis.merge_sub_traps(
#    new_watersheds_second_iteration, landscape.coordinates[:, 2], landscape.num_of_nodes_x, landscape.num_of_nodes_y)
#print len(new_watersheds_third_iteration)
#
#new_watersheds_fourth_iteration = trap_analysis.merge_sub_traps(
#    new_watersheds_third_iteration, landscape.coordinates[:, 2], landscape.num_of_nodes_x, landscape.num_of_nodes_y)
#print len(new_watersheds_fourth_iteration)
#
#new_watersheds_fifth_iteration = trap_analysis.merge_sub_traps(
#    new_watersheds_fourth_iteration, landscape.coordinates[:, 2], landscape.num_of_nodes_x, landscape.num_of_nodes_y)
import sys
import numpy as np
import cPickle
sys.path.insert(0, '/home/anderovo/Dropbox/watershed/trapAnalysis/lib')
sys.path.insert(0, '/home/anderovo/Dropbox/watershedLargeFiles')

import load_geotiff
import plot
import util

saved_files = '/home/anderovo/Dropbox/watershedLargeFiles/'
file_name = saved_files + 'anders_hoh.tiff'

"""
 Plot the watersheds in 2d
"""

landscape = load_geotiff.get_landscape_tyrifjorden(file_name)

nodes_in_watersheds, nr_of_iterations = cPickle.load(open(saved_files + 'watershedsComplete.pkl', 'rb'))
ws_with_above_n_nodes = 0

plot.plot_watersheds_2d(nodes_in_watersheds, landscape, ws_with_above_n_nodes, 4)