<jupyter_start><jupyter_text>Part 4: Plotting the data Written by <NAME> at the University of Edinburgh. Updated 02/09/2021<jupyter_code>import lsdviztools.lsdbasemaptools as bmt
from lsdviztools.lsdplottingtools import lsdmap_gdalio as gio
import lsdviztools.lsdmapwrappers as lsdmw
# %matplotlib notebook
DataDirectory = "./"
Base_file = "shillong_SRTM30_UTM"  
fig = lsdmw.SimpleHillshade(DataDirectory,Base_file,cmap="gist_earth", save_fig=False)
%matplotlib notebook
fig
ChannelFileName = "shillong_SRTM30_UTM_chi_data_map.csv"
channel_img = lsdmw.PrintChannels(DataDirectory,Base_file,ChannelFileName, 
                               cmap = "gist_earth",
                               size_format = "geomorphology", dpi = 300, 
                               plotting_column = "basin_key", save_fig = False)
channel_img
fig
channel_img_name = lsdmw.PrintChannels(DataDirectory,Base_file,ChannelFileName, 
                               cmap = "gist_earth",
                               size_format = "geomorphology", dpi = 300, 
                               plotting_column = "basin_key", save_fig = True)
channel_img_name<jupyter_output><empty_output><jupyter_text>Working with the point data LSDTopoTools outputs point data as csv files, which can be read into geopandas dataframes. You can then use these for plotting.<jupyter_code>import pandas as pd
import geopandas as gpd
import numpy as np
DataDirectory = "./"
Base_file = "shillong_SRTM30_UTM"  
ChannelFileName = Base_file+"_chi_data_map.csv"
chi_csv_fname = DataDirectory+ChannelFileName
df = pd.read_csv(chi_csv_fname)<jupyter_output><empty_output><jupyter_text>The csv file has latitude and longitude coordinates, so we can use these to register the geometry with a `geopandas` dataframe, and we can also set the coordinate reference system (`set_crs`). The `latitude` and `longitude` data produced by `lsdtopotools` is always in `epsg=4326`.<jupyter_code>gdf = gpd.GeoDataFrame(
    df, geometry=gpd.points_from_xy(df.longitude, df.latitude))
gdf = gdf.set_crs(epsg=4326)
print(gdf.head())<jupyter_output>latitude  longitude     chi  elevation  flow_distance  drainage_area  \
0  25.520114  91.901374  11.611     1778.0       113110.0       905400.0   
1  25.519843  91.901377  11.580     1777.0       113080.0       912600.0   
2  25.519574  91.901678  11.535     1777.0       113040.0       942300.0   
3  25.519301  91.901382  11.491     1777.0       113000.0       950400.0   
4  25.519030  91.901384  11.461     1777.0       112970.0       952200.0   

   source_key  basin_key                   geometry  
0           0          0  POINT (91.90137 25.52011)  
1           0          0  POINT (91.90138 25.51984)  
2           0          0  POINT (91.90168 25.51957)  
3           0          0  POINT (91.90138 25.51930)  
4           0          0  POINT (91.90138 25.51903)<jupyter_text>So after some experimenting, it turns out that the plotting functions are not very happy if you don't keep everything in the same coordinate system. So I need to transform the geopandas dataframe to the correct UTM coordinate system. You will probably need to make sure your rasters and your dataframes are alyways in the same coordinate system.<jupyter_code>gdf2 = gdf.to_crs("EPSG:32646")<jupyter_output><empty_output><jupyter_text>Before we plot these, I want to make a scaling function that sets the marker size as a function of drainage area. But I need to scale the marker sizes. I use a scaling with the log (base 10) of the drainage area:<jupyter_code>def log_value_scaler(vals, min_scale = 0.5, max_scale = 6):
    logvals = np.log10(vals)
    minval = np.min(logvals)
    maxval = np.max(logvals)
    newvals  = np.subtract(logvals,minval)
    newvals = np.divide(newvals,(maxval-minval))
    newvals = np.multiply(newvals,max_scale-min_scale)
    newvals = np.add(newvals,min_scale)
    return newvals
logv = log_value_scaler(gdf2.drainage_area,min_scale=0.5, max_scale = 4)
gdf2["scaled_area"] = logv
print(gdf2.head())<jupyter_output>latitude  longitude     chi  elevation  flow_distance  drainage_area  \
0  25.520114  91.901374  11.611     1778.0       113110.0       905400.0   
1  25.519843  91.901377  11.580     1777.0       113080.0       912600.0   
2  25.519574  91.901678  11.535     1777.0       113040.0       942300.0   
3  25.519301  91.901382  11.491     1777.0       113000.0       950400.0   
4  25.519030  91.901384  11.461     1777.0       112970.0       952200.0   

   source_key  basin_key                        geometry  scaled_area  
0           0          0  POINT (389604.973 2822997.254)     0.503067  
1           0          0  POINT (389604.967 2822967.250)     0.507128  
2           0          0  POINT (389634.969 2822937.253)     0.523549  
3           0          0  POINT (389604.974 2822907.253)     0.527937  
4           0          0  POINT (389604.967 2822877.249)     0.528907<jupyter_text>Okay, lets plot a single basin, with the drainage area (selected by the scaled area) thinned.<jupyter_code>gdf_b1 = gdf2[(gdf2['basin_key'] == 0) & (gdf2['scaled_area'] > 1.5)]
print(gdf_b1.head())
import matplotlib.pyplot as plt

fig = plt.figure(figsize = (8,4))
ax = fig.add_subplot(1, 1, 1)
scat = ax.scatter(gdf_b1.chi,gdf_b1.elevation,c=gdf_b1.flow_distance,s=gdf_b1['scaled_area'])
cb = fig.colorbar(scat,)
cb.set_label(label="Flow distance (m)",size=16)

plt.text(0.5, 1800, "Chi plot, Basin 0", size=14,
         ha="left", va="top",
         bbox=dict(boxstyle="square",
                   ec=(0., 0., 0.),
                   fc=(1., 1.0, 1.0),
                   )
        )

plt.xlabel(r"$\chi$ (m)",size=20)
plt.ylabel("Elevation (m)",size=20)
ax.set_ylim(0,2000)
fig.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09165502793296089, 'fraction_numerical': 0.12796787709497207, 'mean_word_length': 2.6771501925545573, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 25, 'https://': 0, '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': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '239464', 'license': 'MIT', 'n_tokens_mistral': 2491, 'n_tokens_neox': 2053, 'n_words': 502, 'path': 'lsdviztools/simple_chi_analysis/Chi_point_plots.ipynb', 'repo_name': 'LSDtopotools/lsdtt_notebooks', 'size': '5735'}