AstroHuntsman / gunagala

6 stars 10 forks source link

crval not set before imager.make_noiseless_image is run #17

Closed lspitler closed 5 years ago

lspitler commented 6 years ago

Crafting a PSF using a simulated galaxy, where I hacked together a new instance of a Huntsman imager:

huntsman_galaxy = imager.Imager(optic=huntsman.optic,
                        camera=huntsman.camera,
                        filters=huntsman.filters,
                        psf=galaxy_psf,
                        sky=huntsman.sky)

Solution was to call huntsman_galaxy.get_pixel_coords(centre), which sets self.wcs.wcs.crval and allows imager.make_noiseless_image to run.

lspitler commented 6 years ago

@bazkiaei is this still an issue? @AnthonyHorton do you have a suggested fix for us to implement?

bazkiaei commented 6 years ago

@bazkiaei is this still an issue? @AnthonyHorton do you have a suggested fix for us to implement?

I believe it is solved due to clipping below zero pixel values within "Fix axis 18 WIP" pull request and adding a warning to the code.

lspitler commented 6 years ago

@bazkiaei I just tried running the jupyter notebook code using this branch and it fails on the 5th cell running:

sky_image = huntsman.make_noiseless_image(centre='14h41m -60d54m',
                                         obs_time='2018-04-12T08:00',
                                         filter_name='g')

I get this error:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-5-47b8d37b5389> in <module>()
----> 1 sky_image = huntsman.make_noiseless_image(centre='14h41m -60d54m',
      2                                          obs_time='2018-04-12T08:00',
      3                                          filter_name='g')
      4 
      5 plt.imshow(sky_image)

AttributeError: 'Imager' object has no attribute 'make_noiseless_image'

Do you get the same error?

bazkiaei commented 6 years ago

@bazkiaei I just tried running the jupyter notebook code using this branch and it fails on the 5th cell running:

sky_image = huntsman.make_noiseless_image(centre='14h41m -60d54m',
                                         obs_time='2018-04-12T08:00',
                                         filter_name='g')

I get this error:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-5-47b8d37b5389> in <module>()
----> 1 sky_image = huntsman.make_noiseless_image(centre='14h41m -60d54m',
      2                                          obs_time='2018-04-12T08:00',
      3                                          filter_name='g')
      4 
      5 plt.imshow(sky_image)

AttributeError: 'Imager' object has no attribute 'make_noiseless_image'

Do you get the same error?

I was getting that error at the first days I was working on Mock Image Generator. I think the reason is that you are on develop branch of gunagala. In that case you should change the branch to image_sime.

AnthonyHorton commented 6 years ago

@bazkiaei That axes order fix and CRVAL are unrelated. CRVAL is used to set the RA and dec of the 'reference pixel', i.e. it determines where on the sky the imager is pointing. Might be work checking the axis order of CRPIX, though...

@lee It doesn't get set until make_noiseless_image is run because I was assuming that the on sky position of the imager would only become relevant when creating a simulated image, at which point it gets set from the centre argument of the make_noiseless_image call. There's not really any sensible default value, and (at the time, at least) there didn't seem to be any reason for setting it before the make_noiseless_image call. Could add a method for pre-setting CRVAL if there is a need, though?

bazkiaei commented 6 years ago

@bazkiaei That axes order fix and CRVAL are unrelated. CRVAL is used to set the RA and dec of the 'reference pixel', i.e. it determines where on the sky the imager is pointing. Might be work checking the axis order of CRPIX, though...

@lee It doesn't get set until make_noiseless_image is run because I was assuming that the on sky position of the imager would only become relevant when creating a simulated image, at which point it gets set from the centre argument of the make_noiseless_image call. There's not really any sensible default value, and (at the time, at least) there didn't seem to be any reason for setting it before the make_noiseless_image call. Could add a method for pre-setting CRVAL if there is a need, though?

Oh, I thought this is related to the error that was arising. @AnthonyHorton thank you for informing me.

lspitler commented 6 years ago

@AnthonyHorton the trouble is that make_noiseless_image make a call implying there is a WCS before one has been set if self.sky doesn't have an attribute 'relative_brightness'. The offending line is: pixel_coords = self.wcs.all_world2pix(((coords.ra.degree, coords.dec.degree),), 0) \

I think you just want to set pixel_coords = self.get_pixel_coords(centre) no matter what?

lspitler commented 6 years ago

I'm going to try and fix it and PR it...

AnthonyHorton commented 6 years ago

@lee Ah, OK. Probably quite a bit of scope for tidying up there. Rather too much setting things as a side effect of doing other things going on, which makes bugs like this more likely.

AnthonyHorton commented 5 years ago

Fixed by #25