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

Use list comprehension for shift the theta coordinate from 0 to 2pi #164

Merged
merged 3 commits into from
Oct 9, 2024

Conversation

Edgar-21
Copy link
Contributor

@Edgar-21 Edgar-21 commented Oct 8, 2024

I experienced an error with nwl_utils.py as currently written, since theta_coords is a list. This approach, or changing theta_coords to a numpy array will alleviate that error.

Fixed a missing comma in invessel_build.py

Copy link
Collaborator

@connoramoreno connoramoreno left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be better practice to use a NumPy array instead of relying on list comprehension, as you mentioned.

Comment on lines 190 to 192
theta_coords = [
(theta_coord + 2 * np.pi) % 2 * np.pi for theta_coord in theta_coords
]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be better to change theta_coords to a NumPy array

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moving to arrays rather than lists would be somewhat large rework, as we make use of append to deal with the variable length iterables that come from the multithreading approach, I'd prefer to keep this PR as a minimal change to get things into a working state.

Regardless, I realized we can just put this coordinate shift in the function where we calculate theta, which I think is a bit more elegant.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The whole nwl_utils could possibly be reworked similar to what Connor has done for radial_distance_utils, but I think that would be better for a different PR.

Copy link
Collaborator

@connoramoreno connoramoreno left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm happy with this change if @gonuke approves. See my comment about documentation.

@@ -145,7 +145,7 @@ def find_coords(data):
bounds=[(-np.pi, np.pi)],
args=(vmec, wall_s, coords[0], coords[1]),
)
thetas.append(theta.x[0])
thetas.append((theta.x[0] + 2 * np.pi) % (2 * np.pi))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For our future benefit, it's best to add a comment here explaining (briefly) this conversion

Copy link
Collaborator

@connoramoreno connoramoreno left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! I'll wait to see what Paul thinks before merging. Thanks @Edgar-21

@gonuke gonuke merged commit e52ed76 into main Oct 9, 2024
3 checks passed
@connoramoreno connoramoreno deleted the comprehend_list_nwl branch October 9, 2024 19:45
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.

3 participants