Re: Filling in Degrees in a Circle (Astronomy)

2008-08-26 Thread Lie
On Aug 23, 6:12 am, "W. eWatson" <[EMAIL PROTECTED]> wrote:
> The other night I surveyed a site for astronomical use by measuring the
> altitude (0-90 degrees above the horizon) and az (azimuth, 0 degrees north
> clockwise around the site to 360 degrees, almost north again) of obstacles,
> trees. My purpose was to feed this profile of obstacles (trees) to an
> astronomy program that would then account for not sighting objects below the
> trees.
>
> When I got around to entering them into the program by a file, I found it
> required the alt at 360 azimuth points in order from 0 to 360 (same as 0).
> Instead I have about 25 points, and expected the program to be able to do
> simple linear interpolation between those.
>
> Is there some simple operational device in Python that would allow me to
> create an array (vector) of 360 points from my data by interpolating between
> azimuth points when necessary? All my data I rounded to the nearest integer.
> Maybe there's an interpolation operator?
>
> As an example, supposed I had made 3 observations: (0,0) (180,45) and
> (360,0). I would want some thing like (note the slope of the line from 0 to
> 179 is 45/180 or 0.25):
> alt: 0, 0.25, 0.50, 0.75, ... 44.75, 45.0
> az : 0, 1,    2,    3,              180
>
> Of course, I don't need the az.
>
> --
>             Wayne Watson (Watson Adventures, Prop., Nevada City, CA)
>
>               (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
>                Obz Site:  39° 15' 7" N, 121° 2' 32" W, 2700 feet
>
>                      Web Page: 

Linear interpolation is simple, any mathematician would know. It's
just like this:

hA = height at point A
hB = height at point B
hN = height at point N (what we're finding)
l = horizontal distance between A and B
n = horizontal position measured from A

hN = hA + ((n / l) * (hB - hA))

so:

def interpolate(n, A, B):
# A, B is two-tuple of (angle, height) of
# the nearest known points surrounding n
oA, hA = A
oB, hB = B
l = oB - oA
return hA + ((n / l) * (hB - hA))

--
http://mail.python.org/mailman/listinfo/python-list


Re: Filling in Degrees in a Circle (Astronomy)

2008-08-25 Thread Gerard flanagan

W. eWatson wrote:
The other night I surveyed a site for astronomical use by measuring the 
altitude (0-90 degrees above the horizon) and az (azimuth, 0 degrees 
north clockwise around the site to 360 degrees, almost north again) of 
obstacles, trees. My purpose was to feed this profile of obstacles 
(trees) to an astronomy program that would then account for not sighting 
objects below the trees.


When I got around to entering them into the program by a file, I found 
it required the alt at 360 azimuth points in order from 0 to 360 (same 
as 0). Instead I have about 25 points, and expected the program to be 
able to do simple linear interpolation between those.


Is there some simple operational device in Python that would allow me to 
create an array (vector) of 360 points from my data by interpolating 
between azimuth points when necessary? All my data I rounded to the 
nearest integer. Maybe there's an interpolation operator?


As an example, supposed I had made 3 observations: (0,0) (180,45) and 
(360,0). I would want some thing like (note the slope of the line from 0 
to 179 is 45/180 or 0.25):

alt: 0, 0.25, 0.50, 0.75, ... 44.75, 45.0
az : 0, 1,2,3,  180

Of course, I don't need the az.



Using one of the Python maths packages (scipy, sage, ...) is no doubt 
better, but out of interest here is some first-principles interpolation:


8<-

class NewtonInterpolatingPolynomial(object):

def __init__(self):
self._domain = []
self._codomain = []
self._diffs = None
self._coeffs = []

def add_data_point(self, x, y):
self._domain.append(x)
self._codomain.append(y)
if self._diffs is None:
self._diffs = {}
else:
degree = len(self._domain) - 2
_x = self._domain[-2]
_y = self._codomain[-2]
self._diffs[(degree, degree+1)] = (y - _y) / (x - _x)
indices = range(degree+2)
for t in ( tuple(indices[i:]) for i in 
reversed(indices[:-2]) ):

denominator = self._domain[t[0]] - self._domain[t[-1]]
k, _k = self._diffs[t[1:]], self._diffs[t[:-1]]
self._diffs[t] = (_k - k) / denominator
self._coeffs.append(self._diffs[tuple(indices)])

def __str__(self):
N = len(self._domain)
if not N:
return ''
parts = [str(self._codomain[0])]
multipliers = [''.join(('(X - ',str(C),')')) for C in 
self._domain[:-1]]

for i, k in enumerate(self._coeffs):
parts.append('*'.join([str(k)] + multipliers[:i+1]))
return ' + '.join(parts)

def interpolate(self, gamma):
#return eval(str(self).replace('X', str(gamma)))
ret = self._codomain[0]
K = 1
multipliers = [gamma-C for C in self._domain[:-1]]
for i, k in enumerate(multipliers):
K *= k
ret += self._coeffs[i] * K
return ret

def __call__(self, x):
return self.interpolate(x)


rawdata = '''
018
18   18
27   16
34   20
48   20
59  28
72  32
'''

data = [map(float, line.split() ) for line in rawdata.splitlines() if line]

newton = NewtonInterpolatingPolynomial()

for x, y in data:
newton.add_data_point(x, y)
print newton
for P in range(80):
print P, '-> ', newton(P)

18.0 + 0.0*(X - 0.0) + -0.0082304526749*(X - 0.0)*(X - 18.0) + 
0.00170098903759*(X - 0.0)*(X - 18.0)*(X - 27.0) + -8.87803681143e-05*(X 
- 0.0)*(X - 18.0)*(X - 27.0)*(X - 34.0) + 3.29057245545e-06*(X - 0.0)*(X 
- 18.0)*(X - 27.0)*(X - 34.0)*(X - 48.0) + -8.98633510787e-08*(X - 
0.0)*(X - 18.0)*(X - 27.0)*(X - 34.0)*(X - 48.0)*(X - 59.0)

0 ->  18.0
1 ->  26.0156268043
2 ->  31.8038369501
3 ->  35.719116702
4 ->  38.0797664434
5 ->  39.1701395406
6 ->  39.2428165062
7 ->  38.5207144606
8 ->  37.1991318912
9 ->  35.4477287116
10 ->  33.4124416172
11 ->  31.2173347409
12 ->  28.9663856061
13 ->  26.7452063785
14 ->  24.6227004166
15 ->  22.6526541194
16 ->  20.8752640745
17 ->  19.3185995022
18 ->  18.0
19 ->  16.9274085845
20 ->  16.1006400316
21 ->  15.5125845157
22 ->  15.1503465468
23 ->  14.996319206
24 ->  15.0291936797
25 ->  15.2249040921
26 ->  15.5575076355
27 ->  16.0
28 ->  16.525066101
29 ->  17.1057661048
30 ->  17.7161567532
31 ->  18.3318479864
32 ->  18.9304948638
33 ->  19.4922247833
34 ->  20.0
35 ->  20.4399154416
36 ->  20.8014318237
37 ->  21.0775440624
38 ->  21.2648849859
39 ->  21.3637643445
40 ->  21.3781431185
41 ->  21.3155431251
42 ->  21.1868919232
43 ->  21.0063030167
44 ->  20.7907913565
45

Re: Filling in Degrees in a Circle (Astronomy)

2008-08-24 Thread [EMAIL PROTECTED]
On Aug 23, 10:11 am, Scott David Daniels <[EMAIL PROTECTED]>
wrote:
> W. eWatson wrote:
> > ...
> > I'm working on this now, but my knowledge of python needs refreshing.
> > Right now I have a file of all the az,el data I've collected, and I'd
> > like to open it with Python for XP. However, Python doesn't like this:
>
> > junkfile = open('c:\tmp\junkpythonfile','w')
>
> > I get
> >     junkfile = open('c:\tmp\junkpythonfile','w')
> > IOError: [Errno 2] No such file or directory: 'c:\tmp\\junkpythonfile'
>
> > This problematic segment is just a hack of a similar statement which has
> > the same problem and a much longer path. I suspect the problem is with
> > the back slash.
>
> A standard windows error. note that '\t' is a tab, and I doubt you have
> a directory named   .  Get in the habit of _always_ using:
>     junkfile = open(r'c:\tmp\junkpythonfile','w')
> or
>     junkfile = open('c:\\tmp\\junkpythonfile','w')
> for file names.
>
> --Scott David Daniels
> [EMAIL PROTECTED]

Avoid backslashes whenever possible.
 junkfile = open('c:/tmp/junkpythonfile','w')
--
http://mail.python.org/mailman/listinfo/python-list


Re: Filling in Degrees in a Circle (Astronomy)

2008-08-24 Thread tom



http://matplotlib.sourceforge.net/

I'm using Python 2.4. The install looks pretty complicated for Windows. 
It doesn't seem like matplotlib is a module.




Maybe going with the enthought edition would be easiest for you as it is 
a very complete set of tools all in one package.  It's at 
http://www.enthought.com/products/epd.php


These are really nice tools for scientific (and other) data analysis, 
and are very competitive with most professional packages.  There are 
other bundles as well, like Sage.  I've always used enthought.


On the other hand, I think making tools that use these in a bundled exe 
might be more difficult, and if possible, might not be consistent with 
their license agreements, and might make for large packages.  I never 
really looked into this.


Also, with matplotlib, you might just try installing it without anything 
else and see how it goes.  Just download the exe and double-click, or 
the egg file and do whatever one does with those.  I bet it will work... 
I think it will just default to using Tk for the GUI, which you already 
have installed with Python, and it won't use agg (an anti-aliasing 
library), so your plots won't be quite as pretty.  But they'll still be 
nice, and it will likely work.




--
http://mail.python.org/mailman/listinfo/python-list


Re: Filling in Degrees in a Circle (Astronomy)

2008-08-24 Thread W. eWatson

David wrote:



What modules do I need to use pylab? I've installed scipy and numpy.



http://matplotlib.sourceforge.net/

I'm using Python 2.4. The install looks pretty complicated for Windows. It 
doesn't seem like matplotlib is a module.


--
   Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

 (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
  Obz Site:  39° 15' 7" N, 121° 2' 32" W, 2700 feet

Web Page: 
--
http://mail.python.org/mailman/listinfo/python-list


Re: Filling in Degrees in a Circle (Astronomy)

2008-08-24 Thread David



What modules do I need to use pylab? I've installed scipy and numpy.



http://matplotlib.sourceforge.net/

--
Have Fun,
David A.

Powered by Gentoo GNU/LINUX
http://www.linuxcrazy.com

--
http://mail.python.org/mailman/listinfo/python-list


Re: Filling in Degrees in a Circle (Astronomy)

2008-08-24 Thread Roel Schroeven

W. eWatson schreef:
I completed a Win Python program and it has generated the necessary data, 
which I have in turn used successfully with the telescope software. Is there 
some way to turn this into an executable program for people who do not have 
Python?


Yes, you can use py2exe (http://www.py2exe.org/) for that.

--
The saddest aspect of life right now is that science gathers knowledge
faster than society gathers wisdom.
  -- Isaac Asimov

Roel Schroeven
--
http://mail.python.org/mailman/listinfo/python-list


Re: Filling in Degrees in a Circle (Astronomy)

2008-08-23 Thread W. eWatson

tom wrote:

W. eWatson wrote:

tom wrote:

W. eWatson wrote:
The other night I surveyed a site for astronomical use by measuring 
the altitude (0-90 degrees above the horizon) and az (azimuth, 0 
degrees north clockwise around the site to 360 degrees, almost north 
again) of obstacles, trees. My purpose was to feed this profile of 
obstacles (trees) to an astronomy program that would then account 
for not sighting objects below the trees.


When I got around to entering them into the program by a file, I 
found it required the alt at 360 azimuth points in order from 0 to 
360 (same as 0). Instead I have about 25 points, and expected the 
program to be able to do simple linear interpolation between those.


Is there some simple operational device in Python that would allow 
me to create an array (vector) of 360 points from my data by 
interpolating between azimuth points when necessary? All my data I 
rounded to the nearest integer. Maybe there's an interpolation 
operator?


As an example, supposed I had made 3 observations: (0,0) (180,45) 
and (360,0). I would want some thing like (note the slope of the 
line from 0 to 179 is 45/180 or 0.25):

alt: 0, 0.25, 0.50, 0.75, ... 44.75, 45.0
az : 0, 1,2,3,  180

Of course, I don't need the az.




If I understand you right, I think using interpolation as provided by 
scipy would do what you need.


Here's an example:

from scipy.interpolate.interpolate import interp1d

angles = [0, 22, 47.5, 180, 247.01, 360]
altitudes = [18, 18, 26, 3, 5, 18]

desired_angles = range(0, 361)

skyline = interp1d(angles, altitudes, kind="linear")
vals = skyline(desired_angles)

# that is, vals will be the interpolated altitudes at each of the
# desired angles.

if 1:  # plot this out with matplotlib
import pylab as mx
mx.figure()
mx.plot(angles, altitudes, 'x')
mx.plot(desired_angles, vals)
mx.show()
I decided this morning and roll up my sleeves and write the program. I 
plan to take a deeper plunge in the next month than my so far erratic 
look over the last 18 or more months  It's working.


The above looks like it's on the right track. Is scipy some collection 
of astro programs? mx is a graphics character plot?


I just hauled it into IDLE and tried executing it.
from scipy.interpolate.interpolate import interp1d
ImportError: No module named scipy.interpolate.interpolate

Apparently, something is missing.

I posted a recent msg a bit higher that will probably go unnoticed, so 
I'll repeat most of it. How do I get my py code into some executable 
form so that Win users who don't have python can execute it?





Both scipy and matplotlib are not part of the standard Python 
distribution so they would need to be installed separately.  Scipy is 
useful for scientific data analysis, and matplotlib is useful for making 
plots.


Since you want to wrap everything into a  Windows executable, it's 
probably easiest for you not to use scipy.  At the least, I suspect it 
would make your executable file much larger, but I've never made a 
Windows executable so I don't know the details.


As for making an executable, I'm not the one to ask, but googling leads 
to this:
http://effbot.org/pyfaq/how-can-i-create-a-stand-alone-binary-from-a-python-script.htm 


which looks like a good place to start.

Tom


What modules do I need to use pylab? I've installed scipy and numpy.

--
   Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

 (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
  Obz Site:  39° 15' 7" N, 121° 2' 32" W, 2700 feet

Web Page: 
--
http://mail.python.org/mailman/listinfo/python-list


Re: Filling in Degrees in a Circle (Astronomy)

2008-08-23 Thread Ken Starks

tom wrote:



Both scipy and matplotlib are not part of the standard Python 
distribution so they would need to be installed separately.  Scipy is 
useful for scientific data analysis, and matplotlib is useful for making 
plots.




For a review of a really nice looking wrapper around lots of open-source
mathematical tools, look here:

http://vnoel.wordpress.com/2008/05/03/bye-matlab-hello-python-thanks-sage/

it is called SAGE and includes both of the above and lots more goodies.

for sage itself:

http://www.sagemath.org/
--
http://mail.python.org/mailman/listinfo/python-list


Re: Filling in Degrees in a Circle (Astronomy)

2008-08-23 Thread tom

W. eWatson wrote:

tom wrote:

W. eWatson wrote:
The other night I surveyed a site for astronomical use by measuring 
the altitude (0-90 degrees above the horizon) and az (azimuth, 0 
degrees north clockwise around the site to 360 degrees, almost north 
again) of obstacles, trees. My purpose was to feed this profile of 
obstacles (trees) to an astronomy program that would then account for 
not sighting objects below the trees.


When I got around to entering them into the program by a file, I 
found it required the alt at 360 azimuth points in order from 0 to 
360 (same as 0). Instead I have about 25 points, and expected the 
program to be able to do simple linear interpolation between those.


Is there some simple operational device in Python that would allow me 
to create an array (vector) of 360 points from my data by 
interpolating between azimuth points when necessary? All my data I 
rounded to the nearest integer. Maybe there's an interpolation operator?


As an example, supposed I had made 3 observations: (0,0) (180,45) and 
(360,0). I would want some thing like (note the slope of the line 
from 0 to 179 is 45/180 or 0.25):

alt: 0, 0.25, 0.50, 0.75, ... 44.75, 45.0
az : 0, 1,2,3,  180

Of course, I don't need the az.




If I understand you right, I think using interpolation as provided by 
scipy would do what you need.


Here's an example:

from scipy.interpolate.interpolate import interp1d

angles = [0, 22, 47.5, 180, 247.01, 360]
altitudes = [18, 18, 26, 3, 5, 18]

desired_angles = range(0, 361)

skyline = interp1d(angles, altitudes, kind="linear")
vals = skyline(desired_angles)

# that is, vals will be the interpolated altitudes at each of the
# desired angles.

if 1:  # plot this out with matplotlib
import pylab as mx
mx.figure()
mx.plot(angles, altitudes, 'x')
mx.plot(desired_angles, vals)
mx.show()
I decided this morning and roll up my sleeves and write the program. I 
plan to take a deeper plunge in the next month than my so far erratic 
look over the last 18 or more months  It's working.


The above looks like it's on the right track. Is scipy some collection 
of astro programs? mx is a graphics character plot?


I just hauled it into IDLE and tried executing it.
from scipy.interpolate.interpolate import interp1d
ImportError: No module named scipy.interpolate.interpolate

Apparently, something is missing.

I posted a recent msg a bit higher that will probably go unnoticed, so 
I'll repeat most of it. How do I get my py code into some executable 
form so that Win users who don't have python can execute it?





Both scipy and matplotlib are not part of the standard Python 
distribution so they would need to be installed separately.  Scipy is 
useful for scientific data analysis, and matplotlib is useful for making 
plots.


Since you want to wrap everything into a  Windows executable, it's 
probably easiest for you not to use scipy.  At the least, I suspect it 
would make your executable file much larger, but I've never made a 
Windows executable so I don't know the details.


As for making an executable, I'm not the one to ask, but googling leads 
to this:

http://effbot.org/pyfaq/how-can-i-create-a-stand-alone-binary-from-a-python-script.htm
which looks like a good place to start.

Tom

--
http://mail.python.org/mailman/listinfo/python-list


Re: Filling in Degrees in a Circle (Astronomy)

2008-08-23 Thread W. eWatson

Dennis Lee Bieber wrote:

On Fri, 22 Aug 2008 23:18:17 -0700, "W. eWatson"
<[EMAIL PROTECTED]> declaimed the following in comp.lang.python:


I'll take a look. I just posted above yours with a more insightful set of 
data than the first three pointer. Yes, some way of bisecting, or chopping 
is the trick here. One is just trying to fill in all the gaps with 
interpolation and produce 360 points to feed to the telescope software. It's 
sort of like giving someone, and forgetting interpolation here, the sequence 
20, 30, blank, 60, 70, 80 and asking for the two missing tens between 30 and 
60. 40 and 50, of course.


Presuming the data is an ordered list (in azimuth) of az/el pairs,
AND that the last measurement does not close the circle (eg: (0, 1),
(90, 5), (180, 5), (270, 2) ) the first step would be to append a data
point consisting of the first azimuth data point + 360, but with the
same elevation value. With normalization at the output, this would work
if the first data point was not at 0. Then one would perform repeated
interpolations over pairs of data points, outputting the first pair as
the first value, and stopping when the azimuth reached the second pair.

Something like (watch out for line wrapping):

-=-=-=-=-=-=-
import pprint

def gatherPoints():
pointList = []
while True:
cAz = raw_input("Enter Azimuth in integer degrees (blank line to
exit) : ")
cAz = cAz.strip()
if not cAz: break
az = int(cAz)
cEl = raw_input("Enter Elevation in real degrees for azimuth %s
: " % az).strip()
el = float(cEl)
pointList.append( (az, el) )
if pointList:
pointList.append( (pointList[0][0] + 360, pointList[0][1]) )
return pointList

def interpolate(start, end, step):
slope = float(end[1] - start[1]) / (end[0] - start[0])
iPoints = [ (i, (slope * (i - start[0])) + start[1])
for i in range(start[0], end[0], step) ]
return iPoints


if __name__ == "__main__":
points = gatherPoints()
output = []
if points:
for s in range(len(points) - 1):
output.extend(interpolate(points[s], points[s+1], 1))
pprint.pprint(output)
-=-=-=-=-=-=-
Close. A nice looking piece of code. Something for me to learn from. I play 
with python on a pretty irregular basis.


The game here is like someone gives you five distinct integer numbers from 1 
to 10 in order, and one needs to write a program to fill in the gaps. In my 
case, the numbers go from 0 to 359, and I have lots of gaps. I gave a pretty 
illustrative example in a post above. 11:10 pm last night. Of course, not 
only the gaps from 0 to 359 need to be filled in, but the interpolated 
values of the related values need to be obtained. Elevation.


As I just posted to the fellow below you. I decided this morning and roll up 
my sleeves and write the program. I plan to take a deeper plunge in the next 
month than my so far erratic look over the last 18 or more months  It's working.



--
   Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

 (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
  Obz Site:  39° 15' 7" N, 121° 2' 32" W, 2700 feet

Web Page: 
--
http://mail.python.org/mailman/listinfo/python-list


Re: Filling in Degrees in a Circle (Astronomy)

2008-08-23 Thread W. eWatson

tom wrote:

W. eWatson wrote:
The other night I surveyed a site for astronomical use by measuring 
the altitude (0-90 degrees above the horizon) and az (azimuth, 0 
degrees north clockwise around the site to 360 degrees, almost north 
again) of obstacles, trees. My purpose was to feed this profile of 
obstacles (trees) to an astronomy program that would then account for 
not sighting objects below the trees.


When I got around to entering them into the program by a file, I found 
it required the alt at 360 azimuth points in order from 0 to 360 (same 
as 0). Instead I have about 25 points, and expected the program to be 
able to do simple linear interpolation between those.


Is there some simple operational device in Python that would allow me 
to create an array (vector) of 360 points from my data by 
interpolating between azimuth points when necessary? All my data I 
rounded to the nearest integer. Maybe there's an interpolation operator?


As an example, supposed I had made 3 observations: (0,0) (180,45) and 
(360,0). I would want some thing like (note the slope of the line from 
0 to 179 is 45/180 or 0.25):

alt: 0, 0.25, 0.50, 0.75, ... 44.75, 45.0
az : 0, 1,2,3,  180

Of course, I don't need the az.




If I understand you right, I think using interpolation as provided by 
scipy would do what you need.


Here's an example:

from scipy.interpolate.interpolate import interp1d

angles = [0, 22, 47.5, 180, 247.01, 360]
altitudes = [18, 18, 26, 3, 5, 18]

desired_angles = range(0, 361)

skyline = interp1d(angles, altitudes, kind="linear")
vals = skyline(desired_angles)

# that is, vals will be the interpolated altitudes at each of the
# desired angles.

if 1:  # plot this out with matplotlib
import pylab as mx
mx.figure()
mx.plot(angles, altitudes, 'x')
mx.plot(desired_angles, vals)
mx.show()
I decided this morning and roll up my sleeves and write the program. I plan 
to take a deeper plunge in the next month than my so far erratic look over 
the last 18 or more months  It's working.


The above looks like it's on the right track. Is scipy some collection of 
astro programs? mx is a graphics character plot?


I just hauled it into IDLE and tried executing it.
from scipy.interpolate.interpolate import interp1d
ImportError: No module named scipy.interpolate.interpolate

Apparently, something is missing.

I posted a recent msg a bit higher that will probably go unnoticed, so I'll 
repeat most of it. How do I get my py code into some executable form so that 
Win users who don't have python can execute it?



--
   Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

 (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
  Obz Site:  39° 15' 7" N, 121° 2' 32" W, 2700 feet

Web Page: 
--
http://mail.python.org/mailman/listinfo/python-list


Re: Filling in Degrees in a Circle (Astronomy)

2008-08-23 Thread W. eWatson
I completed a Win Python program and it has generated the necessary data, 
which I have in turn used successfully with the telescope software. Is there 
some way to turn this into an executable program for people who do not have 
Python?


--
   Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

 (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
  Obz Site:  39° 15' 7" N, 121° 2' 32" W, 2700 feet

Web Page: 
--
http://mail.python.org/mailman/listinfo/python-list


Re: Filling in Degrees in a Circle (Astronomy)

2008-08-23 Thread tom

W. eWatson wrote:
The other night I surveyed a site for astronomical use by measuring the 
altitude (0-90 degrees above the horizon) and az (azimuth, 0 degrees 
north clockwise around the site to 360 degrees, almost north again) of 
obstacles, trees. My purpose was to feed this profile of obstacles 
(trees) to an astronomy program that would then account for not sighting 
objects below the trees.


When I got around to entering them into the program by a file, I found 
it required the alt at 360 azimuth points in order from 0 to 360 (same 
as 0). Instead I have about 25 points, and expected the program to be 
able to do simple linear interpolation between those.


Is there some simple operational device in Python that would allow me to 
create an array (vector) of 360 points from my data by interpolating 
between azimuth points when necessary? All my data I rounded to the 
nearest integer. Maybe there's an interpolation operator?


As an example, supposed I had made 3 observations: (0,0) (180,45) and 
(360,0). I would want some thing like (note the slope of the line from 0 
to 179 is 45/180 or 0.25):

alt: 0, 0.25, 0.50, 0.75, ... 44.75, 45.0
az : 0, 1,2,3,  180

Of course, I don't need the az.




If I understand you right, I think using interpolation as provided by 
scipy would do what you need.


Here's an example:

from scipy.interpolate.interpolate import interp1d

angles = [0, 22, 47.5, 180, 247.01, 360]
altitudes = [18, 18, 26, 3, 5, 18]

desired_angles = range(0, 361)

skyline = interp1d(angles, altitudes, kind="linear")
vals = skyline(desired_angles)

# that is, vals will be the interpolated altitudes at each of the
# desired angles.

if 1:  # plot this out with matplotlib
import pylab as mx
mx.figure()
mx.plot(angles, altitudes, 'x')
mx.plot(desired_angles, vals)
mx.show()
--
http://mail.python.org/mailman/listinfo/python-list


Re: Filling in Degrees in a Circle (Astronomy)

2008-08-23 Thread W. eWatson

Scott David Daniels wrote:

W. eWatson wrote:

...
I'm working on this now, but my knowledge of python needs refreshing. 
Right now I have a file of all the az,el data I've collected, and I'd 
like to open it with Python for XP. However, Python doesn't like this:


junkfile = open('c:\tmp\junkpythonfile','w')

I get
junkfile = open('c:\tmp\junkpythonfile','w')
IOError: [Errno 2] No such file or directory: 'c:\tmp\\junkpythonfile'

This problematic segment is just a hack of a similar statement which 
has the same problem and a much longer path. I suspect the problem is 
with the back slash.




A standard windows error. note that '\t' is a tab, and I doubt you have
a directory named   .  Get in the habit of _always_ using:
   junkfile = open(r'c:\tmp\junkpythonfile','w')
or
   junkfile = open('c:\\tmp\\junkpythonfile','w')
for file names.

--Scott David Daniels
[EMAIL PROTECTED]


Thanks. r did the job nicely.

--
   Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

 (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
  Obz Site:  39° 15' 7" N, 121° 2' 32" W, 2700 feet

Web Page: 
--
http://mail.python.org/mailman/listinfo/python-list


Re: Filling in Degrees in a Circle (Astronomy)

2008-08-23 Thread Scott David Daniels

W. eWatson wrote:

...
I'm working on this now, but my knowledge of python needs refreshing. 
Right now I have a file of all the az,el data I've collected, and I'd 
like to open it with Python for XP. However, Python doesn't like this:


junkfile = open('c:\tmp\junkpythonfile','w')

I get
junkfile = open('c:\tmp\junkpythonfile','w')
IOError: [Errno 2] No such file or directory: 'c:\tmp\\junkpythonfile'

This problematic segment is just a hack of a similar statement which has 
the same problem and a much longer path. I suspect the problem is with 
the back slash.




A standard windows error. note that '\t' is a tab, and I doubt you have
a directory named   .  Get in the habit of _always_ using:
   junkfile = open(r'c:\tmp\junkpythonfile','w')
or
   junkfile = open('c:\\tmp\\junkpythonfile','w')
for file names.

--Scott David Daniels
[EMAIL PROTECTED]

--
http://mail.python.org/mailman/listinfo/python-list


Re: Filling in Degrees in a Circle (Astronomy)

2008-08-22 Thread W. eWatson

Carl Banks wrote:

On Aug 22, 7:12 pm, "W. eWatson" <[EMAIL PROTECTED]> wrote:

Is there some simple operational device in Python that would allow me to
create an array (vector) of 360 points from my data by interpolating between
azimuth points when necessary? All my data I rounded to the nearest integer.
Maybe there's an interpolation operator?


There's nothing built in, but see the bisect module.  It is a good way
to determine which interval you are in, and you can interpolate the
points yourself.


Carl Banks
I'll take a look. I just posted above yours with a more insightful set of 
data than the first three pointer. Yes, some way of bisecting, or chopping 
is the trick here. One is just trying to fill in all the gaps with 
interpolation and produce 360 points to feed to the telescope software. It's 
sort of like giving someone, and forgetting interpolation here, the sequence 
20, 30, blank, 60, 70, 80 and asking for the two missing tens between 30 and 
60. 40 and 50, of course.


The fellow above wrote an interpolate function that will probably fit the bill.

--
   Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

 (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
  Obz Site:  39° 15' 7" N, 121° 2' 32" W, 2700 feet

Web Page: 
--
http://mail.python.org/mailman/listinfo/python-list


Re: Filling in Degrees in a Circle (Astronomy)

2008-08-22 Thread W. eWatson

Maric Michaud wrote:

Le Saturday 23 August 2008 01:12:48 W. eWatson, vous avez écrit :

The other night I surveyed a site for astronomical use by measuring the
altitude (0-90 degrees above the horizon) and az (azimuth, 0 degrees north
clockwise around the site to 360 degrees, almost north again) of obstacles,
trees. My purpose was to feed this profile of obstacles (trees) to an
astronomy program that would then account for not sighting objects below
the trees.

When I got around to entering them into the program by a file, I found it
required the alt at 360 azimuth points in order from 0 to 360 (same as 0).
Instead I have about 25 points, and expected the program to be able to do
simple linear interpolation between those.

Is there some simple operational device in Python that would allow me to
create an array (vector) of 360 points from my data by interpolating
between azimuth points when necessary? All my data I rounded to the nearest
integer. Maybe there's an interpolation operator?

As an example, supposed I had made 3 observations: (0,0) (180,45) and
(360,0). I would want some thing like (note the slope of the line from 0 to
179 is 45/180 or 0.25):
alt: 0, 0.25, 0.50, 0.75, ... 44.75, 45.0
az : 0, 1,2,3,  180

Of course, I don't need the az.


Not sure I got it, but is that fulfill your specs ?


[20]: def interpolate(a, b) :

slope = float(b[1] - a[1]) / (b[0] - a[0])
return [ slope * float(i) for i in xrange(b[0]-a[0] + 1) ]
   :


[23]: interpolate((0, 0), (180, 45))

...[23]:
[0.0,
 0.25,
 0.5,
 0.75,

 44.5,
 44.75,
 45.0]


[29]: interpolate((80, 20), (180, 45))

[0.0,
 0.25,
 0.5,
 0.75,
 1.0,
 1.25,
...
 24.5,
 24.75,
 25.0]



Yes, the interpolation part looks right, but the tricky part is to be able 
to go through the list and find where one needs to generate all the missing 
az angles. A chunk of my data is in a post above yours. Here's a more 
revealing set of data where four data points are known:


az el
0 10
4 14 (slope is 1)
12 30 (slope is 2)
15 15 (slope is -5)


16 points need to be generated, 0 to 15, representing 15 degrees around the 
circle.

So, I'm doing this in my head, one would get
0 10 (slope is 1)
1 11
2 12
3 13
4 14
5 16 (slope is 2)
6 18
7 18
...
12 30
13 25
14 20
15 15

I use Python occasionally, and starting up requires some effort, but I've 
finally decided to take a go at this.


I'm working on this now, but my knowledge of python needs refreshing. Right 
now I have a file of all the az,el data I've collected, and I'd like to open 
it with Python for XP. However, Python doesn't like this:


junkfile = open('c:\tmp\junkpythonfile','w')

I get
junkfile = open('c:\tmp\junkpythonfile','w')
IOError: [Errno 2] No such file or directory: 'c:\tmp\\junkpythonfile'

This problematic segment is just a hack of a similar statement which has the 
same problem and a much longer path. I suspect the problem is with the back 
slash.


--
   Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

 (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
  Obz Site:  39° 15' 7" N, 121° 2' 32" W, 2700 feet

Web Page: 
--
http://mail.python.org/mailman/listinfo/python-list


Re: Filling in Degrees in a Circle (Astronomy)

2008-08-22 Thread Carl Banks
On Aug 22, 7:12 pm, "W. eWatson" <[EMAIL PROTECTED]> wrote:
> Is there some simple operational device in Python that would allow me to
> create an array (vector) of 360 points from my data by interpolating between
> azimuth points when necessary? All my data I rounded to the nearest integer.
> Maybe there's an interpolation operator?

There's nothing built in, but see the bisect module.  It is a good way
to determine which interval you are in, and you can interpolate the
points yourself.


Carl Banks
--
http://mail.python.org/mailman/listinfo/python-list


Re: Filling in Degrees in a Circle (Astronomy)

2008-08-22 Thread Maric Michaud
Le Saturday 23 August 2008 01:12:48 W. eWatson, vous avez écrit :
> The other night I surveyed a site for astronomical use by measuring the
> altitude (0-90 degrees above the horizon) and az (azimuth, 0 degrees north
> clockwise around the site to 360 degrees, almost north again) of obstacles,
> trees. My purpose was to feed this profile of obstacles (trees) to an
> astronomy program that would then account for not sighting objects below
> the trees.
>
> When I got around to entering them into the program by a file, I found it
> required the alt at 360 azimuth points in order from 0 to 360 (same as 0).
> Instead I have about 25 points, and expected the program to be able to do
> simple linear interpolation between those.
>
> Is there some simple operational device in Python that would allow me to
> create an array (vector) of 360 points from my data by interpolating
> between azimuth points when necessary? All my data I rounded to the nearest
> integer. Maybe there's an interpolation operator?
>
> As an example, supposed I had made 3 observations: (0,0) (180,45) and
> (360,0). I would want some thing like (note the slope of the line from 0 to
> 179 is 45/180 or 0.25):
> alt: 0, 0.25, 0.50, 0.75, ... 44.75, 45.0
> az : 0, 1,2,3,  180
>
> Of course, I don't need the az.

Not sure I got it, but is that fulfill your specs ?

>>>[20]: def interpolate(a, b) :
slope = float(b[1] - a[1]) / (b[0] - a[0])
return [ slope * float(i) for i in xrange(b[0]-a[0] + 1) ]
   :

>>>[23]: interpolate((0, 0), (180, 45))
...[23]:
[0.0,
 0.25,
 0.5,
 0.75,

 44.5,
 44.75,
 45.0]

>>>[29]: interpolate((80, 20), (180, 45))
[0.0,
 0.25,
 0.5,
 0.75,
 1.0,
 1.25,
...
 24.5,
 24.75,
 25.0]



-- 
_

Maric Michaud
--
http://mail.python.org/mailman/listinfo/python-list


Re: Filling in Degrees in a Circle (Astronomy)

2008-08-22 Thread W. eWatson

Mensanator wrote:

On Aug 22, 6:12 pm, "W. eWatson" <[EMAIL PROTECTED]> wrote:

The other night I surveyed a site for astronomical use by measuring the
altitude (0-90 degrees above the horizon) and az (azimuth, 0 degrees north
clockwise around the site to 360 degrees, almost north again) of obstacles,
trees. My purpose was to feed this profile of obstacles (trees) to an
astronomy program that would then account for not sighting objects below the
trees.

When I got around to entering them into the program by a file, I found it
required the alt at 360 azimuth points in order from 0 to 360 (same as 0).
Instead I have about 25 points, and expected the program to be able to do
simple linear interpolation between those.

Is there some simple operational device in Python that would allow me to
create an array (vector) of 360 points from my data by interpolating between
azimuth points when necessary? All my data I rounded to the nearest integer.
Maybe there's an interpolation operator?

As an example, supposed I had made 3 observations: (0,0) (180,45) and
(360,0). I would want some thing like (note the slope of the line from 0 to
179 is 45/180 or 0.25):
alt: 0, 0.25, 0.50, 0.75, ... 44.75, 45.0
az : 0, 1,2,3,  180

Of course, I don't need the az.


On Aug 22, 6:12 pm, "W. eWatson" <[EMAIL PROTECTED]> wrote:

The other night I surveyed a site for astronomical use by measuring the
altitude (0-90 degrees above the horizon) and az (azimuth, 0 degrees north
clockwise around the site to 360 degrees, almost north again) of obstacles,
trees. My purpose was to feed this profile of obstacles (trees) to an
astronomy program that would then account for not sighting objects below the
trees.

When I got around to entering them into the program by a file, I found it
required the alt at 360 azimuth points in order from 0 to 360 (same as 0).
Instead I have about 25 points, and expected the program to be able to do
simple linear interpolation between those.

Is there some simple operational device in Python that would allow me to
create an array (vector) of 360 points from my data by interpolating between
azimuth points when necessary? All my data I rounded to the nearest integer.
Maybe there's an interpolation operator?

As an example, supposed I had made 3 observations: (0,0) (180,45) and
(360,0). I would want some thing like (note the slope of the line from 0 to
179 is 45/180 or 0.25):
alt: 0, 0.25, 0.50, 0.75, ... 44.75, 45.0
az : 0, 1,2,3,  180

Of course, I don't need the az.



for az in xrange(181):

print (az,az*0.25),

(0, 0.0) (1, 0.25) (2, 0.5) (3, 0.75)
(4, 1.0) (5, 1.25) (6, 1.5) (7, 1.75)
(8, 2.0) (9, 2.25) (10, 2.5) (11, 2.75)
(12, 3.0) (13, 3.25) (14, 3.5) (15, 3.75)
(16, 4.0) (17, 4.25) (18, 4.5) (19, 4.75)
(20, 5.0) (21, 5.25) (22, 5.5) (23, 5.75)
etc.
Yes, that works, but that was only a simple illustration. My data looks in 
fact looks like this (only a few values given:

Az   Alt
018
18   18
27   16
34   20
48   20
...
268  28
290  32
...
So the python software should generate
0  18
1  18
2  18
3  18
... the trees are all about 18 degrees high
18 18
19 17.9 we have a slight slope. I'm using values that might be close
20 27.75
21
...
27 16
28 16.4 now the trees are starting to get a little higher
29 16.9
...
359 18 (most likely. I didn't have the patience to make a measure at 359)

That should pretty well illustrate it. In actuality, as I swept around the 
circle, the tree line becomes much more abrupt than those first few data 
points. The tallest tree is at 36 degrees and is among some other equally 
tall trees.




But are you saying if you have two readings of tree tops

*
*
  x *
  x *
* x *
* x *
*_x_*__


And you linearly interpret between them

exactly. I put a value there -- x


/
   /*
  / *
 /  *
/   *
   /*   *
*   *
*___*__

that the area below the dashed line is assumed to be hidden?
Yes, the telescope software will see that it cannot move the telescope into 
that area. Surprisingly, they use interpolation. For example, suppose the 
two trees in your illustration are at an az of 100 and 101, and the two 
altitudes are 3 and 7. Suppose the telescope wants to go below the line into 
100.622 az and an alt of 2.42. The software will say no you don't.


That wouldn't necessarily be true, as the tree profile could
dip below the line.

/
   /*
  / *
 / **
/  ***
   /*  
** 
___***_

Of course, if you take enough points, the open areas may be small
enough not to be practical to worry about.


--
http://mail.python.org/mailman/listinfo/python-list


Re: Filling in Degrees in a Circle (Astronomy)

2008-08-22 Thread Mensanator
On Aug 22, 6:12 pm, "W. eWatson" <[EMAIL PROTECTED]> wrote:
> The other night I surveyed a site for astronomical use by measuring the
> altitude (0-90 degrees above the horizon) and az (azimuth, 0 degrees north
> clockwise around the site to 360 degrees, almost north again) of obstacles,
> trees. My purpose was to feed this profile of obstacles (trees) to an
> astronomy program that would then account for not sighting objects below the
> trees.
>
> When I got around to entering them into the program by a file, I found it
> required the alt at 360 azimuth points in order from 0 to 360 (same as 0).
> Instead I have about 25 points, and expected the program to be able to do
> simple linear interpolation between those.
>
> Is there some simple operational device in Python that would allow me to
> create an array (vector) of 360 points from my data by interpolating between
> azimuth points when necessary? All my data I rounded to the nearest integer.
> Maybe there's an interpolation operator?
>
> As an example, supposed I had made 3 observations: (0,0) (180,45) and
> (360,0). I would want some thing like (note the slope of the line from 0 to
> 179 is 45/180 or 0.25):
> alt: 0, 0.25, 0.50, 0.75, ... 44.75, 45.0
> az : 0, 1,    2,    3,              180
>
> Of course, I don't need the az.

On Aug 22, 6:12 pm, "W. eWatson" <[EMAIL PROTECTED]> wrote:
> The other night I surveyed a site for astronomical use by measuring the
> altitude (0-90 degrees above the horizon) and az (azimuth, 0 degrees north
> clockwise around the site to 360 degrees, almost north again) of obstacles,
> trees. My purpose was to feed this profile of obstacles (trees) to an
> astronomy program that would then account for not sighting objects below the
> trees.
>
> When I got around to entering them into the program by a file, I found it
> required the alt at 360 azimuth points in order from 0 to 360 (same as 0).
> Instead I have about 25 points, and expected the program to be able to do
> simple linear interpolation between those.
>
> Is there some simple operational device in Python that would allow me to
> create an array (vector) of 360 points from my data by interpolating between
> azimuth points when necessary? All my data I rounded to the nearest integer.
> Maybe there's an interpolation operator?
>
> As an example, supposed I had made 3 observations: (0,0) (180,45) and
> (360,0). I would want some thing like (note the slope of the line from 0 to
> 179 is 45/180 or 0.25):
> alt: 0, 0.25, 0.50, 0.75, ... 44.75, 45.0
> az : 0, 1,2,3,  180
>
> Of course, I don't need the az.

>>> for az in xrange(181):
print (az,az*0.25),

(0, 0.0) (1, 0.25) (2, 0.5) (3, 0.75)
(4, 1.0) (5, 1.25) (6, 1.5) (7, 1.75)
(8, 2.0) (9, 2.25) (10, 2.5) (11, 2.75)
(12, 3.0) (13, 3.25) (14, 3.5) (15, 3.75)
(16, 4.0) (17, 4.25) (18, 4.5) (19, 4.75)
(20, 5.0) (21, 5.25) (22, 5.5) (23, 5.75)
etc.

But are you saying if you have two readings of tree tops

*
*
*
*
*   *
*   *
*___*__


And you linearly interpret between them

/
   /*
  / *
 /  *
/   *
   /*   *
*   *
*___*__

that the area below the dashed line is assumed to be hidden?

That wouldn't necessarily be true, as the tree profile could
dip below the line.

/
   /*
  / *
 / **
/  ***
   /*  
** 
___***_

Of course, if you take enough points, the open areas may be small
enough not to be practical to worry about.

> --
> Wayne Watson (Watson Adventures, Prop., Nevada City, CA)
>
>   (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
>Obz Site:  39° 15' 7" N, 121° 2' 32" W, 2700 feet
>
>  Web Page: 



> --
>             Wayne Watson (Watson Adventures, Prop., Nevada City, CA)
>
>               (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
>                Obz Site:  39° 15' 7" N, 121° 2' 32" W, 2700 feet
>
>                      Web Page: 

--
http://mail.python.org/mailman/listinfo/python-list