astropy / photutils

Astropy package for source detection and photometry. Maintainer: @larrybradley
https://photutils.readthedocs.io
BSD 3-Clause "New" or "Revised" License
250 stars 138 forks source link

ellipse.fit_image() not fitting for the full galaxy #814

Closed PrayaagKatta closed 5 years ago

PrayaagKatta commented 5 years ago

Hello. I am facing an issue with ellipse.fit() where it is not fitting for the disk of the galaxy, and stops after the bulge/bar portion. If I keep the maxsma as the size of the galaxy, the ellipses still does not fit for the galaxy. What can I do to fix this? This is my first time posting here, so please tell me if I haven't followed the protocols correctly. I have attached the image below. Thank you! image

PrayaagKatta commented 5 years ago

Hello, I am ready to give the image used for this code, if it helps. I also tried increasing the maxrit, and playing with other parameters, but the issue is still persisting.

larrybradley commented 5 years ago

@ibusko Can you please take a look at this?

ibusko commented 5 years ago

@larrybradley yes, I will see what can be done.

ibusko commented 5 years ago

@PrayaagKatta from the looks of the image, I suspect that there is a large jump in the ellipse geometric parameters (basically position angle and ellipticity) at about the point it stops working. It could be that the algorithm, with the settings you used, is unable to follow the rapid change and thus gives up. If you don't mind, I would like to have a copy of the image so I can try it myself. Challenging cases like this can be good in helping to perfect the algorithm.

PrayaagKatta commented 5 years ago

Thanks for the reply! It has not properly for the following images - ngc936_gb.fits.zip (This is the one in the example.) And also VCC857_g.fits.zip (Another case)

Please ask me if anything else is needed. Thank you.

ibusko commented 5 years ago

@PrayaagKatta I have been experimenting with one of the images, VCC857_g.fits. It looks like the cause of the premature stopping is the presence of the bar. The bar distorts the intensity sample taken at sma values around 20 or so to the point where the algorithm can't proceed. The distortion caused by a bar has a symmetry similar to the distortions caused by ellipticity values that are way off of the true value, when the ligth distribution is perfectly elliptical. In other words, the algorithm mis-interprets the extra ligth coming from the bar as an indication that the ellipticity parameter is off. It tries to adjust it and wanders off course in the process. The underlying probem is that the algorith was designed with elliptical light distributions in mind, so sometimes large deviations from an elliptical distribution just can't be handled by it. A suggestion would be to build a masked numpy array from the raw numpy array in the fits file, masking the regions where the bar is strongest.

An example on how to build masked arrays is in the advanced tutorial: https://github.com/astropy/photutils-datasets/blob/master/notebooks/isophote/isophote_example4.ipynb

ibusko commented 5 years ago

Same thing seems to be happening with image ngc936_gb.fits. In this case, it's the faint ring at the bar end points that seems to be the culprit. It distorts the elliptical intensity samples to the point where the algorithm gets lost. For cases like this, maybe you should resort to a more finer-grained approach using the fit_isophote method instead of fit_image. That way, you can tweak things in between successive increments of sma.

You can plot the intensity samples as shown on the tutorial examples using code like this. Assuming the output of ellipse was stored in the 'isolist' list, you plot the last one with this):

import matplotlib.pyplot as plt %matplotlib inline isophote = isolist[-1] plt.figure(figsize=(10, 3)) plt.plot(isophote.sample.values[0]/np.pi*180., isophote.sample.values[2]) plt.ylabel("Intensity") plt.xlabel("Angle (deg.)")

PrayaagKatta commented 5 years ago

@ibusko Thank you for taking time to go through this issue. I will definitely use your suggestions to try and fix the problem. I'll get back to you soon with the results.

PrayaagKatta commented 5 years ago

@ibusko Hello again! I followed your advice, and it has given positive results. I am attaching the file to show it to you. ngc936git

This is actually the kind of fitting that we wanted! So, I thank you for guiding me towards it.

ibusko commented 5 years ago

Glad it did work! In case you run into problems again, just ask.

larrybradley commented 5 years ago

Thanks, @ibusko.