Public Lab Research note


Fat percent in milk

by wagnerc4 | February 05, 2014 19:37 05 Feb 19:37 | #10012 | #10012

I work in a litter industry that process milk cow, here the fat percent is measured with: Gerber method. Some industries have a instrument that measures some parameters of the milk, but is too expensive... I think this instrument is some kind of spectrometer. So I try to measure the fat percent, with the publiclab spectrometer.

Materials: - spectrometer - lamp 30 watts - tube and carton

DSC00567.JPG

DSC00568.JPG

In the spectrum I only evaluate blue.

To analyse the spectrum I use debian testing, and install these packages:

apt-get install mplayer python-imaging python-matplotlib

Script milk_fat.py:

#! /usr/bin/env python
"""
Author: Wagner Corrales M.
"""

from bisect import bisect
from subprocess import call
from Image import open
from matplotlib.pyplot import plot, show

values = {96.00: 4.0,
          96.70: 3.9,
          97.30: 3.8,
          97.90: 3.7,
          98.40: 3.6,
          98.80: 3.5,
          99.15: 3.4,
          99.50: 3.3,
          99.80: 3.2,
          100.10: 3.1,
          100.40: 3.0,
          100.70: 2.9,
          100.95: 2.8,
          101.15: 2.7,
          101.35: 2.6,
          101.50: 2.5,
          101.65: 2.4,
          101.75: 2.3,
          101.85: 2.2,
          101.90: 2.0,
          101.95: 1.9,
          102.00: 1.8}
v_keys = sorted(values.keys())
v_values = [values[k] for k in v_keys]

def info(spectrum):
  s0, s1 = 0, 0
  for s in spectrum[5:355]:
    s0 = s0 + s
  for s in spectrum[355:635]:
    s1 = s1 + s
  key = ((s1/280.0)*100)/((s0+s1)/630.0)
  index = bisect(v_keys, key)
  print key, v_values[index]

call("mplayer tv:// -tv device=/dev/video1:width=640:height=480:outfmt=rgb24 -frames 5 -vo png", shell=True)

pix = open('00000005.png').load()
r = [pix[i, 240][0] for i in range(640)]
g = [pix[i, 240][1] for i in range(640)]
b = [pix[i, 240][2] for i in range(640)]
plot(r, "r")
plot(g, "g")
plot(b, "b")
show()

info(b)

The script need execution permissions: chmod a+x milk_fat.py

Then execute the script: ./milk_fat.py

Examples:

fat3.5.png

fat2.7.png

These result perfect!!!


I did this Help out by offering feedback! Browse other activities for "spectrometry"


People who did this (0)

None yet. Be the first to post one!


10 Comments

Hello - very interesting project! Were you able to distinguish different percents of milkfat? What do the two graphs you used represent?

You can post code by putting four spaces before each line, or by putting code inside of these marks. Er, the marks are these: `

If you like, I am an admin and can help you do it, just ask.

Is this a question? Click here to post it to the Questions page.

Reply to this comment...


Hi! the first graph is from milk with fat 3.5% and the second with fat 2.7%. I compare many samples and at the frequency 355 to 640, I see the behavior that I expected. The function info is the way I measure the changes from each sample.

Reply to this comment...


Wow, that's great. Did you use SpectralWorkbench to collect your data about the different samples you used to build your model? It'd be great to see all of them graphed together in a set.

Could we try to create a macro for SpectralWorkbench for this, so people could run it on their phones? I imagine it's quite dependent on calibrating the intensity of the light source, no?

Is this a question? Click here to post it to the Questions page.

Reply to this comment...


Yes, it is important to have the same light intensity in all the samples. But to have a exact intensity is hard, that is the reason that I only evaluate the blue because its behavior at light intensity.

Reply to this comment...


I didn't use SpectralWorkbench. I try to install in my computer and I have many troubles. Did you consider to write the SpectralWorkbench in Python? Python is perfect for educational purposes and I think this facilitate to contribute in code especially to this project.

Is this a question? Click here to post it to the Questions page.

Reply to this comment...


Where did you try to install it from? SpectralWorkbench.org has been a purely web-based program that does not require installation for a couple years now. If there is a link somewhere telling you to download software and run it, we need to fix that information! Thank you for mentioning it!

Is this a question? Click here to post it to the Questions page.

Reply to this comment...


Where can I download the source code of this SpectralWorkbench purely web-based program???

Is this a question? Click here to post it to the Questions page.

Reply to this comment...


The program runs in the browser, such as Chrome, Firefox, or Opera: https://spectralworkbench.org

In the footer of every page is a link to the source code, but you do not need to download it to use it. You are of course welcome to download the source if you are interested in contributing to it! That would be great.

https://github.com/jywarren/spectral-workbench/

Reply to this comment...


In the commercial spectrometer measuring milk fat%, the range is mostly between 600-1100nm. Could you correlate the peaks with the actual fat% in this (355-640nm) range? I am starting working on this project : Milk fat% determination with a diy spectrometer in the range 600-1100. I am using fridge lamp (15w) as a source. But its gets really heated up. Also thinking on other sources such as multiple LEDs to make the whole spectra.

Is this a question? Click here to post it to the Questions page.

Reply to this comment...


I see the test tube, test tube holder, and bit of cardboard -- straightforward! Was there any preparation you did to the milk itself before / during scanning?

Is this a question? Click here to post it to the Questions page.

Reply to this comment...


Login to comment.