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

Test calc rmax closes #48 #49

Closed
wants to merge 4 commits into from
Closed

Test calc rmax closes #48 #49

wants to merge 4 commits into from

Conversation

oceandie
Copy link
Contributor

  • Closes #xxxx
  • Tests added
  • Passes pre-commit run --all-files
  • Changes are documented in whats-new.rst
  • New functions/methods are listed in api.rst
  • Project, label, and assignee tabs are populated

@oceandie oceandie requested review from jdha and malmans2 June 25, 2021 21:04
@oceandie
Copy link
Contributor Author

https://www.dropbox.com/s/u3nl4htrynfi89x/bathymeter_mo_ps43.nc?dl=0
this is the link for AMM7 bathymetry ... let me know if you cannot use it

@oceandie
Copy link
Contributor Author

I added the last implementation of xarray-calc_max (using the maximum rather than the average). I hope I am not doing anything stupidly wrong, if yes, sorry in advance :)

@jdha
Copy link
Contributor

jdha commented Jun 26, 2021

Not that I should be looking at this, but ...

To reproduce your SlopeParam code @oceandie [which looks very much like my old Matlab ;) ] I did the following (see below). The large values seem to appear in the outer halo as they where included in the np.diff (your code only goes from the second index to the last but one) ... I also think I'd got the indices out of sync by 1 - but I'm not too sure ... I'll look again on Monday (and do an XR version of this).

If I diff the the results from the following code with SlopeParam they match.

def calc_rmax_np(depth):
    """
    Calculate rmax: measure of steepness

    This function returns the slope steepness criteria rmax, which is simply
    (H[0] - H[1]) / (H[0] + H[1])
    Parameters
    ----------
    depth: float
            Bottom depth (units: m).
    Returns
    -------
    rmax: float
            Slope steepness value (units: None)
    """
    
    rmax_x, rmax_y = np.zeros_like(depth), np.zeros_like(depth)

    rmax_x[1:-1, 1:-1] = np.maximum (
        np.abs( np.diff(depth[1:-1, :-1], axis=1) / (depth[1:-1,  :-2] + depth[1:-1, 1:-1]) ),
        np.abs( np.diff(depth[1:-1,1:  ], axis=1) / (depth[1:-1, 1:-1] + depth[1:-1, 2:  ]) )
    )
    rmax_y[1:-1, 1:-1] = np.maximum (
        np.abs( np.diff(depth[ :-1, 1:-1], axis=0) / (depth[ :-2, 1:-1] + depth[1:-1, 1:-1]) ) ,
        np.abs( np.diff(depth[1:  , 1:-1], axis=0) / (depth[1:-1, 1:-1] + depth[2:,   1:-1]) )
    )

    return np.maximum(np.abs(rmax_x), np.abs(rmax_y))

@jdha
Copy link
Contributor

jdha commented Jun 26, 2021

for xr updated see #48

Update calc_rmax_np to match conservative approach
@oceandie oceandie closed this Jun 27, 2021
@oceandie oceandie deleted the test_calc_rmax branch June 27, 2021 15:27
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

Successfully merging this pull request may close these issues.

2 participants