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

BP Map recipe template and test #168

Merged
merged 37 commits into from
Sep 3, 2024
Merged

BP Map recipe template and test #168

merged 37 commits into from
Sep 3, 2024

Conversation

juliamilton
Copy link
Collaborator

Describe your changes

  • Wrote recipe template for bad pixel map generation
  • Implemented test_bp_map.py which tests the BP map generation on both simulated data and TVAC noise maps. Confirmed output with plots.
  • Updated elements of the Darks and Data to handle cases where image data is found in header[0], as it is in the TVAC files. Ran previous e2e tests to make sure these updates did not break those tests.
  • Updated the walker to handle the bp map, which doesn't provide input files, only a master dark and flat field

Type of change

New feature

Reference any relevant issues (don't forget the #)

Create recipe template for generating a BadPixelMap Calibration #149

Checklist before requesting a review

  • I have linted my code
  • I have verified that all unit tests pass in a clean environment and added new unit tests, as needed
  • I have verified that all docstrings are properly formatted and added new documentation, as needed

Linter output: (No data and header member outputs are false positives)

************* Module test_bp_map
tests/e2e_tests/test_bp_map.py:1:0: C0114: Missing module docstring (missing-module-docstring)
tests/e2e_tests/test_bp_map.py:15:0: R0914: Too many local variables (61/15) (too-many-locals)
tests/e2e_tests/test_bp_map.py:54:22: E1101: Instance of 'HDUList' has no 'header' member (no-member)
tests/e2e_tests/test_bp_map.py:56:22: E1101: Instance of 'HDUList' has no 'header' member (no-member)
tests/e2e_tests/test_bp_map.py:72:18: E1101: Instance of 'HDUList' has no 'data' member; maybe '_data'? (no-member)
tests/e2e_tests/test_bp_map.py:74:18: E1101: Instance of 'HDUList' has no 'data' member; maybe '_data'? (no-member)
tests/e2e_tests/test_bp_map.py:76:27: E1101: Instance of 'HDUList' has no 'data' member; maybe '_data'? (no-member)
tests/e2e_tests/test_bp_map.py:97:19: E1101: Instance of 'HDUList' has no 'data' member; maybe '_data'? (no-member)
tests/e2e_tests/test_bp_map.py:102:17: E1101: Instance of 'HDUList' has no 'header' member (no-member)
tests/e2e_tests/test_bp_map.py:103:17: E1101: Instance of 'HDUList' has no 'header' member (no-member)
tests/e2e_tests/test_bp_map.py:152:27: E1101: Instance of 'HDUList' has no 'data' member; maybe '_data'? (no-member)
tests/e2e_tests/test_bp_map.py:206:27: E1101: Instance of 'HDUList' has no 'data' member; maybe '_data'? (no-member)
tests/e2e_tests/test_bp_map.py:15:0: R0915: Too many statements (137/50) (too-many-statements)


Your code has been rated at 6.65/10 (previous run: 6.58/10, +0.06)

@juliamilton juliamilton linked an issue Aug 22, 2024 that may be closed by this pull request
3 tasks
@juliamilton
Copy link
Collaborator Author

Automated code checks are failing because it can't find the TVAC FITS files I use locally to run the test_bp_map.py e2e test.

@semaphoreP
Copy link
Contributor

You should add the @pytest.mark.e2e decorator to your e2e test so pytest doesn't automatically run it as part of the automated testing (Automated testing not set up to run e2e tests)

Copy link
Contributor

@semaphoreP semaphoreP left a comment

Choose a reason for hiding this comment

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

I have a few comments to simplify your implementation a bit. Also, have you tried running this code on the TVAC data from the Box folder? We want to make sure all the tests will run using just the files available there.

Also, it looks like you changed quite a few files that are out of scope of the BPMap recipe template and test. I would recommend not adding these to PRs in the future, since it just complicates the PR. If there are issues with other lines of code, please make a separate PR and issue about it.

corgidrp/darks.py Outdated Show resolved Hide resolved
corgidrp/darks.py Outdated Show resolved Hide resolved
corgidrp/data.py Outdated Show resolved Hide resolved
corgidrp/data.py Outdated Show resolved Hide resolved
corgidrp/data.py Outdated Show resolved Hide resolved
tests/test_data/simastrom/guesses.csv Outdated Show resolved Hide resolved
tests/e2e_tests/test_bp_map.py Outdated Show resolved Hide resolved
tests/e2e_tests/test_bp_map.py Outdated Show resolved Hide resolved
corgidrp/caldb.py Outdated Show resolved Hide resolved
bp_map_outputdir = os.path.join(e2eoutput_path, "bp_map_output")
if not os.path.exists(bp_map_outputdir):
os.mkdir(bp_map_outputdir)
dark_current_filename = "dark_current_20240322.fits"
Copy link
Contributor

Choose a reason for hiding this comment

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

all these filenames should match the filenames on Box.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Echoing an above comment - there are issues with the files on Box. Once Marie is able to fix them I will update the names

@juliamilton
Copy link
Collaborator Author

Merged changes that allow get_calib to take None as input. Addressed other comments above and separated tests into two different files (can put both functions in one file, whatever your preference is).

Copy link
Contributor

@semaphoreP semaphoreP left a comment

Choose a reason for hiding this comment

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

Looks good. Thanks for promptly addressing those comments! I would prefer both tests in the same file, so if you can do that move, that'd be great.

There's also a tiny merge conflict in caldb.py that I think should be trivial (just keep the changes in main, since the change in indentation is intentional). It looks like this branch's version has a different line ending setting.

Copy link
Contributor

@semaphoreP semaphoreP left a comment

Choose a reason for hiding this comment

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

Actually, sorry, I just tried running the tests, and the filepaths don't quite work with the Box data as the filenames aren't the same.

@juliamilton
Copy link
Collaborator Author

Actually, sorry, I just tried running the tests, and the filepaths don't quite work with the Box data as the filenames aren't the same.

Marie was going to update the noise map calibration files on Box, let me check with her on status of that.

@mygouf
Copy link
Contributor

mygouf commented Aug 30, 2024

Actually, sorry, I just tried running the tests, and the filepaths don't quite work with the Box data as the filenames aren't the same.

Marie was going to update the noise map calibration files on Box, let me check with her on status of that.

That's right, yesterday afternoon didn't go as planned but I'm working on it right now. Thanks for your patience.

@mygouf
Copy link
Contributor

mygouf commented Aug 30, 2024

Actually, sorry, I just tried running the tests, and the filepaths don't quite work with the Box data as the filenames aren't the same.

Marie was going to update the noise map calibration files on Box, let me check with her on status of that.

That's right, yesterday afternoon didn't go as planned but I'm working on it right now. Thanks for your patience.

Now done. Please note the changes to file names from
image
to
image
to be consistent with the TVAC file names. I'm not sure if that change breaks other parts of the code so this is something to keep an eye on.

@juliamilton
Copy link
Collaborator Author

One final item to note is that build_synthesized_dark takes in a dataset and looks for KGAIN in the headers. Since I am just using a dummy dataset of L1 frames for now (because BP map doesn't require any real input frames), I just set the KGAIN to a value since that parameter is not found in the header of L1 frames. In the future, however, will this mean that the frames need to be processed before passing them to build_synthesized_dark?

Merge 'main' into 'julia_bp_map' to update with latest changes
@semaphoreP
Copy link
Contributor

One final item to note is that build_synthesized_dark takes in a dataset and looks for KGAIN in the headers. Since I am just using a dummy dataset of L1 frames for now (because BP map doesn't require any real input frames), I just set the KGAIN to a value since that parameter is not found in the header of L1 frames. In the future, however, will this mean that the frames need to be processed before passing them to build_synthesized_dark?

Yes, I guess this is true, that the input dataset must have already gone through the convert_to_electrons. So, it cannot be a raw L1 frame.

Copy link
Contributor

@semaphoreP semaphoreP left a comment

Choose a reason for hiding this comment

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

Ok, just a couple remaining small things, so that the tests can be picked out correctly when I run pytest in e2e mode.

thisfile_dir = os.path.dirname(__file__)

@pytest.mark.e2e
def bp_map_master_dark_e2e(tvacdata_path, e2eoutput_path):
Copy link
Contributor

Choose a reason for hiding this comment

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

One last thing: based on how conftest.py collects tests for automated testing, the two tests here don't get identified unless the functions start with test_*. We just need to prepend "test_" to each function name.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

output_path = os.path.join(bp_map_outputdir, "bp_map_master_dark_test.png")
plt.savefig(output_path)

def bp_map_simulated_dark_e2e(tvacdata_path, e2eoutput_path):
Copy link
Contributor

Choose a reason for hiding this comment

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

In addition to preprending "test_", we also need the @pytest.mark.e2e decorator.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

@semaphoreP semaphoreP merged commit 2bf4941 into main Sep 3, 2024
1 check passed
@semaphoreP semaphoreP deleted the julia_bp_map branch September 3, 2024 17:11
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.

Create recipe template for generating a BadPixelMap Calibration
3 participants