Choose Language Hide Translation Bar

In My Defense, I Was Left Unsupervised: Hacking an Aquarium with JMP and the Stuff in my Junk Drawer (2021-US-45MP-884)

Level: Intermediate

 

Mike Anderson, SAS Institute, SAS Institute

 

What do a handful of Legos, a webcam, two razor blades, a DVD-R, and some double-stick tape have in common? Well, if you happen to have an interest in aquaculture and a background in chemistry, they have the makings of a decent spectrometer. If you throw JMP into the mix, then you have the makings of a system that can be used to detect the presence of harmful waste byproducts in a fish tank with startling accuracy. Join Mike Anderson on his adventure in setting up and “cycling” a new 36-gallon fish tank using a homemade spectrometer and JMP Pro’s Functional Data Explorer to monitor the process.

 

 

Auto-generated transcript...

 


Speaker

Transcript

Mike Anderson Hi everybody!
  I have a bit of a confession to make. I was, during the early part of the pandemic, having some trouble filling the hours, shall we say, and so I took the hobby of setting up aquariums and learning how to do that.
  It was a lot of fun. I got a chance to hang out with my daughter more. We went to the fish store and picked out some pretty fish.
  But, first, I had to set up a safe environment for my fish. And what I want to spend today talking about is answering, really, this question, "why did my fish just die?"
  And this goes back to the this age old thing that we have when we we go to the pet store, we buy this nice little aquarium,
  And we put the gravel in, we put the water in, you know, maybe we'll put a few chemicals in, we set up the filter, we set up the bubbler, and we dump a couple of goldfish in there and hope for the best.
  And, all is well for about three or four days, and then you wake up one morning to tear-filled eyes in your kid, to their tear-filled eyes, and you know your kids are crying and the
  The fish died. And then the question you're sitting back asking is, "why?"" You know that the tanks clean. We didn't feed 'em too much, we did everything we're supposed to do. Well,
  It turns out that, in many ways the problem, probably was fish poop.
  And, you know, not to get overly scatological, today we're going to talk about waste management. In a lot of respects, that's really what we're talking about today.
  And how do we manage the fact that when you feed a fish, you know it comes out the other end. I mean that's all it can do. And, it turns out that, if you leave that stuff in the tank too long, it will kill your fish.
  Well, in many cases, these fish are coming from nature so nature is really the best,the best teacher when it comes to this situation.
  So, how does nature deal with the fish poop? I mean, think about these ponds and things that
  are, in many ways are locked. They don't really have a strong inflow and outflow. They're fairly static. So, how do they deal with the fact that they're are fish in there all the time, eating and going to the bathroom...
  Well, they have... There's a cycle in the in the aquarium ... in the in the aquatic world called "The Nitrogen Cycle" and that's what we're going to try and mimic in the aquarium.
  The nitrogen cycle is fairly simple to understand. The fish eat the food,
  and they...
  process it.
  And, that processed food turns into, or starts giving off, ammonia.
  And the ammonia,
  in nature,
  is eaten by a little bacterial species that lives in the water, and lives in the ground - on the rocks, and all that stuff on the bottom of the... in the mud on the bottom of the of the
  Body water, wherever it is. And that bug converts the ammonia into a species called nitrite.
  Well, it turns out that nitrite is actually more toxic than ammonia. So, that's a problem, in and of itself. When we're doing this in the aquarium world, if the ammonia doesn't get you the nitrite will.
  So, you're kind of in a lot of trouble in these first two steps. So, in nature,
  Then there's another species of bacteria that takes the nitrite, and converts it nitrate. And, that one letter change makes something very dangerous into something very, very safe.
  And it turns out you're actually just tacking on an extra oxygen to it in the process. That's all you're really doing.
  But, once you get it to that nitrate stage, the plants in the in the aquatic environment can use that nitrate as food. They can use it as fertilizer.
  That, in turn, provides food for the fish, or other creatures or the algae eat it. All those things. What doesn't get consumed by those... by the aquatic environment.
  That nitrate gets flushed out through the, you know, whatever outlet the body water may have.
  So, nature's got a great way of setting this up - of dealing, particularly with these two primary, and particularly deadly, species of nitrogen compounds that can sit in the water column, all because fish poop.
  Then the question becomes, how do we deal with this in an aquarium?
  We have to essentially mimic nature in an aquarium.
  Well, if you go on the Internet. If you look online, at all the discussion forums, or read books or things like that, or go down and talk to your local aquarian store, they'll talk about something called a bio filter. Or, they'll talk about something called cycling your tank.
  And, the bio filter is populating the aquarium with these two species of bacteria.
  And, once you've got them, they very quickly can cycle the ammonia into nitrate. And then, if you're so inclined, you put plants in your aquarium and that takes care of the nitrate or the nitrates, or you do water changes or both. That's what I end up doing to deal with a nitrate.
  - Which is not nearly as toxic. But, you still need to keep it down, because eventually we'll get to a point where it's toxic. But, you've got a lot more time than you do with the other two species.
  But, we have a bit of a problem. Because, in order to get this whole process started - of establishing the bio filter - we need a source of ammonia and the source of ammonia nature is fish poop.
  So, to have fish poop, you need to have fish. They don't just sell fish manure on the on the shelf for you to do this.
  So, the question becomes, "How do we deal with that?"
  Well, we actually remove the fish from the equation entirely. Because, it doesn't matter what the ammonia source is.
  And, it turns out, we've got an incredibly clean, and cheap, and easy to work with source of ammonia in the form of ammonium chloride.
  And, in fact, aquarists have little buckets of this stuff. -Little jars in this stuff. - The ones that are serious about doing this - to do this process without fish. It's called a "No Fish Cycling."
  And what we do is we substitute low doses of ammonium chloride,
  into the water to feed the bio filter as it's becoming established. And, once we've got it to the point where we can add ammonium chloride...
  And 24 hours later there's no ammonia registered in the system, we know our tank is cycled. Which means the nitrogen cycle is established within the tank and we can safely add fish.
  So this is the entire process. You can look at that, on your own time, if you'd like. But, for the for the sake of what we're doing, the parts that we can monitor, or that we need to monitor, - that we need to keep an eye on are the these three steps that have colored.
  The first one is the one we're going to focus on today. Because this ammonium chloride step is kind of a fun one to watch.
  The other the others just kind of happen on their own, but notice that it takes almost a month to establish this bio filter.
  But what we do is we add low doses ammonia as food to the bio filter. The first species of bacteria grow and multiply and become happy.
  And they start turning things into the nitrite. The nitrate species pick that up and start growing multiplying and get happy, and so forth. And, in each step of this we can monitor that process. And, once you're done with that you just change out 50% of the water and add fish.
  This is what that process looks like if we were to do it with a fish. We're not proposing that we do this. But, this is what you would see with the fish. You'd start out in the tank with zero ammonia,
  And a fish, and you feed the fish. The fish would convert the food into stuff that makes ammonia. The ammonia levels would climb, and climb, and climb, and climb.
  And there's a very good chance the fish would die somewhere along this way and but eventually the ammonia levels would start coming down.
  And then the nitrite levels would start climbing more dramatically. Eventually, those would start coming down and that's when the nitrates would start picking up.
  This is what we want to mimic without any fish involved.
  Okay. So, how do we monitor that? Well, traditionally, if you go down to the fish store they'll sell you this test kit that uses colorimetric indicators. They're little chemical reagents that you add, and they turn colors.
  - A range of colors depending on the amount of whatever is your testing. They'll, turn in this case, greens, based on the amount of ammonia in the system. Purples for nitrite. And reds to yellows and oranges are for nitrates.
  The thing is that your eye can get really fooled. Particularly down in this low area - samples D, E, and F.
  Your eye can get really easily fooled as to when there's a low concentration of ammonia or no ammonia.
  And you really want to know when "no ammonia" is. So, me being a chemist, and having a lot of time on my hands during the pandemic, decided that i'm gonna see if there's a better way to do that.
  And it turns out that spectroscopy is the way to do that. I remember back from my Gen-Chem days when we talked about this thing called, Beer's Law and we'll talk about it more in a minute.
  But, let me introduce you to what spectroscopy is really quick, for for those in the audience may not know what we're talking about.
  Spectroscopy is basically using light to gather information about a sample.
  And what a spectrometer is, if you boil it down to its simplest components, and there are incredibly complex spectrometers. But, when you boil them down to just what they are, they are a light source,
  that you then pass through a sample. And, as the light passes through the sample it picks up information about what's in the sample.
  And then we pass that light through some slits. And, the purpose of that is just to create a nice clean line of light. So, you want your light to be very thin very thin very tall beam, so you have these nice lines.
  And we pass through a couple of collimators. In the case of my spectrometer, it turns out that my light source was so bright, relative to the spectrometer, that part of what I was doing here was also bleeding off extra light.
  I had too much light, so I had to really kind of bleed off intensity as I was, as I was working through this. So, I kind of detuned my spectrometer and a couple of cases. Which was surprisingly not something I was expecting to do.
  But after we get through the two slits then we come to this thing called the diffraction grating. This is what we use in modern times. We use these diffraction gratings and they're they're basically films that have lines of a very particular spacing carved into them,
  Either through lithography or through a pressing process. And the old days they used to use prisms. So, you can do this if you have a prism, too. But the point of either a prism or the diffraction greeting is to break the light up into its component wavelengths.
  which are then passed.
  To the detector in my case it's a webcam.
  Yeah, it's a webcam.
  So this is a couple of examples of, on the left side, of very, very simple spectrometer. We have a prism and we have a single slit and we have a light source.
  And if we look at the middle image, on this side, we can see - this is an incandescent light,
  As it passes through the slit, we can see that it breaks up into all the component wavelengths, this is a black body spectrum. It's got all of the wavelengths of light in the rainbow that we have.
  And if we look at something like a CFL bulb, at the bottom of this, we can see that there are distinct signatures, and those are the emission lines of the mercury, or whatever, whatever gas is being used to create the fluorescence in the bulb.
  But that's the thing that we're doing. We're doing the same thing with the spectrometers. We are going to separate out - we're going to pass light through a sample,
  and separate out the component wavelengths of the sample so we can see what is going on in the sample by looking at the light.
  This is a fancier one on the left, or on the right here, we have a nice halogen light source.
  Really nice and bright. And it's bouncing light from one point to another to another. This is actually the diffraction grading. This is a optical quality diffraction grading.
  And that, in turn, is bounced off this, which is sent over to a detector. It's a double bounce system. So like I said, they get very, very complex.
  Mine was less so.
  I had legos. I had some razor blades. I had a DVD-R that I had kicking around that I could pry apart to get the diffraction greeting out of it. And I had an old busted webcam that I could use. So, that's what I went with.
  This is what it looks like. The point here though is it has all the same component parts. I have a sample cell. I was even able to get a cheap little cuvette.
  You can't see the the the optical slits because I took them out. So you can see the rest of the system. This is the diffraction grating.
  DVD-R or you can get these really cheap off Amazon, too. They're like a 99 cents for 12 of them or something. And then the cheap webcam out the back.
  And that webcam can then be plugged into something like ImageJ or can be plugged into something that can help you gather the spectra and integrate it, so that we can use it JMP, work with it in JMP.
  Which is what we get here. On the bottom is the example of a spectrum for a blank. On the top, we can see the spectrum for the red, green, and blue channels. And we can see the average channel for this sample as well.
  So it works now let's go over to JMP. Enough PowerPoint!
  I mentioned earlier, we talked about this idea of Beer's Law. And, Beer's Law basically says that, for a given series of concentrations, if you have a... and, if we call those concentrations, "c."
  They will be proportional to an observed absorbence, "A".
  And the proportionality is based on the path length, so, the amount of material that the light has to pass through. For a cuvette that it's about us is usually a centimeter so. And then a constant of proportionality, "Eta."
  So that's basically a straight line. And when I took my serial dilutions data that you saw earlier - Those cuvettes that had that we're going from green to yellow,
  And, looked at the concentrations, which were known, and looked at the absorbence of those, that they fell on a nice straight line. Which is something we love to see when something like this happens. And, more importantly, when we look at that nice straight line it follows the same formula that we would expect to see.
  There's my concentration. That's my constant of proportionality. And this number might as well be zero. If we look at the confidence interval,in fact can't say it's not zero for the 95% confidence interval. So, it follows Beer's Law really nicely.
  Which is great, but it required me to do a lot of processing. Every spectra, I had to go in and extract the maximum absorbence. I had to go and do some cleanup of the data. It was just a mess, and to quite a long time to do each one of those.
  So the question becomes, how can I do that when i've got 36, 37, 40 different spectrum to deal with?
  Well, I can do it with functional data analysis fairly easily.
  Now let's talk briefly about the data set that i'm working with here.
  Here's my calibration set and we can see that, as my concentration increases through this data set,
  We see the intensity of the of the green region of the spectrum, which is all i've got displayed right now, go up. So, the colors go from a dark red all the way up to a bright light yellow color. So, we see an increase in intensity with concentration. That's Beer's Law at work right there.
  Now.
  The question that I had to answer when I was getting started with this is which of the channels... Do I use an average absorbence for the whole spectra?
  Or do I choose one of those three channels to work with?
  And if we look at the spectrum in total, we can see that there's a lot of yellow a lot of bright saturated colors in the blue region of the spectrum, which is the the stuff on the side, right here and in the red region of the spectrum over here.
  That tends to indicate that those regions are quickly becoming saturated. They don't have the upper end dynamic range that I need...
  ...to be able to make sure i've got a nice linear response across the range of my detector.
  So, what I ended up doing was focusing just in on the green region of the spectrum. Which, you'll notice, it's got some highs and some lows and some stuff in the middle. It's got a nice wide dynamic range and it's using all of the dynamic range of the detector. And by "detector" I mean "webcam."
  Another way to look at that - right here, Let's have a look at those spectra. So, this is the blank This is with nothing in it.
  And, if we add a little bit of ammonia, a tiny bit of ammonia, we see that the red jumps right up. We don't want that. We want it to jump up very, very incrementally. Wery, very slowly.
  And we can see that, more correctly, that's what happens when we use the green region of the spectrum right in here.
  And we can see that, particularly between the 2 ppm and the 3 ppm sample the red saturates out at 2ppm, and the green saturates out at 3 ppm.
  Which is important. That's a big difference. That's a lot of additional ammonia that you would add in. And being able to detect that difference is important, because that establishes the trajectory early on.
  Now, how do we deal with that, and how do we deal with this in in Functional Data Explorer? Well, we got the curves. That makes sense. FDE is a great tool for working with curves.
  But how do we extract concentrations for unknowns when we're working with a calibration curve like that?
  Well, the secret comes in, that... Well, first of all, we set up everything like we would expect.
  Our traces for our different samples go into Y, the wavelength goes into X, the sample ID goes into the ID function.
  And what we're going to do is, we're going to give the concentrations from the calibration set, from that Beer's Law calibration line that we created. We're going to put those into the concentration. That's the magic.
  Let me show you why. Well, what i'm going to do is, i'm going to start out by establishing my first unknown as my target function.
  Why did I just do that? Well, let me show you in a second. I'm going to hide the plot, the data processing, the data summaries. I don't need that right now. I'm going to go to the models. I'm just going to use a b-spline here.
  And again i'm doing it doing this for mechanics. I would have gone in and done a little bit more fine tuning of the FDE model of the Functional DOE model when I do this.
  But, the big thing to bring up, is right here. When we look at the integrated error, which is our target function it's this low - it's got a minima.
  And, it turns out, that that minimum is the concentration of ammonia in the unknown sample.
  So, all I have to do to find that minima...
  is maximize my desirability...
  and read off...
  my concentration.
  Now, unfortunately, I can't go back and establish a new target function in this same instance of FDE.
  So, I have to do that, once every time I want to do this for each function. Gratefully, I was only doing this once a day, so it didn't get tedious. But, if I had more data, had to do this, all at once, it'd take a little bit.
  But let's look at what that ends up looking like.
  Let's go back to Beer's Law. So, the blue data points here are the calibration data sets. Those are the ones that... Those are the serial delusions that I used to establish the model.
  We can see that the unknowns all fall nicely along Beer's Law. Yay, science works! Right? And, more importantly, we see this nice dynamic range, we see that we can detect everything.
  And it works fairly well.
  Let's look at what happens over time, because that's kind of an interesting piece here.
  So, looking at the data over time. And i've added a spline just to kind of help your eye with this. We can see that our concentration goes down.
  And if you kind of step back and squint (and ignore that maximum - we'll talk about that in a second), you can see that it's following that same curve, that we would expect to see, on the back half...
  Of this...
  Ammonia curve in the nitrogen cycle.
  Now, what about this maxima?
  Well, I did a couple of things a little bit differently than a traditional cycle. One of them was I took my filter that I had, and I put it in a tank that was already cycled. I have one that i'd had for a couple of years.
  And I put it into that tank to get the filter already populated with a bio filter.
  So I started with a - I won't say a mature filter - but I started with a filter that was already populated with the ammonia eating species. So, I got a lot of nitrite in my tank very quickly.
  And, it got to the point where it was saturating out the detectors. I couldn't detect changes.
  So, right here is where I did a water change. And generally you're not... you don't need to do a water change in the middle of this process. But, I did a water change in here, just so I could get my nitrites back down to where it could measure them again.
  Unfortunately, the process of doing that I also disturbed the ammonia eating bacteria. I lost some of the... some of that colony, and I had to wait for it to come back up to finish out the cycle.
  So, what you're seeing there is me perturbing my system before it was mature and ready to handle that kind of a...
  invasive procedure.
  But, again, the point being that we got to the we got to the end of this down here at the bottom when we hit zero I did another edition of ammonia,
  waited 24 hours, measured it again. I had zero again. Checked my nitrites, had zero nitrites. Checked my nitrates. They were through the roof, like I was expecting them to be. And did a water change. And I went to the fish store. and we're ready to go.
  First of all, if you're going to start an aquarium just, PS.. Public Service Announcement... PSA.
  Don't forget to cycle your aquarium first. There are little bottles of goo that people claim that... that have on the side, that say "No cycle aquarium, can add fish immediately."
  Don't believe it. Take the long way around. Your fish will be happier. They'll be...They will live longer. And, you'll have a much more enjoyable experience with them.
  So, don't forget to cycle your aquarium when you add fish.
  Point two - Legos are not just for creating a minefield in the living room. You can use them to do real science, like we saw here. I built a spectrometer out of Legos with a webcam and a DVD. And, it works.
  Step three, or point three is, never leave an engineer unsupervised for long periods of time. You never know what you're going to come home to.
  Thanks and have fun with your aquariums.