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

Inefficient distance along contour calculation in Cross-contour_transport.ipynb #403

Closed
adele-morrison opened this issue Jul 3, 2024 · 2 comments · Fixed by #423
Closed

Comments

@adele-morrison
Copy link
Collaborator

adele-morrison commented Jul 3, 2024

The code that calculates the distance along the contour in the Cross-contour_transport.ipynb script is very slow (~10 minutes). Probably we could come up with a better way of doing this. Maybe use the lat and lon along the contour instead to compute the shortest distance between each set of coordinates on the contour?

@anton-seaice
Copy link
Collaborator

I suspect this for loop (currently cell 38) is the problem :

for count in range(1, num_points):
    if skip == True:
        skip = False
        continue
    if count in y_indices:
        if count + 1 in y_indices:
            # note dxu and dyt do not vary in x:
            jj = np.where(mask_y_transport_numbered==count)[0]
            distance_along_contour[count-1] = (dxu[jj])[0]
        else:
            jj0 = np.where(mask_y_transport_numbered==count)[0]
            jj1 = np.where(mask_x_transport_numbered==count+1)[0]
            half_diagonal_distance = 0.5 * np.sqrt((dxu[jj0])[0]**2 + (dyt[jj1])[0]**2)
            distance_along_contour[count-1] = half_diagonal_distance
            distance_along_contour[count] = half_diagonal_distance
            # skip to next count:
            skip = True
            ...

which leads to this line (and the other similar lines) :

np.where(mask_y_transport_numbered==count)[0]

which hopefully can be done as a whole array rather than one at a time ...

which leads back to fixing #179 first and then flowing the changes through the rest of the workbook

@adele-morrison
Copy link
Collaborator Author

I completely replaced that loop in this PR: #406.

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