guaix-ucm / megaradrp

MEGARA (Multi-Espectrógrafo en GTC de Alta Resolución para Astronomía) is a facility instrument designed for the 10.4m GTC telescope in La Palma (Spain).
https://guaix.fis.ucm.es/megara/
GNU General Public License v3.0
12 stars 6 forks source link

create_cube_from_rss returns nans for flux and velocity map #279

Open amanda-olmo opened 4 years ago

amanda-olmo commented 4 years ago

While trying to draw contours with visualization, I have found that create_cube_from_rss returns a cube full of nans (line 421 in visualization). This happens when the contours are to be taken from the flux or velocity column. It does not happen when the continuum column is selected.

python -m megaradrp.visualization mrk324_f2_ha.fits --contour --contour-image mrk324_f2_ha.fits --contour-image-column 17 -c 2 --hex-rel-size 1.26 world coordinates in pixel use column 2 world coordinates in pixel use column 17 fiber coordinates in arcsec fiber coordinates in arcsec Estoy aqui WARNING: FITSFixedWarning: CUNIT3 = / Units of coordinate increment and value a string value was expected. [astropy.wcs.wcs] /Users/root2/opt/anaconda3/envs/megaradev/lib/python3.7/site-packages/matplotlib/contour.py:1520: UserWarning: Warning: converting a masked element to nan. self.zmax = float(z.max()) /Users/root2/opt/anaconda3/envs/megaradev/lib/python3.7/site-packages/matplotlib/contour.py:1521: UserWarning: Warning: converting a masked element to nan. self.zmin = float(z.min()) /Users/root2/opt/anaconda3/envs/megaradev/lib/python3.7/site-packages/matplotlib/contour.py:1169: RuntimeWarning: invalid value encountered in less under = np.nonzero(lev < self.zmin)[0] /Users/root2/opt/anaconda3/envs/megaradev/lib/python3.7/site-packages/matplotlib/contour.py:1171: RuntimeWarning: invalid value encountered in greater over = np.nonzero(lev > self.zmax)[0] /Users/root2/opt/anaconda3/envs/megaradev/lib/python3.7/site-packages/matplotlib/contour.py:1200: RuntimeWarning: invalid value encountered in greater inside = (self.levels > self.zmin) & (self.levels < self.zmax) /Users/root2/opt/anaconda3/envs/megaradev/lib/python3.7/site-packages/matplotlib/contour.py:1200: RuntimeWarning: invalid value encountered in less inside = (self.levels > self.zmin) & (self.levels < self.zmax) /Users/root2/opt/anaconda3/envs/megaradev/lib/python3.7/site-packages/megaradrp-0.10.dev0-py3.7.egg/megaradrp/visualization.py:423: UserWarning: No contour levels were found within the data range. mm = ax.contour(interp, transform=tt_d) contour levels [nan]

sergiopasra commented 4 years ago

@amanda-olmo Could you send me the image? Thanks

sergiopasra commented 4 years ago

@amanda-olmo Amanda, the image itself has nan values. Cube doesn't mask or handle specially nan values as they are not expected to appear. nan values usually spoil all the math operations unless handled specially. This means that if you image has nan values, the contours will be nan also.

My question is, the nan values represent something, missing data for example, or are they simply the result of a bad math operation, like 0 / 0? If it is the later, then this is not a bug

amanda-olmo commented 4 years ago

The input file for the contours (mrk324_f2_ha.fits) is the output of the program analyse_rss.py which performs a fitting of the emission lines. In order to do the fit in a spaxel, the line must be above a certain signal to noise ratio. If the fit is not done, the program outputs a nan in almost every channel for that spaxel. So, the nan values represent missing data.

I am not working with visualization.py anymore. I am using visualization_mine.py from Armando. The input of the program is the same as visualization.py, but it does not have this problem with the nan values. It can draw the contours.

sergiopasra commented 4 years ago

Well, I can review the solution in @gildepaz program and see if it is feasible to use it in visualization