Index: /trunk/tools/heathers_plots/alpha/README
===================================================================
--- /trunk/tools/heathers_plots/alpha/README	(revision 35198)
+++ /trunk/tools/heathers_plots/alpha/README	(revision 35198)
@@ -0,0 +1,30 @@
+this is how I make my plots...
+
+Step 1: on ippc18 get whatever has been processed in LAP label for addstar etc:
+
+mysql -h ippdb01 -u ipp -pipp gpc1 < grab_cam_LAP.sql > cam.20130215.txt
+mysql -h ippdb01 -u ipp -pipp gpc1 < grab_skycal_LAP.sql > skycal.20130215.txt
+
+Step 2: rsync those files back home:
+
+rsync -rvua skycal.20130215.txt heather@canoes:
+rsync -rvua cam.20130215.txt heather@canoes:
+
+Step 3: parse the .txt files to something for my script:
+
+perl mangle.LAP.cam.pl cam.20130215.txt > cam.20130215.mng
+perl mangle.LAP.cam.pl skycal.20130215.txt > skycal.20130215.mng
+
+(yes, same perl script for both)
+
+Step 4: edit plot.cam.py and plot.sky.py to use the correct input files and make the correct output files
+
+Step 5: run plot.cam.py and plot.sky.py
+
+python plot.cam.py
+python plot.sky.py
+
+Step 6: look at plots :)
+
+(see http://svn.pan-starrs.ifa.hawaii.edu/trac/ipp/wiki/AddStarLap20120706)
+
Index: /trunk/tools/heathers_plots/alpha/grab_cam_LAP.sql
===================================================================
--- /trunk/tools/heathers_plots/alpha/grab_cam_LAP.sql	(revision 35198)
+++ /trunk/tools/heathers_plots/alpha/grab_cam_LAP.sql	(revision 35198)
@@ -0,0 +1,1 @@
+select ra,decl, addRun.state, addProcessedExp.fault from addRun left join addProcessedExp using (add_id) join camRun on stage_id = cam_id join chipRun using (chip_id) join rawExp using (exp_id) where stage = 'cam' and addRun.dvodb = 'LAP.20120706';
Index: /trunk/tools/heathers_plots/alpha/grab_skycal_LAP.sql
===================================================================
--- /trunk/tools/heathers_plots/alpha/grab_skycal_LAP.sql	(revision 35198)
+++ /trunk/tools/heathers_plots/alpha/grab_skycal_LAP.sql	(revision 35198)
@@ -0,0 +1,1 @@
+select radeg*3.1415927/180., decdeg*3.1415927/180., addRun.state, addProcessedExp.fault FROM    addRun left join addProcessedExp using (add_id) join    skycalRun on skycal_id = stage_id JOIN skycalResult using (skycal_id) JOIN staticskyInput using (sky_id, stack_id) JOIN staticskyRun using (sky_id) JOIN stackRun using (stack_id)  JOIN skycell using (tess_id, skycell_id) where stage = 'skycal' and addRun.dvodb = 'LAP.20120706' 
Index: /trunk/tools/heathers_plots/alpha/mangle.LAP.cam.pl
===================================================================
--- /trunk/tools/heathers_plots/alpha/mangle.LAP.cam.pl	(revision 35198)
+++ /trunk/tools/heathers_plots/alpha/mangle.LAP.cam.pl	(revision 35198)
@@ -0,0 +1,38 @@
+#!/usr/bin/env perl
+
+#this script expects ra dec state fault
+
+#state 0 - full and no fault
+#state 1 - new and pending
+#state 2 - faulted somehow
+
+
+
+
+while (<>) {
+    if ($_ =~ 'ra') { next;}
+ my @split = split /\s+/, $_;
+ if ($split[2] =~ 'full') {
+     if ($split[3] == 0) {
+	 $state = 0;
+     } else {
+	 $state = 2; 
+     }
+ } else {
+     #assume it is 'new'
+     if ($split[3] =~ 'NULL') {
+	 $state = 1;
+     } else {
+	 $state = 2;
+     }
+     
+ }
+
+ $ra = $split[0]*180/3.1415927;
+ $dec = $split[1]*180/3.1415927;
+
+
+    print "$ra $dec $state\n";
+
+ 
+}
Index: /trunk/tools/heathers_plots/alpha/plot.cam.py
===================================================================
--- /trunk/tools/heathers_plots/alpha/plot.cam.py	(revision 35198)
+++ /trunk/tools/heathers_plots/alpha/plot.cam.py	(revision 35198)
@@ -0,0 +1,36 @@
+import numpy as np
+#np.seterr("raise")
+import matplotlib.pyplot as plt
+import matplotlib as mpl
+from pylab import *
+filename = 'cam.20130219.mng'
+
+stuff = np.loadtxt(filename,usecols=(0,1,2),dtype = [('f0','<f8'),('f1','<f8'),('f2','<f8')], unpack = False)
+ra = stuff['f0']
+dec = stuff['f1']
+colorind = stuff['f2']
+colorsind = range(len(colorind))
+colors = []
+for i in xrange(len(colorsind)):
+ temp = colorsind[i] 
+ if (colorind[i] == 0  ) :
+    colors.append('#00FF00')
+ elif (colorind[i] == 1  ):
+    colors.append('#0033CC')
+ elif (colorind[i] == 2  ):
+    colors.append('#FF0000')
+ else:
+    colors.append('#FF0000')
+deg2rad = pi/180.
+
+fig=plt.figure()
+ax= subplot(111, projection="hammer")
+ax.scatter(pi-ra*deg2rad,dec*deg2rad,c=colors,lw=0, s=1)
+ax.set_xlim(0,360*deg2rad)
+ax.set_title("addstar : camera stage")
+ax.grid(True)
+ax.yaxis.set_ticklabels(['',''])
+ax.xaxis.set_ticklabels(['',''])
+
+#ax.xaxis.set_ticklabels(['22h', '20h', '18h','16h','14h','12h','10h','08h','06h','04h','02h'])
+plt.savefig('cam.20130219.png', dpi=100, facecolor="white", edgecolor="white")
Index: /trunk/tools/heathers_plots/alpha/plot.sky.py
===================================================================
--- /trunk/tools/heathers_plots/alpha/plot.sky.py	(revision 35198)
+++ /trunk/tools/heathers_plots/alpha/plot.sky.py	(revision 35198)
@@ -0,0 +1,36 @@
+import numpy as np
+#np.seterr("raise")
+import matplotlib.pyplot as plt
+import matplotlib as mpl
+from pylab import *
+filename = 'skycal.20130219.mng'
+
+stuff = np.loadtxt(filename,usecols=(0,1,2),dtype = [('f0','<f8'),('f1','<f8'),('f2','<f8')], unpack = False)
+ra = stuff['f0']
+dec = stuff['f1']
+colorind = stuff['f2']
+colorsind = range(len(colorind))
+colors = []
+for i in xrange(len(colorsind)):
+ temp = colorsind[i] 
+ if (colorind[i] == 0  ) :
+    colors.append('#00FF00')
+ elif (colorind[i] == 1  ):
+    colors.append('#0033CC')
+ elif (colorind[i] == 2  ):
+    colors.append('#FF0000')
+ else:
+    colors.append('#FF0000')
+deg2rad = pi/180.
+
+fig=plt.figure()
+ax= subplot(111, projection="hammer")
+ax.scatter(pi-ra*deg2rad,dec*deg2rad,c=colors,lw = 0, s=1)
+ax.set_xlim(0,360*deg2rad)
+ax.set_title("addstar : skycal stage")
+ax.grid(True)
+ax.yaxis.set_ticklabels(['',''])
+ax.xaxis.set_ticklabels(['',''])
+
+#ax.xaxis.set_ticklabels(['22h', '20h', '18h','16h','14h','12h','10h','08h','06h','04h','02h'])
+plt.savefig('skycal.20130219.png', dpi=100, facecolor="white", edgecolor="white")
Index: /trunk/tools/heathers_plots/heathers_plots.py
===================================================================
--- /trunk/tools/heathers_plots/heathers_plots.py	(revision 35198)
+++ /trunk/tools/heathers_plots/heathers_plots.py	(revision 35198)
@@ -0,0 +1,126 @@
+#!/usr/bin env python
+
+"""
+
+This script runs on ippc11 once a day at 7:00 HST under the ipp account
+
+"""
+
+import MySQLdb
+import numpy as np
+import matplotlib as mpl
+import matplotlib.pyplot as plt
+import pylab
+import math 
+import datetime 
+import os 
+
+class HeathersPlot:
+    """No need for a class here but I'm too lazy to reimplement it
+    """
+
+    COLORS = ['#00FF00', '#0033CC', '#FF0000']
+
+    IMAGES_DIRECTORY = "/data/ipp009.0/czartool_plots/heathers_plots"
+    CAM_WEB_FILENAME = "/data/ipp009.0/czartool_plots/heathers_plots/cam.png"
+    SKYCAL_WEB_FILENAME = "/data/ipp009.0/czartool_plots/heathers_plots/skycal.png"
+
+    def __init__(self):
+        self.db = MySQLdb.connect("ippdb01", "ipp", "ipp", "gpc1")
+
+    CAM_STATEMENT ="""SELECT ra, decl, addRun.state, addProcessedExp.fault 
+FROM addRun 
+ LEFT JOIN addProcessedExp USING(add_id) 
+ JOIN camRun ON stage_id = cam_id 
+ JOIN chipRun USING(chip_id) 
+ JOIN rawExp USING(exp_id)
+WHERE stage = 'cam' and addRun.dvodb = 'LAP.20120706'
+"""
+    SKYCAL_STATEMENT = """SELECT radeg*3.1415927/180., decdeg*3.1415927/180., addRun.state, addProcessedExp.fault 
+FROM addRun
+ LEFT JOIN addProcessedExp USING(add_id)
+ JOIN skycalRun ON skycal_id = stage_id
+ JOIN skycalResult USING (skycal_id)
+ JOIN staticskyInput USING (sky_id, stack_id)
+ JOIN staticskyRun USING (sky_id)
+ JOIN stackRun USING (stack_id)
+ JOIN skycell using (tess_id, skycell_id)
+WHERE stage = 'skycal' AND addRun.dvodb = 'LAP.20120706' 
+"""
+
+    def fetch_data(self, statement):
+        cursor = self.db.cursor()
+        cursor.execute(statement)
+        ras = [ ]
+        decs = [ ]
+        states = [ ]
+        for row in cursor.fetchall():
+            if row[2] == "full":
+                if row[3] == 0:
+                    state = 0
+                else:
+                    state = 2
+            else:
+                if row[3] is None:
+                    state = 1
+                else:
+                    state = 2
+            ras.append(row[0])
+            decs.append(row[1])
+            states.append(state)
+        return (ras, decs, states)
+
+    def plot(self, _ras, _decs, states, stage):
+        today = datetime.date.today().isoformat()
+        output_filename = '%s/%s.%s.png' % (HeathersPlot.IMAGES_DIRECTORY, stage, today)
+        ras = np.array(_ras)
+        decs = np.array(_decs)
+        colors = [ ]
+        for state in states:
+            colors.append(HeathersPlot.COLORS[state])
+        fig = plt.figure()
+        ax = pylab.subplot(111, projection="hammer")
+        ax.scatter(math.pi-ras, decs, c = colors, lw=0, s=1)
+        ax.set_xlim(0, 2*math.pi)
+        ax.set_title("addstar: %s stage - %s" % (stage, today))
+        ax.grid(True)
+        ax.yaxis.set_ticklabels(['',''])
+        ax.xaxis.set_ticklabels(['',''])
+        #Heather doesn't like this: ax.xaxis.set_ticklabels(['22h', '20h', '18h','16h','14h','12h','10h','08h','06h','04h','02h'])
+        plt.savefig(output_filename, dpi=100, facecolor="white", edgecolor="white")
+        return output_filename
+
+    def relink_webfiles(self, web_filename, new_filename):
+        print "Have to replace %s by %s" % (web_filename, new_filename)
+        try:
+            os.unlink(web_filename)
+        except OSError: # No such file or directory
+            pass
+        os.symlink(new_filename, web_filename)
+
+    @staticmethod
+    def mkdir(dirname):
+        try:
+            os.makedirs(dirname)
+        except OSError, e:
+            if str(e).startswith("[Errno 17] File exists"):
+                pass
+            else:
+                raise e
+
+    def update_cam_plot(self):
+        HeathersPlot.mkdir(HeathersPlot.IMAGES_DIRECTORY)
+        (ras, decs, states) = self.fetch_data(HeathersPlot.CAM_STATEMENT)
+        new_filename = self.plot(ras, decs, states, 'Camera')
+        self.relink_webfiles(HeathersPlot.CAM_WEB_FILENAME, new_filename)
+
+    def update_skycal_plot(self):
+        HeathersPlot.mkdir(HeathersPlot.IMAGES_DIRECTORY)
+        (ras, decs, states) = self.fetch_data(HeathersPlot.SKYCAL_STATEMENT)
+        new_filename = self.plot(ras, decs, states, 'SkyCal')
+        self.relink_webfiles(HeathersPlot.SKYCAL_WEB_FILENAME, new_filename)
+
+if __name__ == "__main__":
+    hp = HeathersPlot()
+    hp.update_cam_plot()
+    hp.update_skycal_plot()
