%22%22%22Interactive%20development%20examples%20for%20Py-Fatigue.%22%22%22%0A%0Aimport%20marimo%0A%0A__generated_with%20%3D%20%220.26.0%22%0Aapp%20%3D%20marimo.App(css_file%3D%22..%2Fdocs%2Fstylesheets%2Fcustom.css%22)%0A%0A%0A%40app.cell%0Adef%20imports()%3A%0A%20%20%20%20import%20marimo%20as%20mo%0A%20%20%20%20import%20matplotlib.pyplot%20as%20plt%0A%20%20%20%20import%20numpy%20as%20np%0A%20%20%20%20from%20py_fatigue%20import%20SNCurve%2C%20__version__%0A%20%20%20%20from%20py_fatigue.cycle_count.rainflow%20import%20rainflow%0A%20%20%20%20from%20_examples.charts%20import%20plot_views%0A%0A%20%20%20%20return%20SNCurve%2C%20__version__%2C%20mo%2C%20np%2C%20plot_views%2C%20plt%2C%20rainflow%0A%0A%0A%40app.cell%0Adef%20introduction(__version__%2C%20mo)%3A%0A%20%20%20%20mo.md(f%22%22%22%0A%20%20%20%20%20%20%20%20%23%20Py-Fatigue%20development%20guide%0A%0A%20%20%20%20%20%20%20%20Running%20Py-Fatigue%20%7B__version__%7D.%0A%0A%20%20%20%20%20%20%20%20The%20first%20digit%20groups%20the%20lessons.%20**1x**%20covers%20cycle%20counting%20and%0A%20%20%20%20%20%20%20%20residual%20recovery%2C%20**2x**%20covers%20stress-life%20analysis%2C%20and%20**3x**%20covers%0A%20%20%20%20%20%20%20%20crack%20growth.%20Each%20lesson%20runs%20with%20its%20own%20example%20inputs.%0A%0A%20%20%20%20%20%20%20%20Start%20here%20to%20compare%20rainflow%20methods%20and%20see%20how%20several%20S%E2%80%93N%0A%20%20%20%20%20%20%20%20curves%20can%20share%20one%20figure.%20Run%20each%20lesson%20in%20marimo%20to%20modify%20inputs%0A%20%20%20%20%20%20%20%20and%20inspect%20how%20the%20curves%20change.%0A%20%20%20%20%20%20%20%20%22%22%22)%0A%0A%0A%40app.cell%0Adef%20compare_rainflow(mo%2C%20np%2C%20plot_views%2C%20plt%2C%20rainflow)%3A%0A%20%20%20%20signal%20%3D%20np.array(%0A%20%20%20%20%20%20%20%20%5B%0A%20%20%20%20%20%20%20%20%20%20%20%204%2C%0A%20%20%20%20%20%20%20%20%20%20%20%207%2C%0A%20%20%20%20%20%20%20%20%20%20%20%202%2C%0A%20%20%20%20%20%20%20%20%20%20%20%2010%2C%0A%20%20%20%20%20%20%20%20%20%20%20%205%2C%0A%20%20%20%20%20%20%20%20%20%20%20%209%2C%0A%20%20%20%20%20%20%20%20%20%20%20%203%2C%0A%20%20%20%20%20%20%20%20%20%20%20%204%2C%0A%20%20%20%20%20%20%20%20%20%20%20%202%2C%0A%20%20%20%20%20%20%20%20%20%20%20%2012%2C%0A%20%20%20%20%20%20%20%20%20%20%20%205%2C%0A%20%20%20%20%20%20%20%20%20%20%20%2011%2C%0A%20%20%20%20%20%20%20%20%20%20%20%201%2C%0A%20%20%20%20%20%20%20%20%20%20%20%204%2C%0A%20%20%20%20%20%20%20%20%20%20%20%203%2C%0A%20%20%20%20%20%20%20%20%20%20%20%2010%2C%0A%20%20%20%20%20%20%20%20%20%20%20%206%2C%0A%20%20%20%20%20%20%20%20%20%20%20%2012%2C%0A%20%20%20%20%20%20%20%20%20%20%20%204%2C%0A%20%20%20%20%20%20%20%20%20%20%20%208%2C%0A%20%20%20%20%20%20%20%20%20%20%20%201%2C%0A%20%20%20%20%20%20%20%20%20%20%20%209%2C%0A%20%20%20%20%20%20%20%20%20%20%20%204%2C%0A%20%20%20%20%20%20%20%20%20%20%20%206%2C%0A%20%20%20%20%20%20%20%20%5D%2C%0A%20%20%20%20%20%20%20%20dtype%3Dfloat%2C%0A%20%20%20%20)%0A%20%20%20%20fig%2C%20ax%20%3D%20plt.subplots()%0A%20%20%20%20ax.plot(signal%2C%20color%3D%22%23666666%22%2C%20label%3D%22Stress%20history%22)%0A%20%20%20%20for%20label%2C%20method%2C%20marker%20in%20%5B%0A%20%20%20%20%20%20%20%20(%22ASTM%22%2C%20%22astm%22%2C%20%22o%22)%2C%0A%20%20%20%20%20%20%20%20(%22Four-point%22%2C%20%22fourpoint%22%2C%20%22D%22)%2C%0A%20%20%20%20%5D%3A%0A%20%20%20%20%20%20%20%20_%2C%20residuals%2C%20indices%20%3D%20rainflow(%0A%20%20%20%20%20%20%20%20%20%20%20%20signal%2C%20method%3Dmethod%2C%20extended_output%3DTrue%0A%20%20%20%20%20%20%20%20)%0A%20%20%20%20%20%20%20%20ax.plot(%0A%20%20%20%20%20%20%20%20%20%20%20%20indices%2C%20residuals%2C%20linestyle%3D%22none%22%2C%20marker%3Dmarker%2C%20label%3Dlabel%0A%20%20%20%20%20%20%20%20)%0A%20%20%20%20ax.set(xlabel%3D%22Sample%22%2C%20ylabel%3D%22Stress%22)%0A%20%20%20%20ax.legend()%0A%0A%20%20%20%20mo.vstack(%0A%20%20%20%20%20%20%20%20%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22%23%23%20Compare%20rainflow%20residuals%5Cn%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22The%20markers%20identify%20which%20turning%20points%20each%20algorithm%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22leaves%20in%20the%20residual%20sequence.%22%0A%20%20%20%20%20%20%20%20%20%20%20%20)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20plot_views(fig%2C%20height%3D%22420px%22)%2C%0A%20%20%20%20%20%20%20%20%5D%0A%20%20%20%20)%0A%0A%0A%40app.cell%0Adef%20sn_curves(SNCurve%2C%20mo%2C%20plot_views%2C%20plt)%3A%0A%20%20%20%20curves%20%3D%20%5B%0A%20%20%20%20%20%20%20%20SNCurve(%0A%20%20%20%20%20%20%20%20%20%20%20%20slope%3Dslope%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20intercept%3Dintercept%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20norm%3D%22DNVGL-RP-C203%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20environment%3D%22Free%20corrosion%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20curve%3Dlabel%2C%0A%20%20%20%20%20%20%20%20)%0A%20%20%20%20%20%20%20%20for%20slope%2C%20intercept%2C%20label%20in%20%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20(3%2C%2012.436%2C%20%22B1%22)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20(%5B3%5D%2C%2012.115%2C%20%22C%22)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20(3%2C%20%5B11.533%5D%2C%20%22E%22)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20(%5B3%5D%2C%20%5B10.493%5D%2C%20%22W3-C%22)%2C%0A%20%20%20%20%20%20%20%20%5D%0A%20%20%20%20%5D%0A%20%20%20%20sn_fig%2C%20sn_ax%20%3D%20plt.subplots()%0A%20%20%20%20for%20curve%20in%20curves%3A%0A%20%20%20%20%20%20%20%20curve.plot(fig%3Dsn_fig%2C%20ax%3Dsn_ax)%0A%20%20%20%20%20%20%20%20sn_ax.lines%5B-1%5D.set_label(curve.curve)%0A%20%20%20%20sn_ax.legend()%0A%20%20%20%20mo.vstack(%0A%20%20%20%20%20%20%20%20%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20mo.md(%22%23%23%20S%E2%80%93N%20curves%20in%20free%20corrosion%22)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20plot_views(sn_fig%2C%20height%3D%22420px%22)%2C%0A%20%20%20%20%20%20%20%20%5D%0A%20%20%20%20)%0A%20%20%20%20return%20(curves%2C)%0A%0A%0A%40app.cell%0Adef%20long_case(curves%2C%20np%2C%20plt)%3A%0A%20%20%20%20from%20_examples.synthetic%20import%20(%0A%20%20%20%20%20%20%20%20long_case_view%2C%0A%20%20%20%20%20%20%20%20synthetic_peaks%2C%0A%20%20%20%20%20%20%20%20tensile_waveform%2C%0A%20%20%20%20)%0A%20%20%20%20from%20py_fatigue%20import%20CycleCount%0A%20%20%20%20from%20py_fatigue.damage%20import%20get_pm%0A%0A%20%20%20%20peaks%20%3D%20synthetic_peaks()%0A%20%20%20%20counted%20%3D%20CycleCount.from_timeseries(tensile_waveform(peaks))%0A%20%20%20%20edges%20%3D%20np.histogram_bin_edges(counted.stress_range%2C%20bins%3D60)%0A%20%20%20%20centres%20%3D%20(edges%5B%3A-1%5D%20%2B%20edges%5B1%3A%5D)%20%2F%202%0A%20%20%20%20long_fig%2C%20long_ax%20%3D%20plt.subplots()%0A%20%20%20%20for%20sn%20in%20curves%3A%0A%20%20%20%20%20%20%20%20damage_by_range%2C%20_%20%3D%20np.histogram(%0A%20%20%20%20%20%20%20%20%20%20%20%20counted.stress_range%2C%20bins%3Dedges%2C%20weights%3Dget_pm(counted%2C%20sn)%0A%20%20%20%20%20%20%20%20)%0A%20%20%20%20%20%20%20%20long_ax.plot(centres%2C%20damage_by_range%2C%20label%3Dsn.curve)%0A%20%20%20%20long_ax.set(%0A%20%20%20%20%20%20%20%20xlabel%3D%22Stress%20range%20(MPa)%22%2C%20ylabel%3D%22Miner%20damage%20per%20range%20bin%22%0A%20%20%20%20)%0A%20%20%20%20long_ax.legend()%0A%20%20%20%20long_case_view(%0A%20%20%20%20%20%20%20%20long_fig%2C%0A%20%20%20%20%20%20%20%20f%22Rainflow-count%20**%7Bpeaks.size%3A%2C%7D%20generated%20cycles**.%20Apply%20the%20four%20%22%0A%20%20%20%20%20%20%20%20%22S%E2%80%93N%20curves%20above%20to%20the%20same%20spectrum%20and%20compare%20which%20stress%20%22%0A%20%20%20%20%20%20%20%20%22ranges%20contribute%20the%20most%20Miner%20damage.%22%2C%0A%20%20%20%20)%0A%0A%0Aif%20__name__%20%3D%3D%20%22__main__%22%3A%0A%20%20%20%20app.run()%0A
8f59d3700199a40f074a3be3146304c2