Script to calculate water salt additions - Home Brew Forums
Register Now For Free!

 Home Brew Forums > Script to calculate water salt additions

01-12-2011, 10:36 PM   #1
doobliebop
Recipes

Mar 2009
Denver, CO
Posts: 244
Liked 5 Times on 2 Posts

I wrote this script to calculate the optimal amount of brewing salts to add to your water profile to end up with a target profile. I grabbed most of my numbers from ProMash, and so far this seems to be working well for me.

It is a python script, so you'll need the python interpreter with numpy, and the PyIMSL numerical libraries (freely available here: http://www.imslaps.com/products/imsl/pyimsl/)

Code:
```from numpy import *
from imsl.math.linLsqLinConstraints import linLsqLinConstraints
from imsl.math.writeMatrix import writeMatrix
from imsl.math.vectorNorm import vectorNorm

#Replace the values in base_water with your water profile
base_water = [26.0, 3.6, 13.2, 28.0, 12.2, 68]
#################Values taken from ProMash################
burton_on_trent = [268., 62., 30., 638., 36., 141.]
calistoga_mineral = [11.1, 62., 30., 638., 36., 141.]
distilled_water = [0.,0.,0.,0.,0.,0.]
dortmund = [260.,23.,69.,240.,206.,270.]
dublin = [118., 4., 12., 54., 19., 319.]
edinburgh = [140., 36., 92., 231., 60., 270.]
london = [90., 4., 24., 58., 18., 123.]
marin_county_ca = [12., 10., 15., 17., 13., 74.]
munich = [76., 18., 1., 10., 2., 152.]
pilsen = [7., 3., 3.2, 5.8, 5., 9.]
vienna = [200., 60., 8., 125., 12., 120.]
yorkshire = [105., 17., 23., 66., 30., 153.]
###########################################################
target = burton_on_trent

#Salt contents (PPM / (grams per gallon))
caso4 =  [61.5, 0.0, 0.0, 147.4, 0.0, 0.0]
mgso4 =  [0.0, 26.1, 0.0, 103.0, 0.0, 0.0]
nacl =   [0.0, 0.0, 103.9, 0.0, 160.3, 0.0]
nahco3 = [0.0, 0.0, 72.0, 0.0, 0.0, 189.0]
cacl2 =  [72.0, 0.0, 0.0, 0.0, 127.4, 0.0]
caco3 =  [105.8, 0.0, 0.0, 0.0, 0.0, 158.4]

# The overall goal here is to find x ST:
# Ax =~ b
# x >= 0

a = transpose([caso4, mgso4, nacl, nahco3, cacl2, caco3])
b = array(target) - array(base_water)
xlb = [0.] * 6
xub = [-1.0e30] * 6
c = []
con_type = []
bu = []
bl = []
residual = []
x = linLsqLinConstraints(a, b, c, bl, bu, con_type,  xlb, xub, residual=residual)

ion_labels = ['', 'Ca', 'Mg', 'Na', 'SO4', 'Cl', 'HCO3']
salt_labels = ['', 'CaSO4', 'MgSO4', 'NaCl', 'NaHCO3', 'CaCl2', 'CaCO3']
writeMatrix("Salt amounts to add \n(Grams per Gallon)", x, colLabels=salt_labels)
writeMatrix("Target Profile \n(PPM)", target, colLabels=ion_labels)
writeMatrix("Base Water + Recomended Salt Additions \n(PPM)", dot(a,x) + array(base_water), colLabels=ion_labels)
writeMatrix("Residuals \n(PPM)", residual, colLabels=ion_labels)
print ("\nNorm of residual = %f" % (vectorNorm(residual)))```
Here's a run calculating additions from my water to Burton on Trent. Plugging these numbers back into ProMash I get these exact totals.
Code:
```[email protected]/* <![CDATA[ */!function(t,e,r,n,c,a,p){try{t=document.currentScript||function(){for(t=document.getElementsByTagName('script'),e=t.length;e--;)if(t[e].getAttribute('data-cfhash'))return t[e]}();if(t&&(c=t.previousSibling)){p=t.parentNode;if(a=c.getAttribute('data-cfemail')){for(e='',r='0x'+a.substr(0,2)|0,n=2;a.length-n;n+=2)e+='%'+('0'+('0x'+a.substr(n,2)^r).toString(16)).slice(-2);p.replaceChild(document.createTextNode(decodeURIComponent(e)),c)}p.removeChild(t)}}catch(u){}}()/* ]]> */:~/Desktop\$ python water.py

Salt amounts to add
(Grams per Gallon)
CaSO4        MgSO4         NaCl       NaHCO3        CaCl2        CaCO3
2.888        1.817        0.106        0.000        0.083        0.489

Target Profile
(PPM)
Ca           Mg           Na          SO4           Cl         HCO3
268           62           30          638           36          141

Base Water + Recomended Salt Additions
(PPM)
Ca           Mg           Na          SO4           Cl         HCO3
261.3         51.0         24.2        640.8         39.8        145.5

Residuals
(PPM)
Ca           Mg           Na          SO4           Cl         HCO3
-6.67       -10.98        -5.81         2.78         3.77         4.45

Norm of residual = 15.513117```
Hope somebody finds this useful!
__________________
The Keg Ran Out Club
Broomfield, Colorado
http://www.kroc.org/

09-07-2012, 05:29 AM   #2
htc
Recipes

Oct 2010
Potosi, Missouri
Posts: 137
Liked 13 Times on 9 Posts

This is the first calculator I've found that (supposedly) calculates the proper additions to reach a desired water profile, rather than calculating the profile based on my additions. The first problem is that the link above for the python interpreter doesn't work. The second problem is that I have no idea what "python" or "numpy" are. Help please.

09-11-2012, 07:11 PM   #3
HopSong
Senior Member

Recipes

Sep 2011
Santa Rosa, CA
Posts: 1,945
Liked 101 Times on 89 Posts

Got an 500 Error.. Internal Server on the link
__________________
Cheers, Bill
Hop Song Brewing

09-16-2012, 03:50 AM   #4
hafmpty
Recipes

Jan 2010
Cincinnat, OH
Posts: 542
Liked 59 Times on 40 Posts

I'd love to be able to use this. Unfortunately, like a previous poster, I don't know how exactly. I've used a python script a couple times for something I was doing about a year ago, but I had no idea what I was doing. Could you (would you?) put together a "How-To" of getting the proper software/program and actually running the script? That would make this uber-helpful. Thanks so much.

09-19-2012, 09:33 PM   #5
htc
Recipes

Oct 2010
Potosi, Missouri
Posts: 137
Liked 13 Times on 9 Posts

^^^^=awesome!

 Thread Tools

 Similar Threads Thread Thread Starter Forum Replies Last Post iamacheetah Brewing Software 1 08-28-2010 10:57 PM aaron4osu Brewing Software 2 08-05-2009 02:46 AM eulipion2 Brewing Software 3 06-03-2009 01:31 PM bgough Brewing Software 2 05-03-2009 08:41 PM baker0408 Brewing Software 9 12-30-2007 03:15 PM

 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home Sponsor Showcase     Sponsor Showcase Home Brewing Beer     Beginners Beer Brewing Forum     General Beer Discussion     Fermentation & Yeast     All Grain & Partial Mash Brewing     BIAB Brewing     Extract Brewing     Gluten Free Brewing     General Techniques     Recipes/Ingredients     Equipment/Sanitation     Electric Brewing     Automated Brewing Forum     DIY Projects         Kegerators & Keezers         Brew Stands         Cleaners & Cleaning         Chillers & Stir Plates         Kettles, Mash Tuns & Hot Liquor Tanks         Fermenters     Bottling/Kegging     Label Display & Discussion     Brew Science     Lambic & Wild Brewing     Hops Growing     Home Brewing Photo Forum     Brewing Software Wine, Mead, Cider, Sake & Soda     Winemaking Forum     Mead Forum     Cider Forum     Soda Making     Kombucha & Fermented Tea Forum HomeBrewTalk.com Recipe Database     Homebrew Lager Recipes     Homebrew Ale Recipes     Homebrew Sours & Wilds Recipes     Specialty, Fruit, Historical, Other Homebrew Recipes     Mead Recipes     Wine Recipes     Cider Recipes Home Brew Market     Sampling and Critiquing and Beer Swapping     For Sale     Want to Buy     Group Buys     Homebrew Crowdfunding Food and Beverage     Cheese Making Forum     Cooking & Pairing     Coffee Brewing & Roasting     Meat Smoking, Curing and Sausage Making Home Brewing Community     General Chit Chat     Drunken Ramblings and Mindless Mumbling     Commercial Brew Discussion     Beer Blogs & Articles     Company Reviews Brewing Events & Local Gatherings     North West Homebrew Forum     South West Homebrew Forum     Great Lakes Homebrew Forum     South East Homebrew Forum     North East Homebrew Forum     North Central Homebrew Forum     South Central Homebrew Forum     International