vrodgom / statmorph Goto Github PK
View Code? Open in Web Editor NEWPython code for calculating non-parametric morphological diagnostics of galaxy images.
License: BSD 3-Clause "New" or "Revised" License
Python code for calculating non-parametric morphological diagnostics of galaxy images.
License: BSD 3-Clause "New" or "Revised" License
>>> source_morphs = statmorph.source_morphology(data, segmap, weightmap=np.ones_like(data))
TypeError Traceback (most recent call last)
<ipython-input-10-6e5293b8e978> in <module>
----> 1 source_morphs = statmorph.source_morphology(data, segmap, weightmap=np.ones_like(data))
~/anaconda3/lib/python3.7/site-packages/statmorph/statmorph.py in source_morphology(image, segmap, **kwargs)
2472 sources_morph = []
2473 for label in segmap.labels:
-> 2474 sources_morph.append(SourceMorphology(image, segmap, label, **kwargs))
2475 print('Finished processing source %d.\n' % (label))
2476
~/anaconda3/lib/python3.7/site-packages/statmorph/statmorph.py in __init__(self, image, segmap, label, mask, weightmap, gain, psf, cutout_extent, min_cutout_size, n_sigma_outlier, annulus_width, eta, petro_fraction_gini, skybox_size, petro_extent_cas, petro_fraction_cas, boxcar_size_mid, niter_bh_mid, sigma_mid, petro_extent_flux, boxcar_size_shape_asym, sersic_maxiter, segmap_overlap_ratio)
443
444 # For simplicity, evaluate all "lazy" properties at once:
--> 445 self._calculate_morphology()
446
447 # Check if image is background-subtracted; set flag=1 if not.
~/anaconda3/lib/python3.7/site-packages/statmorph/statmorph.py in _calculate_morphology(self)
544 ]
545 for q in quantities:
--> 546 tmp = self[q]
547
548 def _check_segmaps(self):
~/anaconda3/lib/python3.7/site-packages/statmorph/statmorph.py in __getitem__(self, key)
457
458 def __getitem__(self, key):
--> 459 return getattr(self, key)
460
461 def _get_badpixels(self, image):
~/anaconda3/lib/python3.7/site-packages/astropy/utils/decorators.py in __get__(self, obj, owner)
756 return val
757 else:
--> 758 val = self.fget(obj)
759 obj.__dict__[self._key] = val
760 return val
~/anaconda3/lib/python3.7/site-packages/statmorph/statmorph.py in xc_asymmetry(self)
1563 relative to the original image.
1564 """
-> 1565 return self.xmin_stamp + self._asymmetry_center[0]
1566
1567 @lazyproperty
~/anaconda3/lib/python3.7/site-packages/astropy/utils/decorators.py in __get__(self, obj, owner)
756 return val
757 else:
--> 758 val = self.fget(obj)
759 obj.__dict__[self._key] = val
760 return val
~/anaconda3/lib/python3.7/site-packages/statmorph/statmorph.py in _asymmetry_center(self)
1540 center_asym = opt.fmin(self._asymmetry_function, center_0,
1541 args=(self._cutout_stamp_maskzeroed, 'cas'),
-> 1542 xtol=1e-6, disp=0)
1543
1544 # Check if flag was activated by _asymmetry_function:
~/anaconda3/lib/python3.7/site-packages/scipy/optimize/optimize.py in fmin(func, x0, args, xtol, ftol, maxiter, maxfun, full_output, disp, retall, callback, initial_simplex)
441 'initial_simplex': initial_simplex}
442
--> 443 res = _minimize_neldermead(func, x0, args, callback=callback, **opts)
444 if full_output:
445 retlist = res['x'], res['fun'], res['nit'], res['nfev'], res['status']
~/anaconda3/lib/python3.7/site-packages/scipy/optimize/optimize.py in _minimize_neldermead(func, x0, args, callback, maxiter, maxfev, disp, return_all, initial_simplex, xatol, fatol, adaptive, **unknown_options)
584
585 for k in range(N + 1):
--> 586 fsim[k] = func(sim[k])
587
588 ind = numpy.argsort(fsim)
~/anaconda3/lib/python3.7/site-packages/scipy/optimize/optimize.py in function_wrapper(*wrapper_args)
325 def function_wrapper(*wrapper_args):
326 ncalls[0] += 1
--> 327 return function(*(wrapper_args + args))
328
329 return ncalls, function_wrapper
~/anaconda3/lib/python3.7/site-packages/statmorph/statmorph.py in _asymmetry_function(self, center, image, kind)
1486 # Create aperture for the chosen kind of asymmetry
1487 if kind == 'cas':
-> 1488 r = self._petro_extent_cas * self._rpetro_circ_centroid
1489 ap = photutils.CircularAperture(center, r)
1490 elif kind == 'outer':
~/anaconda3/lib/python3.7/site-packages/astropy/utils/decorators.py in __get__(self, obj, owner)
756 return val
757 else:
--> 758 val = self.fget(obj)
759 obj.__dict__[self._key] = val
760 return val
~/anaconda3/lib/python3.7/site-packages/statmorph/statmorph.py in _rpetro_circ_centroid(self)
1008 """
1009 center = np.array([self._xc_stamp, self._yc_stamp])
-> 1010 return self._rpetro_circ_generic(center)
1011
1012 @lazyproperty
~/anaconda3/lib/python3.7/site-packages/statmorph/statmorph.py in _rpetro_circ_generic(self, center)
978 AstropyUserWarning)
979 self.flag = 1
--> 980 curval = self._petrosian_function_circ(r, center)
981 if curval == 0:
982 warnings.warn('[rpetro_circ] We found rpetro by pure chance!',
~/anaconda3/lib/python3.7/site-packages/statmorph/statmorph.py in _petrosian_function_circ(self, r, center)
937 # Force mean fluxes to be positive:
938 circ_annulus_mean_flux = np.abs(_aperture_mean_nomask(
--> 939 circ_annulus, image, method='exact'))
940 circ_aperture_mean_flux = np.abs(_aperture_mean_nomask(
941 circ_aperture, image, method='exact'))
~/anaconda3/lib/python3.7/site-packages/statmorph/statmorph.py in _aperture_mean_nomask(ap, image, **kwargs)
90 return ap.do_photometry(image, **kwargs)[0][0] / ap.area()
91 else:
---> 92 return ap.do_photometry(image, **kwargs)[0][0] / ap.area
93
94 def _fraction_of_total_function_circ(r, image, center, fraction, total_sum):
TypeError: unsupported operand type(s) for /: 'float' and 'method'
Hello,
I'm using the package to determine morphological parameters of sometimes "single clump" sources. For these sources, the code sets the M statistic to 0 and triggers a flag. This behavior is problematic for inspecting the quality of the other statistics.
Hello, I just want to use this code to calculate the Gini index and M20 for my image. I had got my own PSF, image, sigma maps and others. I obtained the sky mean from my own method, which is obtained via the 3-sigma clip from the cleaned sky image. However, this code use its own method to get the sky_mean. Thus, my results for the sersic index is much off from the Galfit. Is there any place for me to input my own sky mean and sky median?
Under python 3.5.4 I cannot import the statmorph module. I get the following error:
Traceback (most recent call last):
File "tryCAS.py", line 8, in <module>
import statmorph
File "/Users/tdavis/anaconda/lib/python3.5/site-packages/statmorph/__init__.py", line 1, in <module>
from .statmorph import SourceMorphology, source_morphology
File "/Users/tdavis/anaconda/lib/python3.5/site-packages/statmorph/statmorph.py", line 15, in <module>
import skimage.measure
File "/Users/tdavis/anaconda/lib/python3.5/site-packages/skimage/__init__.py", line 158, in <module>
from .util.dtype import *
File "/Users/tdavis/anaconda/lib/python3.5/site-packages/skimage/util/__init__.py", line 5, in <module>
from .apply_parallel import apply_parallel
File "/Users/tdavis/anaconda/lib/python3.5/site-packages/skimage/util/apply_parallel.py", line 8, in <module>
import dask.array as da
File "/Users/tdavis/anaconda/lib/python3.5/site-packages/dask/array/__init__.py", line 46, in <module>
from . import random, linalg, ghost, learn, fft
File "/Users/tdavis/anaconda/lib/python3.5/site-packages/dask/array/ghost.py", line 8, in <module>
from toolz.curried import map
File "/Users/tdavis/anaconda/lib/python3.5/site-packages/toolz/curried/__init__.py", line 53, in <module>
_curry_namespace(vars(toolz)),
File "/Users/tdavis/anaconda/lib/python3.5/site-packages/toolz/curried/__init__.py", line 48, in _curry_namespace
for name, f in ns.items() if '__' not in name
File "/Users/tdavis/anaconda/lib/python3.5/site-packages/toolz/curried/__init__.py", line 48, in <genexpr>
for name, f in ns.items() if '__' not in name
File "/Users/tdavis/anaconda/lib/python3.5/site-packages/toolz/curried/__init__.py", line 42, in _should_curry
return (callable(f) and _nargs(f) > 1 or f in do_curry)
File "/Users/tdavis/anaconda/lib/python3.5/site-packages/toolz/curried/__init__.py", line 35, in _nargs
return len(inspect.getargspec(f).args)
File "/Users/tdavis/anaconda/lib/python3.5/inspect.py", line 1050, in getargspec
raise ValueError("Function has keyword-only arguments or annotations"
ValueError: Function has keyword-only arguments or annotations, use getfullargspec() API which can support them
It seems to work ok on old Python 2.7 (assuming I remove the print brackets from the example, which seems to be in Python 3...)
Many thanks!
Hello, I tired to run your turtorial code and reproduce the results. I found that there is an offset between the original image and fitted image, as the image shows below.
If I applied the code below, just moved the center. Then it would looks better.
morph.sersic_xc = morph.sersic_xc - 0.5
morph.sersic_yc = morph.sersic_yc - 0.5
My system environment is Anaconda 3.7.1
Values computed for the first moments/centroids seem wrong in some circumstances and the centroid can some times be well outside of the segmap. It might be a bug in skimage as the following _cutout_stamp_maskzeroed_no_bg leads to a centroid of 0.2, 3.07.
[[ 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0.
0. 0. ]
[ 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0.
0. 0. ]
[ 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0.
0. 0. ]
[ 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0.
0. 0. ]
[ 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0.
0. 0. ]
[ 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0.
0. 0. ]
[ 0. 0. 0. 0. 0. 0.
-0.07184662 0.01405155 0. 0.0648425 0. 0.
0. 0. ]
[ 0. 0. 0. 0. 0. 0.
0.07072073 0.18174913 0.08616358 -0.14542499 0. 0.
0. 0. ]
[ 0. 0. 0. 0. 0. 0.
0. 0.31161529 0.0283908 -0.03631837 0. 0.
0. 0. ]
[ 0. 0. 0. 0. 0. 0.
0. 0.09580147 -0.14492505 -0.01777303 -0.12393956 0.
0. 0. ]
[ 0. 0. 0. 0. 0. 0.
0. 0. 0. -0.16527912 0. 0.
0. 0. ]
[ 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0.
0. 0. ]
[ 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0.
0. 0. ]
[ 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0.
0. 0. ]]
_sky_smoothness is 0 when boxcar_size = 1, which is the case for all of my sources. This is because ndi.uniform_filter(bkg, size=boxcar_size) returns bkg, which causes the difference between the two to be 0.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.