How to use the healpy.rotator.dir2vec function in healpy

To help you get started, we’ve selected a few healpy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github healpy / healpy / healpy / projector.py View on Github external
def xy2vec(self, x, y=None, direct=False):
        if y is None:
            x, y = np.asarray(x)
        else:
            x, y = np.asarray(x), np.asarray(y)
        flip = self._flip
        theta = pi / 2.0 - y * dtor  # convert in radian
        phi = flip * x * dtor  # convert in radian
        # dir2vec does not support 2d arrays, so first use flatten and then
        # reshape back to previous shape
        if not direct:
            vec = self.rotator.I(R.dir2vec(theta.flatten(), phi.flatten()))
        else:
            vec = R.dir2vec(theta.flatten(), phi.flatten())
        vec = [v.reshape(theta.shape) for v in vec]
        return vec
github healpy / healpy / healpy / projaxes.py View on Github external
See Also
        --------
        projplot, projscatter
        """
        if phi is None:
            theta, phi = np.asarray(theta)
        else:
            theta, phi = np.asarray(theta), np.asarray(phi)
        rot = kwds.pop("rot", None)
        if rot is not None:
            rot = np.array(np.atleast_1d(rot), copy=1)
            rot.resize(3)
            rot[1] = rot[1] - 90.0
        coord = self.proj.mkcoord(kwds.pop("coord", None))[::-1]
        lonlat = kwds.pop("lonlat", False)
        vec = R.dir2vec(theta, phi, lonlat=lonlat)
        vec = (R.Rotator(rot=rot, coord=coord, eulertype="Y")).I(vec)
        x, y = self.proj.vec2xy(vec, direct=kwds.pop("direct", False))
        return self.text(x, y, s, **kwds)
github healpy / healpy / healpy / projector.py View on Github external
w = np.where(mask == False)
        if not mask.any():
            mask = np.ma.nomask
        if not hasattr(x, "__len__"):
            if mask is not np.ma.nomask:
                return np.nan, np.nan, np.nan
            else:
                rho = np.sqrt(x ** 2 + y ** 2)
                if lamb:
                    c = 2.0 * np.arcsin(rho / 2.0)
                else:
                    c = rho
                lat = np.arcsin(y * np.sin(c) / rho)
                phi = np.arctan2(x * np.sin(c), (rho * np.cos(c)))
                phi *= flip
                vec = R.dir2vec(pi / 2.0 - lat, phi)
                if not direct:
                    return self.rotator.I(vec)
                else:
                    return vec
        else:
            vec = (
                np.zeros(x.shape) + np.nan,
                np.zeros(x.shape) + np.nan,
                np.zeros(x.shape) + np.nan,
            )
            rho = np.sqrt(x[w] ** 2 + y[w] ** 2)
            if lamb:
                c = 2.0 * np.arcsin(rho / 2.0)
            else:
                c = rho
            lat = np.arcsin(y[w] * np.sin(c) / rho)
github healpy / healpy / healpy / projector.py View on Github external
def ang2xy(self, theta, phi=None, lonlat=False, direct=False):
        return self.vec2xy(R.dir2vec(theta, phi, lonlat=lonlat), direct=direct)
github DarkEnergySurvey / ugali / ugali / scratch / PlotAllSkyHealpix.py View on Github external
targets = numpy.genfromtxt(opts.targets,unpack=True,dtype=None)
        if not targets.shape: targets = targets.reshape(-1)
        coord = 'CG' # For RA/DEC input
        healpy.projscatter(targets['f1'],targets['f2'],
                           lonlat=True,coord=coord,marker='o',c='w')
        fig = plt.gcf()
        # This is pretty hackish (but is how healpy does it...)
        for ax in fig.get_axes():
            if isinstance(ax,healpy.projaxes.SphericalProjAxes): break

        for target in targets:
            text = TARGETS[target[0]][0]
            kwargs = TARGETS[target[0]][1]
            glon,glat = celToGal(target[1],target[2])

            vec = healpy.rotator.dir2vec(glon,glat,lonlat=True)
            vec = (healpy.rotator.Rotator(rot=None,coord='G',eulertype='Y')).I(vec)

            x,y = ax.proj.vec2xy(vec,direct=False)
            ax.annotate(text,xy=(x,y),xycoords='data',**kwargs)

    plt.savefig(opts.outfile)
github healpy / healpy / healpy / projaxes.py View on Github external
elif len(args) == 3:
            if type(args[2]) is not str:
                raise TypeError("Third argument must be a string")
            else:
                theta, phi = np.asarray(args[0]), np.asarray(args[1])
                fmt = args[2]
        else:
            raise TypeError("Three args maximum")
        rot = kwds.pop("rot", None)
        if rot is not None:
            rot = np.array(np.atleast_1d(rot), copy=1)
            rot.resize(3)
            rot[1] = rot[1] - 90.0
        coord = self.proj.mkcoord(kwds.pop("coord", None))[::-1]
        lonlat = kwds.pop("lonlat", False)
        vec = R.dir2vec(theta, phi, lonlat=lonlat)
        vec = (R.Rotator(rot=rot, coord=coord, eulertype="Y")).I(vec)
        x, y = self.proj.vec2xy(vec, direct=kwds.pop("direct", False))
        x, y = self._make_segment(
            x, y, threshold=kwds.pop("threshold", self._segment_threshold)
        )
        thelines = []
        for xx, yy in zip(x, y):
            if fmt is not None:
                try:  # works in matplotlib 1.3 and earlier
                    linestyle, marker, color = matplotlib.axes._process_plot_format(fmt)
                except:  # matplotlib 1.4 and later
                    linestyle, marker, color = matplotlib.axes._axes._process_plot_format(
                        fmt
                    )
                kwds.setdefault("linestyle", linestyle)
                kwds.setdefault("marker", marker)