{"database": "pelican", "table": "content", "rows": [["ryan", "musings", "I have a 10 year old daughter in the fifth grade. She has participated in the\nScience Fair almost every year, but this year was different. This year was\nrequired participation.\n\ndun \u2026 dun \u2026 dun \u2026\n\nShe and her friend had a really interesting idea on what to do. They wanted to\nask the question, **\u201cIs Soap and Water the Best Cleaning Method?** \u201d\n\nThe two Scientists decided that they would test how well the following\ncleaning agents cleaned a white t-shirt (my white t-shirt actually) after it\ngot dirty:\n\n  * Plain Water\n  * Soap and Water\n  * Milk\n  * Almond Milk\n\nWhile working with them we experimented on how to make the process as\nscientific as possible. Our first attempt was to just take a picture of the\nClean shirt, cut the shirt up and get it dirty. Then we\u2019d try each cleaning\nagent to see how it went.\n\nIt did not go well. It was immediately apparent that there would be no way to\ntest the various cleaning methods efficacy.\n\nNo problem. In our second trial we decided to approach it more scientifically.\n\nWe would draw 12 equally sized squares on the shirt and take a picture:\n\n![Clean Shirt](/images/uploads/2016/12/Clean-Shirt-Grid-small-300x200.png)\n\nWe needed 12 squares because we had 4 cleaning methods and 3 trials that\nneeded to be performed\n\n> > 4 Cleaning Methods X 3 Trials = 12 Samples\n\nNext, the Scientists would get the shirt dirty. We then cut out the squares so\nthat we could test cleaning the samples.\n\nHere\u2019s an outline of what the Scientists did to test their hypothesis:\n\n  1. Take a picture of each piece BEFORE they get dirty\n  2. Get each sample dirty\n  3. Take a picture of each dirty sample\n  4. Clean each sample\n  5. Take a picture of each cleaned sample\n  6. Repeat for each trial\n\nFor the \u2018Clean Each Sample\u2019 step they placed 1/3 of a cup of the cleaning\nsolution into a small Tupperware tub that could be sealed and _vigorously_\nshook for 5 minutes. They had some tired arms at the end.\n\nOnce we had performed the experiment we our **raw** data:\n\n# Trial 1\n\nMethod Start Dirty Cleaned\n\n* * *\n\nWater\n![Trial1_Start_Water](/images/uploads/2016/12/Trial1_Start_Water-300x300.jpg)\n![Trial1_Dirty_Water](/images/uploads/2016/12/Trial1_Dirty_Water-300x300.jpg)\n![Trial1_Clean_Water](/images/uploads/2016/12/Trial1_Clean_Water-300x300.jpg)\nSoap And Water\n![Trial1_Start_SoapAndWater](/images/uploads/2016/12/Trial1_Start_SoapAndWater-300x300.jpg)\n![Trial1_Dirty_SoapAndWater](/images/uploads/2016/12/Trial1_Dirty_SoapAndWater-300x300.jpg)\n![Trial1_Clean_SoapAndWater](/images/uploads/2016/12/Trial1_Clean_SoapAndWater-300x300.jpg)\nMilk\n![Trial1_Start_Milk](/images/uploads/2016/12/Trial1_Start_Milk-300x300.jpg)\n![Trial1_Dirty_Milk](/images/uploads/2016/12/Trial1_Dirty_Milk-300x300.jpg)\n![Trial1_Clean_Milk](/images/uploads/2016/12/Trial1_Clean_Milk-300x300.jpg)\nAlmond Milk\n![Trial1_Start_Milk](/images/uploads/2016/12/Trial1_Start_Milk-300x300.jpg)\n![Trial1_Dirty_Milk](/images/uploads/2016/12/Trial1_Dirty_Milk-300x300.jpg)\n![Trial1_Clean_Milk](/images/uploads/2016/12/Trial1_Clean_Milk-300x300.jpg)\n\n* * *\n\n# Trial 2\n\nMethod Start Dirty Cleaned\n\n* * *\n\nWater\n![Trial2_Start_Water](/images/uploads/2016/12/Trial2_Start_Water-300x300.jpg)\n![Trial2_Dirty_Water](/images/uploads/2016/12/Trial2_Dirty_Water-300x300.jpg)\n![Trial2_Clean_Water](/images/uploads/2016/12/Trial2_Clean_Water-300x300.jpg)\nSoap And Water\n![Trial2_Start_SoapAndWater](/images/uploads/2016/12/Trial2_Start_SoapAndWater-300x300.jpg)\n![Trial2_Dirty_SoapAndWater](/images/uploads/2016/12/Trial2_Dirty_SoapAndWater-300x300.jpg)\n![Trial2_Clean_SoapAndWater](/images/uploads/2016/12/Trial2_Clean_SoapAndWater-300x300.jpg)\nMilk\n![Trial2_Start_Milk](/images/uploads/2016/12/Trial2_Start_Milk-300x300.jpg)\n![Trial2_Dirty_Milk](/images/uploads/2016/12/Trial2_Dirty_Milk-300x300.jpg)\n![Trial2_Clean_Milk](/images/uploads/2016/12/Trial2_Clean_Milk-300x300.jpg)\nAlmond Milk\n![Trial2_Start_AlmondMilk](/images/uploads/2016/12/Trial2_Start_AlmondMilk-300x300.jpg)\n![Trial2_Dirty_AlmondMilk](/images/uploads/2016/12/Trial2_Dirty_AlmondMilk-300x300.jpg)\n![Trial2_Clean_AlmondMilk](/images/uploads/2016/12/Trial2_Clean_AlmondMilk-300x300.jpg)\n\n* * *\n\n# Trial 3\n\nMethod Start Dirty Cleaned\n\n* * *\n\nWater\n![Trial3_Start_Water](/images/uploads/2016/12/Trial3_Start_Water-300x300.jpg)\n![Trial3_Dirty_Water](/images/uploads/2016/12/Trial3_Dirty_Water-300x300.jpg)\n![Trial3_Clean_Water](/images/uploads/2016/12/Trial3_Clean_Water-300x300.jpg)\nSoap And Water\n![Trial3_Start_SoapAndWater](/images/uploads/2016/12/Trial3_Start_SoapAndWater-300x300.jpg)\n![Trial3_Dirty_SoapAndWater](/images/uploads/2016/12/Trial3_Dirty_SoapAndWater-300x300.jpg)\n![Trial3_Clean_SoapAndWater](/images/uploads/2016/12/Trial3_Clean_SoapAndWater-300x300.jpg)\nMilk\n![Trial3_Start_Milk](/images/uploads/2016/12/Trial3_Start_Milk-300x300.jpg)\n![Trial3_Dirty_Milk](/images/uploads/2016/12/Trial3_Dirty_Milk-300x300.jpg)\n![Trial3_Clean_Milk](/images/uploads/2016/12/Trial3_Clean_Milk-300x300.jpg)\nAlmond Milk\n![Trial3_Start_AlmondMilk](/images/uploads/2016/12/Trial3_Start_AlmondMilk-300x300.jpg)\n![Trial3_Dirty_AlmondMilk](/images/uploads/2016/12/Trial3_Dirty_AlmondMilk-300x300.jpg)\n![Trial3_Clean_AlmondMilk](/images/uploads/2016/12/Trial3_Clean_AlmondMilk-300x300.jpg)\n\nThis is great and all, but now what? We can\u2019t really use subjective measures\nto determine cleanliness and call it science!\n\nMy daughter and her friend aren\u2019t coders, but I did explain to them that we\nneeded a more scientific way to determine cleanliness. I suggested that we use\n`python` to examine the image and determine the brightness of the image.\n\nWe could then use some math to compare the brightness. 1\n\nNow, onto the code!\n\nOK, let\u2019s import some libraries:\n\n    \n    \n    from PIL import Image, ImageStat\n    import math\n    import glob\n    import pandas as pd\n    import matplotlib.pyplot as plt\n    \n\nThere are 2 functions to determine `brightness` that I found\n[here](http://stackoverflow.com/questions/3490727/what-are-some-methods-to-\nanalyze-image-brightness-using-python). They were super useful for this\nproject. As an aside, I love StackOverflow!\n\n    \n    \n    #Convert image to greyscale, return average pixel brightness.\n    def brightness01( im_file ):\n       im = Image.open(im_file).convert('L')\n       stat = ImageStat.Stat(im)\n       return stat.mean[0]\n    \n    #Convert image to greyscale, return RMS pixel brightness.\n    def brightness02( im_file ):\n       im = Image.open(im_file).convert('L')\n       stat = ImageStat.Stat(im)\n       return stat.rms[0]\n    \n\nThe next block of code takes the images and processes them to get the return\nthe brightness levels (both of them) and return them to a `DataFrame` to be\nused to write to a `csv` file.\n\nI named the files in such a way so that I could automate this. It was a bit\ntedious (and I did have the scientists help) but they were struggling to\nunderstand why we were doing what we were doing. Turns out teaching CS\nconcepts is harder than it looks.\n\n    \n    \n    f = []\n    img_brightness01 = []\n    img_brightness02 = []\n    trial = []\n    state = []\n    method = []\n    for filename in glob.glob('/Users/Ryan/Dropbox/Abby/Science project 2016/cropped images/**/*', recursive=True):\n        f.append(filename.split('/')[-1])\n        img_brightness01.append(round(brightness01(filename),0))\n        img_brightness02.append(round(brightness02(filename),0))\n    for part in f:\n        trial.append(part.split('_')[0])\n        state.append(part.split('_')[1])\n        method.append(part.split('_')[2].replace('.png', '').replace('.jpg',''))\n    \n    dic = {'TrialNumber': trial, 'SampleState': state, 'CleaningMethod': method, 'BrightnessLevel01': img_brightness01, 'BrightnessLevel02': img_brightness02}\n    \n    results = pd.DataFrame(dic)\n    \n\nI\u2019m writing the output to a `csv` file here so that the scientist will have\ntheir data to make their graphs. This is where my help with them ended.\n\n    \n    \n    #write to a csv file\n    results.to_csv('/Users/Ryan/Dropbox/Abby/Science project 2016/results.csv')\n    \n\nSomething I wanted to do though was to see what our options were in `python`\nfor creating graphs. Part of the reason this wasn\u2019t included with the science\nproject is that we were on a time crunch and it was easier for the Scientists\nto use [Google Docs](https://docs.google.com) to create their charts, and part\nof it was that I didn\u2019t want to cheat them out of creating the charts on their\nown.\n\nThere is a formula below to determine a `score` which is given by a normalized\npercentage that was used by them, but the graphing portion below I did after\nthe project was turned in.\n\nLet\u2019s get the setup out of the way:\n\n    \n    \n    #Create Bar Charts\n    trials = ['Trial1','Trial2','Trial3']\n    \n    n_trials = len(trials)\n    index = np.arange(n_trials)\n    bar_width = 0.25\n    bar_buffer = 0.05\n    opacity = 0.4\n    \n    graph_color = ['b', 'r', 'g', 'k']\n    methods = ['Water', 'SoapAndWater', 'Milk', 'AlmondMilk']\n    \n    graph_data = []\n    \n\nNow, let\u2019s loop through each cleaning method and generate a list of scores\n(where one score is for one trial)\n\n    \n    \n    for singlemethod in methods:\n        score= []\n        for trialnumber in trials:\n            s = results.loc[results['CleaningMethod'] == singlemethod].loc[results['TrialNumber'] == trialnumber].loc[results['SampleState'] == 'Start'][['BrightnessLevel01']]\n            s = list(s.values.flatten())[0]\n            d = results.loc[results['CleaningMethod'] == singlemethod].loc[results['TrialNumber'] == trialnumber].loc[results['SampleState'] == 'Dirty'][['BrightnessLevel01']]\n            d = list(d.values.flatten())[0]\n            c = results.loc[results['CleaningMethod'] == singlemethod].loc[results['TrialNumber'] == trialnumber].loc[results['SampleState'] == 'Clean'][['BrightnessLevel01']]\n            c = list(c.values.flatten())[0]\n            scorepct =  float((c-d) / (s - d))\n            score.append(scorepct)\n        graph_data.append(score)\n    \n\nThis last section was what stumped me for the longest time. I had such a\nmental block converting from iterating over items in a list to item counts of\na list. After much [Googling](https://www.google.com) I was finally able to\nmake the breakthrough I needed and found the idea of looping through a range\nand everything came together:\n\n    \n    \n    for i in range(0, len(graph_data)):\n        plt.bar(index+ (bar_width)*i, graph_data[i], bar_width-.05, alpha=opacity,color=graph_color[i],label=methods[i])\n        plt.xlabel('Trial Number')\n        plt.axvline(x=i-.025, color='k', linestyle='--')\n        plt.xticks(index+bar_width*2, trials)\n        plt.yticks((-1,-.75, -.5, -.25, 0,0.25, 0.5, 0.75, 1))\n        plt.ylabel('Brightness Percent Score')\n        plt.title('Comparative Brightness Scores')\n        plt.legend(loc=3)\n    \n\nThe final output of this code gives:\n\n![Results_Graph](/images/uploads/2016/12/Results_Graph-300x212.png)\n\nFrom the graph you can see the results are \u2026 inconclusive. I\u2019m not sure what\nthe heck happened in Trial 3 but the Scientists were able to make the samples\ndirtier. Ignoring `Trial 3` there is no clear winner in either `Trial 1` or\n`Trial 2`.\n\nI think it would have been interesting to have 30 - 45 trials and tested this\nwith a some statistics, but that\u2019s just me wanting to show something to be\nstatistically valid.\n\nI think the best part of all of this was the time I got to spend with my\ndaughter and the thinking through the experiment. I think she and her friend\nlearned a bit more about the scientific method (and hey, isn\u2019t that what this\ntype of thing is all about?).\n\nI was also really excited when her friend said, \u201cScience is pretty cool\u201d and\nthen had a big smile on her face.\n\nThey didn\u2019t go onto district, or get a blue ribbon, but they won in that they\nlearned how neat science can be.\n\n  1. [The score is the ratio of how clean the cleaning method was able to get the sample compared to where it started, i.e. the ratio of the difference of the `cleaned` sample and the `dirty` sample to the difference of the `starting` sample and the `dirty` sample. \u21a9\ufe0e\n\n", "2016-12-17", "its-science", "I have a 10 year old daughter in the fifth grade. She has participated in the\nScience Fair almost every year, but this year was different. This year was\nrequired participation.\n\ndun \u2026 dun \u2026 dun \u2026\n\nShe and her friend had a really interesting idea on what to do. They wanted to\n\u2026\n\n", "It's Science!", "https://www.ryancheley.com/2016/12/17/its-science/"]], "columns": ["author", "category", "content", "published_date", "slug", "summary", "title", "url"], "primary_keys": ["slug"], "primary_key_values": ["its-science"], "units": {}, "query_ms": 1.1913031339645386}