From thomas.robitaille at gmail.com Thu Feb 2 04:33:14 2012 From: thomas.robitaille at gmail.com (Thomas Robitaille) Date: Thu, 2 Feb 2012 10:33:14 +0100 Subject: [AstroPy] Using MacPorts for Python In-Reply-To: References: Message-ID: For the record, the py27-wxpython port has now been fixed, so if you run: sudo port selfupdate to update the package list, you should be able to get wxpython to work. Cheers, Tom On 28 November 2011 18:02, David Johnston wrote: > Yes, I have found it to work well. It is probably the best way to install > these packages on Mac. > > I have found that a few things do not install. I think wxpython was one of > those. Some packages are not available at Mac ports so you should install > those using pip or easyinstall with the --user flag which install them in > your home directory. > Dave > > > > On Mon, Nov 28, 2011 at 10:18 AM, Thomas Robitaille > wrote: >> >> I was wondering whether anyone has used the instructions below to >> install Python on 10.7 using MacPorts, and if so, whether everything >> works fine? >> >> Tom >> >> On 25 July 2011 18:36, Thomas Robitaille >> wrote: >> > Hi Everyone, >> > >> > Earlier this year I was given commit privileges to the MacPorts >> > (http://www.macports.org/) package index, and I've already added a few >> > Astronomy Python packages. After moved between various install methods >> > in the last couple of years (system Python, EPD, source install, >> > python.org distribution, ...) I've now settled on using the Python >> > distribution from MacPorts. One of my main reasons for doing this is >> > that I needed some complex packages (Qt and GTK+) which are not >> > included in EPD, and by far the easiest way to install them has been >> > through MacPorts. However, I believe a MacPorts Python distribution >> > can still be very useful even if you don't need these packages, so >> > I've compiled a list of simple instructions to set up a full Python >> > distribution using MacPorts on Mac: >> > >> > http://astrofrog.github.com/macports-python/ >> > >> > Updating packages is easy, and dependencies are automatically taken >> > care of. For now I recommend using Python 2.7 as indicated in the >> > instructions. I would welcome any feedback, especially if you run into >> > issues, and would also welcome suggestions for other packages to add. >> > For new packages you can either email me directly or open a ticket on >> > MacPorts and cc robitaille at macports.org on the ticket. To report >> > issues with the instructions, open an issue at: >> > >> > https://github.com/astrofrog/macports-python >> > >> > Note that it's possible/easy to install several Python versions with >> > MacPorts at the same time and you can switch which one is the default >> > with 'port select', or call the version you want directly with >> > ipython-3.1 for example. This makes it ideal if you want to be able to >> > test your code using different python versions or want to experiment >> > with Python 3. >> > >> > Cheers, >> > Thomas >> > >> _______________________________________________ >> AstroPy mailing list >> AstroPy at scipy.org >> http://mail.scipy.org/mailman/listinfo/astropy > > From oneaufs at gmail.com Fri Feb 3 05:22:00 2012 From: oneaufs at gmail.com (Prasanth) Date: Fri, 3 Feb 2012 15:52:00 +0530 Subject: [AstroPy] Refractive index calculations (feedback request) Message-ID: Hello, I have written a module in Python for calculating refractive index under different environmental conditions, and for converting wavelength of light between air and vacuum. The code is based on the documentation for the NIST online refractive index of air calculator . It would be great to know how this compares to existing tools used by astronomers in their research level code. The function "ref_index._test_idlastro()" includes some comparison with IDLASTRO vac2air and air2vac procedures. The module is available at http://pypi.python.org/pypi/ref_index. It has no dependencies outside of standard Python libraries. It can be installed using "pip install ref_index". Documentation is available within the source code, and it can also be displayed in interactive Python/iPython session by typing "help(ref_index)" after importing ref_index. All functions also have documentation. The development repository is at https://github.com/phn/ref_index . Thanks Prasanth -------------- next part -------------- An HTML attachment was scrubbed... URL: From jerome_caron_astro at ymail.com Thu Feb 16 05:10:50 2012 From: jerome_caron_astro at ymail.com (Jerome Caron) Date: Thu, 16 Feb 2012 10:10:50 +0000 (GMT) Subject: [AstroPy] strange error with ctypes Message-ID: <1329387050.11957.YahooMailNeo@web24614.mail.ird.yahoo.com> Dear list, ? I am developping since 2 years a library for photometry in Python. Everything is here: www.aspylib.com ? At the moment I have a very strange bug and no idea how to solve it, so I am asking for some help... or recommendations about a better place to ask for help (a different list ?) ? My OS is Windows XP. The Python script is calling a few dll (written in C++) that are interfaced with ctypes. Looking at the messages in the Python console the error occurs when calling one of these dll (this particular?dll is called several hundreds of thousands of times without error just before, and this time there is an error..). The error message is something like: ? File "C:\Documents and Settings\jerome caron\My Documents\Python2\aspylib\astro\transform.py", line 35, in translate_Bspline ??? cdll.Bspline.Translate(dim,dim_x,dim_y,indata,dxy,spline_degree,outdata) WindowsError: exception: access violation reading 0x4158B870 ? The Python code that calls the dll is (I changed it many time without resolving the error) ? if len(images.shape)==2: ??dim = 1 ??dim_x, dim_y = images.shape else: ??dim, dim_x, dim_y = images.shape???? indata = np.ascontiguousarray(np.array(images, dtype = np.float32)) dxy = np.ascontiguousarray(np.array(shift, dtype = np.float32)) outdata = np.ascontiguousarray(np.empty(images.shape, dtype = np.float32)) cdll.Bspline.Translate.argtypes = [c_long, c_long, c_long, ndpointer(dtype=np.float32), ndpointer(dtype=np.float32), c_long, ndpointer(dtype=np.float32)] cdll.Bspline.Translate(dim,dim_x,dim_y,indata,dxy,spline_degree,outdata) The dll prototype in C is int Translate(int dim, int dim_x, int dim_y, float* a, float* shifts, int spline_degree, float* b); ? So everything looks ok and I would suspect an error in the C++ code. But here comes the nasty thing. The code in the dll is very basic and clean. Actually it does not throw any exception as I checked by inserting a try..catch statement try{ all the dll code here} catch(...){printf("there was an error ni the dll!");} ? Investigating further, the error occurs when executing a free() instruction. I don't see how this could create an error ! The piece of C code looks like ? ?Line = (double *)malloc((size_t)(Width * (long)sizeof(double))); ?if (Line == (double *)NULL) { ??printf("Row allocation failed\n"); ??return(1); ?} ??? for (y = 0L; y < Height; y++) { ??????? GetRow(Image, y, Line, Width); ??????? ConvertToInterpolationCoefficients(Line, Width, Pole, NbPoles, DBL_EPSILON); ??????? PutRow(Image, y, Line, Width); ??? } ??? free(Line); And the error occurs at the statement free(Line). ? I am starting to suspect something nasty happening with ctypes. Or maybe I am missing something very basic ? Any suggestion ? I am sure there are experienced programmers on this list, who could advice me. ? Many thanks for your help and patience reading me Kind regards Jerome Caron -------------- next part -------------- An HTML attachment was scrubbed... URL: From jturner at gemini.edu Thu Feb 16 12:52:17 2012 From: jturner at gemini.edu (James Turner) Date: Thu, 16 Feb 2012 14:52:17 -0300 Subject: [AstroPy] strange error with ctypes In-Reply-To: <1329387050.11957.YahooMailNeo@web24614.mail.ird.yahoo.com> References: <1329387050.11957.YahooMailNeo@web24614.mail.ird.yahoo.com> Message-ID: <4F3D4251.7040809@gemini.edu> > Investigating further, the error occurs when executing a free() instruction. I > don't see how this could create an error ! I believe it could cause an error if either the pointer Line has been changed, so you are trying to free the wrong memory, or something has inadvertently overwritten the memory you're trying to free (along with a few bytes of information like the length of the array that malloc keeps just before the allocated block). Fortunately the malloc and free happen close together, so there aren't many likely culprits. My C is sufficiently rusty that I might not spot a problem with the code you sent but I'd have to suspect that one of the 3 calls in your for loop is writing out of bounds, perhaps only when a certain rounding condition occurs (explaining the once-in-a-few-hundred-thousand occurence). Someone more on the ball with C and Windows might have better input, but maybe that gives you an idea where to get started... Cheers, James. > The piece of C code looks like > Line = (double *)malloc((size_t)(Width * (long)sizeof(double))); > if (Line == (double *)NULL) { > printf("Row allocation failed\n"); > return(1); > } > for (y = 0L; y < Height; y++) { > GetRow(Image, y, Line, Width); > ConvertToInterpolationCoefficients(Line, Width, Pole, NbPoles, DBL_EPSILON); > PutRow(Image, y, Line, Width); > } > free(Line); > And the error occurs at the statement free(Line). > I am starting to suspect something nasty happening with ctypes. Or maybe I am > missing something very basic ? Any suggestion ? I am sure there are experienced > programmers on this list, who could advice me. > Many thanks for your help and patience reading me > Kind regards > Jerome Caron > > > > _______________________________________________ > AstroPy mailing list > AstroPy at scipy.org > http://mail.scipy.org/mailman/listinfo/astropy From derek at astro.physik.uni-goettingen.de Thu Feb 16 13:52:43 2012 From: derek at astro.physik.uni-goettingen.de (Derek Homeier) Date: Thu, 16 Feb 2012 19:52:43 +0100 Subject: [AstroPy] Refractive index calculations (feedback request) In-Reply-To: References: Message-ID: <755945BB-A75B-4181-B754-DB6BE2A98B8C@astro.physik.uni-goettingen.de> Thanks a lot for this contribution, Prasanth! On 3 Feb 2012, at 11:22, Prasanth wrote: > I have written a module in Python for calculating refractive index under different environmental conditions, and for converting wavelength of light between air and vacuum. The code is based on the documentation for the NIST online refractive index of air calculator. > > It would be great to know how this compares to existing tools used by astronomers in their research level code. The function > "ref_index._test_idlastro()" includes some comparison with IDLASTRO vac2air and air2vac procedures. > I could only criticize that the test function remains silent when successful, i.e. it might perhaps print a short diagnostic message when it found no discrepancies between the two formulae. I did some comparisons of the various equations; interestingly the older IDL astrolib routine, which is using Edl?n's (1953) original formula 1.e8*(n-1) = 6432.8+2949810/(146-k^2)+25540/(41-k^2) agrees already with the recommended (and adopted in current astrolib) Ciddor formula for standard conditions almost within numerical precision, whereas the later Edl?n (1966) equation at NIST and in ref_index.edlen shows noticeably larger deviations. That said, all versions should probably satisfy typical astronomical requirements, especially as the optional parameters are just free bonus (at least I hope no one will ever have to observe at 60?C, 99% rel. humidity or several % CO2-levels ;-). Only one more suggestion to the code for now: I'd strongly recommend in expressions like ns = 1 + 1e-8 * (A + B / (130.0 - S) + C / (38.9 - S)) ntp = 1 + p * (ns - 1) * X / D to cut the +1 from the definition of ns right away to save numerical precision (in edlen_ri()). Cheers, Derek -- ---------------------------------------------------------------- Derek Homeier Centre de Recherche Astrophysique de Lyon ENS Lyon 46, All?e d'Italie 69364 Lyon Cedex 07, France +33 47272-8894 ---------------------------------------------------------------- From jerome_caron_astro at ymail.com Thu Feb 16 14:47:49 2012 From: jerome_caron_astro at ymail.com (Jerome Caron) Date: Thu, 16 Feb 2012 19:47:49 +0000 (GMT) Subject: [AstroPy] Re : strange error with ctypes In-Reply-To: <4F3D4251.7040809@gemini.edu> References: <1329387050.11957.YahooMailNeo@web24614.mail.ird.yahoo.com> <4F3D4251.7040809@gemini.edu> Message-ID: <1329421669.34719.YahooMailNeo@web24616.mail.ird.yahoo.com> Dear James, ? >I believe it could cause an error if either the pointer Line has been >changed, so you are trying to free the wrong memory, or something has >inadvertently overwritten the memory you're trying to free ? Thanks for the suggestion ! You're right, this could be a possibility. I checked carefully the code, but the only instructions with Line are assignments and arithmetic operations with Line[i], i varying from 0 to Width-1. There is not a single operation with the pointer itself. So I don't see what could be wrong... ? This piece of code in my dll is a third party library (http://bigwww.epfl.ch/thevenaz/interpolation/). The code is nicely written, and it's clear than the author knows what he's doing. ? I am a bit puzzled, I am sure if there was such error there would be an exception thrown by the dll. But there's no exception: Python reports an error in the dll, and the dll does not see any error. It looks like Python and C++ do not understand each other. Might this be something wrong with my Python code, a bad usage of ctypes ?? ? Jerome -------------- next part -------------- An HTML attachment was scrubbed... URL: From embray at stsci.edu Thu Feb 16 15:34:57 2012 From: embray at stsci.edu (Erik Bray) Date: Thu, 16 Feb 2012 15:34:57 -0500 Subject: [AstroPy] Re : strange error with ctypes In-Reply-To: <1329421669.34719.YahooMailNeo@web24616.mail.ird.yahoo.com> References: <1329387050.11957.YahooMailNeo@web24614.mail.ird.yahoo.com> <4F3D4251.7040809@gemini.edu> <1329421669.34719.YahooMailNeo@web24616.mail.ird.yahoo.com> Message-ID: <4F3D6871.9020809@stsci.edu> On 02/16/2012 02:47 PM, Jerome Caron wrote: > Dear James, >>I believe it could cause an error if either the pointer Line has been >>changed, so you are trying to free the wrong memory, or something has >>inadvertently overwritten the memory you're trying to free > Thanks for the suggestion ! You're right, this could be a possibility. I > checked carefully the code, but the only instructions with Line are > assignments and arithmetic operations with Line[i], i varying from 0 to > Width-1. There is not a single operation with the pointer itself. So I > don't see what could be wrong... > This piece of code in my dll is a third party library > (http://bigwww.epfl.ch/thevenaz/interpolation/). The code is nicely > written, and it's clear than the author knows what he's doing. > I am a bit puzzled, I am sure if there was such error there would be an > exception thrown by the dll. But there's no exception: Python reports an > error in the dll, and the dll does not see any error. It looks like > Python and C++ do not understand each other. Might this be something > wrong with my Python code, a bad usage of ctypes ?? > Jerome Forgive my asking, since I know this wasn't really your question. But is there some reason not to use SciPy's interpolation? Erik From jerome_caron_astro at ymail.com Fri Feb 17 00:43:38 2012 From: jerome_caron_astro at ymail.com (Jerome Caron) Date: Fri, 17 Feb 2012 05:43:38 +0000 (GMT) Subject: [AstroPy] Re : Re : strange error with ctypes In-Reply-To: <4F3D6871.9020809@stsci.edu> References: <1329387050.11957.YahooMailNeo@web24614.mail.ird.yahoo.com> <4F3D4251.7040809@gemini.edu> <1329421669.34719.YahooMailNeo@web24616.mail.ird.yahoo.com> <4F3D6871.9020809@stsci.edu> Message-ID: <1329457418.33254.YahooMailNeo@web24615.mail.ird.yahoo.com> I actually found the code from P.Thevenaz is better than Scipy. There is published information about its implementation and performance. It's explained how to use it for images, and finally P.Thevenaz answers?to technical questions by email. The implementation is very nice, mirror conditions?and Bsplines with order 2 to 9. It should also be faster because all in pure C. I like Scipy and I am using several Scipy modules for my library (ndimage, fftpack) but Bspline has a central role so I am concerned about it. Using ctypes is a very strong advantage of Python; I also re-coded the median calculation in C and gained several orders of magnitude wrt computation time. Jerome ? ________________________________ De?: Erik Bray ??: astropy at scipy.org Envoy? le : Jeudi 16 f?vrier 2012 21h34 Objet?: Re: [AstroPy] Re : strange error with ctypes On 02/16/2012 02:47 PM, Jerome Caron wrote: > Dear James, >>I believe it could cause an error if either the pointer Line has been >>changed, so you are trying to free the wrong memory, or something has >>inadvertently overwritten the memory you're trying to free > Thanks for the suggestion ! You're right, this could be a possibility. I > checked carefully the code, but the only instructions with Line are > assignments and arithmetic operations with Line[i], i varying from 0 to > Width-1. There is not a single operation with the pointer itself. So I > don't see what could be wrong... > This piece of code in my dll is a third party library > (http://bigwww.epfl.ch/thevenaz/interpolation/). The code is nicely > written, and it's clear than the author knows what he's doing. > I am a bit puzzled, I am sure if there was such error there would be an > exception thrown by the dll. But there's no exception: Python reports an > error in the dll, and the dll does not see any error. It looks like > Python and C++ do not understand each other. Might this be something > wrong with my Python code, a bad usage of ctypes ?? > Jerome Forgive my asking, since I know this wasn't really your question. But is there some reason not to use SciPy's interpolation? Erik _______________________________________________ AstroPy mailing list AstroPy at scipy.org http://mail.scipy.org/mailman/listinfo/astropy -------------- next part -------------- An HTML attachment was scrubbed... URL: From jerome_caron_astro at ymail.com Mon Feb 20 09:39:53 2012 From: jerome_caron_astro at ymail.com (Jerome Caron) Date: Mon, 20 Feb 2012 14:39:53 +0000 (GMT) Subject: [AstroPy] Re : Re : strange error with ctypes In-Reply-To: <1329421669.34719.YahooMailNeo@web24616.mail.ird.yahoo.com> References: <1329387050.11957.YahooMailNeo@web24614.mail.ird.yahoo.com> <4F3D4251.7040809@gemini.edu> <1329421669.34719.YahooMailNeo@web24616.mail.ird.yahoo.com> Message-ID: <1329748793.50718.YahooMailNeo@web24604.mail.ird.yahoo.com> Dear list, ? Finally I?resolved the error. I am not sure what happened. I found that some numpy arrays sent to the dll had very large size (due to indexing like x[0:-5]), which was not my intention so I corrected it. The dll is now called a large amount of times (>1e6), but only with small arrays (20*20), and it works fine. I don't like it very much, to correct something that I don't understand so I still have an eye on this problem. In any case, the error was detected and managed cleanly by Python (try... except...). Another solution I had in mind was to re-program the dll without dynamic allocation, by oversizing the only dynamic array (variable called "Line") used in the dll. ? At the moment my library works only with WinXP 32 bits. In the next months I will make it compatible with Win 7 32 bits, and Ubuntu. Then I will present it on the list (I believe there is a majority of Linux users..) Thanks for your help Cheers Jerome ? ________________________________ De?: Jerome Caron ??: "astropy at scipy.org" Envoy? le : Jeudi 16 f?vrier 2012 20h47 Objet?: [AstroPy] Re : strange error with ctypes Dear James, ? >I believe it could cause an error if either the pointer Line has been >changed, so you are trying to free the wrong memory, or something has >inadvertently overwritten the memory you're trying to free ? Thanks for the suggestion ! You're right, this could be a possibility. I checked carefully the code, but the only instructions with Line are assignments and arithmetic operations with Line[i], i varying from 0 to Width-1. There is not a single operation with the pointer itself. So I don't see what could be wrong... ? This piece of code in my dll is a third party library (http://bigwww.epfl.ch/thevenaz/interpolation/). The code is nicely written, and it's clear than the author knows what he's doing. ? I am a bit puzzled, I am sure if there was such error there would be an exception thrown by the dll. But there's no exception: Python reports an error in the dll, and the dll does not see any error. It looks like Python and C++ do not understand each other. Might this be something wrong with my Python code, a bad usage of ctypes ?? Jerome _______________________________________________ AstroPy mailing list AstroPy at scipy.org http://mail.scipy.org/mailman/listinfo/astropy -------------- next part -------------- An HTML attachment was scrubbed... URL: