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

Add corrections #33

Merged
merged 34 commits into from
Sep 7, 2023
Merged

Add corrections #33

merged 34 commits into from
Sep 7, 2023

Conversation

AkashA98
Copy link
Collaborator

This address the issue of flux/astrometric corrections to the raw/cropped images. Fixes #20 , #4 , #7 .

@AkashA98 AkashA98 requested review from dlakaplan and ddobie August 10, 2023 16:28
@AkashA98
Copy link
Collaborator Author

I am happy if we wait before merging this branch into dev. I am running this code currently on VAST data right away anyway.

Copy link
Contributor

@mubdi mubdi left a comment

Choose a reason for hiding this comment

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

Only reviewed it for code standardization purposes. Will need a bunch of doc strings and a bit of reorg here.

vast_post_processing/cli/run_corrections.py Show resolved Hide resolved
vast_post_processing/catalogs.py Outdated Show resolved Hide resolved
vast_post_processing/catalogs.py Outdated Show resolved Hide resolved
vast_post_processing/catalogs.py Outdated Show resolved Hide resolved
vast_post_processing/catalogs.py Outdated Show resolved Hide resolved
vast_post_processing/corrections.py Show resolved Hide resolved
vast_post_processing/crossmatch.py Outdated Show resolved Hide resolved
vast_post_processing/crossmatch.py Show resolved Hide resolved
vast_post_processing/crossmatch.py Show resolved Hide resolved
vast_post_processing/crossmatch.py Show resolved Hide resolved
@mubdi
Copy link
Contributor

mubdi commented Aug 10, 2023

@AkashA98 -- @hansenjiang's reorganization has been merged into dev. If you can pull to rebase to use that as an example, that'd be great! Thanks!

Copy link
Collaborator

@ddobie ddobie left a comment

Choose a reason for hiding this comment

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

I've gone through and added some preliminary comments on specific parts of the code. General comments:

  1. As Mubdi has already noted, a lot of this needs more documentation - right now it's very opaque and I'm struggling to understand what a lot of it is doing
  2. Needs to be written in a way such that you can integrate this step into a larger pipeline rather than running it standalone. That means splitting a lot of the larger functions into smaller ones and moving everything but the bare minimum out of the CLI script.
  3. I think we want to pull the reference catalogues from somewhere else or even just include them in the package (e.g. combine them into a single parquet file) - I'm not sure the default directory you're pointing to even has all of the VAST fields?

vast_post_processing/catalogs.py Outdated Show resolved Hide resolved
vast_post_processing/catalogs.py Outdated Show resolved Hide resolved
vast_post_processing/catalogs.py Outdated Show resolved Hide resolved
Comment on lines 80 to 92
if positive_fluxes_only:
logger.info(
"Filtering %d sources with fluxes <= 0.",
(self.table["flux_peak"] <= 0).sum(),
)
self.table = self.table[self.table["flux_peak"] > 0]
logger.info(
"Filtering %d sources with fitted sizes <= 0.",
((self.table["maj_axis"] <= 0) | (self.table["min_axis"] <= 0)).sum(),
)
self.table = self.table[
(self.table["maj_axis"] > 0) & (self.table["min_axis"] > 0)
]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Split into a filter_sources function

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also need to filter on:

  • no nearby sources (use cat.match_to_catalog_sky(cat, nthneighbor=2) or similar
  • compact source (@dlakaplan do you think it's better to use int/peak ratio or to compare the source FWHM to the PSF FWHM?)
  • Some sort of flux or S/N cut - Maybe S/N > 20?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

updated the filter function to select isolated (neighbor>1'), point (peak/integrated<1.5), and bright (snr>20) sources.

vast_post_processing/catalogs.py Outdated Show resolved Hide resolved
vast_post_processing/cli/run_corrections.py Show resolved Hide resolved
vast_post_processing/cli/run_corrections.py Outdated Show resolved Hide resolved
vast_post_processing/cli/run_corrections.py Outdated Show resolved Hide resolved
vast_post_processing/cli/run_corrections.py Outdated Show resolved Hide resolved
vast_post_processing/cli/run_corrections.py Outdated Show resolved Hide resolved
@ddobie
Copy link
Collaborator

ddobie commented Aug 11, 2023

One other thing - you need to write the corrections you're applying to the fits headers and as parameters in the selavy catalogues.

@ddobie
Copy link
Collaborator

ddobie commented Aug 17, 2023

Another general comment - you should use f-strings throughout. e.g. instead of

logger.debug("Using crossmatch radius: %s.", radius)

you can use

logger.debug(f"Using crossmatch radius: {radius}.")

@ddobie
Copy link
Collaborator

ddobie commented Aug 17, 2023

@AkashA98 I suspect that something has gone wrong with the merge and rebase - there's a bunch of commits in this pull from @hansenjiang that I don't think should be in here.

How did you actually do it? Should just be something like

git checkout dev
git pull
git checkout add_corrections
git merge dev

@AkashA98
Copy link
Collaborator Author

@AkashA98 I suspect that something has gone wrong with the merge and rebase - there's a bunch of commits in this pull from @hansenjiang that I don't think should be in here.

How did you actually do it? Should just be something like

git checkout dev
git pull
git checkout add_corrections
git merge dev

I did not merge my branch into dev. As @mubdi suggested, I just rebased it to an updated version of dev branch after @hansenjiang pushed his commits (I did overwrite a couple of conflicts from @hansenjiang to update the correction-related code). I am relatively new to this rebasing stuff, but I thought that the residual commits from @hansenjiang that were not conflicting with mine will remain since I rebased, but maybe I am wrong. Can @mubdi / @hansenjiang confirm if it is the case?

@mubdi
Copy link
Contributor

mubdi commented Aug 17, 2023

@AkashA98 I suspect that something has gone wrong with the merge and rebase - there's a bunch of commits in this pull from @hansenjiang that I don't think should be in here.
How did you actually do it? Should just be something like

git checkout dev
git pull
git checkout add_corrections
git merge dev

I did not merge my branch into dev. As @mubdi suggested, I just rebased it to an updated version of dev branch after @hansenjiang pushed his commits (I did overwrite a couple of conflicts from @hansenjiang to update the correction-related code). I am relatively new to this rebasing stuff, but I thought that the residual commits from @hansenjiang that were not conflicting with mine will remain since I rebased, but maybe I am wrong. Can @mubdi / @hansenjiang confirm if it is the case?

Yep, this is correct -- there was an earlier dev PR that @AkashA98 rebased against. The changes you see made by @hansenjiang were from that commit.

@AkashA98
Copy link
Collaborator Author

One other thing - you need to write the corrections you're applying to the fits headers and as parameters in the selavy catalogues.

Done

@ddobie
Copy link
Collaborator

ddobie commented Aug 17, 2023

@AkashA98 I suspect that something has gone wrong with the merge and rebase - there's a bunch of commits in this pull from @hansenjiang that I don't think should be in here.
How did you actually do it? Should just be something like

git checkout dev
git pull
git checkout add_corrections
git merge dev

I did not merge my branch into dev. As @mubdi suggested, I just rebased it to an updated version of dev branch after @hansenjiang pushed his commits (I did overwrite a couple of conflicts from @hansenjiang to update the correction-related code). I am relatively new to this rebasing stuff, but I thought that the residual commits from @hansenjiang that were not conflicting with mine will remain since I rebased, but maybe I am wrong. Can @mubdi / @hansenjiang confirm if it is the case?

Yep, this is correct -- there was an earlier dev PR that @AkashA98 rebased against. The changes you see made by @hansenjiang were from that commit.

But those changes should already be on dev shouldn't they? And hence shouldn't be showing as changed files on this PR?

The way I've always done things (which might not be best practice) is to merge the latest version of dev into your own branch and then submit a PR from your branch to dev. Just concerned that Akash might have rebased against an older version of dev, or a different branch, and hence this PR is actually undoing changes

@AkashA98
Copy link
Collaborator Author

@AkashA98 I suspect that something has gone wrong with the merge and rebase - there's a bunch of commits in this pull from @hansenjiang that I don't think should be in here.
How did you actually do it? Should just be something like

git checkout dev
git pull
git checkout add_corrections
git merge dev

I did not merge my branch into dev. As @mubdi suggested, I just rebased it to an updated version of dev branch after @hansenjiang pushed his commits (I did overwrite a couple of conflicts from @hansenjiang to update the correction-related code). I am relatively new to this rebasing stuff, but I thought that the residual commits from @hansenjiang that were not conflicting with mine will remain since I rebased, but maybe I am wrong. Can @mubdi / @hansenjiang confirm if it is the case?

Yep, this is correct -- there was an earlier dev PR that @AkashA98 rebased against. The changes you see made by @hansenjiang were from that commit.

But those changes should already be on dev shouldn't they? And hence shouldn't be showing as changed files on this PR?

The way I've always done things (which might not be best practice) is to merge the latest version of dev into your own branch and then submit a PR from your branch to dev. Just concerned that Akash might have rebased against an older version of dev, or a different branch, and hence this PR is actually undoing changes

No, the dev branch I am rebasing onto is the one that Hansen already pushed the changes to. So, when I try to rebase it, it adds all those commits to my branch that Hansen committed to dev and they are showing up here

@AkashA98
Copy link
Collaborator Author

Another general comment - you should use f-strings throughout. e.g. instead of

logger.debug("Using crossmatch radius: %s.", radius)

you can use

logger.debug(f"Using crossmatch radius: {radius}.")

All such code is now corrected.

@AkashA98
Copy link
Collaborator Author

ok, @mubdi , @ddobie , @hansenjiang . I have tested the code with a couple of epochs of data and it works fine. I still have to come up with a rigorous set of tests for this, but this PR right now is good to go (modulo the init file which I rebased from Hansen's dev branch)

ddobie
ddobie previously requested changes Aug 23, 2023
vast_post_processing/corrections.py Outdated Show resolved Hide resolved
vast_post_processing/corrections.py Outdated Show resolved Hide resolved
vast_post_processing/corrections.py Outdated Show resolved Hide resolved
vast_post_processing/corrections.py Outdated Show resolved Hide resolved
vast_post_processing/corrections.py Outdated Show resolved Hide resolved
@hansenjiang hansenjiang requested a review from ddobie September 6, 2023 21:26
Copy link
Contributor

@mubdi mubdi left a comment

Choose a reason for hiding this comment

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

GTG!

@mubdi mubdi dismissed ddobie’s stale review September 7, 2023 14:34

All now addressed.

@mubdi mubdi merged commit 76f19c8 into dev Sep 7, 2023
@mubdi mubdi deleted the add_corrections branch September 7, 2023 14:35
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.

Implement Flux Scale and Astrometry Correction
4 participants