Skip to content

Instantly share code, notes, and snippets.

@rabbl
Created December 13, 2023 09:05
Show Gist options
  • Save rabbl/4fb909484f45da7ffd75f3f0ab77f88e to your computer and use it in GitHub Desktop.
Save rabbl/4fb909484f45da7ffd75f3f0ab77f88e to your computer and use it in GitHub Desktop.
Rio Primero
This file has been truncated, but you can view the full file.
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"outputs": [],
"source": [
"import sys\n",
"\n",
"sys.path.insert(0, '..')"
],
"metadata": {
"collapsed": false,
"ExecuteTime": {
"end_time": "2023-12-13T09:00:41.820741Z",
"start_time": "2023-12-13T09:00:41.658892Z"
}
},
"id": "ba6761fae9d5e5cb"
},
{
"cell_type": "markdown",
"source": [
"## Setup the Rio Primero project"
],
"metadata": {
"collapsed": false
},
"id": "5ede1ba5e0993dd1"
},
{
"cell_type": "code",
"execution_count": 2,
"outputs": [],
"source": [
"\n",
"from morpheus.modflow.types.ModflowModel import ModflowModel, SpatialDiscretization\n",
"from morpheus.modflow.types.geometry import Polygon\n",
"from morpheus.modflow.types.discretization.spatial import Grid, Rotation\n",
"from morpheus.modflow.types.Metadata import Name, Description, Tags, Metadata\n",
"from morpheus.modflow.types.Project import Project\n",
"from morpheus.modflow.types.User import UserId\n",
"\n",
"user_id = UserId.new()\n",
"\n",
"project = (Project.new(user_id=user_id).with_updated_metadata(\n",
" metadata=Metadata(\n",
" name=Name('Rio Primero'),\n",
" description=Description('Rio Primero Project in Argentina'),\n",
" tags=Tags.from_list(['rio primero', 'argentina'])\n",
" )\n",
"))\n",
"\n",
"model = ModflowModel.new()\n",
"project = project.with_updated_base_model(model)\n",
"model = project.base_model\n",
"\n",
"area = Polygon([[\n",
" (-63.687336, -31.313615),\n",
" (-63.687336, -31.367449),\n",
" (-63.56926, -31.367449),\n",
" (-63.56926, -31.313615),\n",
" (-63.687336, -31.313615)\n",
"]])\n",
"\n",
"spatial_discretization = SpatialDiscretization.from_geometry_with_grid(\n",
" geometry=area,\n",
" grid=Grid.cartesian_from_polygon(\n",
" polygon=area,\n",
" nx=75,\n",
" ny=40,\n",
" rotation=Rotation(0),\n",
" ),\n",
")\n",
"\n",
"model = model.with_updated_spatial_discretization(spatial_discretization=spatial_discretization)"
],
"metadata": {
"collapsed": false,
"ExecuteTime": {
"end_time": "2023-12-13T09:00:42.422406Z",
"start_time": "2023-12-13T09:00:41.669182Z"
}
},
"id": "80429d864c4101f1"
},
{
"cell_type": "markdown",
"source": [
"## Setup Time Discretization"
],
"metadata": {
"collapsed": false
},
"id": "fa27e67f9d801845"
},
{
"cell_type": "code",
"execution_count": 3,
"outputs": [],
"source": [
"from morpheus.modflow.types.discretization.time.TimeUnit import TimeUnit\n",
"from morpheus.modflow.types.discretization.time.Stressperiods import StartDateTime, StressPeriodCollection, \\\n",
" StressPeriod, NumberOfTimeSteps, TimeStepMultiplier, IsSteadyState\n",
"from morpheus.modflow.types.discretization.time import TimeDiscretization\n",
"from datetime import datetime\n",
"\n",
"time_discretization = TimeDiscretization(\n",
" start_date_time=StartDateTime.from_datetime(datetime(2015, 1, 1)),\n",
" end_date_time=StartDateTime.from_datetime(datetime(2020, 12, 31)),\n",
" stress_periods=StressPeriodCollection([\n",
" StressPeriod(\n",
" start_date_time=StartDateTime.from_datetime(datetime(2015, 1, 1)),\n",
" number_of_time_steps=NumberOfTimeSteps(1),\n",
" time_step_multiplier=TimeStepMultiplier(1),\n",
" steady_state=IsSteadyState.yes()\n",
" ),\n",
" ]),\n",
" time_unit=TimeUnit.days()\n",
")\n",
"\n",
"model = model.with_updated_time_discretization(time_discretization=time_discretization)"
],
"metadata": {
"collapsed": false,
"ExecuteTime": {
"end_time": "2023-12-13T09:00:42.429183Z",
"start_time": "2023-12-13T09:00:42.424454Z"
}
},
"id": "8e4e63dd138db9fc"
},
{
"cell_type": "code",
"execution_count": 4,
"outputs": [
{
"data": {
"text/plain": "<folium.folium.Map at 0x137be8560>",
"text/html": "<div style=\"width:100%;\"><div style=\"position:relative;width:100%;height:0;padding-bottom:60%;\"><span style=\"color:#565656\">Make this Notebook Trusted to load map: File -> Trust Notebook</span><iframe srcdoc=\"&lt;!DOCTYPE html&gt;\n&lt;html&gt;\n&lt;head&gt;\n \n &lt;meta http-equiv=&quot;content-type&quot; content=&quot;text/html; charset=UTF-8&quot; /&gt;\n \n &lt;script&gt;\n L_NO_TOUCH = false;\n L_DISABLE_3D = false;\n &lt;/script&gt;\n \n &lt;style&gt;html, body {width: 100%;height: 100%;margin: 0;padding: 0;}&lt;/style&gt;\n &lt;style&gt;#map {position:absolute;top:0;bottom:0;right:0;left:0;}&lt;/style&gt;\n &lt;script src=&quot;https://cdn.jsdelivr.net/npm/leaflet@1.9.3/dist/leaflet.js&quot;&gt;&lt;/script&gt;\n &lt;script src=&quot;https://code.jquery.com/jquery-3.7.1.min.js&quot;&gt;&lt;/script&gt;\n &lt;script src=&quot;https://cdn.jsdelivr.net/npm/bootstrap@5.2.2/dist/js/bootstrap.bundle.min.js&quot;&gt;&lt;/script&gt;\n &lt;script src=&quot;https://cdnjs.cloudflare.com/ajax/libs/Leaflet.awesome-markers/2.0.2/leaflet.awesome-markers.js&quot;&gt;&lt;/script&gt;\n &lt;link rel=&quot;stylesheet&quot; href=&quot;https://cdn.jsdelivr.net/npm/leaflet@1.9.3/dist/leaflet.css&quot;/&gt;\n &lt;link rel=&quot;stylesheet&quot; href=&quot;https://cdn.jsdelivr.net/npm/bootstrap@5.2.2/dist/css/bootstrap.min.css&quot;/&gt;\n &lt;link rel=&quot;stylesheet&quot; href=&quot;https://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css&quot;/&gt;\n &lt;link rel=&quot;stylesheet&quot; href=&quot;https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@6.2.0/css/all.min.css&quot;/&gt;\n &lt;link rel=&quot;stylesheet&quot; href=&quot;https://cdnjs.cloudflare.com/ajax/libs/Leaflet.awesome-markers/2.0.2/leaflet.awesome-markers.css&quot;/&gt;\n &lt;link rel=&quot;stylesheet&quot; href=&quot;https://cdn.jsdelivr.net/gh/python-visualization/folium/folium/templates/leaflet.awesome.rotate.min.css&quot;/&gt;\n \n &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width,\n initial-scale=1.0, maximum-scale=1.0, user-scalable=no&quot; /&gt;\n &lt;style&gt;\n #map_34d8ed398b2a6f308f730d567c99aaab {\n position: relative;\n width: 100.0%;\n height: 100.0%;\n left: 0.0%;\n top: 0.0%;\n }\n .leaflet-container { font-size: 1rem; }\n &lt;/style&gt;\n \n&lt;/head&gt;\n&lt;body&gt;\n \n \n &lt;div class=&quot;folium-map&quot; id=&quot;map_34d8ed398b2a6f308f730d567c99aaab&quot; &gt;&lt;/div&gt;\n \n&lt;/body&gt;\n&lt;script&gt;\n \n \n var map_34d8ed398b2a6f308f730d567c99aaab = L.map(\n &quot;map_34d8ed398b2a6f308f730d567c99aaab&quot;,\n {\n center: [50.965, 13.922],\n crs: L.CRS.EPSG3857,\n zoom: 12,\n zoomControl: true,\n preferCanvas: false,\n }\n );\n\n \n\n \n \n var tile_layer_f852f1648f14b6774a9e9c58e4e40c90 = L.tileLayer(\n &quot;https://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}{r}.png&quot;,\n {&quot;attribution&quot;: &quot;\\u0026copy; \\u003ca href=\\&quot;https://www.openstreetmap.org/copyright\\&quot;\\u003eOpenStreetMap\\u003c/a\\u003e contributors \\u0026copy; \\u003ca href=\\&quot;https://carto.com/attributions\\&quot;\\u003eCARTO\\u003c/a\\u003e&quot;, &quot;detectRetina&quot;: false, &quot;maxNativeZoom&quot;: 20, &quot;maxZoom&quot;: 20, &quot;minZoom&quot;: 0, &quot;noWrap&quot;: false, &quot;opacity&quot;: 1, &quot;subdomains&quot;: &quot;abcd&quot;, &quot;tms&quot;: false}\n );\n \n \n tile_layer_f852f1648f14b6774a9e9c58e4e40c90.addTo(map_34d8ed398b2a6f308f730d567c99aaab);\n \n \n\n function geo_json_ae8a2ecfd5989651e43e1a48846b54d9_onEachFeature(feature, layer) {\n layer.on({\n });\n };\n var geo_json_ae8a2ecfd5989651e43e1a48846b54d9 = L.geoJson(null, {\n onEachFeature: geo_json_ae8a2ecfd5989651e43e1a48846b54d9_onEachFeature,\n \n });\n\n function geo_json_ae8a2ecfd5989651e43e1a48846b54d9_add (data) {\n geo_json_ae8a2ecfd5989651e43e1a48846b54d9\n .addData(data);\n }\n geo_json_ae8a2ecfd5989651e43e1a48846b54d9_add({&quot;coordinates&quot;: [[[-63.687336, -31.313615], [-63.687336, -31.367449], [-63.56926, -31.367449], [-63.56926, -31.313615], [-63.687336, -31.313615]]], &quot;type&quot;: &quot;Polygon&quot;});\n\n \n \n geo_json_ae8a2ecfd5989651e43e1a48846b54d9.addTo(map_34d8ed398b2a6f308f730d567c99aaab);\n \n \n map_34d8ed398b2a6f308f730d567c99aaab.fitBounds(\n [[-31.367449, -63.687336], [-31.313615, -63.56926]],\n {}\n );\n \n&lt;/script&gt;\n&lt;/html&gt;\" style=\"position:absolute;width:100%;height:100%;left:0;top:0;border:none !important;\" allowfullscreen webkitallowfullscreen mozallowfullscreen></iframe></div></div>"
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import folium\n",
"\n",
"m = folium.Map(tiles=\"cartodbpositron\", crs=\"EPSG3857\", zoom_start=12, location=[50.965, 13.922])\n",
"m.add_child(folium.GeoJson(model.spatial_discretization.geometry.as_geojson()))\n",
"\n",
"m.fit_bounds(m.get_bounds())\n",
"m"
],
"metadata": {
"collapsed": false,
"ExecuteTime": {
"end_time": "2023-12-13T09:00:42.569641Z",
"start_time": "2023-12-13T09:00:42.427314Z"
}
},
"id": "1540b870ae83f298"
},
{
"cell_type": "code",
"execution_count": 5,
"outputs": [
{
"data": {
"text/plain": "<folium.folium.Map at 0x137be8560>",
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment