示例#1
0
def transform(contours, wcs_in, wcs_out, filled=False):

    system_in, equinox_in, units_in = wcs_util.system(wcs_in)
    system_out, equinox_out, units_out = wcs_util.system(wcs_out)

    for contour in contours.collections:

        polygons_out = []
        for polygon in contour.get_paths():

            xp_in = polygon.vertices[:, 0]
            yp_in = polygon.vertices[:, 1]

            xw, yw = wcs_util.pix2world(wcs_in, xp_in, yp_in)

            xw, yw = wcs_util.convert_coords(xw, yw,
                input=(system_in, equinox_in),
                output=(system_out, equinox_out))

            xp_out, yp_out = wcs_util.world2pix(wcs_out, xw, yw)

            if filled:
                polygons_out.append(Path(np.array(zip(xp_out, yp_out)),codes=polygon.codes))
            else:
                polygons_out.append(zip(xp_out, yp_out))

        if filled:
            contour.set_paths(polygons_out)
        else:
            contour.set_verts(polygons_out)

        contour.apl_converted = True
示例#2
0
文件: ticks.py 项目: hamogu/aplpy
def axis_positions(wcs, axis, farside, xmin=False, xmax=False, ymin=False, \
    ymax=False):

    if not xmin:
        xmin = 0.5
    if not xmax:
        xmax = 0.5+wcs.naxis1
    if not ymin:
        ymin = 0.5
    if not ymax:
        ymax = 0.5+wcs.naxis2

    # Check options
    assert axis=='x' or axis=='y', "The axis= argument should be set to x or y"

    # Generate an array of pixel values for the x-axis
    if axis=='x':
        x_pix = math_util.arange2(xmin, xmax, 1.)
        y_pix = np.ones(np.shape(x_pix))
        if(farside):
            y_pix = y_pix * ymax
        else:
            y_pix = y_pix * ymin
    else:
        y_pix = math_util.arange2(ymin, ymax, 1.)
        x_pix = np.ones(np.shape(y_pix))
        if(farside):
            x_pix = x_pix * xmax
        else:
            x_pix = x_pix * xmin

    # Convert these to world coordinates
    x_world, y_world = wcs_util.pix2world(wcs, x_pix, y_pix)

    return x_pix, y_pix, x_world, y_world
示例#3
0
文件: labels.py 项目: hamogu/aplpy
    def _cursor_position(self, x, y):

        xaxis = self._ax1.xaxis
        yaxis = self._ax1.yaxis

        xw, yw = wcs_util.pix2world(self._wcs, x, y)

        xw = au.Angle(degrees=xw, latitude=False)
        yw = au.Angle(degrees=yw, latitude=True)

        hours = 'h' in xaxis.apl_label_form

        if hours:
            xw = xw.tohours()

        if xaxis.apl_labels_style in ['plain', 'latex']:
            sep = ('d', 'm', 's')
            if hours:
                sep = ('h', 'm', 's')
        elif xaxis.apl_labels_style == 'colons':
            sep = (':', ':', '')

        xlabel = xw.tostringlist(format=xaxis.apl_label_form, sep=sep)

        if yaxis.apl_labels_style in ['plain', 'latex']:
            sep = ('d', 'm', 's')
            if hours:
                sep = ('h', 'm', 's')
        elif yaxis.apl_labels_style == 'colons':
            sep = (':', ':', '')

        ylabel = yw.tostringlist(format=yaxis.apl_label_form, sep=sep)

        return string.join(xlabel, "") + " " + string.join(ylabel, "")
示例#4
0
    def _cursor_position(self, x, y):

        xaxis = self._ax1.xaxis
        yaxis = self._ax1.yaxis

        xw, yw = wcs_util.pix2world(self._wcs, x, y)

        xw = au.Angle(degrees=xw, latitude=False)
        yw = au.Angle(degrees=yw, latitude=True)

        hours = 'h' in xaxis.apl_label_form

        if hours:
            xw = xw.tohours()

        if xaxis.apl_labels_style in ['plain', 'latex']:
            sep = ('d', 'm', 's')
            if hours:
                sep = ('h', 'm', 's')
        elif xaxis.apl_labels_style == 'colons':
            sep = (':', ':', '')

        xlabel = xw.tostringlist(format=xaxis.apl_label_form, sep=sep)

        if yaxis.apl_labels_style in ['plain', 'latex']:
            sep = ('d', 'm', 's')
            if hours:
                sep = ('h', 'm', 's')
        elif yaxis.apl_labels_style == 'colons':
            sep = (':', ':', '')

        ylabel = yw.tostringlist(format=yaxis.apl_label_form, sep=sep)

        return string.join(xlabel, "") + " " + string.join(ylabel, "")
示例#5
0
def axis_positions(wcs, axis, farside, xmin=False, xmax=False, ymin=False, \
    ymax=False):

    if not xmin:
        xmin = 0.5
    if not xmax:
        xmax = 0.5 + wcs.naxis1
    if not ymin:
        ymin = 0.5
    if not ymax:
        ymax = 0.5 + wcs.naxis2

    # Check options
    assert axis == 'x' or axis == 'y', "The axis= argument should be set to x or y"

    # Generate an array of pixel values for the x-axis
    if axis == 'x':
        x_pix = math_util.arange2(xmin, xmax, 1.)
        y_pix = np.ones(np.shape(x_pix))
        if (farside):
            y_pix = y_pix * ymax
        else:
            y_pix = y_pix * ymin
    else:
        y_pix = math_util.arange2(ymin, ymax, 1.)
        x_pix = np.ones(np.shape(y_pix))
        if (farside):
            x_pix = x_pix * xmax
        else:
            x_pix = x_pix * xmin

    # Convert these to world coordinates
    x_world, y_world = wcs_util.pix2world(wcs, x_pix, y_pix)

    return x_pix, y_pix, x_world, y_world
示例#6
0
文件: labels.py 项目: cdeil/aplpy
    def _cursor_position(self, x, y):

        xaxis = self._ax1.xaxis
        yaxis = self._ax1.yaxis

        if self._ax1._cursor_world:

            xw, yw = wcs_util.pix2world(self._wcs, x, y)

            xw = au.Angle(degrees=xw, latitude=False)
            yw = au.Angle(degrees=yw, latitude=True)

            hours = "h" in xaxis.apl_label_form

            if hours:
                xw = xw.tohours()

            if xaxis.apl_labels_style in ["plain", "latex"]:
                sep = ("d", "m", "s")
                if hours:
                    sep = ("h", "m", "s")
            elif xaxis.apl_labels_style == "colons":
                sep = (":", ":", "")

            xlabel = xw.tostringlist(format=xaxis.apl_label_form, sep=sep)

            if yaxis.apl_labels_style in ["plain", "latex"]:
                sep = ("d", "m", "s")
                if hours:
                    sep = ("h", "m", "s")
            elif yaxis.apl_labels_style == "colons":
                sep = (":", ":", "")

            ylabel = yw.tostringlist(format=yaxis.apl_label_form, sep=sep)

            return string.join(xlabel, "") + " " + string.join(ylabel, "") + " (world)"

        else:

            return "%g %g" % (x, y) + " (pixel)"