Spaces:
Running
Running
File size: 3,658 Bytes
843a502 1ffa54d 843a502 bb7886f 1ffa54d 843a502 aa4aab0 843a502 1ffa54d 843a502 1ffa54d 843a502 1ffa54d 843a502 1ffa54d 843a502 1ffa54d 843a502 1ffa54d 843a502 1ffa54d 843a502 1ffa54d fbe4618 702ad4b 843a502 1ffa54d 6935076 1ffa54d 843a502 1ffa54d 843a502 1ffa54d 843a502 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 | import marimo
__generated_with = "0.11.9"
app = marimo.App(width="medium")
@app.cell
def _():
import marimo as mo
import pycek_public as cek
lab = cek.stats_lab(make_plots=True)
return cek, lab, mo
@app.cell
def _(mo):
mo.md(
"""
# Statistics lab
This numerical lab consists a few small tasks, which cover the key statistics topics that were introduced in the previous chapter.
They are also preparatory for the following labs, where you would have to use the same concepts in more complicated situations.
In particular, if you are using python, it would be beneficial to solve some of this exercises by creating specific functions that can the be reused (maybe with small modifications) in the following labs.
## Tasks
1. Average and standard error
2. Propagation of uncertainty
3. Comparison of averages
4. Linear Fit
5. Non linear fit
6. Outlier detection
## Instructions
1. Type your student ID
2. Select a task
3. Click "Run Experiment"
4. Analysed the data
___
"""
)
return
@app.cell
def _(cek, lab, mo):
def set_ID(value):
return cek.set_ID(mo, lab, value)
student_ID = mo.ui.text(value="", label="Student ID:", on_change=set_ID)
def set_fname(value):
lab.output_file = value
exp_ID = mo.ui.text(value="Automatic", label="Output file:", on_change=set_fname)
sample_selector = mo.ui.dropdown(
options=lab.available_samples, value=None, label="Select task:"
)
run_button = mo.ui.run_button(label="Run Experiment")
reset_button = mo.ui.run_button(label="Reset Counter")
# Create download button using marimo's download function
mo.vstack([student_ID, exp_ID, sample_selector, run_button, reset_button])
return (
exp_ID,
reset_button,
run_button,
sample_selector,
set_ID,
set_fname,
student_ID,
)
@app.cell
def _(cek, lab, mo, reset_button, run_button, sample_selector, student_ID):
if reset_button.value:
lab.ID = 0
lab.output_file = None
image = ""
message = ""
download_button = ""
data = None
file_content = None
fname = None
plot = None
# print(run_button.value)
if run_button.value:
mo.stop(
not student_ID.value.isdigit(),
mo.md(f"### Invalid Student ID: {student_ID.value}"),
)
mo.stop(sample_selector.value is None, mo.md("### No sample selected !!"))
lab.set_parameters(number_of_values=12, sample=sample_selector.value)
data = lab.create_data_for_lab()
file_content = lab.write_data_to_string()
fname = lab.output_file
if not fname:
fname = lab.filename_gen.random
if not fname.endswith('.csv'):
fname += '.csv'
message = "### Running Experiment\n"
for k, v in lab.metadata.items():
message += f"####{k} = {v}\n"
message += f"#### File created = {fname}\n"
download_button = mo.download(
file_content,
filename=fname,
label=f"Download {fname}",
)
plot = cek.plotting()
image = plot.quick_plot(scatter=data, output="marimo")
mo.hstack([mo.vstack([mo.md(message), download_button]), image])
return (
data,
download_button,
file_content,
fname,
image,
k,
message,
plot,
v,
)
@app.cell
def _():
return
if __name__ == "__main__":
app.run()
|