Project 1 This repository contains two files eog_wells_in_nd.csv and nd_production.csv in the datasets directory. The file eog_wells_in_nd.csv contains the latitude and longitude for all permitted...

1 answer below »

Project 1


This repository contains two files
eog_wells_in_nd.csv
and
nd_production.csv
in thedatasetsdirectory. The file
eog_wells_in_nd.csv
contains the latitude and longitude for all permitted wells owned by EOG in North Dakota. The file
nd_production.csv
contains the monthly production history forallwells in North Dakota identified by their API numbers. I encourage you to inspect the formatting of these two files. For this project, you will have two tasks:


Task 1


You should read the file
eog_wells_in_nd.csv
into the class attributewell_df(Do not change the name). However, you should not hard-code the "eog" part of the file name, instead use the class instantiation argumenttickerto create the file name. This is so we can use this class to read in many files of this type. So ifticker = 'xom'then the class will read in a filedatasets/xom_wells_in_nd.csv, ifticker = 'nbl'then the class will read in a filedatasets/nbl_wells_in_nd.csv, etc.


Next, we want to add two new columns to thewell_df. These columns should be labeledexactly
'cumulative_oil'and'cumulative_gas'and they should contain the total production (summed of over all months) for the corresponding API number in
nd_production.csv
. There are wells in
eog_wells_in_nd.csv
that do not have any production history, either because they have been permitted and not drilled, they were dry holes, the data is missing, etc.


It's possible to compute this total production for all the wells with a one line series of Pandas operations. A few Dataframe member functions you may want to look into areisin,groupby, andsum. You could also loop over all the unique wells summing individually, but this will likely be very slow.


After you've added the new columns to thewell_dfDataFrame, run the member functiondropna(inplace=True)on it to get rid of any missing values.


Task 2


You should complete the functioncreate_well_map_plot. I've provided a few imports and template code already to set the tile provider toOpenStreetMap. Here are a couple of settings to get everything right, youmustdo these:




  • Create the figure withplot_width = 500,plot_height = 400,tools='tap,box_select,box_zoom,pan,reset'and possibly other options we've already used to create a map project, set labels, etc.




  • Use acircleglyph withsize = 5,line_color=None,fill_alpha=0.8,name='wells'and possible other options we've already used.




  • Color the circles via their'cumulative_oil'or'cumulative_gas'production values. These should be selectable at class instantiation with thecolor_byargument. Add a color bar on the left side of the figure. Use aViridis256color pallete where the miniumum color bar value is the minimum'cumulative_[oil/gas]value for all wells. Likewise for the maximum.ThisStack Overflow post can assist you in setting the color bar.




The figures must be identical for the tests to pass. If everything works correctly, you should get a plot with this interactivity by running theshow_plot()function.



img


Please make plot using matplotlib

Answered 1 days AfterApr 06, 2021

Answer To: Project 1 This repository contains two files eog_wells_in_nd.csv and nd_production.csv in the...

Sanchi answered on Apr 08 2021
135 Votes
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Project 1\n",
"\n",
"This repository contains two files [`eog_wells_in_nd.csv`](datasets/eog_wells_in_nd.csv) and [`nd_production.csv`](datasets/nd_production.csv) in the `datasets` directory. The file [`eog_wells_in_nd.csv`](datasets/eog_wells_in_nd.csv) contains the latitude and longitude for all permitted wells owned by EOG in North Dakota. The file [`nd_production.csv`](datasets/nd_production.csv) contains the monthly production history for *all* wells in North Dakota identified by their API numbers. I encourage you to inspect the formatting of these two files. For this project, you will have two tasks:\n",
"\n",
"## Task 1\n",
"\n",
"You should read the file [`eog_wells_in_nd.csv`](datasets/eog_wells_in_nd.csv) into the class attribute `well_df` (**Do not change the name**). However, you should not hard-code the \"eog\" part of the file name, instead use the class instantiation argument `ticker` to create the file name. This is so we can use this class to read in many files of this type. So if `ticker = 'xom'` then the class will read in a file `datasets/xom_wells_in_nd.csv`, if `ticker = 'nbl'` then the class will read in a file `datasets/nbl_wells_in_nd.csv`, etc.\n",
"\n",
"Next, we want to add two new columns to the `well_df`. These columns should be labeled **exactly** `'cumulative_oil'` and `'cumulative_gas'` and they should
contain the total production (summed of over all months) for the corresponding API number in [`nd_production.csv`](datasets/nd_production.csv). There are wells in [`eog_wells_in_nd.csv`](datasets/eog_wells_in_nd.csv) that do not have any production history, either because they have been permitted and not drilled, they were dry holes, the data is missing, etc.\n",
"\n",
"It's possible to compute this total production for all the wells with a one line series of Pandas operations. A few Dataframe member functions you may want to look into are [isin](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.isin.html?highlight=isin#pandas.DataFrame.isin), [groupby](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.groupby.html?highlight=groupby#pandas.DataFrame.groupby), and [sum](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.sum.html?highlight=sum#pandas.Series.sum). You could also loop over all the unique wells summing individually, but this will likely be very slow.\n",
"\n",
"After you've added the new columns to the `well_df` DataFrame, run the member function `dropna(inplace=True)` on it to get rid of any missing values.\n",
"\n",
"## Task 2\n",
"\n",
"You should complete the function `create_well_map_plot`. I've provided a few imports and template code already to set the tile provider to [OpenStreetMap](https://www.openstreetmap.org/). Here are a couple of settings to get everything right, you *must* do these:\n",
"\n",
" * Create the figure with `plot_width = 500`, `plot_height = 400`, `tools='tap,box_select,box_zoom,pan,reset'` and possibly other options we've already used to create a map project, set labels, etc.\n",
"\n",
" * Use a `circle` glyph with `size = 5`, `line_color=None`, `fill_alpha=0.8`, `name='wells'` and possible other options we've already used.\n",
" \n",
" * Color the circles via their `'cumulative_oil'` or `'cumulative_gas'` production values. These should be selectable at class instantiation with the `color_by` argument. Add a color bar on the left side of the figure. Use a `Viridis256` color pallete where the miniumum color bar value is the minimum `'cumulative_[oil/gas]` value for all wells. Likewise for the maximum. [This](https://stackoverflow.com/questions/50013378/how-to-draw-a-circle-plot-the-linearcolormapper-using-python-bokeh) Stack Overflow post can assist you in setting the color bar.\n",
"\n",
"The figures must be identical for the tests to pass. If everything works correctly, you should get a plot with this interactivity by running the `show_plot()` function.\n",
"\n",
"![img](images/wells.gif)"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"data": {
"application/javascript": [
"\n",
"(function(root) {\n",
" function now() {\n",
" return new Date();\n",
" }\n",
"\n",
" var force = true;\n",
"\n",
" if (typeof root._bokeh_onload_callbacks === \"undefined\" || force === true) {\n",
" root._bokeh_onload_callbacks = [];\n",
" root._bokeh_is_loading = undefined;\n",
" }\n",
"\n",
" var JS_MIME_TYPE = 'application/javascript';\n",
" var HTML_MIME_TYPE = 'text/html';\n",
" var EXEC_MIME_TYPE = 'application/vnd.bokehjs_exec.v0+json';\n",
" var CLASS_NAME = 'output_bokeh rendered_html';\n",
"\n",
" /**\n",
" * Render data to the DOM node\n",
" */\n",
" function render(props, node) {\n",
" var script = document.createElement(\"script\");\n",
" node.appendChild(script);\n",
" }\n",
"\n",
" /**\n",
" * Handle when an output is cleared or removed\n",
" */\n",
" function handleClearOutput(event, handle) {\n",
" var cell = handle.cell;\n",
"\n",
" var id = cell.output_area._bokeh_element_id;\n",
" var server_id = cell.output_area._bokeh_server_id;\n",
" // Clean up Bokeh references\n",
" if (id != null && id in Bokeh.index) {\n",
" Bokeh.index[id].model.document.clear();\n",
" delete Bokeh.index[id];\n",
" }\n",
"\n",
" if (server_id !== undefined) {\n",
" // Clean up Bokeh references\n",
" var cmd = \"from bokeh.io.state import curstate; print(curstate().uuid_to_server['\" + server_id + \"'].get_sessions()[0].document.roots[0]._id)\";\n",
" cell.notebook.kernel.execute(cmd, {\n",
" iopub: {\n",
" output: function(msg) {\n",
" var id = msg.content.text.trim();\n",
" if (id in Bokeh.index) {\n",
" Bokeh.index[id].model.document.clear();\n",
" delete Bokeh.index[id];\n",
" }\n",
" }\n",
" }\n",
" });\n",
" // Destroy server and session\n",
" var cmd = \"import bokeh.io.notebook as ion; ion.destroy_server('\" + server_id + \"')\";\n",
" cell.notebook.kernel.execute(cmd);\n",
" }\n",
" }\n",
"\n",
" /**\n",
" * Handle when a new output is added\n",
" */\n",
" function handleAddOutput(event, handle) {\n",
" var output_area = handle.output_area;\n",
" var output = handle.output;\n",
"\n",
" // limit handleAddOutput to display_data with EXEC_MIME_TYPE content only\n",
" if ((output.output_type != \"display_data\") || (!output.data.hasOwnProperty(EXEC_MIME_TYPE))) {\n",
" return\n",
" }\n",
"\n",
" var toinsert = output_area.element.find(\".\" + CLASS_NAME.split(' ')[0]);\n",
"\n",
" if (output.metadata[EXEC_MIME_TYPE][\"id\"] !== undefined) {\n",
" toinsert[toinsert.length - 1].firstChild.textContent = output.data[JS_MIME_TYPE];\n",
" // store reference to embed id on output_area\n",
" output_area._bokeh_element_id = output.metadata[EXEC_MIME_TYPE][\"id\"];\n",
" }\n",
" if (output.metadata[EXEC_MIME_TYPE][\"server_id\"] !== undefined) {\n",
" var bk_div = document.createElement(\"div\");\n",
" bk_div.innerHTML = output.data[HTML_MIME_TYPE];\n",
" var script_attrs = bk_div.children[0].attributes;\n",
" for (var i = 0; i < script_attrs.length; i++) {\n",
" toinsert[toinsert.length - 1].firstChild.setAttribute(script_attrs[i].name, script_attrs[i].value);\n",
" toinsert[toinsert.length - 1].firstChild.textContent = bk_div.children[0].textContent\n",
" }\n",
" // store reference to server id on output_area\n",
" output_area._bokeh_server_id = output.metadata[EXEC_MIME_TYPE][\"server_id\"];\n",
" }\n",
" }\n",
"\n",
" function register_renderer(events, OutputArea) {\n",
"\n",
" function append_mime(data, metadata, element) {\n",
" // create a DOM node to render to\n",
" var toinsert = this.create_output_subarea(\n",
" metadata,\n",
" CLASS_NAME,\n",
" EXEC_MIME_TYPE\n",
" );\n",
" this.keyboard_manager.register_events(toinsert);\n",
" // Render to node\n",
" var props = {data: data, metadata: metadata[EXEC_MIME_TYPE]};\n",
" render(props, toinsert[toinsert.length - 1]);\n",
" element.append(toinsert);\n",
" return toinsert\n",
" }\n",
"\n",
" /* Handle when an output is cleared or removed */\n",
" events.on('clear_output.CodeCell', handleClearOutput);\n",
" events.on('delete.Cell', handleClearOutput);\n",
"\n",
" /* Handle when a new output is added */\n",
" events.on('output_added.OutputArea', handleAddOutput);\n",
"\n",
" /**\n",
" * Register the mime type and append_mime function with output_area\n",
" */\n",
" OutputArea.prototype.register_mime_type(EXEC_MIME_TYPE, append_mime, {\n",
" /* Is output safe? */\n",
" safe: true,\n",
" /* Index of renderer in `output_area.display_order` */\n",
" index: 0\n",
" });\n",
" }\n",
"\n",
" // register the mime type if in Jupyter Notebook environment and previously unregistered\n",
" if (root.Jupyter !== undefined) {\n",
" var events = require('base/js/events');\n",
" var OutputArea = require('notebook/js/outputarea').OutputArea;\n",
"\n",
" if (OutputArea.prototype.mime_types().indexOf(EXEC_MIME_TYPE) == -1) {\n",
" register_renderer(events, OutputArea);\n",
" }\n",
" }\n",
"\n",
" \n",
" if (typeof (root._bokeh_timeout) === \"undefined\" || force === true) {\n",
" root._bokeh_timeout = Date.now() + 5000;\n",
" root._bokeh_failed_load = false;\n",
" }\n",
"\n",
" var NB_LOAD_WARNING = {'data': {'text/html':\n",
" \"
\\n\"+\n",
" \"

\\n\"+\n",
" \"BokehJS does not appear to have successfully loaded. If loading BokehJS from CDN, this \\n\"+\n",
" \"may be due to a slow or bad network connection. Possible fixes:\\n\"+\n",
" \"

\\n\"+\n",
" \"
    \\n\"+\n",
    " \"
  • re-rerun `output_notebook()` to attempt to load from CDN again, or
  • \\n\"+\n",
    " \"
  • use INLINE resources instead, as so:
  • \\n\"+\n",
    " \"
\\n\"+\n",
" \"\\n\"+\n",
" \"from bokeh.resources import INLINE\\n\"+\n",
" \"output_notebook(resources=INLINE)\\n\"+\n",
" \"
\\n\"+\n",
" \"
\"}};\n",
"\n",
" function display_loaded() {\n",
" var el = document.getElementById(null);\n",
" if (el != null) {\n",
" el.textContent = \"BokehJS is loading...\";\n",
" }\n",
" if (root.Bokeh !== undefined) {\n",
" if (el != null) {\n",
" el.textContent = \"BokehJS \" + root.Bokeh.version + \" successfully loaded.\";\n",
" }\n",
" } else if (Date.now() < root._bokeh_timeout) {\n",
" setTimeout(display_loaded, 100)\n",
" }\n",
" }\n",
"\n",
"\n",
" function run_callbacks() {\n",
" try {\n",
" root._bokeh_onload_callbacks.forEach(function(callback) {\n",
" if (callback != null)\n",
" callback();\n",
" });\n",
" } finally {\n",
" delete root._bokeh_onload_callbacks\n",
" }\n",
" console.debug(\"Bokeh: all callbacks have finished\");\n",
" }\n",
"\n",
" function load_libs(css_urls, js_urls, callback) {\n",
" if (css_urls == null) css_urls = [];\n",
" if (js_urls == null) js_urls = [];\n",
"\n",
" root._bokeh_onload_callbacks.push(callback);\n",
" if (root._bokeh_is_loading > 0) {\n",
" console.debug(\"Bokeh: BokehJS is being loaded, scheduling callback at\", now());\n",
" return null;\n",
" }\n",
" if (js_urls == null || js_urls.length === 0) {\n",
" run_callbacks();\n",
" return null;\n",
" }\n",
" console.debug(\"Bokeh: BokehJS not loaded, scheduling load and callback at\", now());\n",
" root._bokeh_is_loading = css_urls.length + js_urls.length;\n",
"\n",
" function on_load() {\n",
" root._bokeh_is_loading--;\n",
" if (root._bokeh_is_loading === 0) {\n",
" console.debug(\"Bokeh: all BokehJS libraries/stylesheets loaded\");\n",
" run_callbacks()\n",
" }\n",
" }\n",
"\n",
" function on_error() {\n",
" console.error(\"failed to load \" + url);\n",
" }\n",
"\n",
" for (var i = 0; i < css_urls.length; i++) {\n",
" var url = css_urls[i];\n",
" const element = document.createElement(\"link\");\n",
" element.onload = on_load;\n",
" element.onerror = on_error;\n",
" element.rel = \"stylesheet\";\n",
" element.type = \"text/css\";\n",
" element.href = url;\n",
" console.debug(\"Bokeh: injecting link tag for BokehJS stylesheet: \", url);\n",
" document.body.appendChild(element);\n",
" }\n",
"\n",
" const hashes = {\"https://cdn.bokeh.org/bokeh/release/bokeh-2.2.3.min.js\": \"T2yuo9Oe71Cz/I4X9Ac5+gpEa5a8PpJCDlqKYO0CfAuEszu1JrXLl8YugMqYe3sM\", \"https://cdn.bokeh.org/bokeh/release/bokeh-widgets-2.2.3.min.js\":...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here