Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unexpected behavior for add_contour method #154

Closed
simonweppe opened this issue Jun 12, 2024 · 12 comments
Closed

unexpected behavior for add_contour method #154

simonweppe opened this issue Jun 12, 2024 · 12 comments
Assignees

Comments

@simonweppe
Copy link

Hi @SorooshMani-NOAA ,

Im running into a strange issue when using the add_contour method.

I have defined a shape file that I want to use as my domain, and have tif file with bathy information from which I want to define my size function.
See code below:

hfun_rasters = [Raster(p) for p in dem_paths] #  if memory issues chunk_size=500, overlap=50
size_mesh_min = 100
size_mesh_max = 1000
exp_rate = 0.005

hfun = Hfun(
    deepcopy(hfun_rasters),
    base_shape=base_gs.unary_union,
    base_shape_crs=base_gs.crs,
    hmin=size_mesh_min, 
    hmax=size_mesh_max,
    nprocs = 1, 
    #method='fast'
    )

hfun.add_constant_value(value=size_mesh_max) 
hfun.add_constant_value(value=size_mesh_min, lower_bound=-3, upper_bound=3) # constant element size for size function between lower_bound and upper bound
hfun.add_contour(level=-3, expansion_rate= exp_rate , target_size=size_mesh_min) # element size starts at 100m at depth = -3 below sea level, then expands

Im getting a mesh that is looking good and as expected, expect near the outer ocean boundary where it's refined to size_mesh_min. This seems to be due to the add_contour step, which specifies a size of 100 along the outer edge of my mesh, while it should relax to much larger element size given it's deep through there. As if the computed -3 contour was going around the outer edge of my grid (it's not the case in the tiff).
I've tried a few things and can get more relaxed resolution there using other approaches (e.g. add_topo_bound_constraint, add_subtidal_flow_limiter), but as soon as I use add_contour, I get that odd high res zone.

Am I missing something obvious ? See some snapshots below.

Screenshot from 2024-06-12 13-39-44
Screenshot from 2024-06-12 12-05-48

@SorooshMani-NOAA
Copy link
Collaborator

Hi, I think something has changed in matplotlib recently. Can you try using matplotlib version 3.5.2 and see if this resolves the issue or not?

@SorooshMani-NOAA SorooshMani-NOAA self-assigned this Jun 12, 2024
@SorooshMani-NOAA
Copy link
Collaborator

@felicio93 do you think this is related to #144? Have you had the chance to explore that other ticket?

@simonweppe
Copy link
Author

Thanks for the fast reply @SorooshMani-NOAA ..yes I saw this one other ticket but Im using matplotlib 3.5.1 so shouldnt be the issue.

@SorooshMani-NOAA
Copy link
Collaborator

Another possibility is that when the base shape "cuts" the DEM it creates nan regions. I remember seeing something similar to what you see a couple of years ago when I was implementing this. I don't remember if I ever had a good solution, something like this might work:

Try using the baseshape to create your geometry, but buffer the base shape before passing it to create hfun object. This way, the invalid contours due to cutting will fall outside the domain. Note that you need to play with the buffer size to get a good results with this approach.

@felicio93
Copy link
Collaborator

@SorooshMani-NOAA and @simonweppe,

I agree with I don't think this is related to the matlab problem, at least it is not the same problem.

I tried recreating 2 meshes using the same script I was using before (both cases worked). This is what I get now:

case1 - CA Mesh:
image

case2 - AK Mesh:
image

@SorooshMani-NOAA, do you know if something has changed with our dependencies?

@felicio93
Copy link
Collaborator

FYI, the problem here is not the same of #144. I just tested and the ocsmesh "get_contour" raster function is working as expected.

@SorooshMani-NOAA
Copy link
Collaborator

@felicio93 thanks for testing, I think the problem might then be what I described in #154 (comment)

@simonweppe
Copy link
Author

Thanks @SorooshMani-NOAA @felicio93 I will try your workaround

@felicio93
Copy link
Collaborator

Yes, you are right!

I tested rerunning with the buffer as:

hfun = Hfun(
    hfun_rast_list,
    base_shape=domain.buffer(0.1).unary_union,
    base_shape_crs=geom.crs,
    hmin=100, hmax=2000,
    method='fast')

For the sake of documentation, this is how this looks like:
image

@simonweppe
Copy link
Author

Great - thanks for the quick replies and support on this.

@SorooshMani-NOAA
Copy link
Collaborator

Can we close this ticket now?

@simonweppe
Copy link
Author

simonweppe commented Jul 22, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants