praiteri commited on
Commit
702ad4b
·
1 Parent(s): 1ccc3b2

repo update from private

Browse files
marimo/bomb_calorimetry.py CHANGED
@@ -1,6 +1,6 @@
1
  import marimo
2
 
3
- __generated_with = "0.11.0"
4
  app = marimo.App(width="medium")
5
 
6
 
@@ -94,11 +94,11 @@ def _(cek, lab, mo, reset_button, run_button, sample_selector):
94
  mo.stop(sample_selector.value is None, mo.md(f"### No sample selected !!"))
95
 
96
  lab.set_parameters(sample=sample_selector.value)
97
- _ = lab.create_data()
98
- fname = lab.write_data_to_file()
 
99
 
100
- with open(fname, "r") as f:
101
- file_content = f.read()
102
  message = f"### Running Experiment\n"
103
  for k,v in lab.metadata.items():
104
  message += f"####{k} = {v}\n"
@@ -111,15 +111,13 @@ def _(cek, lab, mo, reset_button, run_button, sample_selector):
111
  )
112
 
113
  plot = cek.plotting()
114
- data,_,_ = lab.read_data_file(fname)
115
- plot.quick_plot(data,output=fname.replace(".csv",".png"))
116
- image = mo.image(fname.replace(".csv",".png"),width=500)
117
 
118
- mo.vstack([mo.md(message),download_button,image])
119
  return (
120
  data,
121
  download_button,
122
- f,
123
  file_content,
124
  fname,
125
  image,
 
1
  import marimo
2
 
3
+ __generated_with = "0.11.2"
4
  app = marimo.App(width="medium")
5
 
6
 
 
94
  mo.stop(sample_selector.value is None, mo.md(f"### No sample selected !!"))
95
 
96
  lab.set_parameters(sample=sample_selector.value)
97
+ data = lab.create_data()
98
+ print(data)
99
+ file_content = lab.write_data_to_string()
100
 
101
+ fname = lab.filename_gen.random
 
102
  message = f"### Running Experiment\n"
103
  for k,v in lab.metadata.items():
104
  message += f"####{k} = {v}\n"
 
111
  )
112
 
113
  plot = cek.plotting()
114
+ print(data)
115
+ image = plot.quick_plot(scatter=data,output="marimo")
 
116
 
117
+ mo.hstack([mo.vstack([mo.md(message),download_button]),image])
118
  return (
119
  data,
120
  download_button,
 
121
  file_content,
122
  fname,
123
  image,
marimo/crystal_violet.py CHANGED
@@ -1,6 +1,6 @@
1
  import marimo
2
 
3
- __generated_with = "0.11.0"
4
  app = marimo.App(width="medium")
5
 
6
 
@@ -46,21 +46,22 @@ def _(mo):
46
  @app.cell
47
  def _(lab, mo):
48
  def set_ID(value):
49
- try:
50
- student_number = int(value.strip())
51
- if student_number <= 0:
 
 
 
 
 
 
52
  print(mo.md(f"### Invalid Student ID: {student_ID.value}"))
53
- else:
54
- print(f"Valid Student ID: {student_number}")
55
- lab.set_student_ID(int(value))
56
- except ValueError:
57
- mo.stop(not student_ID.value.isdigit(), mo.md(f"### Invalid Student ID: {student_ID.value}"))
58
- print(mo.md(f"### Invalid Student ID: {student_ID.value}"))
59
 
60
  student_ID = mo.ui.text(value="", label="Student ID:",on_change=set_ID)
61
 
62
  def set_fname(value):
63
  lab._set_filename(value)
 
64
  exp_ID = mo.ui.text(value="Automatic", label="Output file:", on_change=set_fname)
65
 
66
  cv_volume = mo.ui.number(start=0,stop=100,step=1,value=None,label="Volume of CV solution (mL)")
@@ -104,7 +105,6 @@ def _(
104
  oh_volume,
105
  reset_button,
106
  run_button,
107
- student_ID,
108
  temperature,
109
  ):
110
  if reset_button.value:
@@ -123,11 +123,10 @@ def _(
123
  volumes={'cv': cv_vol, 'oh': oh_vol, 'h2o': h2o_vol},
124
  temperature=temperature.value+273.15
125
  )
126
- _ = lab.create_data()
127
- fname = lab.write_data_to_file()
128
-
129
- with open(fname, "r") as f:
130
- file_content = f.read()
131
  message = f"### Running Experiment\n"
132
  for k,v in lab.metadata.items():
133
  message += f"####{k} = {v}\n"
@@ -140,16 +139,13 @@ def _(
140
  )
141
 
142
  plot = cek.plotting()
143
- data,_,_ = lab.read_data_file(fname)
144
- plot.quick_plot(data,output=fname.replace(".csv",".png"))
145
- image = mo.image(fname.replace(".csv",".png"),width=500)
146
-
147
- mo.vstack([mo.md(message),download_button,image])
148
  return (
149
  cv_vol,
150
  data,
151
  download_button,
152
- f,
153
  file_content,
154
  fname,
155
  h2o_vol,
 
1
  import marimo
2
 
3
+ __generated_with = "0.11.2"
4
  app = marimo.App(width="medium")
5
 
6
 
 
46
  @app.cell
47
  def _(lab, mo):
48
  def set_ID(value):
49
+ try:
50
+ student_number = int(value.strip())
51
+ if student_number <= 0:
52
+ print(mo.md(f"### Invalid Student ID: {student_ID.value}"))
53
+ else:
54
+ print(f"Valid Student ID: {student_number}")
55
+ lab.set_student_ID(int(value))
56
+ except ValueError:
57
+ mo.stop(not student_ID.value.isdigit(), mo.md(f"### Invalid Student ID: {student_ID.value}"))
58
  print(mo.md(f"### Invalid Student ID: {student_ID.value}"))
 
 
 
 
 
 
59
 
60
  student_ID = mo.ui.text(value="", label="Student ID:",on_change=set_ID)
61
 
62
  def set_fname(value):
63
  lab._set_filename(value)
64
+
65
  exp_ID = mo.ui.text(value="Automatic", label="Output file:", on_change=set_fname)
66
 
67
  cv_volume = mo.ui.number(start=0,stop=100,step=1,value=None,label="Volume of CV solution (mL)")
 
105
  oh_volume,
106
  reset_button,
107
  run_button,
 
108
  temperature,
109
  ):
110
  if reset_button.value:
 
123
  volumes={'cv': cv_vol, 'oh': oh_vol, 'h2o': h2o_vol},
124
  temperature=temperature.value+273.15
125
  )
126
+ data = lab.create_data()
127
+ file_content = lab.write_data_to_string()
128
+
129
+ fname = lab.filename_gen.random
 
130
  message = f"### Running Experiment\n"
131
  for k,v in lab.metadata.items():
132
  message += f"####{k} = {v}\n"
 
139
  )
140
 
141
  plot = cek.plotting()
142
+ image = plot.quick_plot(scatter=data,output="marimo")
143
+
144
+ mo.hstack([mo.vstack([mo.md(message),download_button]),image])
 
 
145
  return (
146
  cv_vol,
147
  data,
148
  download_button,
 
149
  file_content,
150
  fname,
151
  h2o_vol,
marimo/statistics_lab.py CHANGED
@@ -100,11 +100,10 @@ def _(cek, lab, mo, reset_button, run_button, sample_selector):
100
  number_of_values = 12,
101
  sample=sample_selector.value
102
  )
103
- _ = lab.create_data()
104
- fname = lab.write_data_to_file()
105
 
106
- with open(fname, "r") as f:
107
- file_content = f.read()
108
  message = f"### Running Experiment\n"
109
  for k,v in lab.metadata.items():
110
  message += f"####{k} = {v}\n"
@@ -117,11 +116,9 @@ def _(cek, lab, mo, reset_button, run_button, sample_selector):
117
  )
118
 
119
  plot = cek.plotting()
120
- data,_,_ = lab.read_data_file(fname)
121
- plot.quick_plot(data,output=fname.replace(".csv",".png"))
122
- image = mo.image(fname.replace(".csv",".png"),width=500)
123
 
124
- mo.vstack([mo.md(message),download_button,image])
125
  return (
126
  data,
127
  download_button,
 
100
  number_of_values = 12,
101
  sample=sample_selector.value
102
  )
103
+ data = lab.create_data()
104
+ file_content = lab.write_data_to_string()
105
 
106
+ fname = lab.filename_gen.random
 
107
  message = f"### Running Experiment\n"
108
  for k,v in lab.metadata.items():
109
  message += f"####{k} = {v}\n"
 
116
  )
117
 
118
  plot = cek.plotting()
119
+ image = plot.quick_plot(scatter=data,output="marimo")
 
 
120
 
121
+ mo.hstack([mo.vstack([mo.md(message),download_button]),image])
122
  return (
123
  data,
124
  download_button,
marimo/surface_adsorption.py CHANGED
@@ -97,28 +97,25 @@ def _(cek, lab, mo, reset_button, run_button, student_ID, temperature):
97
  lab.set_parameters(
98
  temperature = temperature.value+273.15
99
  )
100
- _ = lab.create_data()
101
- fname = lab.write_data_to_file()
102
-
103
- with open(fname, "r") as f:
104
- file_content = f.read()
105
  message = f"### Running Experiment\n"
106
  for k,v in lab.metadata.items():
107
  message += f"####{k} = {v}\n"
108
  message += f"#### File created = {fname}\n"
109
-
110
  download_button = mo.download(
111
  file_content,
112
  filename=fname,
113
  label=f"Download {fname}",
114
  )
115
-
116
  plot = cek.plotting()
117
- data,_,_ = lab.read_data_file(fname)
118
- plot.quick_plot(data,output=fname.replace(".csv",".png"))
119
- image = mo.image(fname.replace(".csv",".png"),width=500)
120
-
121
- mo.vstack([mo.md(message),download_button,image])
122
  return (
123
  data,
124
  download_button,
 
97
  lab.set_parameters(
98
  temperature = temperature.value+273.15
99
  )
100
+ data = lab.create_data()
101
+ file_content = lab.write_data_to_string()
102
+
103
+ fname = lab.filename_gen.random
 
104
  message = f"### Running Experiment\n"
105
  for k,v in lab.metadata.items():
106
  message += f"####{k} = {v}\n"
107
  message += f"#### File created = {fname}\n"
108
+
109
  download_button = mo.download(
110
  file_content,
111
  filename=fname,
112
  label=f"Download {fname}",
113
  )
114
+
115
  plot = cek.plotting()
116
+ image = plot.quick_plot(scatter=data,output="marimo")
117
+
118
+ mo.hstack([mo.vstack([mo.md(message),download_button]),image])
 
 
119
  return (
120
  data,
121
  download_button,
src/pycek_public/bomb_calorimetry.py CHANGED
@@ -113,5 +113,5 @@ class bomb_calorimetry(cek.cek_labs):
113
  y = self._round_values(y)
114
  self.data = np.column_stack((x,y))
115
 
116
- return
117
 
 
113
  y = self._round_values(y)
114
  self.data = np.column_stack((x,y))
115
 
116
+ return self.data
117
 
src/pycek_public/cek_labs.py CHANGED
@@ -160,37 +160,40 @@ class cek_labs(ABC):
160
  filename = self.output_file
161
  self.add_metadata(output_file=filename)
162
 
 
163
  with open(filename, 'w') as f:
164
- # Write the column names
165
- cols = None
166
- if "columns" in kwargs:
167
- cols = kwargs["columns"]
168
- elif "columns" in self.metadata:
169
- cols = self.metadata["columns" ]
170
- if cols is not None:
171
- f.write(",".join(cols) + "\n")
172
-
173
- # Convert NumPy array to list if needed
174
- # if isinstance(self.data, np.ndarray):
175
- # self.data = self.data.tolist()
176
-
177
- # Write data
178
- for row in self.data:
179
- # Handle multiple columns
180
- if isinstance(row, (list, tuple, np.ndarray)):
181
- line = ",".join(map(str, row))
182
- # Handle single-column case
183
- else:
184
- line = str(row)
185
- f.write(line + "\n")
186
-
187
- # Write the kwargs as metadata
188
- self.write_metadata(filename)
189
 
190
  self.list_of_data_files.append( filename )
191
 
192
  return filename
193
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
194
  def read_data_file(self,filename=None):
195
  if filename is None:
196
  raise ValueError("Filename is missing")
 
160
  filename = self.output_file
161
  self.add_metadata(output_file=filename)
162
 
163
+ string = self.write_data_to_string(**kwargs)
164
  with open(filename, 'w') as f:
165
+ f.write(string)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
166
 
167
  self.list_of_data_files.append( filename )
168
 
169
  return filename
170
 
171
+ def write_data_to_string(self,**kwargs):
172
+ if "columns" in kwargs:
173
+ string = ",".join(kwargs["columns"]) + "\n"
174
+ elif "columns" in self.metadata:
175
+ string = ",".join(self.metadata["columns"]) + "\n"
176
+ else:
177
+ string = ""
178
+
179
+ # Write data
180
+ for row in self.data:
181
+ # Handle multiple columns
182
+ if isinstance(row, (list, tuple, np.ndarray)):
183
+ string += ",".join(map(str, row))+"\n"
184
+ # Handle single-column case
185
+ else:
186
+ string += str(row)+"\n"
187
+
188
+ # Write metadata
189
+ for key, value in self.metadata.items():
190
+ s = f"{key}"
191
+ s = s.replace("_"," ")
192
+ s = s[0].upper() + s[1:] + f" = {value}"
193
+ string += f"# {s}\n"
194
+
195
+ return string
196
+
197
  def read_data_file(self,filename=None):
198
  if filename is None:
199
  raise ValueError("Filename is missing")
src/pycek_public/crystal_violet.py CHANGED
@@ -72,5 +72,5 @@ class crystal_violet(cek.cek_labs):
72
  background = self.background,
73
  )
74
 
75
- return
76
 
 
72
  background = self.background,
73
  )
74
 
75
+ return self.data
76
 
src/pycek_public/plotting.py CHANGED
@@ -56,6 +56,8 @@ class plotting():
56
  # Show the plot
57
  if output is None:
58
  plt.show()
 
 
59
  else:
60
  plt.savefig(output)
61
  plt.close()
 
56
  # Show the plot
57
  if output is None:
58
  plt.show()
59
+ elif output == "marimo":
60
+ return plt.gcf()
61
  else:
62
  plt.savefig(output)
63
  plt.close()