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 usage in distance normalization #15

Closed
iannesbitt opened this issue Jun 27, 2019 · 1 comment
Closed

Reduce memory usage in distance normalization #15

iannesbitt opened this issue Jun 27, 2019 · 1 comment
Assignees

Comments

@iannesbitt
Copy link
Owner

iannesbitt commented Jun 27, 2019

During distance normalization, radar array is expanded all at once, which is untenable for medium (0.1 GB) to large files because the expanded array can exceed the RAM size (speaking from experience). Lines 96 and 99 of arrayops.py (below) are the culprits and should be modified.

ar = np.repeat(ar, norm_vel['normalized'].astype(int, casting='unsafe').values, axis=1)
nvm = int(round(norm_vel['normalized'].mean()))
del norm_vel
ar = reducex(ar, by=nvm, verbose=verbose)

Solution: chunk-ify distance normalization by breaking the original array into int(norm_vel['normalized'].mean()) + 1 parts and tacking each normalized chunk on to a processed array to return. That way, max memory usage should only be ~3x filesize, instead of norm_vel['normalized'].mean() *filesize (which is far too often something extreme like 75x).

This will require a slicing for loop around the np.repeat() and readgssi.arrayops.reducex() functions to build the new array block by block.

@iannesbitt
Copy link
Owner Author

Admittedly this is not what I want to be doing the week I have to turn in the first draft of my manuscript, but here's the fix:

for c in np.array_split(ar, nvm, axis=1):
# takes (array, [transform values to broadcast], axis)
c = np.repeat(c, norm_vel['normalized'].astype(int, casting='unsafe').values[on:on+c.shape[1]], axis=1)
c = reducex(c, by=nvm, chnum=i, number=nvm, verbose=verbose)
proc = np.concatenate((proc, c), axis=1)
on += c.shape[1]
i += 1

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

No branches or pull requests

1 participant