-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #58 from openearth/feature/interpolation-mask
implement a better feature interpolation mask
- Loading branch information
Showing
4 changed files
with
164 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |