<jupyter_start><jupyter_text>In this script, we use the geemap (https://github.com/giswqs/geemap) module. Map is plotted on notebook onto which a line is drawn. Water occurrence values at 101 equally spaced points are extracted. Similarly elevation values for the same points are interpolated. The two plots are drawn together for comparison of any relations.<jupyter_code># %matplotlib widget
%matplotlib inline
# %matplotlib qt 

import json

import requests
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
import folium
import geopandas as gpd
from shapely.geometry import box, Polygon
from pyproj import CRS
from tqdm.notebook import tqdm
from tqdm import trange
# remove folium warning
import warnings; warnings.filterwarnings('ignore', 'GeoSeries.notna', UserWarning)
import ee
import geemap
import seaborn as sb

import sklearn
from sklearn.linear_model import LinearRegression
from sklearn.preprocessing import scale
from collections import Counter

import scipy
from scipy.interpolate import griddata
df = pd.read_pickle('../data/out/df.pkl')
df2 = pd.read_pickle('../data/out/df2.pkl')
df3 = pd.read_pickle('../data/out/df3.pkl')
df
df.memory_usage()
df.h.hist(bins=100)
df.water_occurrence.hist(bins=10)
df.track_id.unique()
df.date.unique()
df.beam.unique()
fig, ax = plt.subplots(1, 2, figsize=(20, 5))
# (df.series != 'Noise') & (df.series != 'Buffer') & 
data = df [(df.series != 'Noise') & (df.track_id == '180') & (df.date == '2020-01-07') & (df.beam == 'gt2r')]

ax[0].plot(data.h, '.', markersize=5, alpha=0.2)
ax[1].plot(df.lon, df.lat, 'k.', markersize=0.1, alpha=0.2)
ax[1].plot(data.lon, data.lat, 'r.', markersize=0.1, alpha=0.2)
plt.show()
# Bangladesh
extents = [89.57958670206244, 23.721136875400937, 89.99453684543461, 24.618409448937893] #Extent same as users/gena/AquaMonitor2020/bathymetry-jamuna/bathymetry3-jamuna-2018-2019
zoom = 10
#Map = geemap.Map()
Map = geemap.Map(center=[((23.721136875400937 + 24.618409448937893)/2), ((89.57958670206244 + 89.99453684543461)/2)], zoom=zoom)
#Map = geemap.Map(center(lon = ((89.57958670206244 + 89.99453684543461)/2), lat = ((23.721136875400937 + 24.618409448937893)/2)), zoom = zoom)
Map
# Add Earth Engine dataset
image = ee.Image('users/gena/AquaMonitor2020/bathymetry-jamuna/bathymetry3-jamuna-2018-2019').select('ndwi')

# Set visualization parameters.
# vis_params = {
#   'min': 0,
#   'max': 4000,
#   'palette': ['006633', 'E5FFCC', '662A00', 'D8D8D8', 'F5F5F5']}

# Add Earth Engine DEM to map
#Map.addLayer(image, vis_params, 'NDWI Jamuna 2019-20')
Map.addLayer(image,name = 'NDWI Jamuna 2019-20', opacity=0.75)
#Here we have added the earth engine dataset.. bathymetry data; perhaps we could add the icesat h data as well here, but how?
Map.draw_features
Map.draw_last_feature
line = Map.draw_last_feature
# print(line)
endpoints = line.getInfo()['geometry']['coordinates']
endpoints
step_x = (endpoints[1][0] - endpoints[0][0])/100
step_y = (endpoints[1][1] - endpoints[0][1])/100
coords = []
lon = [endpoints[0][0]]
lat = [endpoints[0][1]]
for i in range(0,100):
    lon.append(step_x + lon[-1])
    lat.append(step_y + lat[-1])
    
coords = list(zip(lon, lat))
type(coords)
#Do we interpolate points or do we draw plots on icesat track lines, that is the question;
df
verts = df[['lon', 'lat', 'h']]
verts
df = df.dropna()
grid_z = griddata((df.lon, df.lat), df.h, (lon, lat), method='linear')
grid_z
results = []

    
features = ee.List(coords).map(lambda o: ee.Feature(ee.Geometry.Point(coords=o)))
#print(features)
features = ee.FeatureCollection(features)
    
values = image.unmask(-999, False).reduceRegions(collection=features, reducer=ee.Reducer.first().setOutputs(['water_occurrence']), scale=10, tileScale=1)
results = results + values.aggregate_array('water_occurrence').getInfo()
x = range(0,101)
y = results
plt.plot(x,y)
plt.plot(x,grid_z)
# create figure and axis objects with subplots()
fig,ax = plt.subplots()
# make a plot
ax.plot(x,y, color="red", marker="o")
# set x-axis label
ax.set_xlabel("division",fontsize=14)
# set y-axis label
ax.set_ylabel("water occurrence",color="red",fontsize=14)





# twin object for two different y-axis on the sample plot
ax2=ax.twinx()
# make a plot with different y-axis using second axis object
ax2.plot(x,grid_z,color="blue",marker="o")
ax2.set_ylabel("altitude",color="blue",fontsize=14)
plt.show()
# twin object for two different y-axis on the sample plot
ax2=ax.twinx()
# make a plot with different y-axis using second axis object
ax2.plot(x,grid_z,color="blue",marker="o")
ax2.set_ylabel("altitude",color="blue",fontsize=14)
plt.show()
# save the plot as a file
# fig.savefig('two_different_y_axis_for_single_python_plot_with_twinx.jpg',
#             format='jpeg',
#             dpi=100,
#             bbox_inches='tight')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14989648033126293, 'fraction_numerical': 0.07494824016563147, 'mean_word_length': 5.249676584734799, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '402667', 'license': 'Apache-2.0', 'n_tokens_mistral': 2029, 'n_tokens_neox': 1783, 'n_words': 436, 'path': 'mn5hk/02 ipynb/04a_UserFriendlyGraphs_DrawLine.ipynb', 'repo_name': 'EtienneKras/eo-bathymetry', 'size': '4830'}