Commit 2fff5f97 authored by Thomas Bruns's avatar Thomas Bruns
Browse files

.

parent c5dbf7f1
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Dec 22 17:15:45 2020
@author: bruns01
"""
import numpy as np
from bokeh.io import curdoc
from bokeh.layouts import column, row
from bokeh.models import ColumnDataSource, Slider, TextInput
from bokeh.plotting import figure
from primes import primes
# Set up callbacks
def update_data(attrname, old, new):
f_std = np.array([1.0, 1.25, 1.6, 2.0, 2.5, 3.2, 4.0, 5.0, 6.3, 8.0 ])
p0 = primes[new]
# pri = primes[(primes<=10*p0) & (primes>p0)]
pri = primes[(primes<=10*p0)]
d = []
for fs in f_std:
try:
f1 = (pri[pri/p0<=fs])[-1]/p0 # lower limit
r1 = (f1-fs)/fs
except:
r1 = 0.5
f2 = (pri[pri/p0>fs])[0]/p0 # upper limit
r2 = (f2-fs)/fs
r = r1 if (np.abs(r1)<np.abs(r2)) else r2
d.append(r)
print( f1 if (np.abs(r1)<np.abs(r2)) else f2)
source.data = dict(x=f_std,y=np.array(d))
base.value = """Base = %d """ % p0
f_std = np.array([1.0, 1.25, 1.6, 2.0, 2.5, 3.2, 4.0, 5.0, 6.3, 8.0 ])
p0 = 7
base = TextInput(value="""Base = xx""")
# Set up plot
source = ColumnDataSource(data=dict(x=[], y=[]))
update_data("offset",0,5)
plot = figure(plot_height=400, plot_width=800, title="prime ratio frequencies",
tools="crosshair,pan,reset,save,wheel_zoom",
x_range=[1.0, 10.0], y_range=[-0.1, 0.2])
plot.circle('x', 'y', source=source, radius=.05)
# Set up widgets
offset = Slider(title="offset", value=5, start=0, end=50, step=1)
offset.on_change('value', update_data)
# Set up layouts and add to document
inputs = row(offset, base)
curdoc().add_root(column(inputs, plot, width=800))
curdoc().title = "Sliders"
\ No newline at end of file
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Dec 22 17:15:45 2020
@author: bruns01
"""
import numpy as np
from bokeh.io import curdoc
from bokeh.layouts import column, row
from bokeh.models import ColumnDataSource, Slider, TextInput,Div
from bokeh.plotting import figure
from primes import primes
# Set up callbacks
def update_data(attrname, old, new):
f_std = np.array([1.0, 1.25, 1.6, 2.0, 2.5, 3.2, 4.0, 5.0, 6.3, 8.0 ])
p0 = primes[new]
# pri = primes[(primes<=10*p0) & (primes>p0)]
pri = primes[(primes<=10*p0)]
d = []
p = []
for fs in f_std:
try:
pr1 = (pri[pri/p0<=fs])[-1] # lower limit prime
f1 = pr1/p0 # lower limit frequency
r1 = (f1-fs)/fs
except:
r1 = 0.5
pr2 = (pri[pri/p0>fs])[0] # upper limit prime
f2 = pr2/p0 # upper limit frequency
r2 = (f2-fs)/fs
r = r1 if (np.abs(r1)<np.abs(r2)) else r2
d.append(r)
p.append((pr1 if (np.abs(r1)<np.abs(r2)) else pr2))
#print( f1 if (np.abs(r1)<np.abs(r2)) else f2)
#print( ("%d/%d" % (pr1,p0)) if (np.abs(r1)<np.abs(r2)) else ("%d/%d" % (pr2,p0)))
source.data = dict(x=f_std,y=np.array(d))
base.value = """Base = %d """ % p0
deviation.text = str(np.amax(np.abs(d))) # display maximum deviation
dd = 100*np.amax(np.abs(np.array(d)))
print("%2.2f %%" % dd)
print(p)
f_std = np.array([1.0, 1.25, 1.6, 2.0, 2.5, 3.2, 4.0, 5.0, 6.3, 8.0 ])
p0 = 7
base = TextInput(value="""Base = xx""")
deviation = Div(text="max")
# Set up plot
source = ColumnDataSource(data=dict(x=[], y=[]))
update_data("offset",0,5)
plot = figure(plot_height=400, plot_width=800, title="prime ratio frequencies",
tools="crosshair,pan,reset,save,wheel_zoom",
x_range=[1.0, 10.0], y_range=[-0.1, 0.2])
plot.circle('x', 'y', source=source, radius=.05)
# Set up widgets
offset = Slider(title="offset", value=5, start=0, end=50, step=1)
offset.on_change('value', update_data)
# Set up layouts and add to document
inputs = row(offset, base, deviation)
curdoc().add_root(column(inputs, plot, width=800))
curdoc().title = "Sliders"
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment