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

U/danielsf/validate centroid #392

Open
wants to merge 44 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
0bb6596
add method to undo CatSim's dePrecess method
danielsf Nov 8, 2016
4f9439a
added scratchSpace/ dir to tests/
danielsf Nov 8, 2016
b9511bc
_rePrecess can handle scalars
danielsf Nov 9, 2016
f03c900
add icrsFromPhoSim
danielsf Nov 9, 2016
493c2c3
add script to compare CatSim centroid file to PhoSim centroid file
danielsf Nov 10, 2016
2d71f83
cast nphot as an int
danielsf Nov 10, 2016
2c69f7d
renamed some variables to be more illuminating
danielsf Nov 10, 2016
405a847
make sure that sources just in PhoSim have ID=0
danielsf Nov 10, 2016
e719b33
added script to predict centroid file from CatSim
danielsf Nov 10, 2016
1b8d211
always manipulate data as a dataframe
danielsf Nov 10, 2016
a315c9c
remove unused code
danielsf Nov 10, 2016
0ff4e1e
remove declarations of dx, dy, nphot
danielsf Nov 10, 2016
d8dbed3
added comment
danielsf Nov 10, 2016
cd6b12c
remove print statement
danielsf Nov 10, 2016
688ee98
plot max displacement as a function of nphot
danielsf Nov 10, 2016
3ffbb00
move CatSim DataFrame generation into separate module
danielsf Nov 10, 2016
0b02be0
remove unused code
danielsf Nov 10, 2016
90bea35
change plot label
danielsf Nov 10, 2016
5276635
remove unused import
danielsf Nov 10, 2016
23d8a59
added Jupyter notebook to validate centroid files
danielsf Nov 10, 2016
e0dbb7d
remove script to compare centroids (it is now redundant with the note…
danielsf Nov 10, 2016
e06425b
add one more comment to ValidateCentroidFile
danielsf Nov 10, 2016
a2a3d53
fix pandas calls in notebook
danielsf Nov 10, 2016
916f8e0
Revert "remove script to compare centroids (it is now redundant with …
danielsf Nov 10, 2016
9d7f9cf
get rid of ValidateCentroidFile ipython notebook
danielsf Nov 10, 2016
a0882fa
use argparser
danielsf Nov 10, 2016
c0c546f
added --clean arg to overwrite old files
danielsf Nov 10, 2016
af9f7cc
adapt lowest resolution min/max in scatter plot
danielsf Nov 10, 2016
98c7cb0
calculate min dist from chip center of catsim-only sources
danielsf Nov 11, 2016
7e52a3c
gather all scalar computations to the end of the script
danielsf Nov 11, 2016
18d091e
put everything in a tex file
danielsf Nov 11, 2016
18dc47e
remove print statements
danielsf Nov 11, 2016
d6bbd41
add min pixel dist from center of just catsim sources to .tex
danielsf Nov 11, 2016
844c36d
make output dir if it does not exist
danielsf Nov 11, 2016
794c1b4
set more sensible default dir
danielsf Nov 11, 2016
b461d3e
add plot showing displacement as function of distance from center
danielsf Nov 11, 2016
9164fe9
center scatter plot on weighted mean displacement
danielsf Nov 11, 2016
2e6e026
rename predictCentroidFile.py to validateCentroidFile.py
danielsf Nov 11, 2016
c7dba8b
move validation to a class
danielsf Nov 11, 2016
8f0b1e3
fix bug
danielsf Nov 14, 2016
e8fa804
add crosshairs on (0,0) in scatter plots
danielsf Nov 14, 2016
bd78e33
make sure cross-hairs are always marked as 0.00
danielsf Nov 14, 2016
2eaeeba
added method to return a dict of the summary scalars
danielsf Nov 14, 2016
1efb46d
added docstrings
danielsf Nov 14, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions bin/compare_centroids.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import argparse
from desc.twinkles import CentroidValidator

if __name__ == "__main__":
parser = argparse.ArgumentParser("Read in an InstanceCatalog and a centroid file. "
"Use CatSim to calculate the pixel positions of "
"objects in the InstanceCatalog. Compare this "
"to the pixel positions as reported in the "
"centroid file.\n\nexample:\n\n"
"python compare_centroids.py --cat myInstanceCatalog.txt "
"--cent myCentroidFile.txt --out_dir my/output/director/")

parser.add_argument("--cat", type=str, help="path to the InstanceCatalog", default=None)
parser.add_argument("--cent", type=str, help="path to the centroid file", default=None)
parser.add_argument("--clean", type=bool, help="delete old files, if names conflict",
default=False)
parser.add_argument("--out_dir", type=str, help="directory where we will put output files",
default=".")

args = parser.parse_args()

if args.cat is None or args.cent is None:
raise RuntimeError("Must specify an InstanceCatalog and a centroid file.\n"
"You specified %s and %s" % (args.cat, args.cent))


validator = CentroidValidator(args.cat, args.cent)
validator.create_tex_file(args.out_dir, args.clean)
print validator.get_scalars()
2 changes: 2 additions & 0 deletions python/desc/twinkles/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
with warnings.catch_warnings():
warnings.filterwarnings('ignore', 'Duplicate object type id', UserWarning)
warnings.filterwarnings('ignore', 'duplicate object identifie', UserWarning)
from .astrometryUtils import *
from .analyseICat import *
from .calc_snr import *
from .cleanupspectra import *
Expand All @@ -17,6 +18,7 @@
from .twinkles_io import *
from .twinkles_sky import *
from .obsHistIDOrdering import *
from .validateCentroidFile import *
try:
from .version import *
except ImportError:
Expand Down
76 changes: 76 additions & 0 deletions python/desc/twinkles/astrometryUtils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import numpy as np
import numbers
from lsst.sims.utils import cartesianFromSpherical, sphericalFromCartesian
from lsst.sims.utils import rotationMatrixFromVectors
from lsst.sims.utils import _observedFromICRS, icrsFromObserved

__all__ = ["_rePrecess", "icrsFromPhoSim"]

def _rePrecess(ra_list, dec_list, obs):
"""
Undo the 'dePrecession' done to mangle observed RA, Dec into the
RA, Dec coordinates expected by PhoSim

Parameters
----------
ra_list a list of dePrecessed RA (in 'observed' frame) in radians

dec_list is a list of dePrecessed Dec (in 'observed' frame) in radians.

*see lsst.sims.utils.AstrometryUtils.observedFromICRS for definition
of 'observed' RA, Dec

obs is an ObservationMetaData characterizing the telescope pointing

Returns
-------
RA and Dec in 'observed' frame in radians
"""

xyz_bore = cartesianFromSpherical(np.array([obs._pointingRA]),
np.array([obs._pointingDec]))

precessedRA, precessedDec = _observedFromICRS(np.array([obs._pointingRA]),
np.array([obs._pointingDec]),
obs_metadata=obs,
epoch=2000.0,
includeRefraction=False)

xyz_precessed = cartesianFromSpherical(precessedRA, precessedDec)

rotMat = rotationMatrixFromVectors(xyz_bore[0], xyz_precessed[0])

xyz_list = cartesianFromSpherical(ra_list, dec_list)

if isinstance(ra_list, numbers.Number):
xyz_re_precessed = np.dot(rotMat, xyz_list)
else:
xyz_re_precessed = np.array([np.dot(rotMat, xx) for xx in xyz_list])

ra_re_precessed, dec_re_precessed = sphericalFromCartesian(xyz_re_precessed)

return ra_re_precessed, dec_re_precessed


def icrsFromPhoSim(ra_list, dec_list, obs):
"""
Parameters
----------
ra_list is the PhoSim ra value in degrees

dec_list is the PhoSim dec value in degrees

obs is the ObservationMetaData characterizing the pointing

Returns
-------
RA, Dec in ICRS in degrees
"""

ra_precessed, dec_precessed = _rePrecess(np.radians(ra_list),
np.radians(dec_list),
obs)

return icrsFromObserved(np.degrees(ra_precessed), np.degrees(dec_precessed),
obs_metadata=obs, epoch=2000.0,
includeRefraction=False)
Loading