Author Topic: Script for Astrophotography  (Read 460 times)

f.javi.pz

  • New to the forum
  • *
  • Posts: 8
Script for Astrophotography
« on: October 27, 2020, 03:45:45 PM »
Hi,

I'm trying to write an script for Astrophotography, to complete the sequence of pics for DARK, BIAS, LIGHT and FLAT corrections.

It seems an easy one, it just have to take several pictures in silent mode at different shutter values, with or without a cap on the objetive. But I'm afraid I'm new with lua. I copied code from other scripts in the forum, examples, etc.

This is the code I write as an starting point (don't be cruel with the rookie):
Code: [Select]
menu.new
{
  name = "Astrophoto",
  help = "Takes several photos to complete BIAS, DARK, LIGHT and FLAT sequences, for astrophotografy",
  select = function(this) task.create(astrophoto) end,
}

function astrophoto()
  menu.close()
  console.show()
  console.clear()
  print "BIAS and DARK initial sequences (10+10 photos)"
  print "Switch to Manual mode and cover the objetive with the cap"
  print "Press any key to start"
  key.wait()
  console.hide()

  -- BIAS sequence
  camera.aperture.value = 3.5
  camera.iso.value = 1600
  camera.shutter.value = 1/4000
local i = 0
while i < 10 do
camera.shoot()
i = i+1
end

  -- DARK sequence
  camera.aperture.value = 3.5
  camera.iso.value = 1600
  camera.shutter.value = 1
  local i = 0
while i < 10 do
camera.shoot()
i = i+1
end
 
  console.show()
  console.clear()
  print "LIGHT sequence (10 photos)"
  print "Uncover the objetive and press any key to start"
  key.wait()
  console.hide()
 
  -- LIGHT sequence
  camera.aperture.value = 3.5
  camera.iso.value = 1600
  camera.shutter.value = 1
  local i = 0
while i < 10 do
camera.shoot()
i = i+1
end

  console.show()
  console.clear()
  print "BIAS and DARK final sequences (10+10 photos)"
  print "Cover the objetive and press any key to start"
  key.wait()
  console.hide()

  -- DARK sequence
  camera.aperture.value = 3.5
  camera.iso.value = 1600
  camera.shutter.value = 1
  local i = 0
while i < 10 do
camera.shoot()
i = i+1
end
 
  -- BIAS sequence
  camera.aperture.value = 3.5
  camera.iso.value = 1600
  camera.shutter.value = 1/4000
  local i = 0
while i < 10 do
camera.shoot()
i = i+1
end

  console.show()
  console.clear()
  print "FLAT sequence (20 photos)"
  print "Cover with an iluminated diffusor and switch to Av mode"
  print "Press any key to start"
  key.wait()
  console.hide()

  -- FLAT sequence
  camera.aperture.value = 3.5
  camera.iso.value = 1600
  local i = 0
while i < 20 do
camera.shoot()
i = i+1
end

  console.show()
  console.clear()
  print "Everything done!"
  print "Press any key to end the script"
  key.wait()
  console.hide()

end

Todo:

1 Get it working!  :-\
2 Print the count of pictures taken/to be taken
3 Automatically change mode to manual/Av/silent (I don't know if can be done)
4 Automatically take shutther/iso/speed values set at the beggining of the script

I'll keep trying, but the truth is... I'm stuck. I would appreciate some help.

garry23

  • Contributor
  • Hero Member
  • *****
  • Posts: 2075
Re: Script for Astrophotography
« Reply #1 on: October 27, 2020, 04:40:10 PM »
@f.javi.pz

Too many questions in one go ;-)

Have a look at my latest script, DOFIS, for some ideas to help you.

Cheers

Garry

f.javi.pz

  • New to the forum
  • *
  • Posts: 8
Re: Script for Astrophotography
« Reply #2 on: October 27, 2020, 04:53:32 PM »
Sorry about the questions. Just get it working is enough, it's true. Take it as a consecuence os being stuck.

I'll check out your DOFIS script, sure. I checked some other of your scripts before posting (you are quite active, thanks!), but I'm afraid they are really complex for me.

Walter Schulz

  • Contributor
  • Hero Member
  • *****
  • Posts: 7616
Re: Script for Astrophotography
« Reply #3 on: October 27, 2020, 05:15:00 PM »
I think you know the drill:
Break it down into smaller pieces. Make piece after piece working and don't try to solve everything at once.

And be sure: garry23 had to struggle in the very beginning, too. We witnessed most of it and his progress. ;-)

AFAIK there is no option to switch modes. I think you have to check for manual mode change, instead.

garry23

  • Contributor
  • Hero Member
  • *****
  • Posts: 2075
Re: Script for Astrophotography
« Reply #4 on: October 27, 2020, 05:29:54 PM »
Walter

How dare you!

What do you mean “garry23 had to struggle in the very beginning”.

I’m still bloody struggling  :) :) :) :) :)


f.javi.pz

  • New to the forum
  • *
  • Posts: 8
Re: Script for Astrophotography
« Reply #5 on: October 27, 2020, 05:44:14 PM »
I think you know the drill:
Break it down into smaller pieces. Make piece after piece working and don't try to solve everything at once.

And be sure: garry23 had to struggle in the very beginning, too. We witnessed most of it and his progress. ;-)

AFAIK there is no option to switch modes. I think you have to check for manual mode change, instead.

Drill started!

Thanks!

Walter Schulz

  • Contributor
  • Hero Member
  • *****
  • Posts: 7616
Re: Script for Astrophotography
« Reply #6 on: October 27, 2020, 05:57:27 PM »
People will help you if you get stuck. Just don't expect throwing a big chunk of code over the fence and get it fixed.

f.javi.pz

  • New to the forum
  • *
  • Posts: 8
Re: Script for Astrophotography
« Reply #7 on: November 04, 2020, 12:57:44 PM »
Hi again,

I followed your advices and get it working! Thank you very much!

Now I'm trying to get a display saying "Taking picture 2 of 20" and so on. The text generator itself already works. The problem is the script is designed to take pics on "silent mode" with LV on.

I tried printing it in the console, pause de Live View before it, showing it with a notify_box... You'll see in the code I have a big mess about it:
Code: [Select]
mymenu = menu.new
{
    name = "Astrophoto",
    help = "Takes several photos to complete BIAS, DARK, LIGHT and FLAT sequences, for astrophotografy",
    submenu =
    {
    {
            name = "Start!",
            help = "Run this script.",
            select  = function(this) task.create(astro) end,
        },
        {
            name = "How many LIGHT photos?",
            help = "DARK, BIAS and FLAT will be the same",
            min = 0,
            max = 30,
            value = 2
        }       
    }
}

--mymenu.submenu["Start!"].select = function(this) task.create(astro) end,

function astro()
local n = mymenu.submenu["How many LIGHT photos?"].value 
  menu.close()
  console.show()
  -- warnings
  if camera.mode ~= MODE.M then
print("Enable MANUAL mode and run again")
key.wait()
return
  end
  console.clear()
  print("BIAS and DARK initial sequences (10+10 photos)".."\n".."Select in MANUAL mode prefered iso/aperture/speed and ".."\n".."cover the objetive with the cap".."\n".."\n".."Press any key to start")
  key.wait()
  console.clear()

  -- Declare local variables to keep camera configuration at the start and use it
 
  local a = camera.aperture.value
  local i = camera.iso.value
  local s = camera.shutter.value

print("Starting the sequence with this configuration:")
print("\n")
print ("Aperture = "..tostring(a))
print ("ISO = "..tostring(i))
print ("Speed = "..tostring(s))
print("\n")
print("\n")
print("You are going to take "..tostring(6*n).." pictures")
print("Silent mode is recomended for this script")
print("\n")
print("\n")
print("Press any key to continue")
key.wait()
  console.clear()
console.hide()
 
  -- BIAS sequence
    camera.aperture.value = a
  camera.iso.value = i
  camera.shutter.value = 1/4000
local r = 0
while r < n do
console.hide()
lv.start()
camera.shoot()
r = r+1
lv.pause()
console.show()
msleep(100)
display.notify_box("Initial BIAS "..tostring(r).." of "..tostring(n).."\n"..
"Initial DARK 0 of"..tostring(n).."\n"..
"LIGHT 0 of "..tostring(n).."\n"..
"Final DARK 0 of "..tostring(n).."\n"..
"Final BIAS 0 of "..tostring(n).."\n"..
"Final FLAT 0 of "..tostring(n).."\n"..
"TOTAL "..tostring(r).." of "..tostring(6*n),3000)
msleep(100)
end

  -- DARK sequence
  camera.aperture.value = a
  camera.iso.value = i
  camera.shutter.value = s
  console.clear()
local r = 0
while r < n do
console.hide()
lv.start()
camera.shoot()
r = r+1
lv.pause()
console.show()
msleep(100)
display.notify_box("Initial BIAS done!".."\n"..
"Initial DARK "..tostring(r).." of "..tostring(n).."\n"..
"LIGHT 0 of "..tostring(n).."\n"..
"Final DARK 0 of "..tostring(n).."\n"..
"Final BIAS 0 of "..tostring(n).."\n"..
"Final FLAT 0 of "..tostring(n).."\n"..
"TOTAL "..tostring(n+r).." of "..tostring(6*n),3000)
msleep(100)
end

  -- LIGHT sequence
  lv.pause()
console.clear()
console.show()
  print("LIGHT sequence (10 photos)","\n","Uncover the objetive","\n","\n","Press half shutter to start")
  key.wait()
  console.clear()
console.hide()

  camera.aperture.value = a
  camera.iso.value = i
  camera.shutter.value = s

local r = 0
while r < n do
console.hide()
lv.start()
camera.shoot()
r = r+1
lv.pause()
console.show()
msleep(100)
display.notify_box("Initial BIAS done!".."\n"..
"Initial DARK done!".."\n"..
"LIGHT "..tostring(r).." of "..tostring(n).."\n"..
"Final DARK 0 of "..tostring(n).."\n"..
"Final BIAS 0 of "..tostring(n).."\n"..
"Final FLAT 0 of "..tostring(n).."\n"..
"TOTAL "..tostring(2*n+r).." of "..tostring(6*n),3000)
msleep(100)
end
lv.stop()
console.clear()
console.show()
  print("Press any key to end")
  key.wait()
console.clear()
  console.hide()
 end

(It's a long code, but just to show I'm lost about the display function)

What is a good way of showing the progress when taking pictures in "silent mode"? Print to console, notify box, stop the Live View before...?

Thanks again, the drill works!

garry23

  • Contributor
  • Hero Member
  • *****
  • Posts: 2075
Re: Script for Astrophotography
« Reply #8 on: November 04, 2020, 01:07:23 PM »
@f.having.pz

From my experience, you need to decide if feedback is essential for the functioning of the script, nice to have or a debug diagnostic.

If essential, then you need to find a solution, clearly.

If nice to have or a debug tool, then a ‘cheap and cheerful’ approach should be ok.

If using the notify box, I use this function:

Code: [Select]
function my_display(text,time,x_pos,y_pos)
    text = string.rep("\n",y_pos)..string.rep(" ",x_pos)..text
    display.notify_box(text,time*1000)
end

Bottom line: know what you are seeking, ie use just enough feedback, and no more ;-)

f.javi.pz

  • New to the forum
  • *
  • Posts: 8
Re: Script for Astrophotography
« Reply #9 on: November 04, 2020, 02:44:55 PM »
OK, no more long codes till the final one.

Probably is somewhere between "nice to have" and "emotionally essential"  ;)

Drama on
It is dark and cold out there, you started an script to take about 100 photos and you are waiting without knowing how long or even if it is working or just emptying the battery...
Drama off

This sequence is logical for notify boxes?

1 start Live View
2 shoot in silent mode
3 pause Live View
4 display the box