Esempio n. 1
0
    def _blur(radius, theta, amount=0.07, random_state="random-seed"):
        """Blur the positions around the centroid of the spiralarm.

        The given positions are blurred by drawing a displacement in radius from
        a normal distribution, with sigma = amount * radius. And a direction
        theta from a uniform distribution in the interval [0, 2 * pi].

        Parameters
        ----------
        radius : `~astropy.units.Quantity`
            Radius coordinate
        theta : `~astropy.units.Quantity`
            Angle coordinate
        amount: float, optional
            Amount of blurring of the position, given as a fraction of `radius`.
        random_state : {int, 'random-seed', 'global-rng', `~numpy.random.RandomState`}
            Defines random number generator initialisation.
            Passed to `~gammapy.utils.random.get_random_state`.
        """
        random_state = get_random_state(random_state)

        dr = Quantity(
            abs(random_state.normal(0, amount * radius, radius.size)), "kpc")
        dtheta = Quantity(random_state.uniform(0, 2 * np.pi, radius.size),
                          "rad")
        x, y = cartesian(radius, theta)
        dx, dy = cartesian(dr, dtheta)
        return polar(x + dx, y + dy)
Esempio n. 2
0
ax_cartesian.set_ylim(-20, 20)
ax_cartesian.set_xlabel('x [kpc]', labelpad=2)
ax_cartesian.set_ylabel('y [kpc]', labelpad=-4)
ax_cartesian.plot(
    0, 8, color='k', markersize=10,
    fillstyle='none', marker='*', linewidth=2,
)
ax_cartesian.annotate(
    'Sun', xy=(0, 8), xycoords='data', xytext=(-15, 15),
    arrowprops=dict(arrowstyle="->", color='k'), weight=400,
)

plt.grid(True)

# TODO: document what these magic numbers are or simplify the code
# `other_idx = [95, 90, 80, 80]` and below `theta_idx = int(other_idx * 0.97)`
for spiral_idx, other_idx in zip(range(4), [95, 90, 80, 80]):
    spiralarm_name = spiral.spiralarms[spiral_idx]
    theta_0 = spiral.theta_0[spiral_idx].value

    theta = Quantity(np.linspace(theta_0, theta_0 + 2 * np.pi, 100), 'rad')
    x, y = spiral.xy_position(theta=theta, spiralarm_index=spiral_idx)
    ax_cartesian.plot(x.value, y.value, color='k')
    rad, phi = polar(x[other_idx], y[other_idx])
    x_pos, y_pos = cartesian(rad + Quantity(1, 'kpc'), phi)
    theta_idx = int(other_idx * 0.97)
    rotation = theta[theta_idx].to('deg').value
    ax_cartesian.text(x_pos.value, y_pos.value, spiralarm_name,
                      ha='center', va='center', rotation=rotation - 90, weight=400)
plt.show()
Esempio n. 3
0
                  fillstyle='none',
                  marker='*',
                  linewidth=2)
ax_cartesian.annotate('Sun',
                      xy=(0, 8),
                      xycoords='data',
                      xytext=(-15, 15),
                      arrowprops=dict(arrowstyle="->", color='k'),
                      weight=400)

plt.grid(True)

ind = [95, 90, 80, 80]

for i in range(4):
    theta_0 = spiral.theta_0[i].value
    theta = Quantity(np.linspace(theta_0, theta_0 + 2 * np.pi, 100), 'rad')
    x, y = spiral.xy_position(theta=theta, spiralarm_index=i)
    ax_cartesian.plot(x.value, y.value, color='k')
    rad, phi = polar(x[ind[i]], y[ind[i]])
    x_pos, y_pos = cartesian(rad + Quantity(1, 'kpc'), phi)
    rotation = theta[ind[i] * 0.97].to('deg').value
    ax_cartesian.text(x_pos.value,
                      y_pos.value,
                      spiral.spiralarms[i],
                      ha='center',
                      va='center',
                      rotation=rotation - 90,
                      weight=400)
plt.show()
Esempio n. 4
0
ax_cartesian.set_aspect('equal')
ax_polar = fig.add_axes(rect, polar=True, frameon=False)
ax_polar.axes.get_xaxis().set_ticklabels([])
ax_polar.axes.get_yaxis().set_ticklabels([])

ax_cartesian.plot(catalog['x'], catalog['y'], marker='.',
                  linestyle='none', markersize=5, alpha=0.3, fillstyle='full')
ax_cartesian.set_xlim(-20, 20)
ax_cartesian.set_ylim(-20, 20)
ax_cartesian.set_xlabel('x [kpc]', labelpad=2)
ax_cartesian.set_ylabel('y [kpc]', labelpad=-4)
ax_cartesian.plot(0, 8, color='k', markersize=10, fillstyle='none', marker='*', linewidth=2)
ax_cartesian.annotate('Sun', xy=(0, 8), xycoords='data',
                      xytext=(-15, 15), arrowprops=dict(arrowstyle="->", color='k'), weight=400)

plt.grid(True)

ind = [95, 90, 80, 80]

for i in range(4):
    theta_0 = spiral.theta_0[i].value
    theta = Quantity(np.linspace(theta_0, theta_0 + 2 * np.pi, 100), 'rad')
    x, y = spiral.xy_position(theta=theta, spiralarm_index=i)
    ax_cartesian.plot(x.value, y.value, color='k')
    rad, phi = polar(x[ind[i]], y[ind[i]])
    x_pos, y_pos = cartesian(rad + Quantity(1, 'kpc'), phi)
    rotation = theta[ind[i] * 0.97].to('deg').value
    ax_cartesian.text(x_pos.value, y_pos.value, spiral.spiralarms[i],
                      ha='center', va='center', rotation=rotation - 90, weight=400)
plt.show()
Esempio n. 5
0
    xytext=(-15, 15),
    arrowprops=dict(arrowstyle="->", color="k"),
    weight=400,
)

plt.grid(True)

# TODO: document what these magic numbers are or simplify the code
# `other_idx = [95, 90, 80, 80]` and below `theta_idx = int(other_idx * 0.97)`
for spiral_idx, other_idx in zip(range(4), [95, 90, 80, 80]):
    spiralarm_name = spiral.spiralarms[spiral_idx]
    theta_0 = spiral.theta_0[spiral_idx].value

    theta = Quantity(np.linspace(theta_0, theta_0 + 2 * np.pi, 100), "rad")
    x, y = spiral.xy_position(theta=theta, spiralarm_index=spiral_idx)
    ax_cartesian.plot(x.value, y.value, color="k")
    rad, phi = polar(x[other_idx], y[other_idx])
    x_pos, y_pos = cartesian(rad + Quantity(1, "kpc"), phi)
    theta_idx = int(other_idx * 0.97)
    rotation = theta[theta_idx].to("deg").value
    ax_cartesian.text(
        x_pos.value,
        y_pos.value,
        spiralarm_name,
        ha="center",
        va="center",
        rotation=rotation - 90,
        weight=400,
    )
plt.show()