def test_colorize_background(): text = "Hello" colored_text = colorize(text, bg=(120, 160, 200)) assert colored_text == f"{CSI}48;2;120;160;200m{text}{RESET_BACKGROUND}" colored_text = colorize(text, bg=(128, 128, 128)) assert colored_text == f"{CSI}48;2;128;128;128m{text}{RESET_BACKGROUND}"
def test_colorize_rgb_color(): text = "Hello" colored_text = colorize(text, c=(120, 160, 200)) assert colored_text == f"{CSI}38;2;120;160;200m{text}{RESET_COLOR}" colored_text = colorize(text, c=(128, 128, 128)) assert colored_text == f"{CSI}38;2;128;128;128m{text}{RESET_COLOR}"
def test_gradient_3_char(): text = "ABC" colored_text = gradient(text, "red", "green") expected = ( colorize("A", c="red") + colorize("B", c=(127, 127, 0)) + colorize("C", c="green") ) print() print("result ", repr(colored_text)) print("expected ", repr(expected)) assert colored_text == expected
def plot(field, zoom_width=None): if zoom_width is None: zoom_width = width if zoom_width is not None: field = field[width // 2 - zoom_width // 2:width // 2 + zoom_width // 2] plt.imshow(colorize(np.repeat([field], zoom_width, axis=0)))
def test_colorize_underline(): text = "Hello" colored_text = colorize(text, c=(120, 160, 200), s="u") assert ( colored_text == f"{CSI}38;2;120;160;200m{UNDERLINE}{text}{RESET_UNDERLINE}{RESET_COLOR}" )
def test_rmitalic_multiple_styles(): text = "Hello" assert rmitalic(cross(italic(text))) == cross(text) assert rmitalic(bold(italic(text))) == bold(text) assert rmitalic(dim(italic(text))) == dim(text) assert rmitalic(blink(italic(text))) == blink(text) assert rmitalic(underline(italic(text))) == underline(text) assert rmitalic(double_underline(italic(text))) == double_underline(text) # more than one in a raw assert rmitalic(bold(dim(italic(text)))) == bold(dim(text)) assert rmitalic(blink(underline(double_underline(bold(italic(text)))))) == blink( underline(double_underline(bold(text))) ) # other syntax assert rmitalic(colorize(text, s="bic")) == colorize(text, s="bc") assert rmitalic(colorize(text, s="bicuU")) == colorize(text, s="bcuU")
view_width = 50 # wave_relation = np.abs(x**1) # momentum_positive *= np.exp(1j * wave_relation * dt) # momentum_negative *= np.exp(-1j * wave_relation * dt) # momentum = momentum_positive + 0*momentum_negative # position = ifft(ifftshift(momentum)) # momentum = momentum_positive * np.exp(1j*i*dt * wave_relation) * 1 + momentum_negative * np.exp(-1j*i*dt * wave_relation) # momentum = fftshift(fft(position)) # momentum=np.imag(momentum) # momentum = np.angle(momentum) # momentum = momentum_initial * multiplier_at_time(i*dt) # position = ifft(ifftshift(momentum)) # plot(momentum - fftshift(fft(np.abs(position)))) # plt.imshow(colorize(np.repeat([momentum[width // 2 - view_width // 2:width // 2 + view_width // 2]/10], view_width, axis=0))) plt.imshow(colorize(np.repeat([position], width, axis=0))) # plot(momentum) # plt.clf() # plt.plot(np.abs(momentum)) plt.pause(0.001) plt.show() position2 = np.exp(-1 * x**2) momentum = fftshift(fft(position)) # momentum *= np.exp(-1j*x) ** 200 position2 = ifft(ifftshift(momentum)) # plt.imshow(colorize(np.repeat([momentum[width//2-view_width//2:width//2+view_width//2]], view_width, axis=0))) # plt.imshow(np.repeat([np.abs(fftshift(fft(position))) / np.abs(fftshift(fft(initial)))], width, axis=0))
def test_re_sgr(): assert re_sgr.findall("Nothing here") == [] assert re_sgr.findall(colorize("Hello", c="red")) == [ f"{CSI}38;2;255;0;0m", RESET_COLOR, ]
def test_colorize_style_only(): text = "Hello" colored_text = colorize(text, s="u") assert colored_text == f"{UNDERLINE}{text}{RESET_UNDERLINE}"
# plt.pause(0.001)]] # img.setImage(np.abs(momentum)) # img.setImage(np.maximum(0,np.abs(position))) # img2.setImage(colorize(positive_momentum_new - positive_momentum)) max_pos = np.max(pos_mag) max_vel = np.max(np.abs(vel)) # pos_mag[0,0] = 1 # img2.setImage(pos_mag % 1) # img2.setImage(colorize(np.exp(2j*pi*pos_mag))) energy = 0 * pos_mag**2 + np.abs(vel)**2 img2.setImage(energy) # img2.setImage(colorize(momentum[2*width//5:3*width//5,2*width//5:3*width//5])) img.setImage(colorize(position.transpose() / np.ceil(max_pos + 0.1))) # img2.setImage(colorize(nonlinear)) print(f'max position: {max_pos}') print(f'max nonlinear: {np.max(np.abs(nonlinear))}') print(f'total energy: {np.sum(energy)}') # img.setImage(colorize(position - to_compare)) # img.setImage(colorize(position.imag)) # img.setImage(colorize(momentum_op)) # img2.setImage(colorize(position)) app.processEvents() # print("normalizing and reshaping") # # from 0 - 1 (nIter, width, width, 3) to 0 - 255 (nIter, 3, width, width) # all_outputs /= np.max(all_outputs) # all_outputs = np.array(all_outputs) * 255 # all_outputs = np.array(np.floor(all_outputs), dtype=int)
def test_rmbackground(): text = "Hello" assert rmbackground(colorize(text, bg="green")) == text assert rmbackground(colorize(text, bg="red")) == text
def test_rmcolor(): text = "Hello" assert rmcolor(colorize(text, c="green")) == text assert rmcolor(colorize(text, c="red")) == text
def test_rmgraphics(): text = "Hello" assert rmgraphics(underline(bold(text))) == text assert rmgraphics(italic(colorize(text))) == text assert rmgraphics(colorize(text, c="red", s="uUcb", bg="yellow")) == text assert rmgraphics(colorize(text, c=(23, 12, 34), s="i", bg="red")) == text
# g += force(g, dt=dt) # g *= 0.999 # dg_dt += field_grad * dt # g += dg_dt * dt # dg_dt += force(dg_dt, dt=dt*1) field += force(field, dt=dt) * field # field += field_to_gain(field, g) * dt * G # g += dg_dt * dt + field * dt # dg_dt += field * dt # dg_dt *= 0.999 # g += force(g,dt=dt) # plt.imshow(colorize(g)) plt.subplot(2, 2, 1) plt.imshow(colorize(field.transpose())) plt.subplot(2, 2, 2) plt.imshow(colorize(g.transpose())) plt.subplot(2, 2, 3) plt.imshow((field_to_gain(field, g) * dt * G).real) # plt.imshow(colorize(dg_dt.transpose())) plt.subplot(2, 2, 4) plt.imshow( (force(field, dt=dt) * field_SPREAD_RATE * field_SPREAD_RATE * field * field).real) # + (field_to_gain(field, g) * dt * G).real) plt.draw_all() plt.pause(0.001) plt.clf()
# potential_op = np.exp(-1j * potential * 0.00001 * dt / 2) for substep in range(1): momentum = fftshift(fft2(position)) momentum *= momentum_op position = ifft2(ifftshift(momentum)) # potential = ground_potential# + 0.00001*1.0 / gaussian_filter(np.abs(np.maximum(position, 0.01)*1), sigma=15)**2 pos_mag = np.abs(position) potential_op = np.exp(-1j * (1 * ground_potential - 1 * 0.11 * (pos_mag * pos_mag)) * 0.3 * dt / 2) position *= potential_op # position -= 0.1*position * (1-pos_mag) # position *= np.exp(-1j * potential * dt / 1000) all_outputs.append(colorize(position / 1)) if iter % 3 == 0: plt.subplot(1, 2, 1) # plt.imshow(np.abs(potential)) # plt.imshow(colorize(momentum)) # plt.imshow(momentum.real) plt.imshow(np.minimum(10, np.sqrt(momentum.real**2 + momentum.imag**2))) #[200:300,200:300]) plt.subplot(1, 2, 2) # plt.imshow(all_outputs[-1]) plt.imshow(np.sqrt(position.real**2 + position.imag**2)) # plt.subplot(1, 3, 3) # plt.imshow(ground_potential + 0.00001*1.0 / gaussian_filter(np.abs(np.maximum(position, 0.01)*1), sigma=15)**2) # plt.imshow(colorize(fftshift(fft2(position)))) plt.draw_all()
# plt.imshow(np.abs(potential)) # plt.imshow(colorize(momentum)) # plt.imshow(momentum.real) # plt.imshow(np.minimum(10, np.sqrt(momentum.real ** 2 + momentum.imag ** 2)))#[200:300,200:300]) # plt.subplot(1, 2, 2) # plt.imshow(all_outputs[-1]) # plt.imshow(np.sqrt(position.real ** 2 + position.imag ** 2)) # plt.subplot(1, 3, 3) # plt.imshow(ground_potential + 0.00001*1.0 / gaussian_filter(np.abs(np.maximum(position, 0.01)*1), sigma=15)**2) # plt.imshow(colorize(fftshift(fft2(position)))) # plt.draw_all() # plt.pause(0.001)]] # img.setImage(np.abs(momentum)) # img.setImage(np.maximum(0,np.abs(position))) # img.setImage(colorize(momentum[150:250, 150:250])) img.setImage(colorize(position)) # img.setImage(colorize(position - to_compare)) # img.setImage(colorize(position.imag)) # img.setImage(colorize(momentum_op)) # img2.setImage(colorize(position)) app.processEvents() print("normalizing and reshaping") # from 0 - 1 (nIter, width, width, 3) to 0 - 255 (nIter, 3, width, width) all_outputs = np.array(all_outputs) * 255 all_outputs = np.array(np.floor(all_outputs), dtype=int) # all_outputs = np.transpose(all_outputs, (0, 3, 1, 2)) print("Writing to video") # array2gif.write_gif(all_outputs, "schrodinger2dOut.gif") print(np.max(all_outputs), np.min(all_outputs)) imageio.mimwrite(first_unoccupied("../images/schrodinger2dOut%s.mp4"),
def test_colorize_bold(): text = "Hello" colored_text = colorize(text, c=(120, 160, 200), s="b") assert ( colored_text == f"{CSI}38;2;120;160;200m{BOLD}{text}{RESET_BOLD_AND_DIM}{RESET_COLOR}")
g += mass_grad * dt g += force(g, dt=dt) g *= 0.999 # dg_dt += mass_grad * dt # g += dg_dt * dt # dg_dt += force(dg_dt, dt=dt*1) mass += force(mass, dt=dt) * MASS_SPREAD_RATE * mass mass += mass_to_gain(mass, g) * dt * G # g += dg_dt * dt + mass * dt # dg_dt += mass * dt # dg_dt *= 0.999 # g += force(g,dt=dt) # plt.imshow(colorize(g)) plt.subplot(2, 2, 1) plt.imshow(mass.real) plt.subplot(2, 2, 2) plt.imshow(colorize(g.transpose())) plt.subplot(2, 2, 3) plt.imshow((mass_to_gain(mass, g) * dt * G).real) # plt.imshow(colorize(dg_dt.transpose())) plt.subplot(2, 2, 4) plt.imshow((force(mass, dt=dt) * MASS_SPREAD_RATE * MASS_SPREAD_RATE * mass * mass).real) # + (mass_to_gain(mass, g) * dt * G).real) plt.draw_all() plt.pause(0.001) plt.clf()
def test_gradient_2_char(): text = "AB" colored_text = gradient(text, "red", "green") assert colored_text == colorize("A", c="red") + colorize("B", c="green")