Changeset 2717 for trunk/python


Ignore:
Timestamp:
01/09/13 12:43:18 (11 years ago)
Author:
Kana Sugimoto
Message:

New Development: Yes

JIRA Issue: No

Ready for Test: Yes

Interface Changes: Yes

What Interface Changed: added a new method, set_grid(), in plothelper class.

Test Programs: test_sdplot[sdplot_gridTest]

Put in Release Notes: Yes

Module(s): asapplotter, sdplot(plottype='grid')

Description:

The method, asapplotter.plotgrid(), considers tangential projection
effects when getting grid center and extents from a scantable.
This affects behavior of plottype='grid' in sdplot task of CASA.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/python/asapplotter.py

    r2715 r2717  
    17671767    # plot spectra by pointing
    17681768    @asaplog_post_dec
    1769     def plotgrid(self, scan=None,center=None,spacing=None,rows=None,cols=None):
     1769    def plotgrid(self, scan=None,center="",spacing=[],rows=None,cols=None):
    17701770        """
    17711771        Plot spectra based on direction.
     
    17731773        Parameters:
    17741774            scan:      a scantable to plot
    1775             center:    the grid center direction (a list) of plots in the
    1776                        unit of DIRECTION column.
     1775            center:    the grid center direction (a string)
    17771776                       (default) the center of map region
     1777                       (example) 'J2000 19h30m00s -25d00m00s'
    17781778            spacing:   a list of horizontal (R.A.) and vertical (Dec.)
    1779                        spacing in the unit of DIRECTION column.
     1779                       spacing.
    17801780                       (default) Calculated by the extent of map region and
     1781                       (example) ['1arcmin', '1arcmin']
    17811782                       the number of rows and cols to cover
    17821783            rows:      number of panels (grid points) in horizontal direction
     
    18021803
    18031804        # Rows and cols
    1804         if rows:
    1805             self._rows = int(rows)
    1806         else:
    1807             msg = "Number of rows to plot are not specified. "
    1808             if self._rows:
    1809                 msg += "Using previous value = %d" % (self._rows)
    1810                 asaplog.push(msg)
    1811             else:
    1812                 self._rows = 1
    1813                 msg += "Setting rows = %d" % (self._rows)
    1814                 asaplog.post()
    1815                 asaplog.push(msg)
    1816                 asaplog.post("WARN")
    1817         if cols:
    1818             self._cols = int(cols)
    1819         else:
    1820             msg = "Number of cols to plot are not specified. "
    1821             if self._cols:
    1822                 msg += "Using previous value = %d" % (self._cols)
    1823                 asaplog.push(msg)
    1824             else:
    1825                 self._cols = 1
    1826                 msg += "Setting cols = %d" % (self._cols)
    1827                 asaplog.post()
    1828                 asaplog.push(msg)
    1829                 asaplog.post("WARN")
    1830 
    1831         # Center and spacing
    1832         dirarr = array(self._data.get_directionval()).transpose()
    1833         print "Pointing range: (x, y) = (%f - %f, %f - %f)" %\
    1834               (dirarr[0].min(),dirarr[0].max(),dirarr[1].min(),dirarr[1].max())
    1835         dircent = [0.5*(dirarr[0].max() + dirarr[0].min()),
    1836                    0.5*(dirarr[1].max() + dirarr[1].min())]
    1837         del dirarr
    1838         if center is None:
    1839             #asaplog.post()
    1840             asaplog.push("Grid center is not specified. Automatically calculated from pointing center.")
    1841             #asaplog.post("WARN")
    1842             #center = [dirarr[0].mean(), dirarr[1].mean()]
    1843             center = dircent
    1844         elif (type(center) in (list, tuple)) and len(center) > 1:
    1845             from numpy import pi
    1846             # make sure center_x is in +-pi of pointing center
    1847             # (assumes dirs are in rad)
    1848             rotnum = round(abs(center[0] - dircent[0])/(2*pi))
    1849             if center[0] < dircent[0]: rotnum *= -1
    1850             cenx = center[0] - rotnum*2*pi
    1851             center = [cenx, center[1]]
    1852         else:
    1853             msg = "Direction of grid center should be a list of float (R.A., Dec.)"
    1854             raise ValueError, msg
    1855         asaplog.push("Grid center: (%f, %f) " % (center[0],center[1]))
    1856 
    1857         if spacing is None:
    1858             #asaplog.post()
    1859             asaplog.push("Grid spacing not specified. Automatically calculated from map coverage")
    1860             #asaplog.post("WARN")
    1861             # automatically get spacing
    1862             dirarr = array(self._data.get_directionval()).transpose()
    1863             wx = 2. * max(abs(dirarr[0].max()-center[0]),
    1864                           abs(dirarr[0].min()-center[0]))
    1865             wy = 2. * max(abs(dirarr[1].max()-center[1]),
    1866                           abs(dirarr[1].min()-center[1]))
    1867             ## slightly expand area to plot the edges
    1868             #wx *= 1.1
    1869             #wy *= 1.1
    1870             xgrid = wx/max(self._cols-1.,1.)
    1871             #xgrid = wx/float(max(self._cols,1.))
    1872             xgrid *= cos(center[1])
    1873             ygrid = wy/max(self._rows-1.,1.)
    1874             #ygrid = wy/float(max(self._rows,1.))
    1875             # single pointing (identical R.A. and/or Dec. for all spectra.)
    1876             if xgrid == 0:
    1877                 xgrid = 1.
    1878             if ygrid == 0:
    1879                 ygrid = 1.
    1880             # spacing should be negative to transpose plot
    1881             spacing = [- xgrid, - ygrid]
    1882             del dirarr, xgrid, ygrid
    1883         #elif isinstance(spacing, str):
    1884         #    # spacing is a quantity
    1885         elif (type(spacing) in (list, tuple)) and len(spacing) > 1:
    1886             for i in xrange(2):
    1887                 val = spacing[i]
    1888                 if not isinstance(val, float):
    1889                     raise TypeError("spacing should be a list of float")
    1890                 if val > 0.:
    1891                     spacing[i] = -val
    1892             spacing = spacing[0:2]
    1893         else:
    1894             msg = "Invalid spacing."
    1895             raise TypeError(msg)
    1896         asaplog.push("Spacing: (%f, %f) (projected)" % (spacing[0],spacing[1]))
    1897 
     1805        if (self._rows is None):
     1806            rows = max(1, rows)
     1807        if (self._cols is None):
     1808            cols = max(1, cols)
     1809        self.set_layout(rows,cols,False)
     1810
     1811        # Select the first IF, POL, and BEAM for plotting
    18981812        ntotpl = self._rows * self._cols
    18991813        ifs = self._data.getifnos()
     
    19221836            asaplog.push(msg)
    19231837            asaplog.post("WARN")
    1924        
     1838
     1839#         # Center and spacing
     1840#         dirarr = array(self._data.get_directionval()).transpose()
     1841#         print "Pointing range: (x, y) = (%f - %f, %f - %f)" %\
     1842#               (dirarr[0].min(),dirarr[0].max(),dirarr[1].min(),dirarr[1].max())
     1843#         dircent = [0.5*(dirarr[0].max() + dirarr[0].min()),
     1844#                    0.5*(dirarr[1].max() + dirarr[1].min())]
     1845#         del dirarr
     1846#         if center is None:
     1847#             #asaplog.post()
     1848#             asaplog.push("Grid center is not specified. Automatically calculated from pointing center.")
     1849#             #asaplog.post("WARN")
     1850#             #center = [dirarr[0].mean(), dirarr[1].mean()]
     1851#             center = dircent
     1852#         elif (type(center) in (list, tuple)) and len(center) > 1:
     1853#             from numpy import pi
     1854#             # make sure center_x is in +-pi of pointing center
     1855#             # (assumes dirs are in rad)
     1856#             rotnum = round(abs(center[0] - dircent[0])/(2*pi))
     1857#             if center[0] < dircent[0]: rotnum *= -1
     1858#             cenx = center[0] - rotnum*2*pi
     1859#             center = [cenx, center[1]]
     1860#         else:
     1861#             msg = "Direction of grid center should be a list of float (R.A., Dec.)"
     1862#             raise ValueError, msg
     1863#         asaplog.push("Grid center: (%f, %f) " % (center[0],center[1]))
     1864
     1865#         if spacing is None:
     1866#             #asaplog.post()
     1867#             asaplog.push("Grid spacing not specified. Automatically calculated from map coverage")
     1868#             #asaplog.post("WARN")
     1869#             # automatically get spacing
     1870#             dirarr = array(self._data.get_directionval()).transpose()
     1871#             wx = 2. * max(abs(dirarr[0].max()-center[0]),
     1872#                           abs(dirarr[0].min()-center[0]))
     1873#             wy = 2. * max(abs(dirarr[1].max()-center[1]),
     1874#                           abs(dirarr[1].min()-center[1]))
     1875#             ## slightly expand area to plot the edges
     1876#             #wx *= 1.1
     1877#             #wy *= 1.1
     1878#             xgrid = wx/max(self._cols-1.,1.)
     1879#             #xgrid = wx/float(max(self._cols,1.))
     1880#             xgrid *= cos(center[1])
     1881#             ygrid = wy/max(self._rows-1.,1.)
     1882#             #ygrid = wy/float(max(self._rows,1.))
     1883#             # single pointing (identical R.A. and/or Dec. for all spectra.)
     1884#             if xgrid == 0:
     1885#                 xgrid = 1.
     1886#             if ygrid == 0:
     1887#                 ygrid = 1.
     1888#             # spacing should be negative to transpose plot
     1889#             spacing = [- xgrid, - ygrid]
     1890#             del dirarr, xgrid, ygrid
     1891#         #elif isinstance(spacing, str):
     1892#         #    # spacing is a quantity
     1893#         elif (type(spacing) in (list, tuple)) and len(spacing) > 1:
     1894#             for i in xrange(2):
     1895#                 val = spacing[i]
     1896#                 if not isinstance(val, float):
     1897#                     raise TypeError("spacing should be a list of float")
     1898#                 if val > 0.:
     1899#                     spacing[i] = -val
     1900#             spacing = spacing[0:2]
     1901#         else:
     1902#             msg = "Invalid spacing."
     1903#             raise TypeError(msg)
     1904#         asaplog.push("Spacing: (%f, %f) (projected)" % (spacing[0],spacing[1]))
     1905
     1906        # Prepare plotter
    19251907        self._assert_plotter(action="reload")
    19261908        self._plotter.hold()
     
    19381920        from asap._asap import plothelper as plhelper
    19391921        ph = plhelper(self._data)
    1940         ph.set_gridval(self._cols, self._rows, spacing[0], spacing[1],
    1941                           center[0], center[1], epoch="J2000", projname="SIN")
     1922        #ph.set_gridval(self._cols, self._rows, spacing[0], spacing[1],
     1923        #                  center[0], center[1], epoch="J2000", projname="SIN")
     1924        if type(spacing) in (list, tuple, array):
     1925            if len(spacing) == 0:
     1926                spacing = ["", ""]
     1927            elif len(spacing) == 1:
     1928                spacing = [spacing[0], spacing[0]]
     1929        else:
     1930            spacing = [spacing, spacing]
     1931        ph.set_grid(self._cols, self._rows, spacing[0], spacing[1], \
     1932                    center, projname="SIN")
     1933
    19421934        # Actual plot
    19431935        npl = 0
Note: See TracChangeset for help on using the changeset viewer.