%23%20%2F%2F%2F%20script%0A%23%20dependencies%20%3D%20%5B%0A%23%20%20%20%20%20%22connectorx%3D%3D0.4.5%22%2C%0A%23%20%20%20%20%20%22leafmap%3D%3D0.63.1%22%2C%0A%23%20%20%20%20%20%22marimo%22%2C%0A%23%20%20%20%20%20%22polars%3D%3D1.44.2%22%2C%0A%23%20%20%20%20%20%22pyarrow%3D%3D25.0.1%22%2C%0A%23%20%20%20%20%20%22pyzmq%3D%3D27.1.0%22%2C%0A%23%20%5D%0A%23%20requires-python%20%3D%20%22%3E%3D3.13%22%0A%23%20%2F%2F%2F%0A%0Aimport%20marimo%0A%0A__generated_with%20%3D%20%220.24.0%22%0Aapp%20%3D%20marimo.App(width%3D%22medium%22)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Mapping%20open-pit%20mines%0A%0A%20%20%20%20Notebook%20by%20Mueez%20Khan%20(%5Bmueezkhan.com%5D(https%3A%2F%2Fmueezkhan.com)).%0A%0A%20%20%20%20The%20first%20chapter%20of%20%5BBad%20Energy%20by%20Joshua%20Frank%5D(https%3A%2F%2Fwww.haymarketbooks.org%2Fbooks%2F2772-bad-energy)%20demonstrates%20negative%20impacts%20of%20open-pit%20mines%2C%20with%20examples%20such%20as%20the%20Berkeley%20Pit.%20Here%20I%20attempt%20to%20map%20locations%20of%20some%20known%20open-pit%20mines%20in%20the%20US.%20You%20can%20click%20on%20a%20marker%20to%20also%20open%20a%20link%20to%20the%20open-pit%20mine's%20Wikipedia%20page%20along%20with%20occasionally%20viewing%20a%20photograph%20about%20the%20mine.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20First%20we'll%20attempt%20to%20import%20necessary%20libraries.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20%23%20Uncomment%20the%20following%20line%20if%20you%20need%20to%20install%20the%20libraries%0A%20%20%20%20%23!uv%20pip%20install%20polars%20leafmap%20connectorx%0A%0A%20%20%20%20%23%20polars%20is%20for%20the%20dataframe%2C%20leafmap%20for%20mapping%2C%20and%20connectorx%20for%20enabling%20the%20Postgres%20connection%20for%20Polars%0A%20%20%20%20%23%20We%20also%20have%20marimo%20for%20marimo%20notebook%20content%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20import%20os%0A%20%20%20%20import%20leafmap%0A%20%20%20%20import%20polars%20as%20pl%0A%20%20%20%20import%20marimo%20as%20mo%0A%0A%20%20%20%20return%20leafmap%2C%20mo%2C%20os%2C%20pl%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20Now%20we%20can%20connect%20to%20our%20Postgres%20database%20and%20read%20the%20relevant%20columns%20from%20the%20%60open_pit_mines%60%20table%20into%20a%20%5BPolars%5D(https%3A%2F%2Fpola.rs)%20dataframe.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(os%2C%20pl)%3A%0A%20%20%20%20uri%20%3D%20os.environ.get(%22MARIMO_DB_URI%22)%0A%20%20%20%20query%20%3D%20%22%22%22%0A%20%20%20%20SELECT%20%22name%22%2C%22latitude%22%2C%22longitude%22%2C%22wikipedia_url%22%2C%22region%22%2C%22country%22%2C%22image_source_url%22%2C%22image_url%22%0A%20%20%20%20FROM%20open_pit_mines%0A%20%20%20%20%22%22%22%0A%20%20%20%20df%20%3D%20pl.read_database_uri(query%3Dquery%2C%20uri%3Duri)%0A%20%20%20%20return%20(df%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20Here%20we%20can%20see%20a%20data%20table%20preview%20of%20our%20dataframe%20where%20each%20row%20is%20data%20about%20an%20open-pit%20mine.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(df%2C%20mo)%3A%0A%20%20%20%20mo.ui.table(df%2C%20page_size%3D15)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20Finally%20we'll%20use%20the%20%5Bleafmap%5D(https%3A%2F%2Fleafmap.org)%20library%20to%20map%20our%20data%2C%20along%20with%20some%20HTML%20for%20the%20popup%20when%20you%20click%20a%20marker%20for%20an%20open-pit%20mine.%0A%0A%20%20%20%20Note%20that%20the%20images%20displayed%20within%20the%20map%20may%20be%20relatively%20old%20from%20years%20ago.%20I%20tried%20to%20find%20public%20domain%20images%20to%20include.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(df%2C%20leafmap)%3A%0A%20%20%20%20m%20%3D%20leafmap.Map(center%3D(40%2C%20-100)%2C%20zoom%3D4)%0A%20%20%20%20m.add_basemap(%22SATELLITE%22)%0A%0A%20%20%20%20for%20row%20in%20df.iter_rows(named%3DTrue)%3A%0A%20%20%20%20%20%20%20%20pit_name%20%3D%20row%5B%22name%22%5D%0A%20%20%20%20%20%20%20%20pit_lat%20%3D%20row%5B%22latitude%22%5D%0A%20%20%20%20%20%20%20%20pit_lon%20%3D%20row%5B%22longitude%22%5D%0A%20%20%20%20%20%20%20%20region%20%3D%20row%5B%22region%22%5D%0A%20%20%20%20%20%20%20%20country%20%3D%20row%5B%22country%22%5D%0A%20%20%20%20%20%20%20%20wikipedia_url%20%3D%20row%5B%22wikipedia_url%22%5D%0A%20%20%20%20%20%20%20%20image_source_url%20%3D%20row.get(%22image_source_url%22)%0A%20%20%20%20%20%20%20%20image_url%20%3D%20row.get(%22image_url%22)%0A%20%20%20%20%20%20%20%20m.add_marker(location%3D%5Bpit_lat%2C%20pit_lon%5D%2C%20popup%3Df%22%22%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%3Cdiv%20style%3D%22min-width%3A%20200px%3B%20max-width%3A%20400px%22%3E%0A%20%20%20%20%20%20%20%20%20%20%20%20%3Ch3%3E%7Bpit_name%7D%3C%2Fh3%3E%0A%20%20%20%20%20%20%20%20%20%20%20%20%3Cspan%3E%7Bregion%7D%20%7C%20%7Bcountry%7D%3C%2Fspan%3E%0A%20%20%20%20%20%20%20%20%20%20%20%20%3Cbr%20%2F%3E%0A%20%20%20%20%20%20%20%20%20%20%20%20%3Ca%20href%3D%5C%22%7Bwikipedia_url%7D%5C%22%20target%3D%22_top%22%3EView%20Wikipedia%20page%20(click%20here)%3C%2Fa%3E%0A%20%20%20%20%20%20%20%20%20%20%20%20%7Bf%22%3Cimg%20style%3D'width%3A%20100%25%3B%20max-width%3A%20200px%3B%20margin-top%3A%201rem%3B%20margin-bottom%3A1rem%3B%20border-radius%3A%201rem%3B'%20alt%3D'%7Bpit_name%7D%20image'%20src%3D%7Bimage_url%7D%3E%3C%2Fimg%3E%3Cbr%20%2F%3E%22%20if%20image_url%20else%20%22%22%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20%7Bf%22%3Ca%20href%3D%5C%22%7Bimage_source_url%7D%5C%22%20target%3D%5C%22_top%5C%22%3EView%20image%20information%3C%2Fa%3E%22%20if%20image_source_url%20else%20%22%22%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20%3C%2Fdiv%3E%0A%20%20%20%20%20%20%20%20%22%22%22%2C%20min_width%3D400%0A%20%20%20%20%20%20%20%20)%0A%20%20%20%20m%0A%20%20%20%20return%0A%0A%0Aif%20__name__%20%3D%3D%20%22__main__%22%3A%0A%20%20%20%20app.run()%0A
8464a30e14af9da7e17041261296ee8d