Skip to content

Commit

Permalink
filter out instance catalog entries with 'inf' as one of the fields
Browse files Browse the repository at this point in the history
  • Loading branch information
jchiang87 committed Sep 13, 2018
1 parent 4a64601 commit d360756
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 1 deletion.
3 changes: 2 additions & 1 deletion python/desc/imsim/trim.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@ def _process_objects(self, sensor_list, chunk_size, radius=0.18,
ichunk = 0
for ichunk, line in zip(range(chunk_size), fd):
nread += 1
if not line.startswith('object'):
if (not line.startswith('object') or
'inf' in line.split()):
continue
object_lines.append(line)
disaggregator = Disaggregator(object_lines, self)
Expand Down
53 changes: 53 additions & 0 deletions tests/bad_instcat.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#comment
rightascension 31.1133844
declination -10.0970060
mjd 59797.2854090
altitude 43.6990272
azimuth 73.7707957
filter 2
rotskypos 69.0922930
rottelpos 0.000
dist2moon 145.1095257
moonalt -11.1383568
moondec -18.7702120
moonphase 59.6288830
moonra 230.9832941
nsnap 2
obshistid 161899
seed 161899
seeing 0.7613760
sunalt -59.1098785
vistime 33.0000000
object MS_inf_8 31.2400746 -10.09365 29.3370237 starSED/phoSimMLT/lte033-4.5-1.0a+0.4.BT-Settl.spec.gz 0 0 0 0 0 0 point none CCM 0.0635117705 3.1
object 811883456516 31.2338048 -10.0578789 26.9267056 starSED/phoSimMLT/lte027-2.0-0.0a+0.0.BT-Settl.spec.gz 0 0 0 0 0 0 point none CCM 0.0630700848 3.1
object 1046816368644 31.2371416 -10.0554117 28.7153047 starSED/phoSimMLT/lte027-2.0-0.0a+0.0.BT-Settl.spec.gz 0 0 0 0 0 0 point none CCM 0.0630379733 3.1
object 1046816356356 31.2305508 -10.0620637 26.7932237 starSED/phoSimMLT/lte033-4.5-1.0a+0.4.BT-Settl.spec.gz 0 0 0 0 0 0 point none CCM 0.0631214889 3.1
object 1046816650244 31.2225696 -10.0784635 29.2177099 starSED/phoSimMLT/lte032-4.5-1.0a+0.4.BT-Settl.spec.gz 0 0 0 0 0 0 point none CCM 0.0632916884 3.1
object 275781785604 31.2570189 -10.0836452 23.454705 starSED/phoSimMLT/lte027-2.0-0.0a+0.0.BT-Settl.spec.gz 0 0 0 0 0 0 point none CCM 0.0638548764 3.1
object 956090372100 31.2608206 -10.0836426 24.218305 starSED/phoSimMLT/lte027-2.0-0.0a+0.0.BT-Settl.spec.gz 0 0 0 0 0 0 point CCM 0.0651282621 3.1 CCM 0.0651282621 3.1
object 956090392580 31.258544 -10.0948714 24.6497053 starSED/phoSimMLT/lte027-2.0-0.0a+0.0.BT-Settl.spec.gz 0 0 0 0 0 0 point CCM 0.0639515271 3.1 none
object 811883374596 31.2499807 -10.032142 23.1621553 starSED/phoSimMLT/lte031-4.5-1.0a+0.4.BT-Settl.spec.gz 0 0 0 0 0 0 point none none
object 811883374597 31.2499807 -10.032142 1000 starSED/phoSimMLT/lte031-4.5-1.0a+0.4.BT-Settl.spec.gz 0 0 0 0 0 0 point none CCM 0.0651531353 3.1
object 34308924793883 31.1323517 -9.98959037 26.0715008 galaxySED/Exp.40E09.02Z.spec.gz 0.548564017 0 0 0 0 0 sersic2d 0.580386579 0.446435213 2.77863669 1 CCM 0.100000001 3.0999999 CCM 0.0594432589 3.1
object 34308823171099 31.1285346 -9.99287262 25.2314701 galaxySED/Const.25E09.02Z.spec.gz 1.57341075 0 0 0 0 0 sersic2d 0.273093104 0.155404001 260.215698 1 CCM 0.300000012 3.0999999 CCM 0.0595355292 3.1
object 34306986342427 31.1297691 -9.99235542 24.9022198 galaxySED/Const.12E10.04Z.spec.gz 0.876115918 0 0 0 0 0 sersic2d 0.233041495 0.188624501 112.236351 1 CCM 0.100000001 3.0999999 CCM 0.0595341165 3.1
object 34314318316571 31.1322004 -9.99203681 25.1736794 galaxySED/Exp.20E09.25Z.spec.gz 1.80202651 0 0 0 0 0 sersic2d 0.342070311 0.0926302001 55.8305664 1 CCM 0.699999988 3.0999999 CCM 0.0595686490 3.1
object 34312970660891 31.1330818 -9.99200572 25.9306793 galaxySED/Exp.50E09.04Z.spec.gz 1.13565516 0 0 0 0 0 sersic2d 0.158763796 0.0786406025 161.559387 1 CCM 0.300000012 3.0999999 CCM 0.0595858998 3.1
object 34304522113051 31.1330224 -9.99137652 23.0075798 galaxySED/Exp.32E09.04Z.spec.gz 0.545978725 0 0 0 0 0 sersic2d 0.4129408 0.269056112 74.1974869 1 CCM 0.200000003 3.0999999 CCM 0.0595516489 3.1
object 34306130287643 31.1312678 -9.99309197 24.3942509 galaxySED/Const.12E10.04Z.spec.gz 1.05881763 0 0 0 0 0 sersic2d 0.581499219 0.496408403 112.920998 1 CCM 0.000000000 3.0999999 CCM 0.0596038563 3.1
object 34308956856347 31.1330884 -9.99204124 25.5936604 galaxySED/Const.32E09.02Z.spec.gz 0.893723488 0 0 0 0 0 sersic2d 0.357829899 0.219305307 167.648987 1 CCM 0.200000003 3.0999999 CCM 0.0595878995 3.1
object 34314197354523 31.1304042 -9.9933643 25.5964203 galaxySED/Const.50E09.04Z.spec.gz 1.2973839 0 0 0 0 0 sersic2d 0.0772624016 0.0265941005 211.138168 1 none CCM 0.0595998126 3.1
object 34307989098523 31.1305255 -9.99285975 24.8188305 galaxySED/Const.25E09.02Z.spec.gz 1.25965774 0 0 0 0 0 sersic2d 0.415663213 0.225128204 107.101799 1 CCM 0.300000012 3.0999999 none
object 34307989098524 31.1305255 -9.99285975 24.8188305 galaxySED/Const.25E09.02Z.spec.gz 1.25965774 0 0 0 0 0 sersic2d 0.225128204 0.415663213 107.101799 1 none none
object 34304522113055 31.1330224 -9.99137652 23.0075798 galaxySED/Exp.32E09.04Z.spec.gz 0.545978725 0 0 0 0 0 knots 0.4129408 0.269056112 74.1974869 23 CCM 0.200000003 3.0999999 CCM 0.0595516489 3.1
object 34304522113056 31.1330224 -9.99137652 23.0075798 galaxySED/Exp.32E09.04Z.spec.gz 0.545978725 0 0 0 0 0 knots 0.4129408 0.269056112 74.1974869 0 CCM 0.200000003 3.0999999 CCM 0.0595516489 3.1
object 1 31.1133844 -10.0970060 18. galaxySED/Const.25E09.02Z.spec.gz 1.25965774 0 0 0 0 0 data/lensed_agn_disk.fits.gz 0.1 0 CCM 0.200000003 3.0999999 CCM 0.0595516489 3.1

# Bad entries with infs follow:
object MS_567_8 31.2400746 -10.09365 29.3370237 starSED/phoSimMLT/lte033-4.5-1.0a+0.4.BT-Settl.spec.gz 0 0 0 0 0 0 point none CCM inf 3.1
object MS_567_8 31.2400746 -10.09365 29.3370237 starSED/phoSimMLT/lte033-4.5-1.0a+0.4.BT-Settl.spec.gz inf 0 0 0 0 0 point none CCM 0.0635117705 3.1

# Good entry with 'inf' in the object id (which is ok)
object MS_inf_8 31.2400746 -10.09365 29.3370237 starSED/phoSimMLT/lte033-4.5-1.0a+0.4.BT-Settl.spec.gz 0 0 0 0 0 0 point none CCM 0.0635117705 3.1
# Good entry with 'inf' in the spec file name
object MS_inf_8 31.2400746 -10.09365 29.3370237 starSED/phoSimMLT/lte033-4.5-1.0a+0.4.BT-Settlinf.spec.gz 0 0 0 0 0 0 point none CCM 0.0635117705 3.1
14 changes: 14 additions & 0 deletions tests/test_trimmer.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,19 @@ def test_InstCatTrimmer(self):
chunk_size=chunk_size)
self.assertEqual(len(objs[sensor]), 24)

def test_inf_filter(self):
"""
Test filtering of the ` inf ` string (i.e., bracked by spaces)
appearing anywhere in the instance catalog entry to avoid
underflows, floating point exceptions, etc.. from badly formed
entries.
"""
instcat = os.path.join(os.environ['IMSIM_DIR'], 'tests',
'bad_instcat.txt')
sensor = 'R:2,2 S:1,1'
objs = desc.imsim.InstCatTrimmer(instcat, [sensor], minsource=10)
self.assertEqual(len(objs[sensor]), 26)


if __name__ == '__main__':
unittest.main()

0 comments on commit d360756

Please sign in to comment.