pyregion
pyregion copied to clipboard
Make ds9 region file parser fast
The docs contain this note: "pyregion is rather slow, likely due to a inefficient parser." ( see http://pyregion.readthedocs.org/en/latest/index.html#documentation )
It's really slow ... parsing 1000 simple circle regions
with open('ds9.reg', 'w') as f:
for _ in range(1000):
f.write('circle(0,0,1)\n')
takes 7 seconds:
%time pyregion.open('ds9.reg')
CPU times: user 7.59 s, sys: 20 ms, total: 7.61 s
Astropy bundles ply, so if someone takes this on it might be worth considering using ply
(currently pyparsing is used).
I'm using pyregion
in a data analysis / image plotting pipeline and region file parsing is actually the bottleneck, but it's acceptable and I'm not very familiar with parsing and region files, so I don't plan to take this on ... just wanted to make a GH issue so this known issue is not forgotten.