<jupyter_start><jupyter_text>Site Location Problem<jupyter_code>import operator
import csv
import matplotlib 
import matplotlib.pyplot
import sys
#!conda install --yes --prefix {sys.prefix} numpy
import numpy
import ipywidgets as widgets
from ipywidgets import Button, Layout
from IPython.display import Javascript, display
from ipywidgets import widgets
def run_all(ev):
    display(Javascript('IPython.notebook.execute_cells_below()'))

button = widgets.Button(description='Click here to run analysis',
           layout=Layout(width='50%', height='80px'), button_style='danger')
button.on_click(run_all)
# Create matPlotLib figure
fig = matplotlib.pyplot.figure(figsize=(15, 10))
matplotlib.pyplot.rcParams['figure.figsize'] = [15, 10]

# Create lists
weightedgeology = []
weightedpopulation = []
weightedtransport = []
weighteddem = []
# Create sliders for values, ranged 0-100, in steps of 10.
slider1 = widgets.IntSlider(value=20,min=0,max=100,step=10,description='Geology:',disabled=False,continuous_update=False,orientation='horizontal',readout=True,readout_format='d')
slider2 = widgets.IntSlider(value=30,min=0,max=100,step=10,description='Transport:',disabled=False,continuous_update=False,orientation='horizontal',readout=True,readout_format='d')
slider3 = widgets.IntSlider(value=20,min=0,max=100,step=10,description='Population:',disabled=False,continuous_update=False,orientation='horizontal',readout=True,readout_format='d')
caption = widgets.Label(value='Please ensure that values below add up to 100 before running analysis')
display(caption, slider1, slider2, slider3);
display(button)
# Importing each CSV file as a numpy array, and multiplying each value in the array by the weighting, 
# as determined by the slider value
# GEOLOGY
geology = numpy.array(list(csv.reader(open("geology.csv", encoding='UTF-8'), delimiter=","))).astype("int")
weightedgeology = geology*slider1.value
# TRANSPORT
transport = numpy.array(list(csv.reader(open("transport.csv", encoding='UTF-8'), delimiter=","))).astype("int")
weightedtransport = transport*slider2.value
# POPULATION
population = numpy.array(list(csv.reader(open("population.csv", encoding='UTF-8'), delimiter=","))).astype("int")
weightedpopulation = population*slider3.value
# WEIGHTED MAP
# Adding together the arrays (note on this element within acompanying report)
sumone = numpy.add(weightedgeology, weightedpopulation)
weighteddem =numpy.add(sumone, weightedtransport)
# Normalise arrays
weighteddemnormalised = numpy.divide(weighteddem, 100)
# Plotting normalised DEM
matplotlib.pyplot.xlim(0, 335)
matplotlib.pyplot.ylim(530, 0)
matplotlib.pyplot.imshow(weighteddemnormalised, cmap='magma')
matplotlib.pyplot.title('Weighted DEM', fontdict=None, loc='center', pad=None)
matplotlib.pyplot.colorbar()
matplotlib.pyplot.show()
# Saving output DEM to CSV
numpy.savetxt("output_dem.csv", weighteddemnormalised, delimiter=",", fmt='%i')
# Testing the output CSV works by re-importing and adding to a new plot. Plot should match one produced above.
output = numpy.array(list(csv.reader(open("output_dem.csv", encoding='UTF-8'), delimiter=","))).astype("int")

matplotlib.pyplot.xlim(0, 335)
matplotlib.pyplot.ylim(530, 0)
matplotlib.pyplot.imshow(output, cmap='magma')
matplotlib.pyplot.title('Weighted DEM (Test re-import)', fontdict=None, loc='center', pad=None)
matplotlib.pyplot.colorbar()
matplotlib.pyplot.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1358313817330211, 'fraction_numerical': 0.022540983606557378, 'mean_word_length': 8.285326086956522, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '192934', 'license': 'MIT', 'n_tokens_mistral': 1174, 'n_tokens_neox': 1073, 'n_words': 232, 'path': 'Site location problem/5003 Report v3.ipynb', 'repo_name': 'eilishrose/5003Report', 'size': '3416'}