Fix: Implement path portability and add default resolution to train.py and data.py #112
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
This PR improves the robustness of the training pipeline by addressing path resolution issues and preventing null-pointer errors during the PSF kernel setup in Grid_based_strong_lensing_for_unsupervised_super_resolution_Anirudh_Shankar/data.py and Grid_based_strong_lensing_for_unsupervised_super_resolution_Anirudh_Shankar/train.py
Changes
1.Path Portability:
Introduced script_dir using os.path.dirname(os.path.abspath(file)).
Defined grid_dir to explicitly point to the grid_matrices folder.
Updated all torch.load calls to use os.path.join(), ensuring the script can find its dependencies regardless of the working directory.
2.Argparse Improvements:
Added default=0.1 to the --resolution argument. This ensures that the physical lensing calculations have a valid numerical input even if the user does not manually specify the resolution.
3.Updated data.py:
To use os.path.join for dataset indexing. This ensures robust path construction regardless of whether the input directory string contains trailing slashes and improves cross-platform compatibility.
Impact
These changes make the repository much easier to use for new contributors, as the "out-of-the-box" execution of train.py no longer requires manual file moving or specific terminal positioning.
Testing
Verified by running: python Grid_based_strong_lensing_for_unsupervised_super_resolution_Anirudh_Shankar/train.py from the repository root. The script now correctly identifies the matrices and initializes the PSF kernel without errors.