Farming in a Shipping Container
I’ll state up front I am naive to the complexities and why the idea below won’t work. I’m just starting to think about this. If I’m still thinking about it months later, perhaps the idea isn’t so bad. If I start talking to folks (in the idea below this would be folks running shelters for example) and they agree it is a good idea, perhaps I’ll move ahead. Please let me know if you have thoughts/criticisms that I can learn from.
I’m thinking this youtube video on shipping container farming is a great way to get fresh produce into our cities. I’d like to evolve a container to take advantage of sun as well as external CO2 to supplement (LED) lighting. I do like the way the shipping container farm minimizes water use…and then figure out a way to gather up the food waste into compost to reuse as fertilizer (nutrients)….hmmm…. where seeds check in and cities are fed…. …partner with a local shelter to train folks to work on it (and by working on it they get not just a “minimum wage” but a livable environment -> housing + food + healthcare + education + love) ….provide produce to the shelter…hmm.
What’s Up Today?
I want to evolve the Python script(s) I wrote that will help me analyze the Leaf Spa’s log files. This will be an ongoing effort. One thing I am doing is changing the code such that summary results is written out to a separate CSV file. The filename will be <input CSV filename>_summary.csv.
I can now run the script from a terminal window by typing Python leafspa.py within the folder that contains the python files.
The Python scripts I’ll be referring to are located at this GitHub location (version ae9b9db).
This Python Experience
My Python code update experience feels like this:
Happy to be learning. Snug in a save Python IDE environment…but so…so…so…so much to learn! 🙂 …ummm…I should probably point out the obvious – and of course, I am so…so…so…NOT AS CUTE…
Changing to the Atom Editor
Ugh…Eclipse with PyDev just made me sad. The Eclipse Neon environment lost my Python environment. I can’t shake the feeling that at least for Python development Eclipse has gotten bloated.
Once I get a food visual associated with something I find it hard to shake (such is the power of food on my ability to think!)…the visualization I get is one in which I see when I leave something in the refrigerator too long and it takes on a green/gray color as it seems to bloat in a very unpleasant way.
Hmmmm….I shall move on…
I’m feeling positive about using Atom as my Python IDE now that I have had a few days using Atom. While not as rich as Eclipse, it is good enough and much lighter to set up and work in. Also – Once I finish coding/debugging…it is a snap for me to run the script from the command line. YIPPEE!
The first bumbling I ran into was installing the terminal-plus package in order to get a command line so that I could run Python from within Atom…I had forgotten I already had a way to run Python within Atom based on what I documented in this post (i.e.: installing and using the Script package). So I deleted the terminal-plus package based on AbeEstrada’s advice:
You can list your packages from terminal with this command
And then you can uninstall with
apm uninstall PACKAGENAME
I found I could drag-n-drop the tab of an open file to the desktop. This creates a text file which contains the full pathname to the file.
This technique was very useful when inputing the full filename.
Test How Stuff Works in Python
Since I am still at the floaty stage with Python, I constantly need to try out Python commands. To do this, I installed the script package. I then added a playground.py file to the project. I add / delete lines and then run just this script (command – i ). Note: I tried running just by line number but got back an error message letting me know line level execution is not supported in Python. Not a big deal.
I am not ready to take off my Python floats yet. Besides, I just love the crutch of a source line debugger. This led me to install the Python debugger package. It could be my error, but at times I think I’m using the debugger correctly and I don’t get expected results..The challenge appears to be getting enough practice with this debugger in Atom to efficiently using it. Once I gained practice, the debugger became very useful.
The link above documents the few commands. The ones I rely on include:
- alt-r -> brings up the debugger
- shift-alt-r -> set/remove a breakpoint. I use this only when starting the debugger. I then step into the function that is in another file to switch the debugger to that file. Then I can use the b command (see below) to set breakpoints within the current file.
- input is put on the input line. For example, I input the log file with something like: -i /Users/…/03312017a.csv
- p <variable name> on the debugger command line displays the value of the variable.
- b -> show which breakpoints are active
As I learn to swim in the Python pool with my floaties on, I discover stuff that perhaps will let me swim in this python pool with more elegance. Understanding and using Python better is one of the reasons I am enthusiastic to evolve this script.
Python’s Logging library is AWESOME (see the documentation). Here’s an example of how I’m using it:
FORMAT = ‘In: %(filename)s Line: %(lineno)d %(message)s’
logger = logging.getLogger(__name__)
SDfilepath = “/Volumes/LeafSpa/”
SDfilename = SDfilepath + “DATALOG.TXT”
theLogFile = open(SDfilename)
logger.error(‘ERROR! ‘+SDfilename+ ‘ (on the SD CARD) could not be opened.’)
Results from Running Code
In: leafspa.py Line: 39 ERROR! /Volumes/LeafSpa/DATALOG.TXT (on the SD CARD) could not be opened.
A Better Way To Handle a Switch Statement
Since Python didn’t support a switch statement, I didn’t search to see if there is something more elegant than:
if rowType == 3: #LED is turned on inLEDonState = True continue if rowType == 4: # LED is turned off inLEDonState = False continue if rowType == 0: # A reading temp = float(row['info1']) humidity = float(r...
My goal in the evolution of my coding skills is to write code that helps in readability. Most folks seem to focus on efficiency…again – that code shredder that we all marvel at who can solve the answer to any question with one line of highly unreadable code…The challenge I have is what happens the next time I need to pick up the code…or you want to figure out what is going on? Given that microprocessors are powerful and heck – this code is in an abstract language like Python – what is Pythonic (an approved way to write something in Python) while at the same time more readable? And this is where using a dictionary to handle options that I’m currently handling with if this option:….if that option:…..
Using a Dictionary
Digging deeper into using a “switch dictionary” in an effort to have more maintainable code, I found these two articles useful:
- Use Python to do Switch Case by eva
- A StackOverflow Q&A – Executing functions within switch dictionary
Determining Light On
- As noted – a record in the log file is a light on/off record.
- There is a settings record that has noted when the light is to be turned on and off. Using this info, if the sensor record’s time stamp is between the lights on hours, the sensor reading happened when the light was on.
- If there are CO2 on/off (record type 5 and 6) interspersed with the sensor readings since CO2 is released only when the light is on. Note: there will still be chances to miscategorize a sensor reading.