Pump calibration tweaking

Hi - I’ve been enjoying my pioreactor so far, and I’m preparing some turbidostat experiments. I used our balance to calibrate all the pumps, but then I realized post-calibration that the units it expects are grams, not mg. So all volumetric dosing in the UI is essentially 1000-fold too short.

I’m lazy and don’t want to recalibrate them, so I’m trying to make a fix to the profiles in the db.

Can I just SELECT * from calibrations then update the volumes to grams? Is the PWM calibration calculated on the fly, or is the regression stored somewhere? Is that the “duration_”, then?

Hey @chri-s!

mg vs g is something I never thought about! Yea, I’m pretty sure that scaling duration_ is the only thing you need to do, but we need to update it in the right spot.

For now, here’s what you can do to update your calibrations. The calibrations a Pioreactor uses are stored in two places:

  1. the main database (as your SELECT would retrieve), but this is a copy meant for the UI (and later for changing/editing calibrations via the UI).
  2. On the Pioreactor the calibration was run on as a file. This is what you want to edit. Here’s how:

  1. First, SSH into the Pioreactor you want to change the calibration for.
  2. Run pio run pump_calibration display. This lists all the active pump calibrations - find the one you want to edit, and make note of it’s name.
  3. We are going to add a Python script to your machine to make some edits to the calibration¹. Type sudo nano edit_calibration.py, and paste in the following code: edit_calibration.py · GitHub. Edit lines 4 and 10 as you need. Type ctrl-x and y when prompted to save and exit.
  4. Run the script with python3 edit_calibration.py. This will update the data.
  5. Finally, run pio run pump_calibration change_current <name>.
  6. To check it saved correctly, you can run pio run pump_calibration display to see the new data.

Let me know if you encounter any problems, or if a step is unclear!

¹ in typing this out, I wish this was easier…

Thanks - this worked a treat! I appreciate the intro to the architecture too.

I tweaked it to divide by 1000 (duration_ is ml/sec, right?), and it looks like it’s perfect now.

Side bug report, though: running pio run pump_calibration change_current waste-2023-05-12 works, but throws an error (see below). Actually, pio run pump_calibration itself throws the same error, even though it also works as far as setting values.

Thanks again!

Traceback (most recent call last):
  File "/usr/local/bin/pio", line 8, in <module>
    sys.exit(pio())
  File "/usr/local/lib/python3.9/dist-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.9/dist-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.9/dist-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.9/dist-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.9/dist-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.9/dist-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.9/dist-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/usr/local/lib/python3.9/dist-packages/pioreactor/actions/pump_calibration.py", line 597, in click_change_current
    change_current(name)
  File "/usr/local/lib/python3.9/dist-packages/pioreactor/actions/pump_calibration.py", line 524, in change_current
    f"http://{leader_address}/api/calibrations/{get_unit_name()}/{new_calibration.type}/{new_calibration.name}",
  File "/usr/local/lib/python3.9/dist-packages/pioreactor/structs.py", line 182, in type
    return self.__class__.__struct_tag__  # type: ignore
AttributeError: type object 'WastePumpCalibration' has no attribute '__struct_tag__'

Ah, thanks for reporting. I believe this is fixed in the upcoming release (if you need it, pio update app -b develop to get the latest software).

Oh, great. I was going to submit an issue but haven’t gotten around to it. I will give the dev build a try after this run!

I’m not sure if this is related, but doing OD calibration yields a similar issue: saving after fitting a curve throws an error Failed to swap. Aborted! but the calibration appears to be active and correct if I run pio run od_calibration display.

Thanks again!