Script for automatic observing

PGM scripting language, search and discovery of comets, asteroids and supernova.
Post Reply
Hamza Touhami
Site Admin
Posts: 341
Joined: Sat May 20, 2017 6:05 pm
Location: Phoenix,AZ
Contact:

Fri Jul 20, 2018 6:10 pm

This is a great script written by Alain Maury ( www.spaceobs.com) to help in variable star observing. all your comments and suggestions are welcome. Please remember to change the file extension to ".pgm" to work in PRISM.

Code: Select all

REM Variable star observing
REM originated from the asteroid survey script
REM Alain Maury - January 2014 till September 2017 :)
REM adapted to the 135mm lens on AZEQ6 mount
REM Filters C=1, B=2, V=3, R=4, H=5

REM Cooling of the camera in minutes and degrees
minutestogodowntotemp=15
Detectortemperature=-20

REM difference between local time and UT
deltaUT=3

REM autoguiding
autoguide=FALSE
scoperecentering=FALSE

REM minimum height at which we will observe a star. 15 degrees=0.2618 radians
minimumheight=0.2618
REM minimum distance from the moon we can observe, here we take also 15 degrees.
minimummoondistance=0.2618
REM exposure time used for recentering the telescope, for now 5 seconds, or 5000ms
shortExptimeMS=5000
GuidingExpTime=10

REM the directory of the directories
imagedirectory$="C:\images\"

REM calculating night's date
NOW year month day hour minute second MS

lengthmonth[1]=31
REM bissextile years
yearfrac=year/4
frac yearfrac bissextile
if bissextile=0 then
   lengthmonth[2]=29
else
   lengthmonth[2]=28
endif
lengthmonth[3]=31
lengthmonth[4]=30
lengthmonth[5]=31
lengthmonth[6]=30
lengthmonth[7]=31
lengthmonth[8]=31
lengthmonth[9]=30
lengthmonth[10]=31
lengthmonth[11]=30
lengthmonth[12]=31

if hour<12 then
   if day=1 then
      if month=1 then
         year=year-1
         month=12
         day=31
      else
         month=month-1
      endif
      day=lengthmonth[month]
   else
      day=day-1
   endif
endif
REM directory of the night
REM Year
REM *****

str year year$

str month month$
if month<10 then
   month$="0"+month$
endif

str day day$
if day<10 then
   day$="0"+day$
endif

night$=year$+"-"+month$+"-"+day$
nightdirectory$=imagedirectory$+night$+"\"
createdir nightdirectory$
directorycalib$=nightdirectory$+"preprocess\"
createdir directorycalib$
print "the images will be stored in : " nightdirectory$
print "the processed images will be stored in : " directorycalib$




REM Opening and reading the target list
REM à modifier une fois installé sur le PC\Documents\Prism\Exemples
REM targetlist$="C:\Users\amaur\Documents\Prism\Exemples de script Pgm\sequenceur\targetlist.txt"


targetlist$="C:\Users\Andy's Astro PC\Documents\Prism\Exemples de script Pgm\Sequence\targetlist.txt"
Open_FileTxt_For_Read targetlist targetlist$
numberofstarsintargetlist=0
readnextline:
ENDOFFILE targetlist result
if result=FALSE then
   numberofstarsintargetlist=numberofstarsintargetlist+1
   REM we have not arrived till the end of the file
   ReadFileTxt targetlist line$
   REM we split the line
   CUTSTR line$ " " 1 starname[numberofstarsintargetlist]$
   CUTSTR line$ " " 2 starRAH$
   CUTSTR line$ " " 3 starRAM$
   CUTSTR line$ " " 4 starDecD$
   CUTSTR line$ " " 5 starDecM$
   val starRAH$ starRAH
   val starRAM$ starRAM
   val starDecD$ starDecD
   val starDecM$ starDecM
   starRA[numberofstarsintargetlist]=starRAH+(starRAM/60)
   if starDecD<0 then
      starDec[numberofstarsintargetlist]=starDecD-(starDecM/60)
   else
      starDec[numberofstarsintargetlist]=starDecD+(starDecM/60)
   endif
   print "starname number : " numberofstarsintargetlist " is : " starname[numberofstarsintargetlist]$ " star RA in decimal : " starRA[numberofstarsintargetlist] " star Dec in decimal : " starDec[numberofstarsintargetlist]
   numberofimages[numberofstarsintargetlist]=0
   goto readnextline:
endif
closefiletxt targetlist
print "number of stars in the target list : " numberofstarsintargetlist


REM astrometric catalog
REM ********************
DirCat$="C:\GSC-ACT\"


REM Catalogs that can be used
Cat[1]$="GSC"
Cat[2]$="USNO SA"
Cat[3]$="USNO A1"
Cat[4]$="USNO A2"
Cat[5]$="Hipparcos"
Cat[6]$="SAO"
Cat[7]$="BSC"
Cat[8]$="Tycho1"
Cat[9]$="GSC-ACT"
Cat[10]$="Tycho2"
Cat[11]$="UCAC 2/3/4"
Cat[12]$="NOMAD V1"

REM Catalog that will be used
Cat$=Cat[9]$


REM elevation of the sun to start the telescope, then start observing, latitude and longitude
REM ******************************
GetStdrLongitude Longitude
GetStdrLatitude Latitude
print "Longitude = " Longitude*TODEG " Latitude = " Latitude*TODEG
REM Elevation of the sun at which we start the instrumentation, -5 degrees so in radians 
elevsunstartinitnight=-0.087266

REM *****************************************************************
REM Modification to be able to test the script in the afternoon. PUT IN REM OTHERWISE
elevsunstartinitnight=1
REM 18 degrees below the horizon to start observing, -12 degrees, so 0.2094 radians
elevsunstartbegnight=-0.2094
REM elevsunstartbegnight=1
REM ***********************************
REM Opening the script file to be executed
REM ***********************************
print "please select the script for tonight"

REM opening the script file
GETFILENAME path$
REM Opening the text file
print "Opening " path$
Open_FileTxt_For_Read scriptfile path$




REM Asking to start or not the telescope
question$="Is the telescope already started ?"
getyesno question$ telescopeparked

Gosub beginnighttime:
Gosub endnighttime:

REM Computing the time till the end of the night
now date
timeleft=endofnighttime-date
frac timeleft time
observingtimeleft=time*24
observingtimeleftmin=observingtimeleft*60
print "Remaining observing time : " observingtimeleft " hours or : " observingtimeleftmin " minutes"
REM In the unlikely case the script is started way too late.
if observingtimeleft<0 then
   goto endnight:
endif

REM first we compute the sidereal time
Now date
datetostr date date$
REM This function gives the sidereal time in radians.
SIDERALTIME Date Longitude Tsl
Tsldeg=Tsl*TODEG
Tslhour=Tsl*3.8197186342054880584532103209403
print "Time is : " date$
print "Sidereal time in hours is : " Tslhour

REM at the beginning we recenter the scope, even if not specified
gosub recenterscope:

      
REM here we start reading the program for the night
nextsequence:

REM we print information about the moon.
Now Date
REM We check the position of the moon at the instant.
GetRaDecMoon Date AlphaMoonrad DeltaMoonrad ElevationMoonrad
AlphaMoondeg=AlphaMoonrad*TODEG
DeltaMoondeg=DeltaMoonrad*TODEG
ElevationMoondeg=ElevationMoonrad*TODEG
DATETOSTR Date Date$
print
if ElevationMoondeg<0 then
   print "It is " Date$ " and the moon is " ElevationMoondeg " degrees below the horizon"
else
   print "It is " Date$ " and the moon is " ElevationMoondeg " degrees above the horizon"
endif

REM now parsing the file
REM there are 4 options for the first line, it's either loop n (n cycles), or tilltime T (till such hour) or looptill starname sup H or looptill starname inf H
REM first case it will loop till the time has passed, or till such star is below or above such altitude
REM 7 options :
REM wait HH MM
REM loop n
REM observetill HH MM
REM observetillstar starname sup D
REM observetillstar starname inf D
REM recenterscope on or off
REM autoguide on or off






REM ***************************************************
REM parsing the first condition
REM ***************************************************
readnextline2:
ENDOFFILE scriptfile result
REM If we are not at the end of the file...
if result=FALSE then
   ReadFileTxt scriptfile loop$
   REM we split the line
   REM the first line has to be a condition
   cutstr loop$ " " 1 condition$
   
   REM ************************************************
   REM autoguide
   REM ************************************************
   if condition$="autoguide" then
      cutstr loop$ " " 2 autoguideonoroff$
      if autoguideonoroff$="on" then
         autoguide=TRUE
         print "Autoguiding will be performed on each exposure"
      else
         autoguide=FALSE
      endif
   REM we read the next empty line to be able to read the next instruction later
   ReadFileTxt scriptfile loop$
   goto readnextline2:
   endif
   
   REM ************************************************
   REM autorecenter
   REM ************************************************
   if condition$="recenterscope" then
      cutstr loop$ " " 2 recenteronoroff$
      if recenteronoroff$="on" then
         scoperecentering=TRUE
         print "The telescope will be recentered after each slewing to a new position"
      else
         scoperecentering=FALSE
      endif
   REM we read the next empty line to be able to read the next instruction later
   ReadFileTxt scriptfile loop$
   goto readnextline2:
   endif
   
   REM ************************************************
   REM WAIT
   REM ************************************************
   if condition$="wait" then
      REM we read the time till which we have to wait
      cutstr loop$ " " 2 waithour$
      cutstr loop$ " " 3 waitminute$
      print "The script is now going to wait till " waithour$ ":" waitminute$
      val waithour$ waithour
      val waitminute$ waitminute
      waithour=waithour+deltaUT
      if waithour>24 then
         waithour=waithour-24
      endif
      
      REM dayfrac is the fractional part of the day
      dayfrac=((waitminute/60)+waithour)/24
      now date
      frac date datefrac
      int date dateint
      enddate=dateint+dayfrac
      REM if we are before midnight and the time limit is the following day
      if datefrac>0.5 then
         if dayfrac<0.5 then
            enddate=dateint+dayfrac+1
         endif
      endif

      REM to debug
      REM print "date " date "enddate " enddate
      CONVERTDATETOJULIAN  enddate  JJenddate
      
      startwait:
      now date
      CONVERTDATETOJULIAN  date  JJdate
      if JJdate<JJenddate then
         REM waiting one minute
         NOW year month day hour minute seconde ms
         Delay 60000
         Print "It is now " hour ":" minute " continue waiting..."
         WaitForEndDelay
         goto startwait:
      else
         print "Ooops, wait finished, continuing with the script"
      endif   
   REM we read the next empty line to be able to read the next instruction later
   ReadFileTxt scriptfile loop$
   goto nextsequence:
   endif
   
   
   
   REM ************************************************
   REM OBSERVETILL
   REM ************************************************
   if condition$="observetill" then
      REM We read the time till which the sequence must be run and we observe it
      cutstr loop$ " " 2 numberofhours$
      val numberofhours$ numberofhours
      cutstr loop$ " " 3 numberofminutes$
      val numberofminutes$ numberofminutes
      numberofstarsinloop=0
      REM I take UT into account
      dayfrac=((numberofminutes/60)+numberofhours)/24
      REM CAUTION : if it is past midnight(UT) and the script ask to observe till 23h, it will.
      print
      print " We are going to observe the following sequence till " numberofhours$ ":" numberofminutes$
      
      readloop:
      ReadFileTxt scriptfile star$
      REM here we read the lines following the loop instructions, till we encounter an empty line.

      if star$<>"" then
         numberofstarsinloop=numberofstarsinloop+1
         REM we read a star name, the exposure time and the filter
         cutstr star$ " " 1 star[numberofstarsinloop]$
         cutstr star$ " " 2 exposuretime[numberofstarsinloop]$
         cutstr star$ " " 3 filter[numberofstarsinloop]$
         val exposuretime[numberofstarsinloop]$ exposuretime[numberofstarsinloop]
         print
         print star[numberofstarsinloop]$ " " exposuretime[numberofstarsinloop] " seconds with " filter[numberofstarsinloop]$ " filter"
         
         REM From the star name we get the RA and Dec
         for j=1 numberofstarsintargetlist
            if star[numberofstarsinloop]$=starname[j]$ then
               print "Star number " numberofstarsinloop " found, it is " starname[j]$ 
               RA[numberofstarsinloop]=starRA[j]
               Dec[numberofstarsinloop]=starDec[j]
               print "Star RA in decimal : " RA[numberofstarsinloop] " star Dec in decimal : " Dec[numberofstarsinloop]
               goto readloop:
            endif
         next j
      REM do something in case the star has not been found
      print "No stars have been found, check either target list or script file"
      endif


      if dayfrac>24 then
         dayfrac=dayfrac-24
      endif
      
      now date
      frac date datefrac
      int date dateint
      enddate=dateint+dayfrac
      REM if we are before midnight and the time limit is the following day
      if datefrac>0.5 then
         if dayfrac<0.5 then
            enddate=dateint+dayfrac+1
         endif
      endif

      REM to debug
      REM print "date " date "enddate " enddate
      CONVERTDATETOJULIAN  enddate  JJenddate
      
      DATETOSTR  date  date$
      DATETOSTR  enddate  enddate$
      print
      CONVERTDATETOJULIAN  date  JJdate
      if JJdate>JJenddate then
         print " We are past the requested date, executing next sequence"
         goto readnextline2:
      else 
         print "**********************************************************************"
      endif


      
      REM now we loop through the cycle till enddate is met.
      starttilltime:
      now date
      datetostr date date$
      CONVERTDATETOJULIAN  date  JJdate
      if JJdate<JJenddate then
         print
         print "************************************************************************************"
         print "It is " date$ " we continue till " enddate$
         gosub expose:
      REM checking if the time limit has passed
      goto starttilltime:
      else
         print "time is up, next sequence"
      endif
      
      REM Stopping autoguiding
      if autoguide=TRUE then
         StopGuide_Ex 2 1
      endif
      REM we read the next empty line to be able to read the next instruction later
   ReadFileTxt scriptfile loop$
   goto nextsequence:
   endif




   REM ************************************************
   REM LOOP
   REM ************************************************

   REM we found a loop where we are going to make a sequence numberofcycle times
   if condition$="loop" then
      REM We read the number of time the sequence must be made and we make it
      cutstr loop$ " " 2 numberofcycles$
      val numberofcycles$ numberofcycles
      print "We will run the following cycle " numberofcycles " times"
      REM we read the stars to be observed during this cycle and increment the number of stars
      numberofstarsinloop=0
      readloop2:
      ReadFileTxt scriptfile star$
      REM here we read the lines following the loop instructions, till we encounter an empty line.
      if star$<>"" then
         numberofstarsinloop=numberofstarsinloop+1
         REM we read a star name, the exposure time and the filter
         cutstr star$ " " 1 star[numberofstarsinloop]$
         cutstr star$ " " 2 exposuretime[numberofstarsinloop]$
         cutstr star$ " " 3 filter[numberofstarsinloop]$
         val exposuretime[numberofstarsinloop]$ exposuretime[numberofstarsinloop]
         print star[numberofstarsinloop]$ " " exposuretime[numberofstarsinloop] " seconds with " filter[numberofstarsinloop]$ " filter"
         REM From the star name we get the RA and Dec
         for j=1 numberofstarsintargetlist
            print "star[numberofstarsinloop]$" star[numberofstarsinloop]$
            print "starname[j]$" starname[j]$
            if star[numberofstarsinloop]$=starname[j]$ then
               print "star number " numberofstarsinloop " found, it is " star[numberofstarsinloop]$
               RA[numberofstarsinloop]=starRA[j]
               Dec[numberofstarsinloop]=starDec[j]
               print "star RA in decimal : " RA[numberofstarsinloop] " star Dec in decimal : " Dec[numberofstarsinloop]
               goto readloop2:
            endif
         next j
      REM do something in case the star has not been found
      endif
      REM now we loop numberofcycles time, moving the telescope, exposing, saving the image, moving the telescope, etc...
      for i=1 numberofcycles
         gosub expose:
      next i
   REM we read the next empty line to be able to read the next instruction later
   ReadFileTxt scriptfile loop$
   goto nextsequence:
   endif



   REM ************************************************
   REM LOOPTILL
   REM ************************************************
   REM looptill starname sup H or looptill starname inf H
   if condition$="observetillstar" then
      REM We read the star name, the condition and the altitude
      REM the star must be in the target list file
      cutstr loop$ " " 2 starname$
      cutstr loop$ " " 3 inforsup$
      cutstr loop$ " " 4 limitheightdeg$
      val limitheightdeg$ limitheightdeg
      REM Extracting the useful information to obtain the condition of the loop.
      for j=1 numberofstarsintargetlist
         REM print "starname$ = " starname$ " starname[j] " starname[j]$
         if starname$=starname[j]$ then
            print
            print "The reference star is " starname[j]$ 
            RAref=starRA[j]
            Decref=starDec[j]
            radRAref=RAref*torad*15
            radDecref=Decref*torad
            REM print "star RA in decimal : " RAref " star Dec in decimal : " Decref
            NOW Date
            GETHEIGHT radRAref radDecref Date Longitude Latitude heightref
            RAD_TO_DEC heightref heightref$
            print "the star is at " heightref$
         endif
      next j
      
      if inforsup$="sup" then
      print "this current sequence will run while " starname$ " is above " limitheightdeg " degrees"
      PRINT "Star : " starname$ " is currently at : " heightref$ " degrees"
      print "Star RA in decimal : " RAref " star Dec in decimal : " Decref
      refstarabove=1
      else
      print "This current sequence will run while " starname$ " is below " limitheightdeg " degrees"
      PRINT "Star : " starname$ " is currently at :" heightref$
      print "Star RA in decimal : " RAref " star Dec in decimal : " Decref
      refstarabove=0      
      endif
      
      
      numberofstarsinloop=0
      readloop3:
      ReadFileTxt scriptfile star$
      REM here we read the lines following the loop instructions, till we encounter an empty line.
      if star$<>"" then
         numberofstarsinloop=numberofstarsinloop+1
         REM we read a star name, the exposure time and the filter
         cutstr star$ " " 1 star[numberofstarsinloop]$
         cutstr star$ " " 2 exposuretime[numberofstarsinloop]$
         cutstr star$ " " 3 filter[numberofstarsinloop]$
         val exposuretime[numberofstarsinloop]$ exposuretime[numberofstarsinloop]
         print
         print star[numberofstarsinloop]$ " : " exposuretime[numberofstarsinloop] " seconds with " filter[numberofstarsinloop]$ " filter"
         REM From the star name we get the RA and Dec
         for j=1 numberofstarsintargetlist
            if star[numberofstarsinloop]$=starname[j]$ then
               print "Star number " numberofstarsinloop " in the sequence is " star[numberofstarsinloop]$ 
               RA[numberofstarsinloop]=starRA[j]
               Dec[numberofstarsinloop]=starDec[j]
               print "star RA in decimal : " RA[numberofstarsinloop] " star Dec in decimal : " Dec[numberofstarsinloop]
               goto readloop3:
            endif
         next j
      REM do something in case the star has not been found
      endif

      REM now we loop through the cycle till the reference star is above or below the required altitude.
      checkaltitude:
      now date
      GETHEIGHT radRAref radDecref Date Longitude Latitude heightref
      degheightref=heightref*todeg
      print
      print star[numberofstarsinloop]$ " is at " degheightref " degrees of altitude"
      if refstarabove=1 then
         REM we check that the reference star is still above the reference height
         if degheightref<limitheightdeg then
            print "the reference star is now below the limit, moving to next sequence"
            goto nextsequence:
         endif
      else
         REM we check that the reference star is still below the reference height
         if degheightref>limitheightdeg then
            print "the reference star is now above the limit, moving to next sequence"
            goto nextsequence:
         endif
      endif
   gosub expose:
   goto checkaltitude:
   endif
   REM we read the next empty line to be able to read the next instruction later
   ReadFileTxt scriptfile loop$
   goto nextsequence:
endif   
   
   
   REM ************************************************
   REM End of the night
   REM ************************************************

   if condition$="end" then
      goto endprogram:
   endif

endprogram:
gosub endnight:
end


REM ************************************************
REM all the subroutines used by the script
REM ************************************************

expose:
for j=1 numberofstarsinloop
   REM we convert RA and Dec in radians
   RArad[j]=RA[j]*torad*15
   Decrad[j]=Dec[j]*torad
   RAD_TO_RA RArad[j] alpha$
   RAD_TO_DEC Decrad[j] delta$
   REM we check the observability, first height and air mass, then distance to the moon
   now Date
   GetHeight RArad[j] Decrad[j] Date Longitude Latitude height
   if height>minimumheight then
      REM the star is above minimumheight (15°) then we can observe it, provided the moon is not too far
      REM we check the distance of the moon to the star
      GETRADECMOON Date AlphaM DeltaM ElevationM
      DISTSKY AlphaM RArad[j] DeltaM Decrad[j] Distm
         if Distm>minimummoondistance then
            REM if there is only one star in the loop, no need to re point the telescope.
            if numberofstarsinloop=1 then
               if numberofimages[j]=0 then
                  REM everything is OK we can observe the star
                  REM Calculer la masse d'air
                  GETAIRMASS height airMass
                  print 
                  print "Exposing star " star[j]$ " for " exposuretime[j]$ " seconds using " filter[j]$ " filter"
                  print "Current air mass for this star : " airMass
                  print "Moving telescope to right ascension : " alpha$ " and declination : " delta$
                  MOVETELESCOPE RArad[j] Decrad[j]
                  Decdeg[j]=Decrad[j]*TODEG
                  WaitForEndMoveTelescope
                  REM if the option is on, we recenter the scope
                  if scoperecentering=TRUE then
                     gosub recenterscope:
                  endif
               endif
            else
               REM everything is OK we can observe the star
               REM Calculer la masse d'air
               GETAIRMASS height airMass
               print 
               print "Exposing star " star[j]$ " for " exposuretime[j]$ " seconds using " filter[j]$ " filter"
               print "Current air mass for this star : " airMass
               print "Moving telescope to right ascension : " alpha$ " and declination : " delta$
               MOVETELESCOPE RArad[j] Decrad[j]
               Decdeg[j]=Decrad[j]*TODEG
               WaitForEndMoveTelescope
               if scoperecentering=TRUE then
                  gosub recenterscope:
               endif
            endif
         REM we set the filter
         REM Filters C=1, B=6, V=11, I=16
         if filter[j]$="C" then
            setfilter 1
            print "Rotating to filter C"
         endif
         if filter[j]$="B" then
            setfilter 2
            print "Rotating to filter B"
         endif
         if filter[j]$="V" then
            setfilter 3
            print "Rotating to filter V"
         endif
         if filter[j]$="R" then
            setfilter 4
            print "Rotating to filter R"
         endif
         if filter[j]$="H" then
            setfilter 5
            print "Rotating to filter Halpha"
         endif

         REM Autoguiding
         if autoguide=TRUE then
            print "Starting autoguiding"
            StartGuide_Ex 2 1 GuidingExpTime 40 10 10 0.7 0.7 0.2 10 0.2 10 Decrad[j] 0 0 Valid message$
         endif

         REM Exposure
         val exposuretime[j]$ exposure
         exposureMS=1000*exposure
         print "Starting a " exposure " seconds exposure"
         startExposure exposureMS
         waitForEndExposure
         REM Recovering the image in order to save it
         getLastImageExposure img
         print "Exposure finished"

         REM calculating the image name
         REM the image name must be like name of the object, filter, exposure time and numberofimage
         str exposure exp$
         numberofimages[j]=numberofimages[j]+1
         str numberofimages[j] numberofimages$
         Nameimage$=star[j]$+"-"+filter[j]$+"-"+exp$+"s-"+numberofimages$
         
         savefit img nightdirectory$+Nameimage$
         print "Image " Nameimage$ " saved to disk"
         close img
      else
         REM the star is too close from the moon
         Distm=Distm*todeg
         print
         Print star[j]$ " is " Distm " degrees from the moon and can not be observed, we skip it"
      endif
   else
      REM the star is too low
      heightdeg=height*TODEG
      print 
      Print star[j]$ " is now at " heightdeg " degrees above the horizon, therefore too low, we skip it"
      
   endif
   REM we check if we have arrived at the end of the night
   timeleft=endofnighttime-date
   frac timeleft time
   observingtimeleft=time*24
   observingtimeleftmin=observingtimeleft*60
   if observingtimeleftmin<2 then
      REM we have arrived at the end of the night, we go out of the loop and close the telescope
      goto endnight:
   endif
REM if there are several stars and if the autoguiding is working, we have to stop autoguiding between each repointing.
   if autoguide=TRUE then
      if numberofstarsinloop>1 then
         StopGuide_Ex 2 1
      endif
   endif

next j
      
return




beginnighttime:
REM *******************************************************
REM Initialisation of the night
REM *******************************************************
REM we wait till the sun is 5 degrees below the horizon, then we initialize mount and camera

REM if we are running into this the first time
Now Date
GETRADECSUN  Date  AlphaS  DeltaS  sunelevation
Datetostr Date Date$
RAD_TO_DEC sunelevation ElevationS$
if sunelevation>0
   position$="above"
else
   position$="below"
endif
print "It is : " Date$ " the sun is at " ElevationS$ " degrees " position$ " the horizon"
if sunelevation>elevsunstartinitnight
Print "Waiting one minute..."
   delay 60000
   WAITFORENDDELAY
   goto beginnighttime:
endif
print "The sun is now " ElevationS$ " degrees below horizon, starting up camera and mount"
REM in theory, it would be nice to check the temperature of the camera, either directly or by leaving a given amount of time after this step.
REM to be done later.


REM *******************************************************
REM Initialisation of camera and telescope
REM *******************************************************
if telescopeparked=0 then
   REM on the 135mm telephoto lens, there is no dome to open, I left the lines which would be useful in REM
   REM print "Opening the dome, please wait...."
   REM execexternal "C:\Chile_dome\domecontrol\openclose\opendome.exe" ""
   REM delay 18000
   REM waitforenddelay
   gosub init_camera:
   gosub init_telescope:
   print "Camera and telescope started, waiting for the night to be dark"
else
   REM The telescope was already started, but we still make sure it is in the right configuration
   Detector_number=1
   REM to be changed too...
   nbinning=1
   SetBinningX nBinning
   SetBinningY nBinning
   REM to be tested
   REM SetWindow 37 22 4132 4117
   REM going down in temperature, minutestogodowntotemp minutes to go down to -30°C*
   for i=1 to minutestogodowntotemp
      GETCCDTEMPERATURE  Detector_number  Starttemperature
      print "Current temperature : " Starttemperature
      deltaT=Detectortemperature-Starttemperature
      deltaTperminute=deltaT/minutestogodowntotemp
      Currenttemperature=Starttemperature+(deltaTperminute*i)
      round Currenttemperature Currenttemperature
      print "Going from " Starttemperature " to " Detectortemperature " we need to cool " deltaTperminute " degrees per minute"
      if Currenttemperature<Detectortemperature+2 then
         goto endcooling2:
      else
         SETCCDTEMPERATURE Detector_number Currenttemperature
         print i " minute, CCD going down to " Currenttemperature " degrees"
         delay 60000
         waitforenddelay
      endif
   next i
   endcooling2:
SETCCDTEMPERATURE Detector_number Detectortemperature   
endif
   REM We now wait for the sun to be below 15°, then start observing.
waittillstarttime:
REM if we are running into this the first time
Now Date
GETRADECSUN  Date  AlphaS  DeltaS  sunelevation
Datetostr Date Date$
RAD_TO_DEC sunelevation ElevationS$
if sunelevation>0
   position$="above"
else
   position$="below"
endif
print "It is : " Date$ " the sun is at " ElevationS$ " degrees " position$ " the horizon"
if sunelevation>elevsunstartbegnight
print "Waiting one minute..."
   delay 60000
   WAITFORENDDELAY
   goto waittillstarttime:
endif
print "The sun is now " ElevationS$ " degrees below horizon, starting the observations"
REM putting the telescope back in tracking mode
if telescopeparked=0 then
   RETURN_TELESCOPE_TO_SIDEREAL
endif
return



REM ***************************************************
REM Computing the end of night time.
REM ***************************************************
endnighttime:
REM first check if we are past noon or not.

now year month day hour minute second  MS

REM if past noon we calculate the end of the following night
REM and we put the hours at 4 to start iteration

if hour>12 then
   day=day+1
   endif   
   hour=6

   ENCODEDATETIME  year month day hour minute second MS  Date
begincomputeendnight:
REM 0.003472=5 minutes, we iterate 5 minutes after 5 minutes and calculate sun height
date=date+0.003472

GETRADECSUN  date  AlphaS  DeltaS  sunelevation
sunelevationdeg=sunelevation*180/pi
REM DateToStr date date$
REM print "date = " date$ " sun elevation = " sunelevationdeg
if sunelevationdeg<(-12) then
   goto begincomputeendnight:
endif
endofnighttime=date
DATETOSTR endofnighttime endofnighttime$
print "End of night is : " endofnighttime$ " UT at sun elevation : " sunelevationdeg " degrees"

REM We have the time of the end of the night, so we can get back
return



REM ***************************************************
REM Recentering the telescope on the field
REM ***************************************************
recenterscope:
REM the telescope is started, we aim a given zone, take an image and resynch the scope.
REM at the beginning we suppose that in the park position, the telescope is aiming at the sky
REM i.e. that the dome is not covering the telephoto lens
print "Finding the position of the telescope in the sky, taking a short centering exposure"
setfilter 1
GET_TELESCOPE_POSITION_APP ADAPP DECAPP
STR_RAD_TO_RA ADAPP HH$ MM$ SS$
STR_RAD_TO_DEC DECAPP DD$ DM$ DS$
PRINT "The telescope is at RA : " HH$ "h " MM$ "m " SS$ "s and declination : " DD$ "° " DM$ "' " DS$ "''"
nbinning=1
SetBinningX_Ex 1 nBinning
SetBinningY_Ex 1 nBinning
REM with the 135mm telephoto lens, the full frame is too large a field for the auto centering to work correctly, so I take the center quarter of the field
SetWindow_Ex 1 1503 1002 2505 1670
startExposure shortExptimeMS
waitForEndExposure
REM Recovering the image
getLastImageExposure img
print "recentering exposure done"
print "finding the position of the telescope in a large field"
FIND_ALLSKY_POSITION img 40 40 5 Cat$ Valid
if Valid=1 then
   GET_TELESCOPE_POSITION_APP ADAPP2 DECAPP2   
   STR_RAD_TO_RA ADAPP2 HH$ MM$ SS$
   STR_RAD_TO_DEC DECAPP2 DD$ DM$ DS$
   PRINT "The telescope is at RA : " HH$ "h " MM$ "m " SS$ "s and declination : " DD$ "° " DM$ "' " DS$ "''"

   getalpha img centrealpha
   getdelta img centredelta
   CALIBRATE_TELESCOPE centrealpha centredelta
   Print "Successful recalibration of the telescope."
   RAD_TO_RA centrealpha centrealpha$
   RAD_TO_DEC centredelta centredelta$
   print "the telescope is at : " centrealpha$ " and declination : " centredelta$
   offsetalpha=(centrealpha-adapp)*todeg*3600
   offsetdelta=(centredelta-decapp)*todeg*3600
   print "the telescope was off by " offsetalpha " '' in RA and " offsetdelta " '' in declination"
else
   print "serious problem, field not identified"
   print "press a key to continue"
   pause
endif
close img


nbinning=1
SetBinningX_Ex 1 nBinning
SetBinningY_Ex 1 nBinning
SetWindow_Ex 1 1 1 4008 2672
return


REM *******************************************************
REM Subroutine to initialize the camera, contains informations and settings of the camera
REM *******************************************************

init_camera:
REM We start the camera
print "Connecting the camera"
Detector_number=1
cameraerror$=""
INIT_CCD_CAMERA_EX  Detector_number Valid  cameraerror$
if Valid=2 then
   nbinning=1
   SetBinningX nBinning
   SetBinningY nBinning
   REM modif SetWindow 37 22 4132 4117
   REM going down in temperature, minutestogodowntotemp minutes to go down to -30°C
   goto endcooling1:
   for i=1 to minutestogodowntotemp
      GETCCDTEMPERATURE  Detector_number  Starttemperature
      deltaT=Detectortemperature-Starttemperature
      deltaTperminute=deltaT/minutestogodowntotemp
      print "Going from " Starttemperature " to " Detectortemperature " we need to cool " deltaTperminute " degrees per minute"
      Currenttemperature=Starttemperature+(deltaTperminute*i)
      round Currenttemperature Currenttemperature
      if Currenttemperature<Detectortemperature+2 then
         goto endcooling1:
      else
      SETCCDTEMPERATURE Detector_number Currenttemperature
      print i " minute, CCD going down to " Currenttemperature " degrees"
      delay 60000
      waitforenddelay
      endif
   next i
endcooling1:
SETCCDTEMPERATURE Detector_number Detectortemperature   
else
REM The camera didn't initialize correctly
   print cameraerror$
endif   


REM We initialize the guiding camera
REM in my system, the guiding camera is not cooled. If it were it would be better to modify the loop above to take both cameras into account
REM loop above means the loop starting by    for i=1 to minutestogodowntotemp

print "Connecting the guiding camera"
Detector_number=2
cameraerror$=""
INIT_CCD_CAMERA_EX  Detector_number Valid  cameraerror$
if Valid=2 then
   nbinning=1
   SetBinningX nBinning
   SetBinningY nBinning
else
REM The camera didn't initialize correctly
   print cameraerror$
endif   

return



REM *******************************************************
REM Initializing the telescope
REM *******************************************************
init_telescope:
print "Connecting to the telescope"
OPEN_TELESCOPE_DEVICES 0 0
unpark_telescope
REM we stop sideral tracking in the mean time 
print "stopping the sidereal tracking..."
stoptelescope
return

REM *******************************************************
REM Here we measure the temperature (have to see how) and set focus accordingly
REM *******************************************************
REM this means we will have to determine an equation giving focus position versus ambient temperature
REM for now this function does nothing
checkfocus:
return


REM ************************************************
REM End of night, closing telescope, camera, etc...
REM ***********************************************
endnight:
REM We have to see how to bring the camera back to ambient temperature before closing it.
print "Observing is finished, so closing the telescope..."
REM saving the last preprocessed image, if any


REM Stopping autoguiding before anything.
if autoguide=TRUE then
   StopGuide_Ex 2 1
endif




REM Closing the telescope
print "parking telescope, please wait"
REM print "start the script again if you want to continue..."
REM pause
REM modif need to change the values according to the park position
park_telescope 3.115 -1.18246
CLOSE_TELESCOPE_DEVICES

print "Waiting 15 minutes for the camera to warm up"
REM going up in temperature, minutestogodowntotemp minutes to go back to 0°C
REM going up in temperature, 15 minutes to go back to 0°C
   for i=1 to minutestogodowntotemp
      GETCCDTEMPERATURE  Detector_number  Starttemperature
      deltaTperminute=Starttemperature/minutestogodowntotemp
      abs deltaTperminute deltaTperminute
      delay 60000
      waitforenddelay
      Currenttemperature=Starttemperature+(deltaTperminute*i)
      round Currenttemperature Currenttemperature
      SETCCDTEMPERATURE Detector_number Currenttemperature
      print i " minute, CCD going up to " Currenttemperature " degrees"
   next i

   SETCCDTEMPERATURE 1 0

CLOSE_CCD_CAMERA_EX 1
REM in this script, the guiding camera is not cooled, so we don't go through a cooling sequence.
REM if you guiding camera is cooled, you have to modify the cooling sequence to work on both camera
CLOSE_CCD_CAMERA_EX 2


REM on the 135mm telephoto lens, the PC can not close the dome, it's done automatically by the C14 PC.

REM print "Closing the dome...."
REM ExecProcess processpath$ parameter$ TimeOutSec SuccessStatus ExitCode
REM execexternal "C:\Chile_dome\domecontrol\openclose\closedome.exe" ""
REM delay 20000
REM waitforenddelay
end
return
Attachments
Variable Star Observations.txt
(37.47 KiB) Downloaded 11 times
Hamza Touhami | Site Administrator
Hyperion-Astronomy.com
Post Reply