Skip to content

Commit

Permalink
Merge pull request #92 from DanOlds/even-more-other-dan-things
Browse files Browse the repository at this point in the history
smaller image mode for binder
  • Loading branch information
danielballan authored Jun 5, 2020
2 parents f29e093 + f2f2bb3 commit 658a50b
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 61 deletions.
66 changes: 23 additions & 43 deletions Powder Diffraction/Exposures and Dark Frames.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
"from bluesky.plans import count\n",
"\n",
"%matplotlib inline\n",
"\n",
"#if you'd prefer interactive plots, comment out the above line, and uncomment below\n",
"#%matplotlib widget\n"
]
Expand Down Expand Up @@ -109,6 +110,16 @@
"%run -i utils.py"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"plt.figure()\n",
"plt.plot(q,perfect_int1)"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -364,7 +375,7 @@
"this_intensity = process_data(uids)\n",
"\n",
"plt.figure()\n",
"plt.plot(q,intensity, label=\"'hand-measured' data\")\n",
"plt.plot(q, intensity, label=\"'hand-measured' data\")\n",
"plt.plot(q, this_intensity, label=\"plan-generated data\")\n",
"\n",
"plt.legend()\n",
Expand Down Expand Up @@ -451,12 +462,12 @@
"source": [
"plt.figure()\n",
"ax1=plt.subplot(211)\n",
"plt.plot(process_data(uids))\n",
"plt.plot(q, process_data(uids))\n",
"plt.ylabel('I(Q)');\n",
"\n",
"plt.subplot(212,sharex = ax1)\n",
"plt.plot(process_data(uids,return_light=True),color='b', label='light')\n",
"plt.plot(process_data(uids,return_dark=True),color='k', label='dark')\n",
"plt.plot(q, process_data(uids,return_light=True),color='b', label='light')\n",
"plt.plot(q, process_data(uids,return_dark=True),color='k', label='dark')\n",
"plt.legend(loc=0)\n",
"\n",
"plt.xlabel('Q ($\\AA^{-1}$)');\n",
Expand Down Expand Up @@ -489,12 +500,12 @@
"source": [
"plt.figure()\n",
"ax1=plt.subplot(211)\n",
"plt.plot(process_data(uids))\n",
"plt.plot(q, process_data(uids))\n",
"plt.ylabel('I(Q)');\n",
"\n",
"plt.subplot(212,sharex = ax1)\n",
"plt.plot(process_data(uids,return_light=True),color='b', label='light')\n",
"plt.plot(process_data(uids,return_dark=True),color='k', label='dark')\n",
"plt.plot(q,process_data(uids,return_light=True),color='b', label='light')\n",
"plt.plot(q, process_data(uids,return_dark=True),color='k', label='dark')\n",
"plt.legend(loc=0)\n",
"\n",
"plt.xlabel('Q ($\\AA^{-1}$)');\n",
Expand All @@ -516,20 +527,8 @@
"metadata": {},
"outputs": [],
"source": [
"hard_mode()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#change to noisy detector\n",
"_history['decay_a'] = 50\n",
"_history['noise'] = 1000\n",
"_history['action_time'] = 1.0 # 1.0\n",
"_history['panel_wl'] = 500 # 8000"
"hard_mode()\n",
" "
]
},
{
Expand Down Expand Up @@ -634,15 +633,6 @@
"While the noise-level seems slightly reduced, you may notice the disturbing trend that the background on our average data is starting to rise. Let's plot all 10 of these datasets atop each other to see if we can determine why. You may want to turn on interactive plotting at this point to zoom in on the data."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%matplotlib widget"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -657,16 +647,6 @@
"plt.ylabel('I(Q)');"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#turning interactive plots off.\n",
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -739,9 +719,9 @@
"outputs": [],
"source": [
"plt.figure()\n",
"plt.plot(perfect_int1, label='ideal')\n",
"plt.plot(new_int_list.mean(axis=1),label='new data')\n",
"plt.plot(new_int_list.mean(axis=1) - perfect_int1, label='diff')\n",
"plt.plot(q, perfect_int1, label='ideal')\n",
"plt.plot(q, new_int_list.mean(axis=1),label='new data')\n",
"plt.plot(q, new_int_list.mean(axis=1) - perfect_int1, label='diff')\n",
"\n",
"plt.legend()\n",
"\n",
Expand Down
3 changes: 1 addition & 2 deletions Powder Diffraction/generate_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@


def make_random_peaks(
x, xmin=None, xmax=None, peak_chance=0.1, return_pristine_peaks=False
):
x, xmin=None, xmax=None, peak_chance=0.1, return_pristine_peaks=False):

# select boundaries for peaks
if xmin is None:
Expand Down
28 changes: 20 additions & 8 deletions Powder Diffraction/simulated_hardware.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,33 @@

from generate_data import make_random_peaks, generate_flat_field, generate_image

LIMIT = 1_000_000
LIMIT = 9999.0

big_image_mode = False #use only if running on something that isn't binder machine (otherwise slow)

_time = {"state": 0.0}

_history = {"sample": [], "light": [], "image": []}

_history['decay_a'] = 1000
_history['panel_amp'] = 50
_history['panel_oset'] = 10
_history['panel_wid'] = 128 #32
_history['panel_wid'] = 32
_history['noise'] = 50
_history["panel_wl"] = 80000 #8000
_history["panel_wl"] = 80000
_history["panel_wl_hard"] = 100
_history['action_time'] = 0.5
_history['perfect_data'] = False
_history['integration_bins'] = 101
SHAPE = (128,128)


if big_image_mode:
SHAPE = (512, 512)
_history['panel_wid'] = 128
_history['integration_bins'] = 301
_history['panel_wl_hard'] = 400

def sim_sleep(t):
print (f"sleeping for {t}")
time_travel(current_time()+t)
Expand Down Expand Up @@ -70,16 +81,17 @@ def put(self, value):
sample_selector = SampleSelector(name="sample_selector", value=0)


# Map samples to patterns.
SHAPE = (512, 512)
#SHAPE = (128, 128)
patterns = {}
x = numpy.linspace(0, 30, num=301)
x = numpy.linspace(0, 30, num=_history['integration_bins'])
intensities = {}


for i in range(1, 5):
intensity = make_random_peaks(x) * 1000.0
if big_image_mode:
intensity = make_random_peaks(x, peak_chance=0.1) * 1000.0
else:
intensity = make_random_peaks(x, peak_chance=0.2) * 1000.0

image = generate_image(x, intensity, SHAPE)
intensities[i] = intensity
patterns[i] = image
Expand Down
16 changes: 8 additions & 8 deletions Powder Diffraction/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import numpy as np
from simulated_hardware import current_time

def simple_integration(image, num_bins=301):
def simple_integration(image, num_bins=_history['integration_bins']):
sx, sy = image.shape
x_, y_ = np.mgrid[-sx // 2 : sx // 2, -sy // 2 : sy // 2]
r = np.hypot(x_, y_)
Expand Down Expand Up @@ -47,7 +47,7 @@ def process_data(pair, num_lights = 1, return_light = False, return_dark = False
my_dark = catalog[pair[0]].primary.read().detector_image[0]

if return_dark:
return simple_integration(my_dark, num_bins=301)
return simple_integration(my_dark)

dark_subbed_list = []

Expand All @@ -60,12 +60,12 @@ def process_data(pair, num_lights = 1, return_light = False, return_dark = False
dark_subbed_list.append(this_light - my_dark)

if num_lights == 1:
return simple_integration(dark_subbed_list[0],num_bins=301)
return simple_integration(dark_subbed_list[0])

else: # more than one
int_list = []
for j in range(len(dark_subbed_list)):
int_list.append(simple_integration(dark_subbed_list[j],num_bins=301))
int_list.append(simple_integration(dark_subbed_list[j]))

return np.array(int_list).T

Expand All @@ -76,7 +76,7 @@ def make_ideal_data(sample_num):

this_light = catalog[perfect_pair[1]].primary.read().detector_image[0]

perfect_int = simple_integration(this_light,num_bins=301)
perfect_int = simple_integration(this_light)

_history['perfect_data'] = False

Expand All @@ -94,7 +94,7 @@ def retrieve_im(num):
perfect_int4 = make_ideal_data(4)
history_reset()

q = np.linspace(.1,25, 301)
q = np.linspace(.1,25, _history['integration_bins'])

d = 2.0*np.pi/q

Expand All @@ -103,5 +103,5 @@ def hard_mode():
history_reset()
_history['decay_a'] = 50
_history['noise'] = 1000
#_history['action_time'] = .50 # 1.0
_history['panel_wl'] = 400 # 8000
_history['panel_wl'] = _history['panel_wl_hard']

0 comments on commit 658a50b

Please sign in to comment.