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

Array size doubles when specifying periodic axes #24

Closed
mfschubert opened this issue Mar 9, 2024 · 6 comments
Closed

Array size doubles when specifying periodic axes #24

mfschubert opened this issue Mar 9, 2024 · 6 comments

Comments

@mfschubert
Copy link
Contributor

There is some unexpected behavior when periodic_axes is specified in the length_violations function. Specifically, the violations shape may not match the shape of the input array. Example:

print(f"Density shape is {density.shape}")
violations = imageruler.length_violation(density, diameter=9, periodic_axes=None)
print(f"Violations shape with no periodic axes is {violations.shape}")
violations = imageruler.length_violation(density, diameter=9, periodic_axes=(0, 1))
print(f"Violations shape with periodic axes is {violations.shape}")

Prints the following:

Density shape is (400, 400)
Violations shape with no periodic axes is (400, 400)
Violations shape with periodic axes is (800, 800)
@ianwilliamson
Copy link
Collaborator

Possibly due to the tiling that is applied here:

periodic_axes = np.array(periodic_axes)
reps = (2 if 0 in periodic_axes else 1, 2 if 1 in periodic_axes else 1)
array = np.tile(array, reps)
phys_size = np.array(phys_size) * reps
short_entire_side = min(
phys_size
) # shorter side of the entire design region

but not(?) undone before returning the violations

@stevengj
Copy link
Contributor

stevengj commented Mar 14, 2024

If you know a bugfix, please feel free to submit a PR.

@mawc2019
Copy link
Collaborator

This feature is expected and it did not incur an error. To visualize lengthscale violation of a periodic structure, it does no harm to double this structure along the periodic direction(s).

but not(?) undone before returning the violations

It is not undone.

@ianwilliamson
Copy link
Collaborator

This feature is expected and it did not incur an error. To visualize lengthscale violation of a periodic structure, it does no harm to double this structure along the periodic direction(s).

It is not expected because the function's doc string states that the returned quantity "indicates violations in the input image:"

An array indicating the solid length scale violations in the input image.

A straightforward interpretation is that the mapping is one-to-one. But, if the output array has a different shape than the input array, it is unclear how a user should interpret the quantities in the output array. No documentation or mapping is provided for how violations may be mapped back to features in the input array.

@stevengj
Copy link
Contributor

Yeah, I don't think it makes sense for the function to silently tile the image.

I agree that tiling the image of a periodic structure can be very helpful for visualization, but the user can do this themselves (or there can be a function provided to do this — it's more flexible to provide additional features by composing multiple functions than by adding lots of options to a single function).

@stevengj
Copy link
Contributor

Closed by #30

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

4 participants