#layers.append(layer)
"""

## GeoTiff
"""
import mapping.geotools.coordtrans as ct
tif_filespec = r"D:\GIS-data\Belgium\DEM\ngi_dem1_Lambert.tif"
grd_data = lbm.GdalRasterData(tif_filespec, band_nr=0)
grd_data.srs = ct.get_epsg_srs(31370)
grd_style = lbm.GridImageStyle(alpha=0.75)
layer = lbm.MapLayer(grd_data, grd_style)
layers.append(layer)
"""

## Coastlines
coastline_style = lbm.LineStyle(line_color="k", line_width=1)
data = lbm.BuiltinData("coastlines")
layer = lbm.MapLayer(data, coastline_style)
#layers.append(layer)

## Country borders
data = lbm.BuiltinData("countries")
country_style = lbm.LineStyle(line_color="k", line_width=0.75)
layer = lbm.MapLayer(data, country_style)
#layers.append(layer)

## Countries
country_color = "oldlace"
for country in ("france", "germany", "luxembourg", "netherlands",
                "united_kingdom"):
    gis_filename = country + ".TAB"
#colorbar_style = None
#hillshade_style = lbm.HillshadeStyle(azimuth=45,elevation_angle=30, scale=0.1, color_map="copper")
hillshade_style = None
cmap, norm = lbm.cm.from_cpt_city(r"td/DEM_poster")
#cmap = "gist_earth"
tsc = lbm.ThematicStyleColormap(color_map=cmap, vmin=0, vmax=700)
#tsc.color_map = None
style = lbm.GridStyle(color_map_theme=tsc,
                      colorbar_style=colorbar_style,
                      line_style=None,
                      pixelated=True,
                      hillshade_style=hillshade_style)
#layer = lbm.MapLayer(wcs_data, style)
layer = lbm.MapLayer(gdal_data, style)
layers.append(layer)

## Country borders
data = lbm.BuiltinData("countries")
country_style = lbm.LineStyle(line_color="r", line_width=2, line_pattern='--')
layer = lbm.MapLayer(data, country_style)
layers.append(layer)

## Coastlines
coastline_style = lbm.LineStyle(line_color="r", line_width=2)
data = lbm.BuiltinData("coastlines")
layer = lbm.MapLayer(data, coastline_style)
layers.append(layer)

map = lbm.LayeredBasemap(layers, title, projection, region=region)
map.plot()
#fig_filespec = None
#fig_filespec = "E:\\Home\\_kris\\Projects\\2012 - Electrabel\\Progress Report 2\\Figures\\FocalMechanisms.png"
#fig_filespec = "E:\\Home\\_kris\\Projects\\2013 - cAt_Rev\\Figures\\Maps\\FocalMechanisms.png"
fig_filespec = None

region = (3, 7, 50, 51.5)
projection = "merc"
#title = "ROB focal mechanisms"
title = ""
resolution = "h"
graticule_interval = (1, 0.5)

layers = []

## Coastlines
coastline_style = lbm.LineStyle(line_color="k", line_width=2)
data = lbm.BuiltinData("coastlines")
layer = lbm.MapLayer(data, coastline_style)
layers.append(layer)

## Country borders
data = lbm.BuiltinData("countries")
country_style = lbm.LineStyle(line_color="k", line_width=2, line_pattern='--')
layer = lbm.MapLayer(data, country_style)
layers.append(layer)

## Source model
#sm_name= "Seismotectonic_Hybrid"
sm_name = "Seismotectonic"
gis_filespec = rob_source_models_dict[sm_name].gis_filespec
src_label_name = rob_source_models_dict[sm_name].column_map['id']
## Hazard grid
grd_file = r"D:\PSHA\EC8\CRISIS\Runs\MapInfo\GMT\E8_CRISIS_Ambr95DD_2s5km_475y.grd"
grd_data = lbm.GdalRasterData(grd_file)
#cmap = lbm.cm.get_cmap('hazard', 'gshap')
#norm = lbm.cm.get_norm('hazard', 'gshap')
cmap = 'rainbow'
#cpt_file = r"D:\GIS-data\Misc\Color profiles\PSHA\EC8_BEL_rainbow.cpt"
#cpt_file = r"D:\GIS-data\Misc\Color profiles\GMT\GMT_rainbow.cpt"
#cmap, _ = lbm.cm.from_cpt(cpt_file)
norm = lbm.cm.norm.LinearNorm(vmin=0, vmax=0.18)
color_map_theme = lbm.ThematicStyleColormap(cmap, norm=norm)
label_style = lbm.TextStyle(font_size=6,
                            background_color=(1, 1, 1, 0.67),
                            border_pad=0)
line_style = lbm.LineStyle(line_width=0.5,
                           line_pattern=None,
                           dash_pattern=[3, 3],
                           label_style=label_style)
contour_levels = np.arange(0.02, 0.17, 0.02)
contour_labels = contour_levels[::2]
tick_labels = [
    "%.2f" % contour_levels[i] if i % 2 == 0 else ''
    for i in range(len(contour_levels))
]
colorbar_style = lbm.ColorbarStyle(
    'PGA (g), 10% probability of exceedance in 50 yr',
    format='%.2f',
    spacing='uniform',
    ticks=contour_levels,
    tick_labels=tick_labels)
grd_style = lbm.GridStyle(color_map_theme,
                          contour_levels=contour_levels,
## BlueMarble image
bm_style = None
data = lbm.BuiltinData("bluemarble")
layer = lbm.MapLayer(data, bm_style)
#layers.append(layer)

## Continents
continent_style = lbm.PolygonStyle(fill_color="cornsilk", line_pattern=None, line_width=0)
continent_style.bg_color = "powderblue"
data = lbm.BuiltinData("continents")
layer = lbm.MapLayer(data, continent_style)
layers.append(layer)

## Coastlines
coastline_style = lbm.LineStyle(line_color="burlywood", line_width=2)
data = lbm.BuiltinData("coastlines")
layer = lbm.MapLayer(data, coastline_style)
layers.append(layer)

## Country borders
data = lbm.BuiltinData("countries")
country_style = lbm.LineStyle(line_color="w", line_width=1, line_pattern='-')
layer = lbm.MapLayer(data, country_style)
layers.append(layer)

## Rivers
data = lbm.BuiltinData("rivers")
river_style = lbm.LineStyle(line_color="b", line_width=0.5)
layer = lbm.MapLayer(data, river_style)
#layers.append(layer)
from __future__ import absolute_import, division, print_function, unicode_literals


import mapping.layeredbasemap as lbm


region = (0,8,49,52)
projection = "tmerc"
title = "Circles demo"
resolution = "h"
graticule_interval = (2, 1)

layers = []

## Coastlines
coastline_style = lbm.LineStyle(line_color="k", line_width=2)
data = lbm.BuiltinData("coastlines")
layer = lbm.MapLayer(data, coastline_style)
layers.append(layer)

## Country borders
data = lbm.BuiltinData("countries")
country_style = lbm.LineStyle(line_color="k", line_width=2, line_pattern='--')
layer = lbm.MapLayer(data, country_style)
layers.append(layer)

## Circles
uccle = (4.367785, 50.795003)
distances = [25, 50, 75, 100]
circle_data = lbm.CircleData([uccle[0]]*4, [uccle[1]]*4, distances, values=distances, azimuthal_resolution=5)
thematic_color = lbm.ThematicStyleIndividual(distances, ["yellow", "orange", "red", "purple"], colorbar_style=None)
import os

from eqcatalog.source_models import rob_source_models_dict
import mapping.layeredbasemap as lbm


fig_folder = "E:\\Home\\_kris\\Publications\\2014 - DGEB"
fig_filespec = None
#fig_filespec = os.path.join(fig_folder, "SourceModel_RVRS_CSS.png")


layers = []

## Coastlines
data = lbm.BuiltinData("coastlines")
style = lbm.LineStyle()
layer = lbm.MapLayer(data, style)
layers.append(layer)

## Countries
data = lbm.BuiltinData("countries")
style = lbm.LineStyle(line_pattern="dashed")
layer = lbm.MapLayer(data, style)
layers.append(layer)

## Fault sources (projected fault planes)
sm_name = "RVRS_CSS"
gis_filespec = rob_source_models_dict[sm_name].gis_filespec
gis_filespec = gis_filespec.split('_')[0] + ".TAB"
#src_label_name = rob_source_models_dict[sm_name].column_map['id']
src_label_name = None