Skip to content

Commit efa1cd4

Browse files
committed
first commit. think i have the two packages imported into one namespace.
0 parents  commit efa1cd4

22 files changed

+1423
-0
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
pyvolib-svn-read-only
2+
vaods9-git-read-only
3+
.svn/
4+
*.pyc

CHANGES

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
CHANGES
2+
--------
3+
4+
Version 0.1.0
5+
6+
First public alpha release

INSTALL

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Installing coatpy
2+
+++++++++++++++++
3+
4+
Prerequisites
5+
=============
6+
7+
coatpy requires
8+
9+
Installation
10+
============
11+
12+
To install coatpy, simply run:
13+
14+
python setup.py install

LICENSE

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
coatpy - collection of online astronomy tools in python
2+
Copyright (c) 201? Many
3+
4+
Permission is hereby granted, free of charge, to any person obtaining a
5+
copy of this software and associated documentation files (the "Software"),
6+
to deal in the Software without restriction, including without limitation
7+
the rights to use, copy, modify, merge, publish, distribute, sublicense,
8+
and/or sell copies of the Software, and to permit persons to whom the
9+
Software is furnished to do so, subject to the following conditions:
10+
11+
The above copyright notice and this permission notice shall be included in
12+
all copies or substantial portions of the Software.
13+
14+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20+
DEALINGS IN THE SOFTWARE.

MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include CHANGES INSTALL LICENSE README

README

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Introduction
2+
++++++++++++
3+
4+
coatpy is a package wrapper around a number of other python
5+
modules for accessing and working with online astronomy data
6+
and the tools and formats of the virtual observatory
7+
astronomical data in a uniform way.
8+

coatpy/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from volib import *
2+
from volib import utils
3+
from vaods9 import Client as vaods9

coatpy/vaods9.py

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
import sampy
2+
import urlparse
3+
import os
4+
5+
def ds9echo(response):
6+
print response
7+
8+
class Client(sampy.SAMPIntegratedClient):
9+
10+
def __init__(self,
11+
name="VAO Python Client",
12+
description="An interactive SAMP client for Python by the Virtual Astronomical Observatory", version="0.0.1"):
13+
self.metadata = {"samp.name": name, "samp.description.text": description, "client.version": version}
14+
sampy.SAMPIntegratedClient.__init__(self)
15+
self.do_close_hub = False
16+
if len(self.hub.getRunningHubs()) == 0:
17+
self.samp_hub = sampy.SAMPHubServer()
18+
self.samp_hub.start()
19+
self.do_close_hub = True
20+
self.connect()
21+
self.declareMetadata(self.metadata)
22+
23+
def set(self, cmd, url=""):
24+
message = {"samp.mtype": "ds9.set", "samp.params":{"cmd": cmd, "url":url}}
25+
self.callAll("vaods9set", message)
26+
27+
def get(self, cmd, url="", tag="vaods9get", function=ds9echo):
28+
self.bindReceiveResponse(tag, self.handler_wrapper)
29+
self.handler = function
30+
message = {"samp.mtype": "ds9.get", "samp.params":{"cmd": cmd, "url":url}}
31+
self.callAll(tag, message)
32+
33+
def get_now(self, cmd, url="", tag="vaods9getnow", timeout=1000):
34+
message = {"samp.mtype": "ds9.get", "samp.params":{"cmd": cmd, "url":url}}
35+
try:
36+
response = self.callAndWait(self.ds9_hook, message, timeout)
37+
return response['samp.result']['value']
38+
except:
39+
pass
40+
41+
def basic_handler(self, private_key, sender_id, msg_id, response):
42+
self.last_response = response['samp.result']['value']
43+
44+
def basic_get(self, cmd, url=""):
45+
self.bindReceiveResponse("vaods9basicget", self.basic_handler)
46+
message = {"samp.mtype": "ds9.get", "samp.params":{"cmd": cmd, "url":url}}
47+
self.callAll("vaods9basicget", message)
48+
49+
def cleanup(self):
50+
self.disconnect()
51+
print "client disconnected"
52+
if self.do_close_hub:
53+
self.samp_hub.stop()
54+
55+
def handler_wrapper(self, private_key, sender_id, msg_id, response):
56+
ds9response = response['samp.result']['value']
57+
self.handler(ds9response)
58+
59+
def send(self, mtype, file_id, file_path):
60+
self.file_path = file_path
61+
message = {'samp.mtype': mtype,'samp.params': {'name': file_id, 'url': self.file_url}}
62+
self.callAll("vaods9send", message)
63+
64+
def send_votable(self, name, file_path):
65+
self.send('table.load.votable', name, file_path)
66+
67+
def send_fits_image(self, name, file_path):
68+
self.send('image.load.fits', name, file_path)
69+
70+
def send_fits_table(self, name, file_path):
71+
self.send('table.load.fits', name, file_path)
72+
73+
@property
74+
def file_url(self):
75+
url = urlparse.urlparse(self.file_path)
76+
if url.scheme == '' :
77+
abspath = os.path.abspath(self.file_path)
78+
return 'file://'+abspath
79+
return self.file_path
80+
81+
@property
82+
def ds9_hook(self):
83+
ds9_candidates = self.getSubscribedClients("ds9.get")
84+
if(len(ds9_candidates)==1):
85+
return ds9_candidates.keys()[0]
86+
if(len(ds9_candidates)>=2):
87+
print "Warning, more than one instance of DS9 found"
88+
return ds9_candidates.keys()[0]
89+
print "Error, couldn't find any DS9 instances running"
90+
91+

coatpy/volib/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from xparser import XParser, XNode
2+
from votable import VOTable
3+
from volib import ConeSearch, VOWebService
4+
from volib import Siap, Sesame
5+
import utils
6+
7+
__all__ = ["VOTable","ConeSearch","Siap","Sesame"]

coatpy/volib/utils/Coords.py

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
'''
2+
Created on Mar 9, 2011
3+
4+
Coordinates conversion functions
5+
6+
@author: shkwok
7+
'''
8+
9+
def any2Decimal (str1):
10+
'''
11+
Input str1 as dd:mm:ss
12+
outputs degree as decimal
13+
'''
14+
def split (inStr):
15+
'''
16+
Converts HH:MM:SS to (HH, MM, SS)
17+
'''
18+
str1 = inStr + " 0 0 0"
19+
str1 = str1.strip()
20+
out = str1.replace("h", " ").replace("m", " ").replace("s", " ").replace (":", " ").split(" ")
21+
return (out[0], out[1], out[2])
22+
23+
hh, mm, ss = split (str1)
24+
sign = 1.0
25+
if hh.startswith ('-'):
26+
sign = -1.0
27+
hh = hh.replace ('-', '')
28+
29+
try:
30+
hh = float (hh)
31+
mm = float (mm) / 60.0
32+
ss = float (ss) / 3600.0
33+
return sign * (hh + mm + ss)
34+
except:
35+
return 0
36+
37+
def sexaHour2Degree (str1):
38+
'''
39+
Converts sexagecimal hour to degree
40+
Returns degree
41+
'''
42+
return any2Decimal (str1) * 15.0
43+
44+
def degree2Sexagecimal (deg):
45+
'''
46+
Converts deg to dd:mm:ss.sss
47+
Returns a string
48+
'''
49+
if deg < 0:
50+
t = float (-deg)
51+
sign = '-'
52+
else:
53+
t = float (deg)
54+
sign = ''
55+
dd = int (t)
56+
t = (t - dd) * 60
57+
mm = int (t)
58+
ss = (t - mm) * 60
59+
60+
ssStr = "%.3f" % ss
61+
if int(float(ssStr)) == 60:
62+
ss = 0
63+
mm += 1
64+
if mm >= 60:
65+
mm = 0
66+
dd += 1
67+
68+
ssStr = "%.3f" % ss
69+
if float (ssStr) < 10:
70+
ssStr = '0' + ssStr
71+
72+
return "%s%02d:%02d:%s" % (sign, dd, mm, ssStr)
73+
74+
def hour2Sexagecimal (hour):
75+
'''
76+
Returns hour in sexagecimal string
77+
'''
78+
return degree2Sexagecimal(hour)
79+
80+
def normalize360 (deg):
81+
'''
82+
Returns normalized degree 0 to 360
83+
'''
84+
while deg < 0:
85+
deg += 360
86+
while deg >= 360:
87+
deg -= 360
88+
return deg
89+
90+
def normalize180 (deg):
91+
'''
92+
Returns normalized degree -180 to 180
93+
'''
94+
deg = normalize360(deg)
95+
if deg > 180:
96+
return deg - 360
97+
return deg

coatpy/volib/utils/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from Coords import *
2+
__all__ = ["any2Decimal", "split", "sexaHour2Degree", "degree2Sexagecimal",
3+
"hour2Sexagecimal", "normalize360", "normalize180"]

coatpy/volib/volib/ConeSearch.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
'''
2+
Created on Mar 15, 2011
3+
4+
Class to handle Cone Search according to NVO
5+
Based on version 2005-06-01 by Shui Hung Kwok
6+
7+
8+
@author: shkwok
9+
10+
'''
11+
12+
import sys
13+
#from VOWebService import VOWebService
14+
from . import VOWebService
15+
16+
class ConeSearch (VOWebService):
17+
18+
def __init__ (self, url=''):
19+
VOWebService.__init__ (self, url)
20+
21+
def buildQuery (self, parmList):
22+
mustParams = ["RA", "DEC", "SR"]
23+
for p in mustParams:
24+
if not p in parmList:
25+
raise Exception ("Parameter '%s' missing" % p)
26+
return VOWebService.buildQuery (self, parmList)
27+
28+
def output2CSV (self, votable, writer=sys.stdout.write):
29+
idOrName = votable.getIdOrName()
30+
fields = votable.getFields()
31+
buf = []
32+
for fd in fields:
33+
attrs = fd.getAttributes ()
34+
name = attrs.get (idOrName)
35+
buf.append(name)
36+
writer (",".join(buf))
37+
writer ("\n")
38+
rows = votable.getTableData ()
39+
for row in rows:
40+
flist = []
41+
cells = row.getChildren ("TD")
42+
for cell in cells:
43+
flist.append(cell.getContent ())
44+
writer (",".join(flist))
45+
writer ("\n")

0 commit comments

Comments
 (0)