From 1f7c9d737ecb5ea5a4e86fc1cdac59a138320bb5 Mon Sep 17 00:00:00 2001 From: "Adam Ginsburg (keflavich)" Date: Fri, 20 Sep 2013 14:29:16 -0400 Subject: [PATCH 1/6] added a complicated example --- docs/examples.rst | 61 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 docs/examples.rst diff --git a/docs/examples.rst b/docs/examples.rst new file mode 100644 index 0000000..b9e0ea0 --- /dev/null +++ b/docs/examples.rst @@ -0,0 +1,61 @@ +Example Uses of astrodendro +=========================== + +All of these examples use the Perseus data set + +.. plot:: + :include-source: + + from astrodendro import Dendrogram + from astropy.io import fits + from astrodendro.pruning import min_peak + from astrodendro.analysis import PPStatistic + import pylab as pl + import numpy as np + + f1 = pl.figure(1,figsize=(15,5)) + ax1,ax2,ax3 = (pl.subplot(1,3,ii) for ii in xrange(1,4)) + + image = fits.getdata('PerA_Extn2MASS_F_Gal.fits') + + from astropy import units as u + metadata = {} + metadata['data_unit'] = u.Jy / u.beam + metadata['spatial_scale'] = 6 * u.arcsec + metadata['beam_major'] = 22.9 * u.arcsec # FWHM + metadata['beam_minor'] = 22.9 * u.arcsec # FWHM + + d = Dendrogram.compute(image, min_value=1.0, min_delta=1., min_npix=10, + is_independent=min_peak(3), verbose=True) + + # quantities to plot: + flux = {} + radius = {} + + for leaf in d.leaves: + id = leaf.idx + print "Examining ID ",id + # need one suite of plotted things for each leaf + flux[id] = [] + radius[id] = [] + + while hasattr(leaf,'parent'): + stat = PPStatistic(leaf, metadata=metadata) + flux[id].append(stat.flux.value) + radius[id].append(stat.radius.value) + leaf = leaf.parent + + ax1.loglog(np.array(radius[id])**2 * np.pi, + flux[id], + 'o-') + ax2.loglog(np.array(radius[id])**2 * np.pi, + np.array(flux[id]) / (4/3. * np.pi * np.array(radius[id])**3), + 'o-') + d.plotter().plot_tree(ax3) + + ax1.set_xlabel('Area (arcsec^2)') + ax1.set_ylabel('Flux (Jy)') + ax2.set_xlabel('Area (arcsec^2)') + ax2.set_ylabel('"Density" (Jy/arcsec^3)') + ax3.set_xlabel("Structure") + ax3.set_ylabel("Flux") From 5eeef751a9ee4cd06820120965fcf6f3f2ad887a Mon Sep 17 00:00:00 2001 From: "Adam Ginsburg (keflavich)" Date: Fri, 20 Sep 2013 14:34:45 -0400 Subject: [PATCH 2/6] bugfix & link from index --- docs/examples.rst | 2 +- docs/index.rst | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/examples.rst b/docs/examples.rst index b9e0ea0..cba1d6c 100644 --- a/docs/examples.rst +++ b/docs/examples.rst @@ -34,7 +34,7 @@ All of these examples use the Perseus data set for leaf in d.leaves: id = leaf.idx - print "Examining ID ",id + print("Plotting ID ",id) # need one suite of plotted things for each leaf flux[id] = [] radius[id] = [] diff --git a/docs/index.rst b/docs/index.rst index c730d4d..c5542b0 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -39,6 +39,8 @@ Mapping these terms back onto the structure gives the following: For an example of use of dendrograms on real data, see `Goodman, A. et al (2009) `_. +For some examples of dendrograms in practice, see :doc:`examples` + Documentation ------------- From 19e3fb72e6add71e0225283a18928035a541f5ac Mon Sep 17 00:00:00 2001 From: "Adam Ginsburg (keflavich)" Date: Fri, 20 Sep 2013 20:57:35 -0400 Subject: [PATCH 3/6] examples cont'd --- docs/examples.rst | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/examples.rst b/docs/examples.rst index cba1d6c..45ab154 100644 --- a/docs/examples.rst +++ b/docs/examples.rst @@ -45,17 +45,17 @@ All of these examples use the Perseus data set radius[id].append(stat.radius.value) leaf = leaf.parent - ax1.loglog(np.array(radius[id])**2 * np.pi, + L, = ax1.loglog(np.array(radius[id])**2 * np.pi, flux[id], 'o-') ax2.loglog(np.array(radius[id])**2 * np.pi, np.array(flux[id]) / (4/3. * np.pi * np.array(radius[id])**3), - 'o-') - d.plotter().plot_tree(ax3) + 'o-', color=L.get_color()) + d.plotter().plot_tree(ax3, structure=id, color=L.get_color()) - ax1.set_xlabel('Area (arcsec^2)') + ax1.set_xlabel('Area (arcsec$^2$)') ax1.set_ylabel('Flux (Jy)') - ax2.set_xlabel('Area (arcsec^2)') - ax2.set_ylabel('"Density" (Jy/arcsec^3)') + ax2.set_xlabel('Area (arcsec$^2$)') + ax2.set_ylabel('"Density" (Jy/arcsec$^3$)') ax3.set_xlabel("Structure") ax3.set_ylabel("Flux") From 064651c42ab62afa4185425f0f77639986c42d0e Mon Sep 17 00:00:00 2001 From: "Adam Ginsburg (keflavich)" Date: Fri, 20 Sep 2013 20:58:49 -0400 Subject: [PATCH 4/6] fix to plotter: type(np.int64) is not int, but np.int64 is a subclass --- astrodendro/plot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/astrodendro/plot.py b/astrodendro/plot.py index be2ce2e..6ed8059 100644 --- a/astrodendro/plot.py +++ b/astrodendro/plot.py @@ -184,7 +184,7 @@ def get_lines(self, structure=None, **kwargs): if structure is None: structures = list(self.dendrogram.all_structures) else: - if type(structure) is int: + if isinstance(structure,int): structure = self.dendrogram[structure] structures = structure.descendants + [structure] From 5675db60d75f948cfc8861beb5f213f8a4e56129 Mon Sep 17 00:00:00 2001 From: "Adam Ginsburg (keflavich)" Date: Fri, 20 Sep 2013 21:11:23 -0400 Subject: [PATCH 5/6] a bloody intricate plot --- docs/examples.rst | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/docs/examples.rst b/docs/examples.rst index 45ab154..95637d8 100644 --- a/docs/examples.rst +++ b/docs/examples.rst @@ -10,12 +10,10 @@ All of these examples use the Perseus data set from astropy.io import fits from astrodendro.pruning import min_peak from astrodendro.analysis import PPStatistic + import itertools import pylab as pl import numpy as np - f1 = pl.figure(1,figsize=(15,5)) - ax1,ax2,ax3 = (pl.subplot(1,3,ii) for ii in xrange(1,4)) - image = fits.getdata('PerA_Extn2MASS_F_Gal.fits') from astropy import units as u @@ -28,10 +26,19 @@ All of these examples use the Perseus data set d = Dendrogram.compute(image, min_value=1.0, min_delta=1., min_npix=10, is_independent=min_peak(3), verbose=True) + f1 = pl.figure(1,figsize=(15,5)) + f1.clear() + ax1,ax2,ax3 = (pl.subplot(1,3,ii) for ii in xrange(1,4)) + + p = d.plotter() + p.plot_tree(ax3, color='k', alpha=0.5) + # quantities to plot: flux = {} radius = {} + markers = itertools.cycle(['o','h','s','^','v','<','>','p','D','*']) + for leaf in d.leaves: id = leaf.idx print("Plotting ID ",id) @@ -47,15 +54,21 @@ All of these examples use the Perseus data set L, = ax1.loglog(np.array(radius[id])**2 * np.pi, flux[id], - 'o-') + '-',marker=markers.next(), + alpha=0.5) ax2.loglog(np.array(radius[id])**2 * np.pi, - np.array(flux[id]) / (4/3. * np.pi * np.array(radius[id])**3), - 'o-', color=L.get_color()) - d.plotter().plot_tree(ax3, structure=id, color=L.get_color()) + np.array(flux[id]) / (4/3. * np.pi * np.array(radius[id])**2), + 'o-', color=L.get_color(), marker=L.get_marker(), + alpha=0.5) + p.plot_tree(ax3, structure=id, color=L.get_color(), linewidth=2, alpha=0.5) + lines = p.get_lines(structure=id, color=L.get_color(), linewidth=2, alpha=0.5) + ax3.plot(*lines.get_segments()[0].T,marker=L.get_marker()) + + ax1.set_xlabel('Area (arcsec$^2$)') ax1.set_ylabel('Flux (Jy)') ax2.set_xlabel('Area (arcsec$^2$)') - ax2.set_ylabel('"Density" (Jy/arcsec$^3$)') + ax2.set_ylabel('"Column Density" (Jy/arcsec$^3$)') ax3.set_xlabel("Structure") ax3.set_ylabel("Flux") From 0da19a8e223729f28d6a699407d47bc32fda4a59 Mon Sep 17 00:00:00 2001 From: "Adam Ginsburg (keflavich)" Date: Sat, 21 Sep 2013 10:59:15 -0600 Subject: [PATCH 6/6] added some docs to the example --- docs/examples.rst | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/docs/examples.rst b/docs/examples.rst index 95637d8..96ab584 100644 --- a/docs/examples.rst +++ b/docs/examples.rst @@ -3,6 +3,18 @@ Example Uses of astrodendro All of these examples use the Perseus data set +Example 1 +--------- + +Extract the dendrogram structure using a minimum-peak cutoff, then make some +intricate plots. + +These plots show two derived quantities - the "flux" and the effective radius - +plotted against each other in two different ways. In order to visualize the +structure as plotted, the lines are color- and marker- coded to match each +other. + + .. plot:: :include-source: @@ -17,6 +29,8 @@ All of these examples use the Perseus data set image = fits.getdata('PerA_Extn2MASS_F_Gal.fits') from astropy import units as u + # this metadata isn't really appropriate for this data set, but it is + # useful for the example metadata = {} metadata['data_unit'] = u.Jy / u.beam metadata['spatial_scale'] = 6 * u.arcsec