|
239 | 239 | "raw_data = ess_beamline.get_monitor(\"detector\")[0]\n",
|
240 | 240 | "\n",
|
241 | 241 | "# Visualize\n",
|
242 |
| - "raw_data.hist(event_time_offset=300).sum(\"pulse\").plot()" |
| 242 | + "raw_data.hist(event_time_offset=300).squeeze().plot()" |
243 | 243 | ]
|
244 | 244 | },
|
245 | 245 | {
|
|
290 | 290 | " time_of_flight.providers(), params=time_of_flight.default_parameters()\n",
|
291 | 291 | ")\n",
|
292 | 292 | "workflow[time_of_flight.RawData] = raw_data\n",
|
293 |
| - "workflow[time_of_flight.LtotalRange] = (sc.scalar(75.5, unit='m'),\n", |
294 |
| - " sc.scalar(78.0, unit='m'))\n", |
| 293 | + "workflow[time_of_flight.LtotalRange] = (\n", |
| 294 | + " sc.scalar(75.5, unit=\"m\"),\n", |
| 295 | + " sc.scalar(78.0, unit=\"m\"),\n", |
| 296 | + ")\n", |
295 | 297 | "\n",
|
296 | 298 | "workflow.visualize(time_of_flight.TofData)"
|
297 | 299 | ]
|
|
314 | 316 | "outputs": [],
|
315 | 317 | "source": [
|
316 | 318 | "workflow[time_of_flight.SimulationResults] = time_of_flight.simulate_beamline(\n",
|
317 |
| - " choppers=disk_choppers,\n", |
318 |
| - " neutrons=2_000_000\n", |
| 319 | + " choppers=disk_choppers, neutrons=2_000_000\n", |
319 | 320 | ")"
|
320 | 321 | ]
|
321 | 322 | },
|
|
343 | 344 | "outputs": [],
|
344 | 345 | "source": [
|
345 | 346 | "sim = workflow.compute(time_of_flight.SimulationResults)\n",
|
346 |
| - "# Compute time-of-arrival at the detector\n", |
347 |
| - "tarrival = sim.time_of_arrival + ((Ltotal - sim.distance) / sim.speed).to(unit=\"us\")\n", |
348 |
| - "# Compute time-of-flight at the detector\n", |
349 |
| - "tflight = (Ltotal / sim.speed).to(unit=\"us\")\n", |
350 |
| - "\n", |
351 |
| - "events = sc.DataArray(\n", |
352 |
| - " data=sim.weight,\n", |
353 |
| - " coords={\"wavelength\": sim.wavelength, \"toa\": tarrival, \"tof\": tflight},\n", |
354 |
| - ")\n", |
355 |
| - "fig1 = events.hist(wavelength=300, toa=300).plot(norm=\"log\")\n", |
356 |
| - "fig2 = events.hist(tof=300, toa=300).plot(norm=\"log\")\n", |
| 347 | + "\n", |
| 348 | + "\n", |
| 349 | + "def to_event_time_offset(sim):\n", |
| 350 | + " # Compute event_time_offset at the detector\n", |
| 351 | + " eto = (\n", |
| 352 | + " sim.time_of_arrival + ((Ltotal - sim.distance) / sim.speed).to(unit=\"us\")\n", |
| 353 | + " ) % sc.scalar(1e6 / 14.0, unit=\"us\")\n", |
| 354 | + " # Compute time-of-flight at the detector\n", |
| 355 | + " tof = (Ltotal / sim.speed).to(unit=\"us\")\n", |
| 356 | + " return sc.DataArray(\n", |
| 357 | + " data=sim.weight,\n", |
| 358 | + " coords={\"wavelength\": sim.wavelength, \"event_time_offset\": eto, \"tof\": tof},\n", |
| 359 | + " )\n", |
| 360 | + "\n", |
| 361 | + "\n", |
| 362 | + "events = to_event_time_offset(sim)\n", |
| 363 | + "fig1 = events.hist(wavelength=300, event_time_offset=300).plot(norm=\"log\")\n", |
| 364 | + "fig2 = events.hist(tof=300, event_time_offset=300).plot(norm=\"log\")\n", |
357 | 365 | "fig1 + fig2"
|
358 | 366 | ]
|
359 | 367 | },
|
|
374 | 382 | "metadata": {},
|
375 | 383 | "outputs": [],
|
376 | 384 | "source": [
|
377 |
| - "table = workflow.compute(time_of_flight.TimeOfFlightLookupTable)\n", |
| 385 | + "table = workflow.compute(time_of_flight.TimeOfFlightLookupTable).squeeze()\n", |
378 | 386 | "\n",
|
379 | 387 | "# Overlay mean on the figure above\n",
|
380 |
| - "table[\"distance\", 13].plot(ax=fig2.ax, color=\"C1\", ls='-', marker=None)" |
| 388 | + "table[\"distance\", 13].plot(ax=fig2.ax, color=\"C1\", ls=\"-\", marker=None)" |
381 | 389 | ]
|
382 | 390 | },
|
383 | 391 | {
|
|
447 | 455 | "# Define wavelength bin edges\n",
|
448 | 456 | "wavs = sc.linspace(\"wavelength\", 0.8, 4.6, 201, unit=\"angstrom\")\n",
|
449 | 457 | "\n",
|
450 |
| - "wav_wfm.hist(wavelength=wavs).sum(\"pulse\").plot()" |
| 458 | + "histogrammed = wav_wfm.hist(wavelength=wavs).squeeze()\n", |
| 459 | + "histogrammed.plot()" |
451 | 460 | ]
|
452 | 461 | },
|
453 | 462 | {
|
|
473 | 482 | "\n",
|
474 | 483 | "pp.plot(\n",
|
475 | 484 | " {\n",
|
476 |
| - " \"wfm\": wav_wfm.hist(wavelength=wavs).sum(\"pulse\"),\n", |
| 485 | + " \"wfm\": histogrammed,\n", |
477 | 486 | " \"ground_truth\": ground_truth.hist(wavelength=wavs),\n",
|
478 | 487 | " }\n",
|
479 | 488 | ")"
|
|
530 | 539 | "outputs": [],
|
531 | 540 | "source": [
|
532 | 541 | "raw_data = sc.concat(\n",
|
533 |
| - " [ess_beamline.get_monitor(key)[0] for key in monitors.keys()],\n", |
| 542 | + " [ess_beamline.get_monitor(key)[0].squeeze() for key in monitors.keys()],\n", |
534 | 543 | " dim=\"detector_number\",\n",
|
535 | 544 | ")\n",
|
536 | 545 | "\n",
|
537 | 546 | "# Visualize\n",
|
538 |
| - "pp.plot(\n", |
539 |
| - " sc.collapse(\n", |
540 |
| - " raw_data.hist(event_time_offset=300).sum(\"pulse\"), keep=\"event_time_offset\"\n", |
541 |
| - " )\n", |
542 |
| - ")" |
| 547 | + "pp.plot(sc.collapse(raw_data.hist(event_time_offset=300), keep=\"event_time_offset\"))" |
543 | 548 | ]
|
544 | 549 | },
|
545 | 550 | {
|
|
655 | 660 | "source": [
|
656 | 661 | "# Update workflow\n",
|
657 | 662 | "workflow[time_of_flight.SimulationResults] = time_of_flight.simulate_beamline(\n",
|
658 |
| - " choppers=disk_choppers,\n", |
659 |
| - " neutrons=2_000_000\n", |
| 663 | + " choppers=disk_choppers, neutrons=2_000_000\n", |
660 | 664 | ")\n",
|
661 | 665 | "workflow[time_of_flight.RawData] = ess_beamline.get_monitor(\"detector\")[0]\n",
|
662 | 666 | "\n",
|
663 | 667 | "sim = workflow.compute(time_of_flight.SimulationResults)\n",
|
664 |
| - "# Compute time-of-arrival at the detector\n", |
665 |
| - "tarrival = sim.time_of_arrival + ((Ltotal - sim.distance) / sim.speed).to(unit=\"us\")\n", |
666 |
| - "# Compute time-of-flight at the detector\n", |
667 |
| - "tflight = (Ltotal / sim.speed).to(unit=\"us\")\n", |
668 |
| - "\n", |
669 |
| - "events = sc.DataArray(\n", |
670 |
| - " data=sim.weight,\n", |
671 |
| - " coords={\"wavelength\": sim.wavelength, \"toa\": tarrival, \"tof\": tflight},\n", |
672 |
| - ")\n", |
673 |
| - "events.hist(wavelength=300, toa=300).plot(norm=\"log\")" |
| 668 | + "\n", |
| 669 | + "events = to_event_time_offset(sim)\n", |
| 670 | + "events.hist(wavelength=300, event_time_offset=300).plot(norm=\"log\")" |
674 | 671 | ]
|
675 | 672 | },
|
676 | 673 | {
|
|
696 | 693 | "metadata": {},
|
697 | 694 | "outputs": [],
|
698 | 695 | "source": [
|
699 |
| - "table = workflow.compute(time_of_flight.TimeOfFlightLookupTable)\n", |
| 696 | + "table = workflow.compute(time_of_flight.TimeOfFlightLookupTable).squeeze()\n", |
700 | 697 | "table.plot() / (sc.stddevs(table) / sc.values(table)).plot(norm=\"log\")"
|
701 | 698 | ]
|
702 | 699 | },
|
|
720 | 717 | "metadata": {},
|
721 | 718 | "outputs": [],
|
722 | 719 | "source": [
|
723 |
| - "workflow[time_of_flight.LookupTableRelativeErrorThreshold] = 1.0e-2\n", |
| 720 | + "workflow[time_of_flight.LookupTableRelativeErrorThreshold] = 0.01\n", |
724 | 721 | "\n",
|
725 |
| - "workflow.compute(time_of_flight.MaskedTimeOfFlightLookupTable).plot()" |
| 722 | + "workflow.compute(time_of_flight.TimeOfFlightLookupTable).squeeze().plot()" |
726 | 723 | ]
|
727 | 724 | },
|
728 | 725 | {
|
|
757 | 754 | "\n",
|
758 | 755 | "pp.plot(\n",
|
759 | 756 | " {\n",
|
760 |
| - " \"wfm\": wav_wfm.hist(wavelength=wavs).sum(\"pulse\"),\n", |
| 757 | + " \"wfm\": wav_wfm.hist(wavelength=wavs).squeeze(),\n", |
761 | 758 | " \"ground_truth\": ground_truth.hist(wavelength=wavs),\n",
|
762 | 759 | " }\n",
|
763 | 760 | ")"
|
|
0 commit comments