impactoz
Full Member
Posts: 142
Raspberry Pi: Yes
|
Post by impactoz on Sept 4, 2019 14:00:53 GMT -8
My main issue was to get it working... and it survived the first night for me without an issue. The image is certainly darker than I would like, and darker than what it used to be...
I have been playing with
camera.framerate = 1 camera.shutter_speed = 600000 camera.iso = 800
which changes the. 'quality' of night time images... Shutter_speed does very little... camera.iso does very little... it seems framerate is the key...
My LIMITED understanding is that a shutter speed of 600000 is s seconds... but that does not mean that the shutter is open for 6 seconds like B mode on a SLR... It takes longer than 6 seconds to take a 6 second picture. The frame rate influences how long it takes to take a picture...
A Lower framerate gives a better night time picture = values of .1 or .15 which is close to recommendations from other users taking 6 second images - does work better... but it causes the issue in the code and stops the images being recorded after the first run.
I am thinking that the camera stack gets confused with these lower values, and its the camera stack that dies, and the next time you try to use the camera its dead...
I have tried a value of 0.5 and thought it was successful, but not so sure... A value of 0.25 gives good results but kills the process...
If you have any other ideas, thoughts, play with these fields and report back.... Maybe we can improve it more
|
|
|
Post by jrwilling on Sept 4, 2019 18:30:22 GMT -8
Well, while the images are a bit toward the dark side (insert expected "Star Wars" joke here), my unit did continue to take pictures after switching into "night" mode with the framerate set to "1".
So, progress! And tweaking yet to come.
|
|
impactoz
Full Member
Posts: 142
Raspberry Pi: Yes
|
Post by impactoz on Sept 5, 2019 14:41:39 GMT -8
Id suggest pulling out the night time images - unti I find a better way of doing it...
My system died over night again with;
------Patting The Dog------- Tick! The time is: 2019-09-0WARNING:apscheduler.scheduler:Execution of job "sampleAndDisplay (trigger: interval[0:00:30], next run at: 2019-09-06 08:34:26 AEST)" skipped: maximum number of running instances reached (1) WARNING:apscheduler.scheduler:Execution of job "sampleAndDisplay (trigger: interval[0:00:30], next run at: 2019-09-06 08:34:56 AEST)" skipped: maximum number of running instances reached (1) WARNING:apscheduler.scheduler:Execution of job "sampleAndDisplay (trigger: interval[0:00:30], next run at: 2019-09-06 08:35:26 AEST)" skipped: maximum number of running instances reached (1) WARNING:apscheduler.scheduler:Execution of job "sampleAndDisplay (trigger: interval[0:00:30], next run at: 2019-09-06 08:35:56 AEST)" skipped: maximum number of running instances reached (1) WARNING:apscheduler.scheduler:Execution of job "sampleAndDisplay (trigger: interval[0:00:30], next run at: 2019-09-06 08:36:26 AEST)" skipped: maximum number of running instances reached (1) WARNING:apscheduler.scheduler:Execution of job "sampleAndDisplay (trigger: interval[0:00:30], next run at: 2019-09-06 08:36:56 AEST)" skipped: maximum number of running instances reached (1) WARNING:apscheduler.scheduler:Execution of job "sampleAndDisplay (trigger: interval[0:00:30], next run at: 2019-09-06 08:37:26 AEST)" skipped: maximum number of running instances reached (1)
So the delay in taking long exposure pictures are really screwing with stacks and timing.... it works for a few hours until it all gets screwed up...
Will work on its some more in the next week and let you know - concept is great idea... Execution. doh!
|
|
|
Post by topher2880 on Sept 5, 2019 17:19:28 GMT -8
I changed : camera.framerate = 0.5 camera.shutter_speed = 600000 camera.iso = 800 And all seems ok, can make out objects better than framerate = 1 however the system DOES hang on a reboot. Its powercycle for me or its nothing. I got my 3rd battery this morning, and about to head to work, so wont put it in until tomorrow, but will see how we go today, it make it through the night last night and its middle of the day now. Got a dust storm rolling in, so will leave it as long as it will last (or until the morning) Also received the UV sensor today, so hopefully tomorrow morning I can look at the code for that also and see what joy I have.
|
|
impactoz
Full Member
Posts: 142
Raspberry Pi: Yes
|
Post by impactoz on Sept 5, 2019 20:37:24 GMT -8
A little experimenting - no SkyWeather running - just a test program to take pictures with different parameters;
I ran it 4 times and these were the results... Framerate of 1, ISO 800, Shutter 6000000 - Takes around 5.15 seconds elapsed and close takes around 0.97 sec Framerate of 0.8, ISO 800, Shutter 6000000 - Takes around 5.8 seconds elapsed and close takes around 1.6 sec Framerate of 0.6, ISO 800, Shutter 6000000 - Takes around 7.5 seconds elapsed and close takes around 2 sec Framerate of 0.4, ISO 800, Shutter 6000000 - It hangs - never returns from the capture... It also prevents a reboot
After a reboot, tried again with Framerate 0.4 to see if it was this parameter or was it because I had run it 3 times before that it does not like... What do you think happens ? Framerate of 0.4, ISO 800, Shutter 6000000 - Takes around 10.5 Seconds elapsed - but hangs on the close
There is something definitely strange using python and the PI Camera...
I can from a terminal prompt do a perfect night time issue - using a terminal command like; raspistill -q 100 -t 1 -ss 6000000 -sh 0 -co 50 -br 50 -sa 0 -ev +2 -ex night -awb auto -ISO 800 -mm average -n -o %04d.jpg And I can repeat it and repeat it and repeat it without issue. Maybe is it because it starts a different process and when completed, that process is then dead whether it leaves something open or not, and then next time it runs its anew process ?
So I am going to try calling raspostill to take the night time pictures from within Python and see what happens. See if I can use subprocess.call(cmd, shell=True) to do something...
Be back tomorrow with the results!
|
|
impactoz
Full Member
Posts: 142
Raspberry Pi: Yes
|
Post by impactoz on Sept 6, 2019 1:19:59 GMT -8
OK - I think I have it.... Use at you own peril - but it has been working for nearly 4 hours now... I missed the transition from day to night - and that's my only concern if there is an issue or not... but cant see why there would be a problem... THe night time images are now bright and show detail again - they actually take around 42 seconds elapsed to obtain, there is some additional time because the way they are now called - maybe a second or two... but because its using raspistill there are just so many more parameters that one can play with instead of using python... and the bug in python where you had to use framerate to get it to change the shutter - is no longer an issue.. In fact this new way does not touch framerate at all - good thing I think !!! I moved some of the code around because of some logic needed, you do need to add the import subprocess since now I am kicking off a command line to take the night picture - but all appears to be good. I am sure there is further tweaking on the camera properties - as the first couple of night pictures I took at dusk using night mode looked like they were full daylight!!!! In fact so bright, I decided to change the header on the picture to show if it was a night vision picture or not. The website www.raspberrypi.org/documentation/raspbian/applications/camera.md lists all the parameters you can use on the command to change the camera properties... So its still a work in progress - here is my routines... This is everything I have in SkyCamera.py leading up to the line in the middle that says import base64 - as there are other routines in SkyCamera.py that remain untouched - and will need to remain there... So don't just copy this over the whole contents of the file... Know what your doing - as there are a few other enhancements there from past threads / posts - you may need to edit some of the code...
import requests import time import picamera import state
import hashlib
from PIL import ImageFont, ImageDraw, Image import traceback import util import datetime as dt import astral # Need to install this via sudo pip install astral import pytz import subprocess
# Check for user imports try: import conflocal as config except ImportError: import config
def SkyWeatherKeyGeneration(userKey):
catkey = "AZWqNqDMhvK8Lhbb2jtk1bucj0s2lqZ6" +userKey
md5result = hashlib.md5(catkey) #print ("hashkey =", md5result.hexdigest()) return md5result.hexdigest()
def takeSkyPicture(): sun_altos = astral.Location(info=("Melbourne", "AUS", -37.180594, 144.324194, "Australia/Victoria", config.BMP280_Altitude_Meters)) sun_altos.solar_depression = "civil"
result = sun_altos.sun(date=dt.date.today()) sunsettime = result['sunset'] sunsettimeplus10 = sunsettime + dt.timedelta(minutes=10) sunsettimeless1h = sunsettime + dt.timedelta(hours=-1) tz = pytz.timezone('Australia/Sydney') currtime = dt.datetime.now(tz) print "Sunset: " , sunsettime print "Sunset + 10 mins: " , sunsettimeplus10 print "Sunset - 1hr: " , sunsettimeless1h print "Current Time: " , currtime
if dt.datetime.now().time() > result['dawn'].time() and dt.datetime.now().time() < result['dusk'].time(): #Daytime print "Daytime picture Started" nightvishdr ="" camera = picamera.PiCamera() camera.exposure_mode = "auto" camera.rotation = 180 camera.resolution = (1920, 1080) time.sleep(2) camera.capture('static/skycamera.jpg') time.sleep(2) camera.close() print "Daytime picture Completed" else: #Nighttime print "Night time exposure Started" nightvishdr =" - Night Vision" cmd = "raspistill -q 100 -t 1 -ss 6000000 -vf -hf -sh 0 -co 50 -br 50 -sa 0 -ev +2 -w 1920 -h 1080 -ex night -awb auto -ISO 800 -mm average -n -o static/skycamera.jpg" subprocess.call(cmd, shell=True) print "Night time exposure Completed"
print "Picture Saved" # We have either a night time or day time picture - lets add the information header on it time.sleep(2) # Just in case... pil_im = Image.open('static/skycamera.jpg') draw = ImageDraw.Draw(pil_im) font = ImageFont.truetype("/usr/share/fonts/truetype/freefont/FreeSans.ttf", 25) # set up units #wind val = util.returnWindSpeed(state.ScurrentWindSpeed) WindStval = "{0:0.1f}".format(val) + util.returnWindSpeedUnit() val = util.returnWindSpeed(state.ScurrentWindGust) WindGtval = "{0:0.1f}".format(val) + util.returnWindSpeedUnit() val = util.returnTemperatureCF(state.currentOutsideTemperature) OTtval = "{0:0.1f}".format(val) + util.returnTemperatureCFUnit() val = state.currentTotalRain RDval = "{0:0.1f}".format(val) + "mm" val = state.currentSunlightUVIndex if val < 3: UVval = "Low" elif val >=3 and val < 6: UVval = "Moderate" elif val >=6 and val < 8: UVval = "High" elif val >=8 and val < 11: UVval = "Very High" else: UVval = "Extreme" myText = config.HEADERPIC + nightvishdr + ": %s Wind Speed: %s Wind Gust: %s Temp: %s Rain Today: %s UV: %s" % (dt.datetime.now().strftime('%d-%b-%Y %H:%M'),WindStval, WindGtval, OTtval, RDval, UVval) # Draw the text color = 'rgb(255,255,255)' #draw.text((0, 0), myText,fill = color, font=font) # get text size text_size = font.getsize(myText) # set button size + 10px margins button_size = (text_size[0]+20, text_size[1]+10) # create image with correct size and black background button_img = Image.new('RGBA', button_size, "black") # put text on button with 10px margins button_draw = ImageDraw.Draw(button_img) button_draw.text((10, 5), myText, fill = color, font=font) # put button on source image in position (0, 0) pil_im.paste(button_img, (0, 0)) bg_w, bg_h = pil_im.size
# Save the image pil_im.save('static/skycamera.jpg', format= 'JPEG') time.sleep(2)
if config.Twitter and currtime <= sunsettimeplus10 and currtime > sunsettimeless1h: print "Twitter: Taking Sunset picture at ", dt.date.today(), dt.datetime.now().time() print "Twitter: Sunset is calculated at: ", result['sunset'].time() cmd = "cp static/skycamera.jpg static/sunset.jpg" subprocess.call(cmd, shell=True) basewidth = 440 # New Width of the image img = Image.open('static/sunset.jpg') # Now Resize and Crop it # draw.text((0, 0),myText,(255,0,127),font=font) wpercent = (basewidth / float(img.size[0])) hsize = int((float(img.size[1]) * float(wpercent))) img = img.resize((basewidth, hsize),1) area = (0, 0, 440, 220) img = img.crop(area) # Going to add a header of title (from config) and date.... draw = ImageDraw.Draw(img) font = ImageFont.truetype("/usr/share/fonts/truetype/freefont/FreeSans.ttf", 16) myText = "Twitter: Sunset at " + config.HEADERPIC + ": %s" % (dt.datetime.now().strftime('%d-%b-%Y')) color = 'rgb(255,255,255)' text_size = font.getsize(myText) button_size = (text_size[0]+20, text_size[1]+10) button_img = Image.new('RGBA', button_size, "black") button_draw = ImageDraw.Draw(button_img) button_draw.text((10, 5), myText, fill = color, font=font) img.paste(button_img, (0, 0)) # We have a new image, scaled and cropped for common twitter usage - lets save it for use later tonight img.save('static/sunset.jpg')
if (config.USEWEATHERSTEM == True): sendSkyWeather()
import base64
Currently the code has no error trapping - can add that in later - I was more interested to see what failed when.... And the best thing - the system is not locking up on the camera stack anymore - so you can ctrl C out of it, and a reboot will work again - YAH! If you want to see results - here I am at - skyweather.weatherstem.com/malmsburyIts still in the test location... if the header when zooming in on the picture shows Malmsbury (Olive Trees) - Night Vision: then its a night time picture - location is GMT+10 to try and work out what time it is local to you!
|
|
impactoz
Full Member
Posts: 142
Raspberry Pi: Yes
|
Post by impactoz on Sept 6, 2019 1:47:28 GMT -8
Oh I did forget to mention - if your using the twitter bit, to get the sunset picture - make sure you delete sunset.jpg in the static folder - the new process above does not actually take a separate sunset picture, it just copies the SkyPicture to Sunset for manipulation... The first time you run this new code will cause a permissions error on trying to do that copy of sunset.
I think its ok for subsequent days - once your over the first occurrence...
|
|
|
Post by jrwilling on Sept 6, 2019 7:22:44 GMT -8
OK, perhaps I'm being a bit thick here... But there is something is that has me stumped.
Why is it at the end of the "sun_altos" line you have it dividing the config.BMP280_Altitude_Meters value by 3.2808399?
Some 'cosmic' significance that I can't get my head around?
|
|
impactoz
Full Member
Posts: 142
Raspberry Pi: Yes
|
Post by impactoz on Sept 6, 2019 14:34:58 GMT -8
You know what - I think your right - remove it... It has been over a month ago I was playing - so lost some of my reference points... To me that magic number is feet to meters. The Astral doco is scarce on info here astral.readthedocs.io/en/latest/astral.readthedocs.io/en/latest/module.html does state the value is in meters and so does the BMP280 Altitude... I think there must have been an example I found that made me think that Altos wanted feet or something - and I just copied the example paramaters from that. So good pickup - I have removed it off my system. Not made much of a change that really effects much as my testing is being done at 52 meters, probably would have picked it up when I move it to its proper site of 1500 meters ! (I have removed it from the code sample above - so if you copy that now, its all good!) Thanks - your on the ball!
|
|
|
Post by jrwilling on Sept 7, 2019 7:24:42 GMT -8
Looks to be running well on my unit so far with the current set of changes. Tho I do have a short time where my 'normal' camera exposure darkens out before the 'night vision' kicks in. Will have to decide if I want to tweak the day exposure (fixed values) or the times that it shifts into/out of night mode.
And totally random bit, as I like to know which way the wind is blowing in addition to the speed I added the following to the "#wind" block:
val= util.returnWindDirection(state.ScurrentWindDirection) WindDrval = "{:3}".format(val)
and then tweaked the "myText" output format line to match:
myText = config.HEADERPIC + nightvishdr + ": %s Wind Speed: %s %s Wind Gust: %s Temp: %s Rain Today: %s " % (dt.datetime.now().strftime('%d-%b-%Y %H:%M'),WindStval, WindDrval, WindGtval, OTtval, RDval)
Note: I do not have a UV sensor on my unit currently, so left that part out.
Nice also the addition of the "config.HEADERPIC" argument, saves having to recompile the code every time you want to change the header information.
|
|
|
Post by topher2880 on Sept 12, 2019 16:57:14 GMT -8
Just an interesting observation from out in the Australian desert... the moon has 'crashed' the script 2 nights running since its nearest a full moon at the present time. This morning it was right dead-center of the snapshot when the script stopped responding. Watchdog is no good for me, the watchdog reboots before the script has time to load on start-up, so I cant use it. No real issue, just an interesting observation, id be keen to hear if anyone else has found this with the 'edited' script Pointing southish now, looking for the Southern Cross at night hehe
|
|
|
Post by SDL on Sept 13, 2019 19:19:43 GMT -8
Guys. Post PICTURES! I want to see. I'm living vicariously through you.
BP
|
|
|
Post by topher2880 on Sept 14, 2019 15:06:32 GMT -8
Guys. Post PICTURES! I want to see. I'm living vicariously through you. BP Get your act together, BP, and buy a SkyWeather system. Theyre only $289 currently at this link -> SkyWeather Below is a timelapse of a few days ago. Not photos, I know, but 1st 'night' you can see where I implement ImpactOz night code. A day or so later a dust storm. Watching the moon and Jupiter race across the sky is awesome. I just need to find that sweet spot where I can get sunset, moonset AND get the system to stop crashing.
|
|
|
Post by SDL on Sept 14, 2019 17:00:36 GMT -8
You are a riot topher. I want to see if you guys can really see the stars with this thing. Meteors? I get it. But stars!
BP
|
|
|
Post by topher2880 on Sept 18, 2019 4:43:14 GMT -8
I cant get the milky way (yet) but I have stars
|
|