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

Imexamine radial_profile: background subtraction gives 'UFuncTypeError' #219

Open
ross-dobson opened this issue Dec 6, 2020 · 0 comments

Comments

@ross-dobson
Copy link

ross-dobson commented Dec 6, 2020

I'm not using a viewer, so I have it set up that:

from imexam.imexamine import Imexamine
plots=Imexamine()

I then have an image, that I am attempting to generate the radial profile of, loaded in from a FITS as img.

plots.radial_profile(x=581,y=1907,data=img,genplot=True)

This outputs:

xc=581.2780	yc=1906.6478
Background per pixel: 2124.4217152419224
---------------------------------------------------------------------------
UFuncTypeError                            Traceback (most recent call last)
<ipython-input-32-c96832faaa47> in <module>()
----> 1 plots.radial_profile(x=581,y=1907,data=img1,genplot=True)

/usr/local/lib/python3.6/dist-packages/imexam/imexamine.py in radial_profile(self, x, y, data, form, genplot, fig)
   1161                 self.log.info("Sky background negative, setting to zero")
   1162             self.log.info(f"Background per pixel: {sky_per_pix}")
-> 1163             flux -= sky_per_pix
   1164 
   1165             if getdata:

UFuncTypeError: Cannot cast ufunc 'subtract' output from dtype('float64') to dtype('uint16') with casting rule 'same_kind'

If I disable the background parameter in the radial_profile_pars dict (not done in the most Pythonic way, I admit):

d=imexam.imexam_defpars.radial_profile_pars
d['background'] = [False, 'Subtract background? [bool]']

The function then runs as expected, (because it skips the line causing the UFuncTypeError). However, I would quite like the background subtraction. I wonder if this may just be as simple as changing line in radial_profile shown at 1163 to be flux = flux - sky_per_pix, rather than using -=?

I also notice this is similar to a problem with rimexam, with a similar fix suggested in issue #210:

The offending line seems to be

flux -= sky_per_pix
This seems relevant: https://techoverflow.net/2019/05/22/how-to-fix-numpy-typeerror-cannot-cast-ufunc-subtract-output-from-dtypefloat64-to-dtypeint64-with-casting-rule-same_kind/

Is it as simple as making the line

flux = flux-sky_per_pix

?

Originally posted by @karlglazebrook in #210 (comment)

I tried changing this in a new function and adding it with .register(), but I wasn't sure on exactly how to register the function, so wasn't able to check this myself.


Additionally, when I have had it working (i.e. without the background subtraction), I am getting clearly inaccurate FWHM values (nearly 6 rather than nearly 2.5, measured in IRAF), similar to issue 165 .
EDIT: Apologies, mistake on my half. IRAF was returning the half-FWHM, so the FWHM is being returned correctly. However, the main issue still persists.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant