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

Reduce memory consuption in axis_world_coords (again) #798

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Cadair
Copy link
Member

@Cadair Cadair commented Dec 17, 2024

This PR works, as an alternative to #780 by not generating mesh coords for unneeded pixel axes.

i.e. if the pixel axes are not correlated with a requested world axis then don't generate the coords in the mesh.

@Cadair Cadair marked this pull request as draft December 17, 2024 17:39
@Cadair
Copy link
Member Author

Cadair commented Dec 17, 2024

This PR needs tests which test at least with some DKIST or IRIS WCSes that you can get low-memory axis world coords for uncorrelated axes, and as a counterpoint that correlated axes still work properly.

For example, I have tested that axis_world_coords("time") works fine for this dataset but not that axis_world_coords("lat") works for instance (which should still generate a large grid).

ndcube/ndcube.py Outdated Show resolved Hide resolved
@nabobalis nabobalis added this to the 2.3.0 milestone Dec 17, 2024
@nabobalis
Copy link
Contributor

I do question why I bother to do any programming if its always wrong.

This solution works:

Command line: /home/nabil/.mamba/envs/iris-dev/bin/memray run -f -o output.bin examples/umbral_flashes.py
Start time: Tue Dec 17 2024 11:08:16 GMT-0800 (Pacific Standard Time)
End time: Tue Dec 17 2024 11:08:42 GMT-0800 (Pacific Standard Time)
Duration: 0:00:26.707000
Total number of allocations: 6674037
Total number of frames seen: 17921
Peak memory usage: 2.3 GiB
Python allocator: pymalloc

The biggest allocations are from loading the data:

Screenshot_20241217_111209

@DanRyanIrish
Copy link
Member

This is great news!

@Cadair
Copy link
Member Author

Cadair commented Dec 19, 2024

@nabobalis I can't add a visp WCS without a dkist dependency, I assume you can't either?

@nabobalis
Copy link
Contributor

@nabobalis I can't add a visp WCS without a dkist dependency, I assume you can't either?

I am the same

@nabobalis
Copy link
Contributor

Could we try Wills WCS from his issue?

@nabobalis nabobalis force-pushed the maybe_this_will_work branch from deee62c to 72d8859 Compare January 8, 2025 00:43
@@ -519,6 +560,25 @@ def ndcube_3d_rotated(wcs_3d_ln_lt_t_rotated, simple_extra_coords_3d):
return cube



@pytest.fixture
def ndcube_3d_coupled(wcs_3d_ln_lt_l_coupled):
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure if this is good.

# WCS for a 3D data cube with two celestial axes and one wavelength axis.
# The latitudinal dimension is coupled to the third pixel dimension through
# a single off diagonal element in the PCij matrix
header = {
Copy link
Contributor

Choose a reason for hiding this comment

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

Taken from Wills original issue.

@nabobalis nabobalis marked this pull request as ready for review January 8, 2025 00:44
@nabobalis nabobalis force-pushed the maybe_this_will_work branch 2 times, most recently from ae8bac4 to e15bc13 Compare January 8, 2025 01:41
@Cadair Cadair force-pushed the maybe_this_will_work branch 2 times, most recently from 17ec1ec to ff9db90 Compare January 8, 2025 15:40
@Cadair Cadair mentioned this pull request Jan 8, 2025
Cadair and others added 3 commits January 8, 2025 15:42
If the pixel axes are not correlated with a requested world axis then
don't generate the coords in the mesh
@Cadair Cadair force-pushed the maybe_this_will_work branch from ff9db90 to c440645 Compare January 8, 2025 15:42
@@ -230,6 +230,13 @@ def test_axis_world_coords_wave_ec(ndcube_3d_l_ln_lt_ectime):
assert coords[0].shape == (5,)


@pytest.mark.limit_memory("12 MB")
Copy link
Member Author

@Cadair Cadair Jan 8, 2025

Choose a reason for hiding this comment

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

I grafted this test into the commit history before @nabobalis original #780 and it fails (using 3GB of RAM).

This test doesn't actually fail before this PR though, as this change fixes the case where you want to extract a single world coordinate correlated with two pixel axes where those pixel axes are also correlated with other world axes, i.e. extracting time from this VISP WCS:

<dkist.dataset.dataset.Dataset object at 0x7f0300d66ba0>
This VISP Dataset ADDMM consists of 10444 frames.
Files are stored in /data/dkist/prod/pid_2_114/ADDMM

This Dataset has 4 pixel and 4 world dimensions.

The data are represented by a <class 'dask.array.core.Array'> object:
dask.array<reshape, shape=(4, 2611, 996, 2545), dtype=float64, chunksize=(1, 1, 996, 2545), chunktype=numpy.ndarray>

Array Dim  Axis Name                 Data size  Bounds
        0  raster map repeat number          4  None
        1  raster scan step number        2611  None
        2  dispersion axis                 996  None
        3  spatial along slit             2545  None

World Dim  Axis Name                  Physical Type                   Units
        3  time                       time                            s
        2  helioprojective latitude   custom:pos.helioprojective.lat  arcsec
        1  wavelength                 em.wl                           nm
        0  helioprojective longitude  custom:pos.helioprojective.lon  arcsec

Correlation between pixel and world axes:

                          |                  PIXEL DIMENSIONS
                          |  spatial   | dispersion |   raster   | raster map
                          | along slit |    axis    | scan step  |   repeat
         WORLD DIMENSIONS |            |            |   number   |   number
------------------------- | ---------- | ---------- | ---------- | ----------
helioprojective longitude |     x      |            |     x      |     x
               wavelength |            |     x      |            |
 helioprojective latitude |     x      |            |     x      |     x
                     time |            |            |     x      |     x

@Cadair
Copy link
Member Author

Cadair commented Jan 8, 2025

I would be nice to get a test which tests the 2D usecase.

@nabobalis
Copy link
Contributor

How does one do that?

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