Exemple #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
Exemple #2
0
def plot_latitude(wcs, lon, lat, lat0, alpha=0.5):

    lines_out = []

    # Check if the point with coordinates (0, lat0) is inside the viewport
    xpix, ypix = wcs_util.world2pix(wcs, 0., lat0)

    if in_plot(wcs, xpix, ypix):
        lon_min = 0.
        inside = True
    else:
        inside = False

    # Find intersections that correspond to latitude lat0
    index = np.where(lat==lat0)

    # Produce sorted array of the longitudes of all intersections
    lonnew = np.sort(lon[index])

    # Cycle through intersections
    for l in lonnew:

        # If inside, then current intersection closes arc - plot it
        if(inside):
            lon_max = l
            x_world = math_util.complete_range(lon_min, lon_max, 360) # Plotting every degree, make more general
            y_world = np.ones(len(x_world)) * lat0
            x_pix, y_pix = wcs_util.world2pix(wcs, x_world, y_world)
            lines_out.append(zip(x_pix, y_pix))
            inside = False
        else:
            lon_min = l
            inside = True

    # If still inside when finished going through intersections, then close at longitude 360
    if(inside):
        lon_max = 360.
        x_world = math_util.complete_range(lon_min, lon_max, 360)
        y_world = np.ones(len(x_world)) * lat0
        x_pix, y_pix = wcs_util.world2pix(wcs, x_world, y_world)
        lines_out.append(zip(x_pix, y_pix))
        inside = False

    return lines_out
Exemple #3
0
def plot_longitude(wcs, lon, lat, lon0, alpha=0.5):

    lines_out = []

    # Check if the point with coordinates (10., -90.) is inside the viewport
    xpix, ypix = wcs_util.world2pix(wcs, 10., -90.)

    if in_plot(wcs, xpix, ypix):
        lat_min = -90.
        inside = True
    else:
        inside = False
    # Find intersections that correspond to longitude lon0
    index = np.where(lon==lon0)

    # Produce sorted array of the latitudes of all intersections
    latnew = np.sort(lat[index])

    # Cycle through intersections
    for l in latnew:
        if(inside):
            lat_max = l
            y_world = math_util.complete_range(lat_min, lat_max, 360)
            x_world = np.ones(len(y_world)) * lon0
            x_pix, y_pix = wcs_util.world2pix(wcs, x_world, y_world)
            lines_out.append(zip(x_pix, y_pix))
            inside = False
        else:
            lat_min = l
            inside = True

    if(inside):
        lat_max = 90.
        y_world = math_util.complete_range(lat_min, lat_max, 360)
        x_world = np.ones(len(y_world)) * lon0
        x_pix, y_pix = wcs_util.world2pix(wcs, x_world, y_world)
        lines_out.append(zip(x_pix, y_pix))
        inside = False

    return lines_out
Exemple #4
0
    def _update_norefresh(self, *args):

        if not self._active:
            return self.ax

        if len(args) == 1:
            if id(self.ax) <> id(args[0]):
                raise Exception("ax ids should match")

        lines = []

        if self.x_auto_spacing:
            if self.ax.xaxis.apl_auto_tick_spacing:
                xspacing = default_spacing(self.ax, 'x', self.ax.xaxis.apl_label_form).todegrees()
            else:
                xspacing = self.ax.xaxis.apl_tick_spacing.todegrees()
        else:
            xspacing = self.x_grid_spacing.todegrees()

        if self.y_auto_spacing:
            if self.ax.yaxis.apl_auto_tick_spacing:
                yspacing = default_spacing(self.ax, 'y', self.ax.yaxis.apl_label_form).todegrees()
            else:
                yspacing = self.ax.yaxis.apl_tick_spacing.todegrees()
        else:
            yspacing = self.y_grid_spacing.todegrees()

        # Find longitude lines that intersect with axes
        lon_i, lat_i = find_intersections(self.wcs, 'x', xspacing)

        lon_i_unique = np.array(list(set(lon_i)))

        # Plot those lines
        for l in lon_i_unique:
            for line in plot_longitude(self.wcs, lon_i, lat_i, l):
                lines.append(line)

        # Find longitude lines that don't intersect with axes
        lon_all = math_util.complete_range(0.0, 360.0, xspacing)
        lon_ni = np.sort(np.array(list(set(lon_all)-set(lon_i_unique))))
        lat_ni = np.ones(np.size(lon_ni)) # doesn't matter what value is, is either in or outside

        if np.size(lon_ni) > 0:

            xpix, ypix = wcs_util.world2pix(self.wcs, lon_ni, lat_ni)

            # Plot those lines
            # for i in range(0, np.size(lon_ni)):
            #     if(in_plot(wcs, xpix[i], ypix[i])):
            #         print "Inside longitude : "+str(lon_ni[i])
            #         plot_longitude(wcs, np.array([]), np.array([]), lon_ni[i])

            # Find latitude lines that intersect with axes
        lon_i, lat_i = find_intersections(self.wcs, 'y', yspacing)

        lat_i_unique = np.array(list(set(lat_i)))

        # Plot those lines
        for l in lat_i_unique:
            for line in plot_latitude(self.wcs, lon_i, lat_i, l):
                lines.append(line)

        # Find latitude lines that don't intersect with axes
        lat_all = math_util.complete_range(-90.0, 90.0, yspacing)
        lat_ni = np.sort(np.array(list(set(lat_all)-set(lat_i_unique))))
        lon_ni = np.ones(np.size(lat_ni)) # doesn't matter what value is, is either in or outside

        if np.size(lat_ni) > 0:

            xpix, ypix = wcs_util.world2pix(self.wcs, lon_ni, lat_ni)

            # Plot those lines
            # for i in range(0, np.size(lat_ni)):
            #     if(in_plot(wcs, xpix[i], ypix[i])):
            #         print "Inside latitude : "+str(lat_ni[i])
            #         plot_latitude(wcs, np.array([]), np.array([]), lat_ni[i])

        if self._grid:
            self._grid.set_verts(lines)
        else:
            self._grid = LineCollection(lines, transOffset=self.ax.transData)
            self.ax.add_collection(self._grid, False)

        return self.ax