Skip to content

Instantly share code, notes, and snippets.

@HViktorTsoi
Created July 16, 2020 03:29
Show Gist options
  • Save HViktorTsoi/7b4cd9590f26a60c082d797948ebd45d to your computer and use it in GitHub Desktop.
Save HViktorTsoi/7b4cd9590f26a60c082d797948ebd45d to your computer and use it in GitHub Desktop.
horizon
import time
import matplotlib.pyplot as plt
import numpy as np
def get_omega(position):
position_list = []
for line in range(LINES):
new_position = np.copy(position)
new_position[:, 1] += line * Vhigh
position_list.append(new_position)
position_list = np.row_stack([
position_list
])
return position_list.reshape(-1, 2)
def flatten_gamma_t(t, gamma):
# normalized period
T = t * gamma_period / (2 * np.pi)
# where should be flatten
flatten_indices = np.where(
(0 < ((T + 0.25) % gamma_beta_factor) % (gamma_beta_factor / 2)) &
(((T + 0.25) % gamma_beta_factor) % (gamma_beta_factor / 2) < 0.5)
)
gamma[flatten_indices] *= 0.1
return gamma
OVERLAP_TIME = 50
t = np.arange(0, OVERLAP_TIME * 0.35 * np.pi, 0.0001)
# MAG
Rx, Ry = 8, 1
H = 15
Vlow = 0.15
Vhigh = 0.06
LINES = 5
# PERIOD
alpha_period = 1 * 2 * np.pi
beta_period = 20 * 2 * np.pi
gamma_period = 60 * 2 * np.pi
gamma_beta_factor = gamma_period / beta_period
non_repeat_noise_factor = 0.015
non_repeat_noise_period = 1.4 * 2 * np.pi
alpha = np.column_stack([
Rx * np.cos(alpha_period * t),
Ry * np.sin(alpha_period * t)
])
beta = np.column_stack([
H * np.sin(beta_period * t),
np.zeros_like(t) + non_repeat_noise_factor * np.cos(non_repeat_noise_period * t)
])
gamma = np.column_stack([
np.zeros_like(t),
Vlow * np.cos(gamma_period * t)
])
gamma = flatten_gamma_t(t, gamma)
# position = alpha + beta
position = alpha + beta + gamma
# position = beta + gamma
position = get_omega(position)
print(position.shape)
plt.gcf().set_size_inches(12, 4)
plt.scatter(position[:, 0], position[:, 1], s=0.5)
plt.title('overlap: {}'.format(OVERLAP_TIME))
plt.show()
# plt.ion()
# plt.figure(1)
# for i in range(1, len(position), 10):
# plt.scatter(position[:i, 0], position[:i, 1], s=0.5)
# plt.title('t = {:05f} (gamma), {:05f} (beta)'.format(
# t[i] * gamma_period / (2 * np.pi),
# t[i] * beta_period / (2 * np.pi)
# ))
# plt.draw()
# # plt.pause(0.001)
# plt.waitforbuttonpress(0)
# plt.scatter(alpha[:,0], alpha[:,1])
# plt.show()
# plt.scatter(beta[:,0], beta[:,1])
# plt.plot(beta)
# plt.plot(gamma)
# plt.show()
# plt.plot(beta[:,0])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment