Comments (8)
Yes -10 is inland termination, while -9 is for usual river mouth flowing to ocean,
from pyflwdir.
Hi @Jiangchao3,
Thanks for using pyflwdir!
I had a look at your data and noticed that pits have a value of -10 instead of -9 in the nextxy data. Perhaps this has changed in the recent CaMa-Flood updates? Pinging Prof Yamazaki (@bigasmountain) here to confirm this has indeed changed in which case I'll update the code.
For now you can just change the pit values in the nextxy data to use pyflwdir.
import pyflwdir import rasterio import numpy as np # read data with rasterio.open('nextxy.tif') as src: data = src.read() transform = src.transform latlon = src.crs.is_geographic # change pit values and parse with pyflwdir data = np.where(data==-10, -9, data) flw = pyflwdir.from_array(data, ftype='nextxy')
To make nice visualization you will want to use either the
vectorize
orstreams
method. Both methods can take an additionalxs
andys
argument with the outlet x and y coordinates which will make your visualizations look much better.Hope this helps! Dirk
PS. For a next issue anywhere on github it is always useful if you paste the actual code instead of a screenshot to quickly be able to reproduce it. Otherwise your issue was really clear and had the data for me to debug it!
Hi @DirkEilander , your recomended script worked after replace the pits of -10 with -9. I will spend some time to further learn the whole package of pyflwdir. And looking forward to your update of the code to be able to parse the new river network dataset of cama-flood. Many thanks for your kindly help.
from pyflwdir.
This is fixed in 16b1ac0 (still unrealeased - for now you get the update by updating pyflwdir directly from git)
In addition I've added a convenience method to read the binary CaMa-Flood nextxy data.
The following example should provide a nice plot of your CaMa-Flood rivers.
# %%
import pyflwdir
# %% read data
bbox=[-180, -90, 180, 90]
data, transform = pyflwdir.read_nextxy(
fn='nextxy.bin', nrow=720, ncol=1440, bbox=bbox
)
flw = pyflwdir.from_array(
data,
ftype='nextxy',
latlon=True,
transform = transform
)
# %% vectorize streams
import geopandas as gpd
feats = flw.streams(strord=flw.stream_order(), min_sto=2)
gdf = gpd.GeoDataFrame.from_features(feats, crs=4326)
# %% drop lines crossing anti-meridian
import numpy as np
def check_crossing(line):
return np.any(np.abs(np.diff([xy[0] for xy in line.coords[:]]))>180)
drop_lines = np.vectorize(check_crossing)(gdf.geometry)
gdf1 = gdf[~drop_lines]
#%% plot values by stream order
gdf1.sort_values('strord').plot(column='strord')
from pyflwdir.
Hi @DirkEilander, the above script you provided works well, many thanks to your sincere help!
from pyflwdir.
And I also email to Prof. Dai Yamazaki, he replied that the traditionary GMT and Fortran code for river network visualization don't work now, so I am trying to learn the pyflwdir toolbox recently.
from pyflwdir.
Hi @Jiangchao3,
Thanks for using pyflwdir!
I had a look at your data and noticed that pits have a value of -10 instead of -9 in the nextxy data. Perhaps this has changed in the recent CaMa-Flood updates? Pinging Prof Yamazaki (@bigasmountain) here to confirm this has indeed changed in which case I'll update the code.
For now you can just change the pit values in the nextxy data to use pyflwdir.
import pyflwdir
import rasterio
import numpy as np
# read data
with rasterio.open('nextxy.tif') as src:
data = src.read()
transform = src.transform
latlon = src.crs.is_geographic
# change pit values and parse with pyflwdir
data = np.where(data==-10, -9, data)
flw = pyflwdir.from_array(data, ftype='nextxy')
To make nice visualization you will want to use either the vectorize
or streams
method. Both methods can take an additional xs
and ys
argument with the outlet x and y coordinates which will make your visualizations look much better.
Hope this helps!
Dirk
PS. For a next issue anywhere on github it is always useful if you paste the actual code instead of a screenshot to quickly be able to reproduce it. Otherwise your issue was really clear and had the data for me to debug it!
from pyflwdir.
Hi @DirkEilander and @bigasmountain, thanks very much for your kindly reply.
I will follow your suggestions to paste the code instead of screenshot on any of my next github issue.
And yes I also noticed that the latest CaMa-Flood manual describes that -10 represents the inland termination while -9 represents the river mouth.
from pyflwdir.
So great for providing such a detailed script. I will check it after getting back to office tomorrow! Thanks again!
from pyflwdir.
Related Issues (20)
- Distance to river network HOT 3
- User guide instructions for plotting import error HOT 2
- Failed read MERIT flowdir HOT 4
- Subcatchment routing hierarchy by landuse HOT 8
- unexpected results adjust_dem
- prioritize non-boundary cells with same elevation over boundary cells in dem.fill_depressions
- fix version number in docs
- error in plotting the river mouths using the nextxy.bin dataset HOT 7
- increase short river lengths
- Question: How can I create shapefiles of the upstream area of >10,000 points? HOT 2
- subgrid floodplain schematization
- river branch map
- check compatibility with latest numpy and py3.11
- No implementation of function Function(<built-in function heappush>) found for signature HOT 5
- method to get all upstream nodes for vector based flow directions
- working with circular grids HOT 1
- FlwdirRaster.stream crashed on a ~44000x20000 raster on a machine with 16 GB or less
- FlwdirRaster.accuflux() segmentation faults with a raster ~ (63000, 80000) on machine with >1Tb RAM HOT 9
- Helper function to get coordinates from linear indices HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pyflwdir.