Skip to content

Commit

Permalink
update notebook
Browse files Browse the repository at this point in the history
  • Loading branch information
changliao1025 committed Aug 23, 2023
1 parent ec59d72 commit 518756f
Showing 1 changed file with 77 additions and 32 deletions.
109 changes: 77 additions & 32 deletions notebooks/mpas_example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,48 @@
"import os\n",
"import sys\n",
"from pathlib import Path\n",
"from os.path import realpath"
"from os.path import realpath\n",
"import importlib"
]
},
{
"cell_type": "markdown",
"id": "bf81807a",
"metadata": {},
"source": [
"Then we will check whether some additional packages are installed.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a75e5100",
"metadata": {},
"outputs": [],
"source": [
"#check pyflowline\n",
"iFlag_pyflowline = importlib.util.find_spec(\"pyflowline\") \n",
"if iFlag_pyflowline is not None:\n",
" pass\n",
"else:\n",
" print('The pyflowline package is not installed. Please install it following the quickstart document.')\n",
"\n",
"#check optional packages \n",
"iFlag_cython = importlib.util.find_spec(\"cython\") \n",
"iFlag_cartopy = importlib.util.find_spec(\"cartopy\") \n",
"iFlag_geopandas = importlib.util.find_spec(\"geopandas\") \n",
"if iFlag_cartopy is not None:\n",
" iFlag_cartopy = 1\n",
" pass\n",
"else:\n",
" #if cartopy is not avaialble, we will use the geopanda for visualization\n",
" if iFlag_geopandas is not None:\n",
" pass\n",
" else:\n",
" print('We will install the geopandas package for visualization.')\n",
" !conda install --yes --prefix {sys.prefix} gepandas\n",
" iFlag_geopandas = 1\n",
" pass\n"
]
},
{
Expand Down Expand Up @@ -419,25 +460,26 @@
}
],
"source": [
"iVisualization_method = 1\n",
"if iVisualization_method == 1: # you need to install the geopanda package and matplotlib package using conda or pip\n",
" import geopandas as gpd\n",
" import matplotlib.pyplot as plt\n",
" #use the geopanda package\n",
" #the raw/original geojson file \n",
" sFilename_geojson = oPyflowline.aBasin[0].sFilename_flowline_filter_geojson\n",
" gdf = gpd.read_file(sFilename_geojson)\n",
" gdf.plot()\n",
" plt.show()\n",
"\n",
" pass\n",
"\n",
"else: #use the default visualization method, only experimental\n",
"\n",
"if iFlag_cartopy == 1: # you need to install the geopanda package and matplotlib package using conda or pip\n",
" oPyflowline.plot(sVariable_in = 'flowline_filter' )\n",
" #if you provide a filename, a png file will be saved\n",
" oPyflowline.plot(sVariable_in = 'flowline_filter', sFilename_in = 'filter_flowline.png' )\n",
" pass"
" pass\n",
"else: #use the default visualization method, only experimental\n",
" if iFlag_geopandas = 1:\n",
" import geopandas as gpd\n",
" import matplotlib.pyplot as plt\n",
" #use the geopanda package\n",
" #the raw/original geojson file \n",
" sFilename_geojson = oPyflowline.aBasin[0].sFilename_flowline_filter_geojson\n",
" gdf = gpd.read_file(sFilename_geojson)\n",
" gdf.plot()\n",
" plt.show()\n",
" else:\n",
" print('The visulization packages are not installed.')\n",
" pass\n",
" "
]
},
{
Expand Down Expand Up @@ -491,7 +533,7 @@
"source": [
"\n",
"#the default visualization method has an option to set the extent you want to plot\n",
"if iVisualization_method ==2:\n",
"if iFlag_cartopy ==1:\n",
" #aExtent_full = [-78.5,-75.5, 39.2,42.5]\n",
" aExtent_meander = [-76.5,-76.2, 41.6,41.9] \n",
" oPyflowline.plot( sVariable_in = 'flowline_filter', aExtent_in = aExtent_meander )"
Expand All @@ -515,7 +557,7 @@
}
],
"source": [
"if iVisualization_method ==2:\n",
"if iFlag_cartopy ==1:\n",
" aExtent_braided = [-77.3,-76.5, 40.2,41.0] \n",
" oPyflowline.plot( sVariable_in='flowline_filter' , aExtent_in =aExtent_braided ) "
]
Expand Down Expand Up @@ -604,7 +646,11 @@
],
"source": [
"\n",
"if iVisualization_method == 1: # you need to install the geopanda package and matplotlib package using conda or pip\n",
"if iFlag_cartopy == 1: # use the default visualization method, only experimental\n",
" oPyflowline.plot( sVariable_in='flowline_simplified' ) \n",
"\n",
"else: \n",
" \n",
" import geopandas as gpd\n",
" import matplotlib.pyplot as plt\n",
" #use the geopanda package\n",
Expand All @@ -614,10 +660,7 @@
" gdf.plot()\n",
" plt.show()\n",
"\n",
" pass\n",
"\n",
"else: #use the default visualization method, only experimental\n",
" oPyflowline.plot( sVariable_in='flowline_simplified' ) "
" pass"
]
},
{
Expand Down Expand Up @@ -751,7 +794,11 @@
}
],
"source": [
"if iVisualization_method == 1: # you need to install the geopanda package and matplotlib package using conda or pip\n",
"if iFlag_cartopy == 1: # you need to install the geopanda package and matplotlib package using conda or pip\n",
" oPyflowline.plot( sVariable_in='mesh' ) \n",
"\n",
"else:\n",
" \n",
" import geopandas as gpd\n",
" import matplotlib.pyplot as plt\n",
" #use the geopanda package\n",
Expand All @@ -761,10 +808,7 @@
" gdf.plot()\n",
" plt.show()\n",
"\n",
" pass\n",
"\n",
"else:\n",
" oPyflowline.plot( sVariable_in='mesh' ) "
" pass"
]
},
{
Expand Down Expand Up @@ -879,7 +923,11 @@
],
"source": [
"\n",
"if iVisualization_method == 1: \n",
"if iFlag_cartopy == 1: \n",
" oPyflowline.plot( sVariable_in='overlap') \n",
" pass\n",
"else:\n",
" \n",
" #\n",
" file1_path = oPyflowline.aBasin[0].sFilename_mesh_geojson\n",
" file2_path = oPyflowline.aBasin[0].sFilename_flowline_conceptual_geojson\n",
Expand All @@ -889,9 +937,6 @@
" gdf1.plot(ax=ax, color='blue')\n",
" gdf2.plot(ax=ax, color='red')\n",
" plt.show()\n",
" pass\n",
"else:\n",
" oPyflowline.plot( sVariable_in='overlap') \n",
" pass"
]
},
Expand Down

0 comments on commit 518756f

Please sign in to comment.