Skip to content

Commit

Permalink
more detailed streamlines
Browse files Browse the repository at this point in the history
  • Loading branch information
Fedor Baart committed May 25, 2018
1 parent 37c47eb commit 3028024
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 1 deletion.
2 changes: 1 addition & 1 deletion flowmap/particles.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
def make_tracer_pipeline(
polydata,
seed,
maximum_number_of_steps=200,
maximum_number_of_steps=3000,
maximum_propagation=1000
):
"""Make a tracer pileine based on a polydata and seed.
Expand Down
109 changes: 109 additions & 0 deletions notebooks/create_quiver.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [],
"source": [
"import netCDF4\n",
"import geojson\n",
"import numpy as np\n",
"import shapely.geometry"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"ds = netCDF4.Dataset('/Users/baart_f/data/rijnland/vanGovert/Leerdam/leerdamwest_map.nc')"
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {},
"outputs": [],
"source": [
"\n",
"x = ds.variables['mesh2d_face_x'][:]\n",
"y = ds.variables['mesh2d_face_y'][:]\n",
"ucx = ds.variables['mesh2d_ucx'][-1]\n",
"ucy = ds.variables['mesh2d_ucy'][-1]\n",
"angles = np.rad2deg(np.arctan2(ucy, ucx))\n",
"lengths = np.sqrt(ucx ** 2 + ucy **2 )"
]
},
{
"cell_type": "code",
"execution_count": 34,
"metadata": {},
"outputs": [],
"source": [
"crs = geojson.crs.Named(\n",
" properties={\n",
" \"name\": \"urn:ogc:def:crs:EPSG::{:d}\".format(28992)\n",
" }\n",
")\n",
"features= []\n",
"for i, (x_i, y_i, angle_i, length_i, u_i, v_i) in enumerate(zip(x, y, angles, lengths, ucx, ucy)):\n",
" point = shapely.geometry.Point(x_i, y_i)\n",
" geometry = point.__geo_interface__\n",
" geometry['crs'] = dict(crs)\n",
" feature = geojson.Feature(\n",
" id=i, \n",
" geometry=geometry, \n",
" properties={\n",
" \"angle_east_ccw\": angle_i,\n",
" \"angle_north_cw\": 90 - angle_i,\n",
" \"length\": length_i,\n",
" \"u\": u_i,\n",
" \"v\": v_i\n",
" }\n",
" )\n",
" features.append(feature)\n"
]
},
{
"cell_type": "code",
"execution_count": 35,
"metadata": {},
"outputs": [],
"source": [
"fc = geojson.FeatureCollection(features=features)\n",
"with open('quiver.json', 'w') as f:\n",
" geojson.dump(fc, f)\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.5"
}
},
"nbformat": 4,
"nbformat_minor": 2
}

0 comments on commit 3028024

Please sign in to comment.