made pip package

This commit is contained in:
Jacob Holder 2023-05-08 11:20:51 +02:00
parent e42dab4127
commit d4959b9125
13 changed files with 94 additions and 70 deletions

View File

@ -0,0 +1,2 @@
from .ising import runner
from .main import runner

View File

@ -25,9 +25,9 @@ def average_mean(arr, window_size=20):
def new_merge(files):
wp = []
op = []
spot_1 = []
spot_2 = []
spot_3 = []
spot_rutile = []
spot_mono = []
spot_diff = []
plt.figure()
for file in files:
print(file)
@ -43,43 +43,47 @@ def new_merge(files):
print(out)
out = np.array(out)[:, :, 0]
spot_1.append(out[0, :])
spot_2.append(out[3, :])
spot_3.append(out[2, :])
spot_rutile.append(out[0, :]) #rutile
spot_mono.append(out[2, :]) #mono
spot_diff.append(out[3, :]) #diff
wp = np.concatenate(wp, axis=0)
op = np.concatenate(op, axis=0)
spot_1 = np.concatenate(spot_1, axis=0)
spot_2 = np.concatenate(spot_2, axis=0)
spot_3 = np.concatenate(spot_3, axis=0)
wp = 1-wp
op = 1-op
spot_rutile = np.concatenate(spot_rutile, axis=0)
spot_mono = np.concatenate(spot_mono, axis=0)
spot_diff = np.concatenate(spot_diff, axis=0)
arg_sort = np.argsort(op)
wp = wp[arg_sort]
op = op[arg_sort]
spot_1 = spot_1[arg_sort]
spot_2 = spot_2[arg_sort]
spot_3 = spot_3[arg_sort]
spot_rutile = spot_rutile[arg_sort]
spot_mono = spot_mono[arg_sort]
spot_diff = spot_diff[arg_sort]
win = 100
wp = average_mean(wp, win)
op = average_mean(op, win)
spot_1 = average_mean(spot_1, win)
spot_2 = average_mean(spot_2, win)
spot_3 = average_mean(spot_3, win)
spot_rutile = average_mean(spot_rutile, win)
spot_mono = average_mean(spot_mono, win)
spot_diff = average_mean(spot_diff, win)
x = op
plt.plot(x, spot_1, "r.")
plt.plot(x, spot_2, "g.")
plt.plot(x, spot_3, "b.")
ma = np.max(spot_1+spot_2+spot_3)
spot_1 /= ma
spot_2 /= ma
spot_3 /= ma
plt.plot(x, spot_rutile, "r.", label="rutile")
plt.plot(x, spot_mono, "g.", label="mono")
plt.plot(x, spot_diff, "b.",label="diff" )
plt.legend()
ma = np.max(spot_rutile+spot_mono+spot_diff)
spot_rutile /= ma
spot_mono /= ma
spot_diff /= ma
print("debug....")
print(wp.shape)
plt.savefig("debug.png")
return op, np.stack([spot_2, spot_1, spot_3])
return op, np.stack([spot_rutile, spot_mono, spot_diff])
def merge(files):
@ -129,7 +133,7 @@ def debug(percentage, out):
def stacked_plot(ax, percentage, out, title=""):
stacks = ax.stackplot(percentage, out[[0, 1, 2]], colors=[
stacks = ax.stackplot(percentage, out[[0, 2, 1]], colors=[
"w"], ls=(0, (0, 1)), ec="w")
hatches = ["//", "|", "\\\\"]
for stack, hatch, color in zip(stacks, hatches, ["C1", "C0", "C2"]):
@ -145,8 +149,24 @@ def stacked_plot(ax, percentage, out, title=""):
bbox=dict(boxstyle='square,pad=0.0', ec="None", fc="w"))
ax.text(0.35, 0.73, "diffusive", backgroundcolor="w",
bbox=dict(boxstyle='square,pad=0.0', ec="None", fc="w"))
ax.stackplot(percentage, out[[0, 1, 2]], colors=["None"], ec="k")
ax.stackplot(percentage, out[[0, 2, 1]], colors=["None"], ec="k")
ax.plot([0,1], [0.52,1],":k")
def stacked_plot_norm(ax, percentage, out, title=""):
out = out.copy()
ref = out[0][0]
out[0] = out[0] - ref
sum = out[0] + out[1]
out /= sum
#out[0] += ref
#out /= 1+ref
out[2] = 0.
stacked_plot(ax, percentage, out,title)
def time_scale(ax, p, o):
rut_perc = o[0]
@ -240,10 +260,11 @@ if __name__ == "__main__":
p, o = new_merge(sys.argv[2:])
np.savez("merged.npz", p=p, o=o)
fig, axs = plt.subplots(1, 3)
fig, axs = plt.subplots(1, 4)
fig.set_figheight(2)
stacked_plot(axs[1], p, o)
time_scale(axs[2], p, o)
stacked_plot_norm(axs[2], p, o)
time_scale(axs[3], p, o)
if "intens" in sys.argv[1]:
intens(axs[0], sys.argv[1], p, o)
plt.tight_layout()

View File

@ -1,8 +1,8 @@
import logging
from abc import abstractmethod, ABC
from tools import clean_bounds_offset
from spin_image import FFT
from cache import persist_to_file, timeit
from .tools import clean_bounds_offset
from .spin_image import FFT
from .cache import persist_to_file, timeit
import tqdm
import numpy as np
import matplotlib.pyplot as plt

View File

@ -1,13 +1,13 @@
import logging
import scipy.fftpack as sfft
from plotter import Plotter
from .plotter import Plotter
from scipy import signal
from cache import timeit
from extractors import Rect_Evaluator
from .cache import timeit
from .extractors import Rect_Evaluator
import tqdm
from lattices import SCC_Lattice, VO2_Lattice, VO2_New
from .lattices import SCC_Lattice, VO2_Lattice, VO2_New
import sys
from spin_image import SpinImage
from .spin_image import SpinImage
import numpy as np
import matplotlib.pyplot as plt
plt.style.use(["style", "colors", "two_column"])
@ -21,8 +21,7 @@ ch.setFormatter(formatter)
logger.addHandler(ch)
def ising(file, num):
LEN = 150
def ising(file, num, LEN=40,iterations=500):
#lat = VO2_New(LEN, LEN)
lat = VO2_New(LEN, LEN)
rect = Rect_Evaluator(lat.get_spots())
@ -35,14 +34,15 @@ def ising(file, num):
spins = np.load(file)["s1"]
spins[spins==-1] = 0
ising_percentage=np.mean(spins)
for i in tqdm.tqdm(range(500)):
for i in tqdm.tqdm(range(iterations)):
(ix,iy) = np.random.randint(2000-LEN-LEN,size=2)
maske = spins[ix:ix+2*LEN, iy:iy+2*LEN]
si.apply_mask(lat.parse_mask(maske))
si.gaussian(LEN)
si.gaussian(LEN/2.)
intens = si.fft()
if not already_inited:
@ -55,7 +55,7 @@ def ising(file, num):
percentage.append(np.sum(maske))
[p1, p2] = si.get_intens(lat.parse_mask(maske))
weighted_percentage.append(p1/(p1+p2))
np.savez(f"ising_rect_{num}_temp.npz",
np.savez(f"ising_rect_{num}_temp.npz",i_percentage=ising_percentage,
w_percentage=weighted_percentage, percentage=percentage, out_1=out_rect[0],
out_2=out_rect[1], out_3=out_rect[2], out_4=out_rect[3])
@ -63,22 +63,13 @@ def ising(file, num):
weighted_percentage = np.array(weighted_percentage)
percentage /= np.max(percentage)
np.savez(f"ising_rect_{num}.npz",
np.savez(f"ising_rect_{num}.npz",i_percentage=ising_percentage,
w_percentage=weighted_percentage, percentage=percentage, out_1=out_rect[0],
out_2=out_rect[1], out_3=out_rect[2], out_4=out_rect[3])
def runner(file, idx):
def runner(file, idx, LEN=40, iterations=500):
np.random.seed(1234)
print(f"runnig: {file}")
ising(file,idx)
ising(file=file,num=idx,LEN=LEN,iterations=iterations)
if __name__ == "__main__":
files = sys.argv[2:]
idx = int(sys.argv[1])
print(f"{idx}/{len(files)}")
if idx > len(files):
exit()
if idx < 1:
exit()
runner(files[idx-1], idx)

View File

@ -1,6 +1,6 @@
import matplotlib.pyplot as plt
import numpy as np
from cache import timeit
from .cache import timeit
from abc import ABC, abstractmethod

View File

@ -1,13 +1,13 @@
import logging
import scipy.fftpack as sfft
from plotter import Plotter
from .plotter import Plotter
from scipy import signal
from cache import timeit
from extractors import Rect_Evaluator
from .cache import timeit
from .extractors import Rect_Evaluator
import tqdm
from lattices import SCC_Lattice, VO2_Lattice, VO2_New
from .lattices import SCC_Lattice, VO2_Lattice, VO2_New
import sys
from spin_image import SpinImage
from .spin_image import SpinImage
import numpy as np
import matplotlib.pyplot as plt
plt.style.use(["style", "colors", "two_column"])
@ -21,9 +21,8 @@ ch.setFormatter(formatter)
logger.addHandler(ch)
def random(seed):
def random(idx,seed, LEN=40,iterations=1000):
np.random.seed(seed)
LEN = 40
#lat = VO2_New(LEN, LEN)
lat = VO2_Lattice(LEN, LEN)
maske = np.zeros((LEN, LEN))
@ -46,7 +45,7 @@ def random(seed):
print(counter, i)
si.apply_mask(lat.parse_mask(maske))
si.gaussian(20)
si.gaussian(0.5*LEN)
intens = si.fft()
if not already_inited:
@ -59,6 +58,9 @@ def random(seed):
percentage.append(np.sum(maske))
[p1, p2] = si.get_intens(lat.parse_mask(maske))
weighted_percentage.append(p1/(p1+p2))
np.savez(f"random_rect_{seed}_temp.npz",
w_percentage=weighted_percentage, percentage=percentage, out_1=out_rect[0],
out_2=out_rect[1], out_3=out_rect[2], out_4=out_rect[3])
percentage = np.array(percentage)
weighted_percentage = np.array(weighted_percentage)
@ -68,7 +70,7 @@ def random(seed):
w_percentage=weighted_percentage, percentage=percentage, out_1=out_rect[0],
out_2=out_rect[1], out_3=out_rect[2], out_4=out_rect[3])
def runner():
def runner(idx,LEN=40,iterations=1000):
np.random.seed(1234)
seeds = np.random.randint(0, 10000, 200)
idx = int(sys.argv[1])
@ -77,9 +79,6 @@ def runner():
if idx >= seeds.size:
return
seed = seeds[idx]
random(seed)
random(idx=idx,seed=seed, LEN=LEN,iterations=iterations)
if __name__ == "__main__":
np.random.seed(1234)
runner()

View File

@ -1,5 +1,5 @@
import matplotlib.pyplot as plt
from spin_image import SpinImage, FFT
from .spin_image import SpinImage, FFT
import matplotlib

View File

@ -1,6 +1,6 @@
from dataclasses import dataclass
from tools import clean_bounds, clean_bounds_offset
from cache import timeit
from .tools import clean_bounds, clean_bounds_offset
from .cache import timeit
import scipy.signal
import scipy.fftpack as sfft
import scipy

11
software/setup.py Normal file
View File

@ -0,0 +1,11 @@
from setuptools import setup, find_packages
setup(
name='fft_sim',
version='1.0',
packages=find_packages(),
install_requires=[
'importlib-metadata; python_version == "3.8"',
],
)