These are chat archives for astropy/astropy

19th
May 2016
p3trus
@p3trus
May 19 2016 08:12
How do I keep Table.read from overwriting the fill_values attribute of my custom Data class?I have implemented a custom ascii reader inheriting from astropy.io.ascii.basic.Csv with a custom data class inheriting from astropy.io.ascii.basic.CsvData. Using this reader directly works perfectly fine. Using Table.read however breaks because astropy.io.ascii.ui.read overwrites the fill_values attribute of astropy.io.ascii.basic.CsvData.
amaurea
@amaurea
May 19 2016 19:45
Ok, I've had a reply from Calabretta. Bounds checking is very simple to configure in C. You simply call wcsbchk(&wcs,0), and the problem goes away.
Is this call exposed in the python wrapper?
If not, it would be useful
Could be as simple as providing wcs.bounds_check = False
@eteq: What do you think?
Erik Tollerud
@eteq
May 19 2016 19:48
@amaurea - aha!
Add the following line to your wrap2.py script:
wcs.wcs.bounds_check(False, False)
amaurea
@amaurea
May 19 2016 19:49
Ah, it's already there. I feel stupid now
amaurea @amaurea tries it out
Erik Tollerud
@eteq
May 19 2016 19:49
(right before the for loop)
yep, it’s there. but it’s not at all obvious!
amaurea
@amaurea
May 19 2016 19:50
Well, that
's weird
When I do that, every output is nan
@eteq: Does it work for you?
Erik Tollerud
@eteq
May 19 2016 19:52
sort of: check this out:
import numpy as np
from astropy.wcs import WCS
wcs = WCS(naxis=2)
wcs.wcs.ctype = ["RA---CAR","DEC--CAR"]
wcs.wcs.cdelt = [10,10]
wcs.wcs.crval = [-90,90]
wcs.wcs.crpix = [10,1]

for i in range(40):
    x, y = i, 0
    ra, dec = wcs.wcs_pix2world(x,y,0)
    print "%2d %8.3f %8.3f %8.3f %8.3f" % (i, x, y, ra, dec)

wcs.wcs.bounds_check(False, False)

for i in range(40):
    x, y = i, 0
    ra, dec = wcs.wcs_pix2world(x,y,0)
    print "%2d %8.3f %8.3f %8.3f %8.3f" % (i, x, y, ra, dec)
for me the second time it works
but the first time it does not
amaurea
@amaurea
May 19 2016 19:52
oh
amaurea @amaurea tries
Erik Tollerud
@eteq
May 19 2016 19:52
err, that is, if I cut out the first for loop I get all nans like you did
amaurea
@amaurea
May 19 2016 19:53
perhaps wcs has not been properly initialized before the first call
Erik Tollerud
@eteq
May 19 2016 19:53
that must be it, as this works:
import numpy as np
from astropy.wcs import WCS
wcs = WCS(naxis=2)
wcs.wcs.ctype = ["RA---CAR","DEC--CAR"]
wcs.wcs.cdelt = [10,10]
wcs.wcs.crval = [-90,90]
wcs.wcs.crpix = [10,1]

wcs.wcs_pix2world(0,0,0)
wcs.wcs.bounds_check(False, False)

for i in range(40):
    x, y = i, 0
    ra, dec = wcs.wcs_pix2world(x,y,0)
    print "%2d %8.3f %8.3f %8.3f %8.3f" % (i, x, y, ra, dec)
amaurea
@amaurea
May 19 2016 19:54
I just tried the same thing
Erik Tollerud
@eteq
May 19 2016 19:54
So that does meet your use case, right @amaurea ?
amaurea
@amaurea
May 19 2016 19:54
Yes, that should work. That makes issue #2, about moving the reference point, less important
Calabrette said he would get back to me about that
Perhaps a bug report should be filled about calling bounds_check before any transformations
Erik Tollerud
@eteq
May 19 2016 20:04
Actually, @amaurea, I was going to ask two things of you:
  1. see if you can figure out what might fix that, and either create an issue with your finidings if you can’t, or issue a pull request to Astropy if you can
  2. consider adding a pull request to either add a bounds_check argument to wcs_pix2world, or add an example to the documentation about how to invoke wcs.wcs.bound_check for this use case
amaurea
@amaurea
May 19 2016 20:04
@eteq: Oh, I was just about submitting an issue
*to submit
Erik Tollerud
@eteq
May 19 2016 20:05
Oh, feel free to just do that anyway. But better yet would then be to make a PR that fixes it right away ;)
amaurea
@amaurea
May 19 2016 20:06
I'm fine with the curren bounds_check (though I would have done it as a property instead of a function, the same way the other wcs stuff works)
amaurea
@amaurea
May 19 2016 20:31
@eteq: Fixed it