Masking nodata when reading in a DEM file? #127
Replies: 5 comments 15 replies
-
As you said the right plot could be just due to large fill values, but I don't understand what the problem is with that plot in terms of OCSMesh use? For the size function, if your concern is having a lot of elements in the regions where you don't have any data, I suggest using a large hmax, so that all the regions without actual bathymetry data will get the largest size. The raster size function takes the whole DEM bbox for meshing. Then add a contour or constant value size of your actual hmax size at the max elevation level you're interested in. |
Beta Was this translation helpful? Give feedback.
-
The plot on the right is of the ocsmesh.raster.Raster object before I add any contours which I was hoping to use as a guide to determine where to add contours based on the bathymetry. I'd never used rasterio before starting to work with ocsmesh, so I'm having a hard time plotting the raster and masking (or at least just not plotting) all of the large fill values that are added within the bounding box of the raster but outside of the actual DEM data. I was, however, able to look at the DEM in ArcGIS Pro and tried adding the contour lines based on that. It seems like the way that the contours ended up is opposite of what I intended. I wanted the smaller element sizes along the shoreline/floodplain of the lake and then increase towards the center, but it looks like the smaller element sizes are in the middle and there are only a couple contours (I added 8 in total). The code I have for adding the contours is below:
The ref_r1 value is 74.5 which is the mean surface elevation for Lake Ontario and generally where the coastline is and is also what I used to reference all the levels for the contours. In ArcGIS Pro the DEM got more negative deeper into the lake and more positive outside of the lake which is how I approached adding the contours but that's not how it ended up in the size function (pictured below on the left). It looks a little better than the first attempt I made which I pictured in the original discussion comment I made, but I was trying to get it to resemble this more: but I'm not sure what is wrong with the way that I added the contours so that it's not doing that.. |
Beta Was this translation helpful? Give feedback.
-
Unfortunately I ran the code again with just 2 contours/constants and so far it's been stuck in the same spot as before for about 2.5 hours. I tried it again with 2 different contours/constants to see if that will work but so far it seems like it may also take a long time. What is the easiest way to share the DEM with you? It's about 2.7 gb |
Beta Was this translation helpful? Give feedback.
-
@melissamattwig I tried running the script you provided and ran into memory issue (on my laptop). As you said the DEM is very high resolution (~10k x 40k pixels), which also results in very slow operations in general. The first thing I tried was to try processing the raster in chunks (passing r1 = ocsmesh.Raster(
'from_Melissa/LakeOntarioSeamlessDEMMeshTeamwithStLaurencev3PE15m.tif',
chunk_size=5000,
overlap=100) It successfully went through
but failed at
with a weird error related to multiprocessing (I'm still not sure why). I suggest that you first try the chunking as described above - maybe even try chunks of size To reduce the DEM resolution in OCSMesh you can use method: Lines 1153 to 1156 in 0563a79 I'll wait until you try these out, if these don't help we can again think of other solutions. Right now I don't have a better solution in mind. |
Beta Was this translation helpful? Give feedback.
-
@melissamattwig I was able to get a size function like the snapshot in less than an hour on my laptop. I added a feature in OCSMesh that you need to add in your meshing script to generate the size function faster. I'm still testing it, when it's ready I'll let you know here. |
Beta Was this translation helpful? Give feedback.
-
Is there a way to mask nodata values in a DEM? I'm trying to create a large mesh of Lake Ontario and I'm starting with using a very large DEM to start before adding additional, higher resolution lidar data. I added two contours just to see what it would look like (on the left) and also tried plotting the values of the original DEM raster file and I'm getting a very binary looking plot (on the right).
When I made a plot of the histogram for this DEM file it seems like there is a lot of nodata or fill values because when I read in the DEM using rasterio and having
masked=True
, the values are a lot more evenly distributed.Please let me know if there is a solution or if I am misinterpreting how I should be working with this DEM. Thank you!
Beta Was this translation helpful? Give feedback.
All reactions