-
Notifications
You must be signed in to change notification settings - Fork 13
Adding rubin_proc #25
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
Open
bungerbuilder
wants to merge
10
commits into
schlafly:master
Choose a base branch
from
bungerbuilder:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
11657af
Add files via upload
bungerbuilder c533636
Rename Rubin_proc.py to rubin_proc.py
bungerbuilder b50e892
Update rubin_proc.py
bungerbuilder e645689
Update crowdsource/rubin_proc.py
bungerbuilder cbf31f9
Update crowdsource/rubin_proc.py
bungerbuilder 8387c10
Update crowdsource/rubin_proc.py
bungerbuilder f6b630c
Update crowdsource/rubin_proc.py
bungerbuilder 765fb14
Update rubin_proc.py
bungerbuilder fef56a6
Update rubin_proc.py
bungerbuilder 78b42a0
Update rubin_proc.py
bungerbuilder File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
|
|
||
| import numpy as np | ||
| import argparse, os, pdb | ||
| import crowdsource.psf as psfmod | ||
| from crowdsource import crowdsource_base | ||
| from lsst.daf.butler import Butler | ||
| from functools import partial | ||
|
|
||
|
|
||
| def process(visitId, detector, nx = 4, ny = 4, maxstars = 10000000, fewstars = 60, threshold = 5, **kw): | ||
| """ | ||
| Parameters | ||
| ---------- | ||
| visitId : Rubin images are taken with an associated visitId attatched in the metadata. There are nine | ||
| images associated with one visitId. | ||
| detector: Determines which of the nine images will be processed. | ||
|
|
||
| Process: | ||
| 1. Use the RSP Butler to find the Rubin image | ||
| 2. Get the PSF using wise_psf_fit | ||
| 3. Making the variables for CROWDSOURCE | ||
| 4. Run CROWDSOURCE on an image | ||
|
|
||
| Returns | ||
| ------- | ||
| res : The processed image as an array. | ||
|
|
||
| """ | ||
|
|
||
| butler = Butler("dp1", collections="LSSTComCam/DP1") | ||
|
|
||
| dataset_refs = list(butler.query_datasets( | ||
| "visit_image", | ||
| where="visit.id = :visitId AND detector.id = :detector", | ||
| bind={"visitId": visitId, "detector": detector}, | ||
| )) | ||
|
|
||
| if len(dataset_refs) == 0: | ||
| raise RuntimeError( | ||
| f"No visit_image found for visit={visitId}, detector={detector}") | ||
|
|
||
| else: | ||
| print(f"Visit image found for visit={visitId}, detector={detector}") | ||
|
|
||
| ref = list(dataset_refs)[0] | ||
| visit_image = butler.get(ref) | ||
|
|
||
| #Getting the PSF | ||
| rubin_psf = visit_image.getPsf() | ||
| visit_center = visit_image.getBBox().getCenter() | ||
|
|
||
| psf_stamp_visit = rubin_psf.computeKernelImage(visit_center).array | ||
|
|
||
| stamp = np.clip(np.array(psf_stamp_visit), 1e-10, np.inf) | ||
| stamp = stamp / np.sum(stamp) | ||
|
|
||
| psf = psfmod.SimplePSF(stamp) | ||
|
|
||
| print("Using fit_variable_moffat_psf") | ||
| psf.fitfun = psfmod.fit_variable_moffat_psf | ||
|
|
||
| #crowdsource variables | ||
| im = visit_image.image.array.astype(np.float32) | ||
|
|
||
| var = visit_image.variance.array | ||
| sqivar = np.where(var > 0, 1.0 / np.sqrt(var), 0.0).astype(np.float32) | ||
|
|
||
| mask = visit_image.mask | ||
|
|
||
| bad_bits = 0 | ||
| for plane in ("BAD", "SAT", "CR", "NO_DATA", "EDGE", "INTRP", "STREAK"): | ||
| if plane in mask.getMaskPlaneDict(): | ||
| bad_bits |= mask.getPlaneBitMask(plane) | ||
|
|
||
| flag = (mask.array & bad_bits).astype(np.uint32) | ||
| sqivar[(mask.array & bad_bits) != 0] = 0.0 | ||
|
|
||
| #run crowdsource | ||
| res = crowdsource_base.fit_im(im, psf, sqivar, dq=flag, refit_psf=True, | ||
| verbose = True, ntilex=nx, ntiley=ny, maxiter = 10, threshold = threshold, **kw) | ||
|
|
||
| print("CROWDSOURCE is done!") | ||
|
|
||
| return res | ||
|
|
||
| if __name__ == "__main__": | ||
| from astropy.io import fits | ||
|
|
||
| parser = argparse.ArgumentParser(description='Run crowdsource on a Rubin visit_image') | ||
| # 3 arguments: visitId, detector, outfn | ||
| parser.add_argument('visitId', type=int, nargs=1) | ||
| parser.add_argument('detector', type=int, nargs=1) | ||
| parser.add_argument('outfn', type=str, nargs=1) | ||
| parser.add_argument('--nx', '-x', type=int, default=4, | ||
| help='number of tiles in x') | ||
| parser.add_argument('--ny', '-y', type=int, default=4, | ||
| help='number of tiles in y') | ||
| parser.add_argument('--maxstars', type=int, default=10000000, | ||
| help='maximum number of stars to fit') | ||
| parser.add_argument('--fewstars', type=int, default=60, | ||
| help='number of stars below which a tile is considered to have few stars') | ||
| parser.add_argument('--threshold', '-t', type=float, default=5, | ||
| help='detection threshold in sigma') | ||
| args = parser.parse_args() | ||
|
|
||
| visitId = args.visitId[0] | ||
| detector = args.detector[0] | ||
| outfn = args.outfn[0] | ||
|
|
||
| res = process(visitId, detector, nx=args.nx, ny=args.ny, | ||
| maxstars=args.maxstars, fewstars=args.fewstars, | ||
| threshold=args.threshold) | ||
|
|
||
| fits.writeto(outfn, res[0], overwrite=True) | ||
| fits.append(outfn, res[1][0]) | ||
| fits.append(outfn, res[2][0]) | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mentioned needing an update to psf.py here, but I don't see it. You'll probably need to git add that file.