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

Added a function to reconstruct a symmetric array #103

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

VictorForouhar
Copy link
Collaborator

In SOAP, we compute inertia tensors and store its diagonal and a subset of its off-diagonal elements. To compute the eigenvalues, we need convert these flattened representations into the original shape.

This PR adds a function that can be used to do such reconstruction on all of the computed inertia tensors, rather than doing it one tensor at a time.

I have implemented and tested it assuming swiftsimio is used to load SOAP catalogues. It works for 2D and 3D matricies (e.g. projected and 3D inertia tensors).

It keeps track of units. Here is an example test I ran on COLIBRE SOAP catalogues:

soap_catalogue = sw.load('/snap8/scratch/dp004/dc-mcgi1/soap_colibre_tensors/L0012N0376/Thermal_fiducial/SOAP_uncompressed/halo_properties_0123.hdf5')

# Load only those with non-zero entries
stellar_inertia_tensors = soap_catalogue.bound_subhalo.stellar_inertia_tensor
stellar_inertia_tensors = stellar_inertia_tensors[(stellar_inertia_tensors != 0).any(1)]

# Print an example and how many entries we have
print (stellar_inertia_tensors.shape)
print (stellar_inertia_tensors[0])

# Reshape matricies into their correct form
stellar_inertia_tensors = build_matrix(stellar_inertia_tensors)
print (stellar_inertia_tensors.shape)
print (stellar_inertia_tensors[0])

# Compute eigenvalues
eigenvalues = np.linalg.eigvalsh(stellar_inertia_tensors)
print (eigenvalues.shape)
print (eigenvalues[0])

And here is the output:

(294, 6)
[ 7.3760958e-07  1.0794657e-06  1.1297204e-06  1.8591939e-07
  7.1408937e-07 -3.7456874e-07] Mpc**2 (Physical)
(294, 3, 3)
[[ 7.37609582e-07  1.85919390e-07  7.14089367e-07]
 [ 1.85919390e-07  1.07946573e-06 -3.74568742e-07]
 [ 7.14089367e-07 -3.74568742e-07  1.12972043e-06]] Mpc**2 (Physical)
(294, 3)
[5.32662612e-08 1.15860554e-06 1.73492395e-06] Mpc**2

@robjmcgibbon robjmcgibbon self-assigned this Sep 13, 2024
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