Skip to content

Conversation

@feelgom
Copy link
Contributor

@feelgom feelgom commented May 21, 2025

Implement map_coordinates function

Problem

I attempted to deploy py360convert to AWS Lambda but encountered a deployment failure due to size limitations. AWS Lambda has a restriction that the total size of the deployment package cannot exceed 250MB. The main issue was that scipy, one of our dependencies, takes up approximately 80MB of space.

Investigation

After investigating scipy's usage in our codebase, I found that we only use two functions from scipy:

  1. map_coordinates from scipy.ndimage
  2. Rotation from scipy.spatial.transform

Solution

To resolve this issue, I have:

  1. Implemented our own version of map_coordinates with three interpolation methods:
    • Nearest neighbor (order=0)
    • Linear interpolation (order=1)
    • Cubic interpolation (order=3)
  2. Implemented rotation_matrix_fromRodrigues to replace scipy's Rotation
  3. Added comprehensive unit tests to ensure our implementation matches scipy's behavior

Testing

The implementation has been thoroughly tested against scipy's original functions to ensure compatibility and correctness. The tests include:

  • Comparison with scipy's implementation for 2D images
  • Comparison with scipy's implementation for cube faces
  • Testing all three interpolation methods (nearest, linear, cubic)

Benefits

  • Reduced package size by ~80MB
  • Maintained full functionality
  • Added comprehensive test coverage
  • No changes required in the API interface

Impact

This change will significantly reduce our package size, making it suitable for AWS Lambda deployment while maintaining all existing functionality.

Additional Notes

  • The implementation follows the same API as scipy's functions
  • All existing code using these functions will continue to work without modification
  • The implementation is well-documented and includes type hints

Feedback

Please feel free to provide any feedback or raise any concerns you might have. I'm open to suggestions for improvements and would be happy to address any questions or issues you identify.

feelgom added 3 commits May 21, 2025 17:15
Implement map_coordinates function with nearest,
linear, and cubic interpolation methods; add
corresponding tests for validation.
- Added scipy dependency to pyproject.toml for development.
- Refactored _cubic_kernel and rotation_matrix_fromRodrigues functions for better readability.
- Updated map_coordinates function signature to accept tuple coordinates.
- Cleaned up test_utils.py by removing unnecessary try-except for scipy import.
…nges

- Updated Poetry version from 1.8.5 to 2.1.3.
- Added 'groups' attribute for several packages to categorize them as 'dev'.
- Adjusted 'markers' for compatibility with specific Python versions.
- Updated content hash and lock version in metadata.
@feelgom feelgom closed this May 21, 2025
@BrianPugh
Copy link
Collaborator

Hi @feelgom! Why close this PR?

@feelgom
Copy link
Contributor Author

feelgom commented May 21, 2025

I'm working on implementing a function that produces exactly the same results as scipy's map_coordinates function, specifically focusing on the cubic interpolation method. However, the test cases for map_coordinates_cubic consistently fail.

image Screenshot 2025-05-21 at 10 01 20 PM Screenshot 2025-05-21 at 10 01 32 PM

Now I'm working on https://github.com/feelgom/py360convert/tree/andrew/replace_scipy

@BrianPugh
Copy link
Collaborator

sounds good! feel free to re-open when ready!

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