From hessman at astro.physik.uni-goettingen.de Wed Aug 14 10:47:19 2019 From: hessman at astro.physik.uni-goettingen.de (Frederic V. Hessman) Date: Wed, 14 Aug 2019 16:47:19 +0200 Subject: [AstroPy] BCE Time & Dates? Message-ID: <888A0790-0AA9-4455-AE06-72E4195B0E7C@astro.physik.uni-goettingen.de> I'm simulating Kepler's "Harmony of the Spheres" using the extended JPL ephemerides not usually available so that I can go back to Bischop Ussher's and Kepler's creation dates, thereby using astropy.time.Time for convenience functions. However, although >>> from astropy.time import Time >>> t = Time('4444-10-03T09:00:00') >>> str(t) '4444-10-03T09:00:00.000' >>> t.jd 3344473.875 obviously works, this doesn't: >>> t = Time('-4444-10-03T09:00:00') Traceback (most recent call last): File "", line 1, in File "/opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/astropy/time/core.py", line 399, in __init__ precision, in_subfmt, out_subfmt) File "/opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/astropy/time/core.py", line 454, in _init_from_vals precision, in_subfmt, out_subfmt) File "/opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/astropy/time/core.py", line 505, in _get_time_fmt raise ValueError('Input values did not match {0}'.format(err_msg)) ValueError: Input values did not match any of the formats where the format keyword is optional ['datetime', 'iso', 'isot', 'yday', 'datetime64', 'fits', 'byear_str', 'jyear_str'] nor does this: >>> t = Time(259237.875,format='jd') >>> t.datetime Traceback (most recent call last): File "", line 1, in File "/opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/astropy/time/core.py", line 1542, in __getattr__ value = tm._shaped_like_input(tm._time.to_value(parent=tm)) File "/opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/astropy/time/formats.py", line 682, in to_value out[...] = datetime.datetime(iy, im, id, ihr, imin, isec, ifracsec) ValueError: year is out of range and other attempts simply return garbage along with the message WARNING: ErfaWarning: ERFA function "d2dtf" yielded 1 of "dubious year (Note 5)" [astropy._erfa.core] Why is a BCE date garbagge or "dubious"? Rick From derek at astro.physik.uni-goettingen.de Wed Aug 14 13:30:05 2019 From: derek at astro.physik.uni-goettingen.de (Derek Homeier) Date: Wed, 14 Aug 2019 19:30:05 +0200 Subject: [AstroPy] BCE Time & Dates? In-Reply-To: <888A0790-0AA9-4455-AE06-72E4195B0E7C@astro.physik.uni-goettingen.de> References: <888A0790-0AA9-4455-AE06-72E4195B0E7C@astro.physik.uni-goettingen.de> Message-ID: Hi Rick, > > I'm simulating Kepler's "Harmony of the Spheres" using the extended JPL ephemerides not usually available so that I can go back to Bischop Ussher's and Kepler's creation dates, thereby using astropy.time.Time for convenience functions. However, although > > >>> from astropy.time import Time > >>> t = Time('4444-10-03T09:00:00') > >>> str(t) > '4444-10-03T09:00:00.000' > >>> t.jd > 3344473.875 > > obviously works, this doesn?t: > maybe the Bishop was right? ;-) > >>> t = Time('-4444-10-03T09:00:00') > Traceback (most recent call last): `Time` does support a class of `long*` subformats, which are even automatically recognised, but somewhat less than intuitive - they require a sign+5-digit year format! t = Time(?-04444-10-03T09:00:00?) should work (at least create a valid Time object. Not sure if there is a logical reason why signed 4-digit years cannot be recognised (other than apparently only exactly two year formats being defined; so <4 digits are not accepted either). Might be worth filing an issue. The `datetime` overflow is a limitation of the builtin library: datetime.MINYEAR The smallest year number allowed in a date or datetime object. MINYEAR is 1. so nothing you can really do about it at the Astropy level. HTH Derek From derek at astro.physik.uni-goettingen.de Wed Aug 14 13:53:32 2019 From: derek at astro.physik.uni-goettingen.de (Derek Homeier) Date: Wed, 14 Aug 2019 19:53:32 +0200 Subject: [AstroPy] BCE Time & Dates? In-Reply-To: References: <888A0790-0AA9-4455-AE06-72E4195B0E7C@astro.physik.uni-goettingen.de> Message-ID: <8B49902F-2F01-4100-83A5-4FAE08E6F2AE@astro.physik.uni-goettingen.de> On 14 Aug 2019, at 7:30 pm, Derek Homeier wrote: > >> >>> t = Time('-4444-10-03T09:00:00') >> Traceback (most recent call last): > > `Time` does support a class of `long*` subformats, which are even automatically recognised, > but somewhat less than intuitive - they require a sign+5-digit year format! > > t = Time(?-04444-10-03T09:00:00?) > > should work (at least create a valid Time object. Not sure if there is a logical reason why > signed 4-digit years cannot be recognised (other than apparently only exactly two year > formats being defined; so <4 digits are not accepted either). Might be worth filing an issue. Possibility some justification (as well as discussion of the existence of a ?year 0? - i.e. ?-04444? is the year 4445 BC!) is found in the corresponding FITS paper: https://www.aanda.org/articles/aa/abs/2015/02/aa24653-14/aa24653-14.html Cheers, Derek From leonardo.parisi at gmail.com Thu Aug 15 05:25:21 2019 From: leonardo.parisi at gmail.com (Leonardo Parisi) Date: Thu, 15 Aug 2019 11:25:21 +0200 Subject: [AstroPy] From pixels to RA DEC Message-ID: Hi, I'm looking to the formula used by Astropy to convert from pixels to ra/dec After take care of distortions the formula used is this? [image: Screenshot 2019-08-15 at 10.46.28.png] where RA0 and DEC0 are the coordinates of the center of the image gamma the pixel scale and alpha the rotational angle -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: Screenshot 2019-08-15 at 10.46.28.png Type: image/png Size: 27543 bytes Desc: not available URL: From gordon.b.dennis at gmail.com Sat Aug 17 11:11:03 2019 From: gordon.b.dennis at gmail.com (Gordon Dennis) Date: Sat, 17 Aug 2019 16:11:03 +0100 Subject: [AstroPy] Problem querying NED with astropy Message-ID: <000d01d5550d$fd530570$f7f91050$@gmail.com> Good morning I want to use astropy on Windows 10 to query the NASA extragalactic database (NED), but I'm having a very frustrating time getting even the simplest things to work.. 1. Installed Python36. 2. Tried pip install astropy. Result - fatal error. 3. Tried 2 more times Same result. 4. I read that if you install Python36 using the Anaconda distribution, astropy is included, so: 5. I de-installed Python36 and . 6. . installed Anaconda 7. Ran the Spyder IDE (Spyder is loaded automatically with Anaconda), and tried this very simple code (it's actually an example I copied from the www.astropy.org , apart from the argument 'NGC 1300' which is one of the galaxies I'm studying): from astroquery.ned import Ned result_table = Ned.query_object("NGC 1300") print(result_table) # an astropy.table.Table Now you get the error message 'unable to import Ned'. So, I guess it's seeing astropy but failing to recognize Ned. Obviously line 2 & 3 don't get executed. If I run the line from astroquery.ned import Ned in a windows command box and execute with Python36 I get the same result. 8. I assume (since the example above was copied from the astropy web site that 'Ned' with the uppercase 'N' is correct. I'm now 7 hours down and beginning to loose hope. What am I doing wrong/have missed or whatever? Would greatly appreciate any steers you can give me. Gordon Dennis p.s. yes I do have admin privileges; and my Windows 10 is fully updated. +44(0)1934 838096 / +44(0)7774628110 / Skype: gordon.dennis Sent from my Analytical Engine Description: analyticalEngine -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: image003.jpg Type: image/jpeg Size: 3301 bytes Desc: not available URL: From shupe at ipac.caltech.edu Sun Aug 18 11:18:37 2019 From: shupe at ipac.caltech.edu (Shupe, David L.) Date: Sun, 18 Aug 2019 15:18:37 +0000 Subject: [AstroPy] Problem querying NED with astropy In-Reply-To: <000d01d5550d$fd530570$f7f91050$@gmail.com> References: <000d01d5550d$fd530570$f7f91050$@gmail.com> Message-ID: Hello Gordon, Thank you for your inquiry about using astroquery.ned. The astroquery package is not included with Anaconda, so there is an additional installation needed for it. Following https://astroquery.readthedocs.io/en/latest/, since you have Anaconda installed, you can do ?conda install -c astropy astroquery? to get a tagged release. Or, for the latest version you can instead do ?pip install --pre astroquery?. Please feel free to contact me off-list if you have further questions, or are otherwise having trouble with the module for NED. Regards, David Shupe Caltech/IPAC On Aug 17, 2019, at 8:11 AM, Gordon Dennis > wrote: Good morning I want to use astropy on Windows 10 to query the NASA extragalactic database (NED), but I'm having a very frustrating time getting even the simplest things to work.. 1. Installed Python36. 2. Tried pip install astropy. Result - fatal error. 3. Tried 2 more times Same result. 4. I read that if you install Python36 using the Anaconda distribution, astropy is included, so: 5. I de-installed Python36 and ? 6. ? installed Anaconda 7. Ran the Spyder IDE (Spyder is loaded automatically with Anaconda), and tried this very simple code (it's actually an example I copied from the www.astropy.org , apart from the argument ?NGC 1300? which is one of the galaxies I?m studying): from astroquery.ned import Ned result_table = Ned.query_object("NGC 1300") print(result_table) # an astropy.table.Table Now you get the error message 'unable to import Ned'. So, I guess it?s seeing astropy but failing to recognize Ned. Obviously line 2 & 3 don?t get executed. If I run the line from astroquery.ned import Ned in a windows command box and execute with Python36 I get the same result. 8. I assume (since the example above was copied from the astropy web site that ?Ned? with the uppercase ?N? is correct. I'm now 7 hours down and beginning to loose hope. What am I doing wrong/have missed or whatever? Would greatly appreciate any steers you can give me. Gordon Dennis p.s. yes I do have admin privileges; and my Windows 10 is fully updated. +44(0)1934 838096 / +44(0)7774628110 / Skype: gordon.dennis Sent from my Analytical Engine _______________________________________________ AstroPy mailing list AstroPy at python.org https://mail.python.org/mailman/listinfo/astropy -------------- next part -------------- An HTML attachment was scrubbed... URL: From antigone.lambert-huyghe at cea.fr Fri Aug 23 08:10:17 2019 From: antigone.lambert-huyghe at cea.fr (LAMBERT-HUYGHE Antigone) Date: Fri, 23 Aug 2019 12:10:17 +0000 Subject: [AstroPy] Problem with the latest version of astropy and numpy Message-ID: Hi everyone, I post here because I don't really know where to advise of that problem. I use a convolution function from astropy.convolution package. I call it with result = [astropy.convolution.]convolve(inhdu[0].data, kernel, boundary = 'fill', fill_value = float('NaN'), preserve_nan=True) where inhdu[0].data is a numpy array, type float32, and a size of ~24000x25000 pixels, and where kernel is a gaussian kernel created with [astropy.convolution.]Gaussian2DKernel. I previously had version 3.1.X of astropy, and 1.16.X of numpy, and the convolution was working fine. But the packages went to versions 3.2 on mid-june and 1.17 at the end of july respectively, and I have now an error with the upgraded packages: ~/Bureau/Codes/python_lib/mylib/fits.py in fits_convolve(infits, fromfwhm, tofwhm, GaussianTrim, WriteTo, pixkey, pixkey_unit, returnHDU, verbose) 640 result[i, :, :] = convolve(plane, kernel, boundary = 'fill', fill_value = float('NaN'), preserve_nan=True) 641 else: --> 642 result = convolve(inhdu[0].data, kernel, boundary = 'fill', fill_value = float('NaN'), preserve_nan=True) 643 #result = convolve_fft(inhdu[0].data, kernel) 644 ~/.local/lib/python3.6/site-packages/astropy/nddata/decorators.py in wrapper(data, *args, **kwargs) 244 AstropyUserWarning) 245 --> 246 result = func(data, *args, **kwargs) 247 248 if unpack and repack: ~/.local/lib/python3.6/site-packages/astropy/convolution/convolve.py in convolve(array, kernel, boundary, fill_value, nan_treatment, normalize_kernel, mask, preserve_nan, normalization_zero_tol) 336 if normalize_kernel: 337 if not nan_interpolate: --> 338 result /= kernel_sum 339 else: 340 if nan_interpolate: ~/.local/lib/python3.6/site-packages/astropy/units/quantity.py in __array_ufunc__(self, function, method, *inputs, **kwargs) 473 return result 474 --> 475 return self._result_as_quantity(result, unit, out) 476 477 def _result_as_quantity(self, result, unit, out): ~/.local/lib/python3.6/site-packages/astropy/units/quantity.py in _result_as_quantity(self, result, unit, out) 512 # the output is of the correct Quantity subclass, as it was passed 513 # through check_output. --> 514 out._set_unit(unit) 515 return out 516 AttributeError: 'numpy.ndarray' object has no attribute '_set_unit' I tried to understand the problem, but I'm stuck and I really need that function to work. For the moment I will just reinstall previous versions for both packages, because it was working before the upgrade, but I wanted to let it know if it is a bug due to latest versions. It may be not in astropy package but in numpy package, but I was not able to understand that too. I hope this message is not too long, but I wanted to make it as clear as possible. Best regards Antigone Lambert-Huyghe -------------- next part -------------- An HTML attachment was scrubbed... URL: From kanderso at gemini.edu Fri Aug 23 11:04:23 2019 From: kanderso at gemini.edu (Kenneth Anderson) Date: Fri, 23 Aug 2019 11:04:23 -0400 Subject: [AstroPy] Problem with the latest version of astropy and numpy In-Reply-To: References: Message-ID: Hi Antigone, I cannot be sure how this problem arises for you, but what can be said is that an AttributeError thrown from the numpy object is way off base for that function. According the docstr on the* _result_as_quantity()*, the return object, i.e. the *'out'* object, should be an *astropy.units.Quantity* object, not a *numpy* object. It is unclear where things got confused in the call stack: perhaps an incorrect object type was passed initially? You may want to *absolutely ensure* that this did work under the previous versions. And if so, then it would seem something is amiss in that astropy call stack. >From the docstr: --------------------- *_result_as_quantity(self, result, unit, out): * * [ ... ] * * Parameters * * ---------- * * result : *`~numpy.ndarray` or tuple of `~numpy.ndarray` Array(s) which need to be turned into quantity. * unit : `~astropy.units.Unit` or None * Unit for the quantities to be returned (or `None` if the result should not be a quantity). Should be tuple if result is a tuple. * out : `~astropy.units.Quantity` or None * Possible output quantity. Should be `None` or a tuple if result is a tuple. * Returns * * ------- * * out : `~astropy.units.Quantity` * * With units set.* salud, k -------------- next part -------------- An HTML attachment was scrubbed... URL: From rowen at uw.edu Fri Aug 23 18:37:49 2019 From: rowen at uw.edu (Russell Owen) Date: Fri, 23 Aug 2019 15:37:49 -0700 Subject: [AstroPy] How to compute TAI-UTC using Astropy? In-Reply-To: References: Message-ID: <2B2DEF60-49E8-4F54-AF54-CF3951DE88EC@uw.edu> We do some work with TAI times as unix seconds. Possibly controversial, but it?s what we use. We sometimes need to convert normal unix times (UTC) to this standard. This naive solution does not work: def bogus_tai_from_utc(utc): ???Failed attempt to return TAI in unix seconds given UTC in unix seconds. This fails because given an astropy.time.Time astropy_time: astropy_time.tai.unix == astropy_time.utc.unix """ return astropy.time.Time(utc, format=?unix?, scale=?utc?).tai.unix Is there a nice way to ask AstroPy the value of TAI-UTC in seconds, given a UTC? If so, this would be perfect: tai_from_utc(utc): tai_minus_utc = ?? (presently 37 seconds) return utc + tai_minus_utc The following ugly code works, but has error at the microsecond level and may not work at leap seconds: tai_minus_utc = (astropy_utc.tai.mjd - astropy_utc.utc.mjd)*24*60*60 Regards, Russell From npross at roe.ac.uk Sat Aug 24 07:06:34 2019 From: npross at roe.ac.uk (Nicholas Ross) Date: Sat, 24 Aug 2019 11:06:34 +0000 Subject: [AstroPy] Weird Pyraf issues In-Reply-To: References: Message-ID: <6F23E02E-BA76-4332-8E10-24B8979C421F@roe.ac.uk> Hi there, I am having big difficulties with my Pyraf install, namely, my whole MacBook Pro (OS X 10.14.6) crashes whenever I try and simply open an IRAF graphics window, e.g. > source activate iraf27 (iraf27) ~/DataReduction/20190628 > ipython Python 2.7.16 |Anaconda, Inc.| (default, Aug 22 2019, 10:59:10) Type "copyright", "credits" or "license" for more information. IPython 5.8.0 -- An enhanced Interactive Python. ? -> Introduction and overview of IPython's features. %quickref -> Quick reference. help -> Python's own help system. object? -> Details about 'object', use 'object??' for extra details. Using matplotlib backend: TkAgg In [1]: from pyraf import iraf In [2]: iraf.splot('r2824072.fit[1]?) From here, I get directly booted out and back to the Mac login screen (yup, seriously!) I?ve just re-installed the conda distribution from https://astroconda.readthedocs.io/en/latest/updating.html#updating-conda > conda create -n iraf27 python=2.7 iraf-all pyraf-all stsci However, if I start an xgterm, and then do > cl and run IRAF from that command line, I can then do splot fine. Any help would be *SO* appreciated!! Yours, Nic ==================================== Dr. Nicholas P. Ross STFC Ernest Rutherford Fellow Institute for Astronomy University of Edinburgh Royal Observatory, Blackford Hill Edinburgh EH9 3HJ, United Kingdom +44 (0)131-668 8351 d80b2t.github.io ==================================== From zff1991 at mail.ustc.edu.cn Sat Aug 24 09:41:29 2019 From: zff1991 at mail.ustc.edu.cn (Zhu Fei-Fan) Date: Sat, 24 Aug 2019 09:41:29 -0400 Subject: [AstroPy] Weird Pyraf issues In-Reply-To: <6F23E02E-BA76-4332-8E10-24B8979C421F@roe.ac.uk> References: <6F23E02E-BA76-4332-8E10-24B8979C421F@roe.ac.uk> Message-ID: The recent version of DS9 (mac) also suffer from the very same issue under OS X 10.14.6. On Sat, 24 Aug 2019 at 08:00, Nicholas Ross wrote: > Hi there, > > I am having big difficulties with my Pyraf install, namely, my whole > MacBook Pro (OS X 10.14.6) > crashes whenever I try and simply open an IRAF graphics window, e.g. > > > source activate iraf27 > (iraf27) ~/DataReduction/20190628 > ipython > Python 2.7.16 |Anaconda, Inc.| (default, Aug 22 2019, 10:59:10) > Type "copyright", "credits" or "license" for more information. > IPython 5.8.0 -- An enhanced Interactive Python. > ? -> Introduction and overview of IPython's features. > %quickref -> Quick reference. > help -> Python's own help system. > object? -> Details about 'object', use 'object??' for extra > details. > Using matplotlib backend: TkAgg > > In [1]: from pyraf import iraf > > In [2]: iraf.splot('r2824072.fit[1]?) > > From here, I get directly booted out and back to the Mac login screen > (yup, seriously!) > > I?ve just re-installed the conda distribution from > https://astroconda.readthedocs.io/en/latest/updating.html#updating-conda > > conda create -n iraf27 python=2.7 iraf-all pyraf-all stsci > > However, if I start an xgterm, and then do > > cl > and run IRAF from that command line, I can then do splot fine. > > Any help would be *SO* appreciated!! > > Yours, > Nic > > > ==================================== > Dr. Nicholas P. Ross > STFC Ernest Rutherford Fellow > Institute for Astronomy > University of Edinburgh > Royal Observatory, Blackford Hill > Edinburgh EH9 3HJ, United Kingdom > +44 (0)131-668 8351 > d80b2t.github.io > ==================================== > > > > > > > _______________________________________________ > AstroPy mailing list > AstroPy at python.org > https://mail.python.org/mailman/listinfo/astropy > -------------- next part -------------- An HTML attachment was scrubbed... URL: From aldcroft at head.cfa.harvard.edu Sat Aug 24 17:12:16 2019 From: aldcroft at head.cfa.harvard.edu (Aldcroft, Thomas) Date: Sat, 24 Aug 2019 17:12:16 -0400 Subject: [AstroPy] How to compute TAI-UTC using Astropy? In-Reply-To: <2B2DEF60-49E8-4F54-AF54-CF3951DE88EC@uw.edu> References: <2B2DEF60-49E8-4F54-AF54-CF3951DE88EC@uw.edu> Message-ID: Hi Russell, I think what you want is: In [1]: from astropy.time import Time In [2]: date = '2019-08-24 00:00:00' In [3]: dt = Time(date, scale='utc') - Time(date, scale='tai') In [4]: dt.sec Out[4]: 36.99999999999779 - Tom On Fri, Aug 23, 2019 at 6:46 PM Russell Owen wrote: > We do some work with TAI times as unix seconds. Possibly controversial, > but it?s what we use. > > We sometimes need to convert normal unix times (UTC) to this standard. > > This naive solution does not work: > > def bogus_tai_from_utc(utc): > ???Failed attempt to return TAI in unix seconds given UTC in unix > seconds. > > This fails because given an astropy.time.Time astropy_time: > astropy_time.tai.unix == astropy_time.utc.unix > """ > return astropy.time.Time(utc, format=?unix?, scale=?utc?).tai.unix > > Is there a nice way to ask AstroPy the value of TAI-UTC in seconds, given > a UTC? > If so, this would be perfect: > > tai_from_utc(utc): > tai_minus_utc = ?? (presently 37 seconds) > return utc + tai_minus_utc > > The following ugly code works, but has error at the microsecond level and > may not work at leap seconds: > > tai_minus_utc = (astropy_utc.tai.mjd - astropy_utc.utc.mjd)*24*60*60 > > Regards, > > Russell > _______________________________________________ > AstroPy mailing list > AstroPy at python.org > https://mail.python.org/mailman/listinfo/astropy > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rowen at uw.edu Sat Aug 24 19:24:26 2019 From: rowen at uw.edu (Russell Owen) Date: Sat, 24 Aug 2019 16:24:26 -0700 Subject: [AstroPy] How to compute TAI-UTC using Astropy? In-Reply-To: References: <2B2DEF60-49E8-4F54-AF54-CF3951DE88EC@uw.edu> Message-ID: <665327DD-816A-41AA-BFC0-33D5AB975B3E@uw.edu> Thank you for the suggestion, but I?m afraid I don?t see how it works.. The given date I have to work from is a date in UTC. By specifying ?Time(date, scale=?tai?)? I would be lying to the system: saying the date was TAI when it is UTC. I would expect that to give the wrong answer very near a UTC leap second. My code didn?t work at leap second either, but this code does: def tai_from_utc(utc): """Return TAI in unix seconds, given UTC in unix seconds. """ astropy_utc = astropy.time.Time(utc, scale="utc", format="unix") dt_utc = astropy_utc.utc.to_datetime() dt_tai = astropy_utc.tai.to_datetime() tai_minus_utc = (dt_tai - dt_utc).total_seconds() return utc + tai_minus_utc It seems quite clumsy to have to use datetime objects *and* astropy. I?d welcome a cleaner solution! Regards, Russell > On Aug 24, 2019, at 2:12 PM, Aldcroft, Thomas wrote: > > Hi Russell, > > I think what you want is: > > In [1]: from astropy.time import Time > In [2]: date = '2019-08-24 00:00:00' > In [3]: dt = Time(date, scale='utc') - Time(date, scale='tai') > In [4]: dt.sec > Out[4]: 36.99999999999779 > > - Tom > > On Fri, Aug 23, 2019 at 6:46 PM Russell Owen > wrote: > We do some work with TAI times as unix seconds. Possibly controversial, but it?s what we use. > > We sometimes need to convert normal unix times (UTC) to this standard. > > This naive solution does not work: > > def bogus_tai_from_utc(utc): > ???Failed attempt to return TAI in unix seconds given UTC in unix seconds. > > This fails because given an astropy.time.Time astropy_time: > astropy_time.tai.unix == astropy_time.utc.unix > """ > return astropy.time.Time(utc, format=?unix?, scale=?utc?).tai.unix > > Is there a nice way to ask AstroPy the value of TAI-UTC in seconds, given a UTC? > If so, this would be perfect: > > tai_from_utc(utc): > tai_minus_utc = ?? (presently 37 seconds) > return utc + tai_minus_utc > > The following ugly code works, but has error at the microsecond level and may not work at leap seconds: > > tai_minus_utc = (astropy_utc.tai.mjd - astropy_utc.utc.mjd)*24*60*60 > > Regards, > > Russell > _______________________________________________ > AstroPy mailing list > AstroPy at python.org > https://mail.python.org/mailman/listinfo/astropy > _______________________________________________ > AstroPy mailing list > AstroPy at python.org > https://mail.python.org/mailman/listinfo/astropy -------------- next part -------------- An HTML attachment was scrubbed... URL: From aldcroft at head.cfa.harvard.edu Sun Aug 25 06:42:32 2019 From: aldcroft at head.cfa.harvard.edu (Aldcroft, Thomas) Date: Sun, 25 Aug 2019 06:42:32 -0400 Subject: [AstroPy] How to compute TAI-UTC using Astropy? In-Reply-To: <665327DD-816A-41AA-BFC0-33D5AB975B3E@uw.edu> References: <2B2DEF60-49E8-4F54-AF54-CF3951DE88EC@uw.edu> <665327DD-816A-41AA-BFC0-33D5AB975B3E@uw.edu> Message-ID: On Sat, Aug 24, 2019 at 7:24 PM Russell Owen wrote: > Thank you for the suggestion, but I?m afraid I don?t see how it works.. > The given date I have to work from is a date in UTC. By specifying > ?Time(date, scale=?tai?)? I would be lying to the system: saying the date > was TAI when it is UTC. I would expect that to give the wrong answer very > near a UTC leap second. > I think the code works as expected within a leap second, at the expense of an ERFA warning that you would need to catch: In [2]: dts = [0, 0.5, 1.0, 1.5, 1.99, 2.0, 2.5, 3.0] * u.s In [3]: dates_utc = Time(Time('2015-06-30 23:59:59') + dts, scale='utc') In [4]: dates_tai = Time(dates_utc.iso, scale='tai') WARNING: ErfaWarning: ERFA function "dtf2d" yielded 3 of "time is after end of day (Note 5)" [astropy._erfa.core] In [5]: for date_utc, date_tai in zip(dates_utc, dates_tai): ...: print(f'{date_utc} {(date_utc - date_tai).sec:.2f}') ...: 2015-06-30 23:59:59.000 35.00 2015-06-30 23:59:59.500 35.00 2015-06-30 23:59:60.000 35.00 2015-06-30 23:59:60.500 35.00 2015-06-30 23:59:60.990 35.00 2015-07-01 00:00:00.000 36.00 2015-07-01 00:00:00.500 36.00 2015-07-01 00:00:01.000 36.00 > > My code didn?t work at leap second either, but this code does: > > def tai_from_utc(utc): > """Return TAI in unix seconds, given UTC in unix seconds. > """ > astropy_utc = astropy.time.Time(utc, scale="utc", format="unix") > dt_utc = astropy_utc.utc.to_datetime() > dt_tai = astropy_utc.tai.to_datetime() > tai_minus_utc = (dt_tai - dt_utc).total_seconds() > return utc + tai_minus_utc > On this, I would caution against using the astropy unix format for calculations where the details matter. From the TimeUnix API docs : *NOTE: this quantity is not exactly unix time and differs from the strict POSIX definition by up to 1 second on days with a leap second. POSIX unix time actually jumps backward by 1 second at midnight on leap second days while this class value is monotonically increasing at 86400 seconds per UTC day.* I'm not sure about your test case, but the Python `datetime` does not support leap seconds. I got this exception trying to run your code within a leap second, but maybe I did something differently: ValueError: Time (array(2015, dtype=int32), array(6, dtype=int32), array(30, dtype=int32), array(23, dtype=int32), array(59, dtype=int32), array(60, dtype=int32), array(0, dtype=int32)) is within a leap second but datetime does not support leap seconds Cheers, Tom > > It seems quite clumsy to have to use datetime objects *and* astropy. I?d > welcome a cleaner solution! > > Regards, > > Russell > > On Aug 24, 2019, at 2:12 PM, Aldcroft, Thomas < > aldcroft at head.cfa.harvard.edu> wrote: > > Hi Russell, > > I think what you want is: > > In [1]: from astropy.time import Time > In [2]: date = '2019-08-24 00:00:00' > In [3]: dt = Time(date, scale='utc') - Time(date, scale='tai') > In [4]: dt.sec > Out[4]: 36.99999999999779 > > - Tom > > On Fri, Aug 23, 2019 at 6:46 PM Russell Owen wrote: > >> We do some work with TAI times as unix seconds. Possibly controversial, >> but it?s what we use. >> >> We sometimes need to convert normal unix times (UTC) to this standard. >> >> This naive solution does not work: >> >> def bogus_tai_from_utc(utc): >> ???Failed attempt to return TAI in unix seconds given UTC in unix >> seconds. >> >> This fails because given an astropy.time.Time astropy_time: >> astropy_time.tai.unix == astropy_time.utc.unix >> """ >> return astropy.time.Time(utc, format=?unix?, scale=?utc?).tai.unix >> >> Is there a nice way to ask AstroPy the value of TAI-UTC in seconds, given >> a UTC? >> If so, this would be perfect: >> >> tai_from_utc(utc): >> tai_minus_utc = ?? (presently 37 seconds) >> return utc + tai_minus_utc >> >> The following ugly code works, but has error at the microsecond level and >> may not work at leap seconds: >> >> tai_minus_utc = (astropy_utc.tai.mjd - astropy_utc.utc.mjd)*24*60*60 >> >> Regards, >> >> Russell >> _______________________________________________ >> AstroPy mailing list >> AstroPy at python.org >> https://mail.python.org/mailman/listinfo/astropy >> > _______________________________________________ > AstroPy mailing list > AstroPy at python.org > https://mail.python.org/mailman/listinfo/astropy > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From dburke.gw at gmail.com Sun Aug 25 09:32:57 2019 From: dburke.gw at gmail.com (Doug Burke) Date: Sun, 25 Aug 2019 09:32:57 -0400 Subject: [AstroPy] Weird Pyraf issues In-Reply-To: References: <6F23E02E-BA76-4332-8E10-24B8979C421F@roe.ac.uk> Message-ID: Apple decided to "improve" things in Mojave, which broke DS9. The latest beta release (8.1b2) should fix this - https://twitter.com/SAOImageDS9/status/1161031804695896064 - or, for a more-direct link - see http://ds9.si.edu/site/Beta.html I don't know if this helps Nic [there was unfortunately no follow up to Karl's remark at https://twitter.com/karlglazebrook/status/1161785531551797250 ] Doug On Sat, Aug 24, 2019 at 9:42 AM Zhu Fei-Fan wrote: > The recent version of DS9 (mac) also suffer from the very same issue under > OS X 10.14.6. > > > On Sat, 24 Aug 2019 at 08:00, Nicholas Ross wrote: > >> Hi there, >> >> I am having big difficulties with my Pyraf install, namely, my whole >> MacBook Pro (OS X 10.14.6) >> crashes whenever I try and simply open an IRAF graphics window, e.g. >> >> > source activate iraf27 >> (iraf27) ~/DataReduction/20190628 > ipython >> Python 2.7.16 |Anaconda, Inc.| (default, Aug 22 2019, 10:59:10) >> Type "copyright", "credits" or "license" for more information. >> IPython 5.8.0 -- An enhanced Interactive Python. >> ? -> Introduction and overview of IPython's features. >> %quickref -> Quick reference. >> help -> Python's own help system. >> object? -> Details about 'object', use 'object??' for extra >> details. >> Using matplotlib backend: TkAgg >> >> In [1]: from pyraf import iraf >> >> In [2]: iraf.splot('r2824072.fit[1]?) >> >> From here, I get directly booted out and back to the Mac login screen >> (yup, seriously!) >> >> I?ve just re-installed the conda distribution from >> https://astroconda.readthedocs.io/en/latest/updating.html#updating-conda >> > conda create -n iraf27 python=2.7 iraf-all pyraf-all stsci >> >> However, if I start an xgterm, and then do >> > cl >> and run IRAF from that command line, I can then do splot fine. >> >> Any help would be *SO* appreciated!! >> >> Yours, >> Nic >> >> >> ==================================== >> Dr. Nicholas P. Ross >> STFC Ernest Rutherford Fellow >> Institute for Astronomy >> University of Edinburgh >> Royal Observatory, Blackford Hill >> Edinburgh EH9 3HJ, United Kingdom >> +44 (0)131-668 8351 >> d80b2t.github.io >> ==================================== >> >> >> >> >> >> >> _______________________________________________ >> AstroPy mailing list >> AstroPy at python.org >> https://mail.python.org/mailman/listinfo/astropy >> > _______________________________________________ > AstroPy mailing list > AstroPy at python.org > https://mail.python.org/mailman/listinfo/astropy > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rowen at uw.edu Sun Aug 25 11:20:16 2019 From: rowen at uw.edu (Russell Owen) Date: Sun, 25 Aug 2019 08:20:16 -0700 Subject: [AstroPy] How to compute TAI-UTC using Astropy? In-Reply-To: References: <2B2DEF60-49E8-4F54-AF54-CF3951DE88EC@uw.edu> <665327DD-816A-41AA-BFC0-33D5AB975B3E@uw.edu> Message-ID: > On Aug 25, 2019, at 3:42 AM, Aldcroft, Thomas wrote: > > > > On Sat, Aug 24, 2019 at 7:24 PM Russell Owen > wrote: > Thank you for the suggestion, but I?m afraid I don?t see how it works.. The given date I have to work from is a date in UTC. By specifying ?Time(date, scale=?tai?)? I would be lying to the system: saying the date was TAI when it is UTC. I would expect that to give the wrong answer very near a UTC leap second. > > I think the code works as expected within a leap second, at the expense of an ERFA warning that you would need to catch: > > In [2]: dts = [0, 0.5, 1.0, 1.5, 1.99, 2.0, 2.5, 3.0] * u.s > In [3]: dates_utc = Time(Time('2015-06-30 23:59:59') + dts, scale='utc') > In [4]: dates_tai = Time(dates_utc.iso, scale='tai') > WARNING: ErfaWarning: ERFA function "dtf2d" yielded 3 of "time is after end of day (Note 5)" [astropy._erfa.core] > In [5]: for date_utc, date_tai in zip(dates_utc, dates_tai): > ...: print(f'{date_utc} {(date_utc - date_tai).sec:.2f}') > ...: > 2015-06-30 23:59:59.000 35.00 > 2015-06-30 23:59:59.500 35.00 > 2015-06-30 23:59:60.000 35.00 > 2015-06-30 23:59:60.500 35.00 > 2015-06-30 23:59:60.990 35.00 > 2015-07-01 00:00:00.000 36.00 > 2015-07-01 00:00:00.500 36.00 > 2015-07-01 00:00:01.000 36.00 > > > My code didn?t work at leap second either, but this code does: > > def tai_from_utc(utc): > """Return TAI in unix seconds, given UTC in unix seconds. > """ > astropy_utc = astropy.time.Time(utc, scale="utc", format="unix") > dt_utc = astropy_utc.utc.to_datetime() > dt_tai = astropy_utc.tai.to_datetime() > tai_minus_utc = (dt_tai - dt_utc).total_seconds() > return utc + tai_minus_utc > > On this, I would caution against using the astropy unix format for calculations where the details matter. From the TimeUnix API docs : > > NOTE: this quantity is not exactly unix time and differs from the strict POSIX definition by up to 1 second on days with a leap second. POSIX unix time actually jumps backward by 1 second at midnight on leap second days while this class value is monotonically increasing at 86400 seconds per UTC day. I had missed that warning. Ouch! I think I have been approaching this the wrong way. We are representing timestamps in TAI unix seconds. I have two cases: 1) Generate a TAI unix timestamp using the current time. I really want to get this one right. Originally I had hoped to use `Time.now().tai.unix`. Unfortunately that gives UTC, not TAI. My fallback was `tai_from_utc(ttime.time()) but this is looking even worse, since it?s not completely clear what time.time() will return near the leap second (at least based on the wikipedia article on unix timestamps). The wikipedia article on unix timestamps points out that the POSIX standard specifies one behavior for system time, but that systems that use NTP typically use a different standard (though one that includes useful flags). We?ll be using PTP or NTP. Unfortunately it may not be possible to use the time, datetime, and/or astropy.time packages as none of them appear to pay attention to those flags. 2) Convert a normal unix timestamp (as a float, any other information such as leap seconds flags is gone) to a TAI unix timestamp. In this case we could probably live with a 1 second error at or near a leap second because the information is only used to measure delays in our messaging system (DDS). But if I can get it right, so much the better. > I'm not sure about your test case, but the Python `datetime` does not support leap seconds. I got this exception trying to run your code within a leap second, but maybe I did something differently: > > ValueError: Time (array(2015, dtype=int32), array(6, dtype=int32), array(30, dtype=int32), array(23, dtype=int32), array(59, dtype=int32), array(60, dtype=int32), array(0, dtype=int32)) is within a leap second but datetime does not support leap seconds That is very helpful. My test was missing ?fraction of a second before seconds=60?. With that I get the same error. Of course I can subtract a second from the two times when that error occurs, but it doesn?t help with the fundamental issues. Regards, Russell -------------- next part -------------- An HTML attachment was scrubbed... URL: From peter.erwin at gmail.com Sun Aug 25 16:11:11 2019 From: peter.erwin at gmail.com (Peter Erwin) Date: Sun, 25 Aug 2019 22:11:11 +0200 Subject: [AstroPy] Preliminary/beta version of PyImfit Message-ID: Hi, I'd like to announce the availability of a preliminary version of PyImfit, a Python wrapper around the C++-based galaxy-image-fitting code Imfit Imfit is a fast, flexible system for fitting FITS image (of galaxies or other objects) with simple or complex sets of models, using optional PSF convolution (including convolution of sub-regions using oversampled PSF images) with a choice of multiple fitting algorithms algorithms and several different fit statistics (e.g., standard chi^2 and pure Poisson-based). For more information, see: http://www.mpe.mpg.de/~erwin/code/imfit/ PyImfit allows the use of Imfit models and fitting from within Python, using Numpy arrays. The full package (for Python 3.6 or later on macOS, 3.5 or later on Linux) can be found on Github at https://github.com/perwin/pyimfit and can also be installed via pip: $ pip3 install pyimfit (On macOS, this will install a pre-compiled binary wheel. On Linux, it may be necessary for your version of GCC to be 5.0 or newer.) Limited documentation (currently being expanded) can be found here: https://pyimfit.readthedocs.io/en/latest/ This includes a Jupyter notebook which provides an example of using PyImfit with the MCMC package "emcee": https://github.com/perwin/pyimfit/blob/master/docs/pyimfit_emcee.ipynb The documentation for Imfit will probably also be useful (e.g., currently the only place where the image functions are described in detail): https://imfit.readthedocs.io/en/latest/ http://www.mpe.mpg.de/~erwin/resources/imfit/imfit_howto.pdf Questions, bug reports, and suggestions for improvement are very welcome; you can email me (erwin at sigmaxi.net or erwin at mpe.mpg.de) or open an issue at the Github site (https://github.com/perwin/pyimfit/issues). cheers, Peter ============================================================= Peter Erwin Max-Planck-Insitute for Extraterrestrial erwin at mpe.mpg.de Physics, Giessenbachstrasse tel. +49 (0)176 2481 7713 85748 Garching, Germany fax +49 (0)89 30000 3495 http://www.mpe.mpg.de/~erwin From antigone.lambert-huyghe at cea.fr Mon Aug 26 03:24:08 2019 From: antigone.lambert-huyghe at cea.fr (LAMBERT-HUYGHE Antigone) Date: Mon, 26 Aug 2019 07:24:08 +0000 Subject: [AstroPy] Problem with the latest version of astropy and numpy In-Reply-To: References: , Message-ID: Hi, I re-installed previous versions, more precisely 3.0.4 for astropy and 1.16.4 for numpy. The things are going well, with no error, and the convolution is well done, for any size of map. So I'm sure it is due to new versions of astropy (or numpy). I don't understant why it should be a quantity, because I'm not using directly _result_as_quantity(), but astropy.convolution.convolve(), for which the doc is the following: convolve(array, kernel, boundary='fill', fill_value=0.0, nan_treatment='interpolate', normalize_kernel=True, mask=None, preserve_nan=False, normalization_zero_tol=1e-08) Parameters array NDData or numpy.ndarray or array-like The array to convolve. This should be a 1, 2, or 3-dimensional array or a list or a set of nested lists representing a 1, 2, or 3-dimensional array. If an NDData, the mask of the NDData will be used as the mask argument. kernel numpy.ndarray or Kernel The convolution kernel. The number of dimensions should match those for the array, and the dimensions should be odd in all directions. If a masked array, the masked values will be replaced by fill_value. [...] Returns result numpy.ndarray An array with the same dimensions and as the input array, convolved with kernel. The data type depends on the input array type. If array is a floating point type, then the return array keeps the same data type, otherwise the type is numpy.float. I don't understand why this function is now using _result_as_quantity(), from what I checked in the source code it is indirect use. But from the doc I can use numpy arrays as input for the map to convolve. Best, Antigone ________________________________ De : AstroPy [astropy-bounces+antigone.lambert-huyghe=cea.fr at python.org] de la part de Kenneth Anderson [kanderso at gemini.edu] Envoy? : vendredi 23 ao?t 2019 17:04 ? : Astronomical Python mailing list Objet : Re: [AstroPy] Problem with the latest version of astropy and numpy Hi Antigone, I cannot be sure how this problem arises for you, but what can be said is that an AttributeError thrown from the numpy object is way off base for that function. According the docstr on the _result_as_quantity(), the return object, i.e. the 'out' object, should be an astropy.units.Quantity object, not a numpy object. It is unclear where things got confused in the call stack: perhaps an incorrect object type was passed initially? You may want to absolutely ensure that this did work under the previous versions. And if so, then it would seem something is amiss in that astropy call stack. >From the docstr: --------------------- _result_as_quantity(self, result, unit, out): [ ... ] Parameters ---------- result : `~numpy.ndarray` or tuple of `~numpy.ndarray` Array(s) which need to be turned into quantity. unit : `~astropy.units.Unit` or None Unit for the quantities to be returned (or `None` if the result should not be a quantity). Should be tuple if result is a tuple. out : `~astropy.units.Quantity` or None Possible output quantity. Should be `None` or a tuple if result is a tuple. Returns ------- out : `~astropy.units.Quantity` With units set. salud, k -------------- next part -------------- An HTML attachment was scrubbed... URL: From simon at sconseil.fr Mon Aug 26 05:59:04 2019 From: simon at sconseil.fr (Simon Conseil) Date: Mon, 26 Aug 2019 11:59:04 +0200 Subject: [AstroPy] Problem with the latest version of astropy and numpy In-Reply-To: References: Message-ID: Hi, It is indeed weird that it tries to convert to a quantity if you are using Numpy arrays. There were significant changes in the convolution sub-package in Astropy 3.2 so this is probably worth a bug report, and ideally adding a minimal example to reproduce the issue (showing how you build the kernel). Best, Simon Le 26/08/2019 ? 09:24, LAMBERT-HUYGHE Antigone a ?crit?: > Hi, > > I re-installed previous versions, more precisely 3.0.4 for astropy and 1.16.4 for numpy. The things are going well, with no error, and the convolution is well done, for any size of map. So I'm sure it is due to new versions of astropy (or numpy). > > I don't understant why it should be a quantity, because I'm not using directly _result_as_quantity(), but astropy.convolution.convolve(), for which the doc is the following: > > convolve(array, kernel, boundary='fill', fill_value=0.0, nan_treatment='interpolate', normalize_kernel=True, mask=None, preserve_nan=False, normalization_zero_tol=1e-08) > > Parameters > > array NDData or numpy.ndarray or array-like > > The array to convolve. This should be a 1, 2, or 3-dimensional array or a list or a set of nested lists representing a 1, 2, or 3-dimensional array. If an NDData, the mask of the NDData will be used as the mask argument. > > kernel numpy.ndarray or Kernel > > The convolution kernel. The number of dimensions should match those for the array, and the dimensions should be odd in all directions. If a masked array, the masked values will be replaced by fill_value. > > [...] > Returns > > result numpy.ndarray > > An array with the same dimensions and as the input array, convolved with kernel. The data type depends on the input array type. If array is a floating point type, then the return array keeps the same data type, otherwise the type is numpy.float. > > I don't understand why this function is now using _result_as_quantity(), from what I checked in the source code it is indirect use. But from the doc I can use numpy arrays as input for the map to convolve. > > Best, > > Antigone > ________________________________ > De : AstroPy [astropy-bounces+antigone.lambert-huyghe=cea.fr at python.org] de la part de Kenneth Anderson [kanderso at gemini.edu] > Envoy? : vendredi 23 ao?t 2019 17:04 > ? : Astronomical Python mailing list > Objet : Re: [AstroPy] Problem with the latest version of astropy and numpy > > Hi Antigone, > > I cannot be sure how this problem arises for you, but what can be said is that an AttributeError thrown from the numpy object is way off base for that function. According the docstr on the _result_as_quantity(), the return object, i.e. the 'out' object, should be an astropy.units.Quantity object, not a numpy object. > > It is unclear where things got confused in the call stack: perhaps an incorrect object type was passed initially? You may want to absolutely ensure that this did work under the previous versions. And if so, then it would seem something is amiss in that astropy call stack. > > From the docstr: > --------------------- > _result_as_quantity(self, result, unit, out): > [ ... ] > Parameters > ---------- > result : `~numpy.ndarray` or tuple of `~numpy.ndarray` > Array(s) which need to be turned into quantity. > unit : `~astropy.units.Unit` or None > Unit for the quantities to be returned (or `None` if the result > should not be a quantity). Should be tuple if result is a tuple. > out : `~astropy.units.Quantity` or None > Possible output quantity. Should be `None` or a tuple if result > is a tuple. > > Returns > ------- > out : `~astropy.units.Quantity` > With units set. > > salud, > k > > > > > _______________________________________________ > AstroPy mailing list > AstroPy at python.org > https://mail.python.org/mailman/listinfo/astropy -------------- next part -------------- An HTML attachment was scrubbed... URL: From antigone.lambert-huyghe at cea.fr Mon Aug 26 06:58:09 2019 From: antigone.lambert-huyghe at cea.fr (LAMBERT-HUYGHE Antigone) Date: Mon, 26 Aug 2019 10:58:09 +0000 Subject: [AstroPy] Problem with the latest version of astropy and numpy In-Reply-To: References: , Message-ID: Hi, Ok, where can I send the bug report? I will construct the minimal example ASAP. Best, Antigone ________________________________ De : AstroPy [astropy-bounces+antigone.lambert-huyghe=cea.fr at python.org] de la part de Simon Conseil [simon at sconseil.fr] Envoy? : lundi 26 ao?t 2019 11:59 ? : astropy at python.org Objet : Re: [AstroPy] Problem with the latest version of astropy and numpy Hi, It is indeed weird that it tries to convert to a quantity if you are using Numpy arrays. There were significant changes in the convolution sub-package in Astropy 3.2 so this is probably worth a bug report, and ideally adding a minimal example to reproduce the issue (showing how you build the kernel). Best, Simon Le 26/08/2019 ? 09:24, LAMBERT-HUYGHE Antigone a ?crit : Hi, I re-installed previous versions, more precisely 3.0.4 for astropy and 1.16.4 for numpy. The things are going well, with no error, and the convolution is well done, for any size of map. So I'm sure it is due to new versions of astropy (or numpy). I don't understant why it should be a quantity, because I'm not using directly _result_as_quantity(), but astropy.convolution.convolve(), for which the doc is the following: convolve(array, kernel, boundary='fill', fill_value=0.0, nan_treatment='interpolate', normalize_kernel=True, mask=None, preserve_nan=False, normalization_zero_tol=1e-08) Parameters array NDData or numpy.ndarray or array-like The array to convolve. This should be a 1, 2, or 3-dimensional array or a list or a set of nested lists representing a 1, 2, or 3-dimensional array. If an NDData, the mask of the NDData will be used as the mask argument. kernel numpy.ndarray or Kernel The convolution kernel. The number of dimensions should match those for the array, and the dimensions should be odd in all directions. If a masked array, the masked values will be replaced by fill_value. [...] Returns result numpy.ndarray An array with the same dimensions and as the input array, convolved with kernel. The data type depends on the input array type. If array is a floating point type, then the return array keeps the same data type, otherwise the type is numpy.float. I don't understand why this function is now using _result_as_quantity(), from what I checked in the source code it is indirect use. But from the doc I can use numpy arrays as input for the map to convolve. Best, Antigone ________________________________ De : AstroPy [astropy-bounces+antigone.lambert-huyghe=cea.fr at python.org] de la part de Kenneth Anderson [kanderso at gemini.edu] Envoy? : vendredi 23 ao?t 2019 17:04 ? : Astronomical Python mailing list Objet : Re: [AstroPy] Problem with the latest version of astropy and numpy Hi Antigone, I cannot be sure how this problem arises for you, but what can be said is that an AttributeError thrown from the numpy object is way off base for that function. According the docstr on the _result_as_quantity(), the return object, i.e. the 'out' object, should be an astropy.units.Quantity object, not a numpy object. It is unclear where things got confused in the call stack: perhaps an incorrect object type was passed initially? You may want to absolutely ensure that this did work under the previous versions. And if so, then it would seem something is amiss in that astropy call stack. >From the docstr: --------------------- _result_as_quantity(self, result, unit, out): [ ... ] Parameters ---------- result : `~numpy.ndarray` or tuple of `~numpy.ndarray` Array(s) which need to be turned into quantity. unit : `~astropy.units.Unit` or None Unit for the quantities to be returned (or `None` if the result should not be a quantity). Should be tuple if result is a tuple. out : `~astropy.units.Quantity` or None Possible output quantity. Should be `None` or a tuple if result is a tuple. Returns ------- out : `~astropy.units.Quantity` With units set. salud, k _______________________________________________ AstroPy mailing list AstroPy at python.org https://mail.python.org/mailman/listinfo/astropy -------------- next part -------------- An HTML attachment was scrubbed... URL: From simon at sconseil.fr Mon Aug 26 08:22:31 2019 From: simon at sconseil.fr (Simon Conseil) Date: Mon, 26 Aug 2019 14:22:31 +0200 Subject: [AstroPy] Problem with the latest version of astropy and numpy In-Reply-To: References: Message-ID: <36aab5ae-e434-652b-d701-62493b7485bf@sconseil.fr> The issue tracker is on github: https://github.com/astropy/astropy/issues/new Simon Le 26/08/2019 ? 12:58, LAMBERT-HUYGHE Antigone a ?crit?: > Hi, > > Ok, where can I send the bug report? I will construct the minimal example ASAP. > > Best, > Antigone > ________________________________ > De : AstroPy [astropy-bounces+antigone.lambert-huyghe=cea.fr at python.org] de la part de Simon Conseil [simon at sconseil.fr] > Envoy? : lundi 26 ao?t 2019 11:59 > ? : astropy at python.org > Objet : Re: [AstroPy] Problem with the latest version of astropy and numpy > > > Hi, > > It is indeed weird that it tries to convert to a quantity if you are using Numpy arrays. There were significant changes in the convolution sub-package in Astropy 3.2 so this is probably worth a bug report, and ideally adding a minimal example to reproduce the issue (showing how you build the kernel). > > Best, > > Simon > > Le 26/08/2019 ? 09:24, LAMBERT-HUYGHE Antigone a ?crit : > > Hi, > > I re-installed previous versions, more precisely 3.0.4 for astropy and 1.16.4 for numpy. The things are going well, with no error, and the convolution is well done, for any size of map. So I'm sure it is due to new versions of astropy (or numpy). > > I don't understant why it should be a quantity, because I'm not using directly _result_as_quantity(), but astropy.convolution.convolve(), for which the doc is the following: > > convolve(array, kernel, boundary='fill', fill_value=0.0, nan_treatment='interpolate', normalize_kernel=True, mask=None, preserve_nan=False, normalization_zero_tol=1e-08) > > Parameters > > array NDData or numpy.ndarray or array-like > > The array to convolve. This should be a 1, 2, or 3-dimensional array or a list or a set of nested lists representing a 1, 2, or 3-dimensional array. If an NDData, the mask of the NDData will be used as the mask argument. > > kernel numpy.ndarray or Kernel > > The convolution kernel. The number of dimensions should match those for the array, and the dimensions should be odd in all directions. If a masked array, the masked values will be replaced by fill_value. > > [...] > Returns > > result numpy.ndarray > > An array with the same dimensions and as the input array, convolved with kernel. The data type depends on the input array type. If array is a floating point type, then the return array keeps the same data type, otherwise the type is numpy.float. > > I don't understand why this function is now using _result_as_quantity(), from what I checked in the source code it is indirect use. But from the doc I can use numpy arrays as input for the map to convolve. > > Best, > > Antigone > ________________________________ > De : AstroPy [astropy-bounces+antigone.lambert-huyghe=cea.fr at python.org] de la part de Kenneth Anderson [kanderso at gemini.edu] > Envoy? : vendredi 23 ao?t 2019 17:04 > ? : Astronomical Python mailing list > Objet : Re: [AstroPy] Problem with the latest version of astropy and numpy > > Hi Antigone, > > I cannot be sure how this problem arises for you, but what can be said is that an AttributeError thrown from the numpy object is way off base for that function. According the docstr on the _result_as_quantity(), the return object, i.e. the 'out' object, should be an astropy.units.Quantity object, not a numpy object. > > It is unclear where things got confused in the call stack: perhaps an incorrect object type was passed initially? You may want to absolutely ensure that this did work under the previous versions. And if so, then it would seem something is amiss in that astropy call stack. > > From the docstr: > --------------------- > _result_as_quantity(self, result, unit, out): > [ ... ] > Parameters > ---------- > result : `~numpy.ndarray` or tuple of `~numpy.ndarray` > Array(s) which need to be turned into quantity. > unit : `~astropy.units.Unit` or None > Unit for the quantities to be returned (or `None` if the result > should not be a quantity). Should be tuple if result is a tuple. > out : `~astropy.units.Quantity` or None > Possible output quantity. Should be `None` or a tuple if result > is a tuple. > > Returns > ------- > out : `~astropy.units.Quantity` > With units set. > > salud, > k > > > > > > > > _______________________________________________ > AstroPy mailing list > AstroPy at python.org > https://mail.python.org/mailman/listinfo/astropy > > > > _______________________________________________ > AstroPy mailing list > AstroPy at python.org > https://mail.python.org/mailman/listinfo/astropy -------------- next part -------------- An HTML attachment was scrubbed... URL: From antigone.lambert-huyghe at cea.fr Mon Aug 26 08:24:51 2019 From: antigone.lambert-huyghe at cea.fr (LAMBERT-HUYGHE Antigone) Date: Mon, 26 Aug 2019 12:24:51 +0000 Subject: [AstroPy] Problem with the latest version of astropy and numpy In-Reply-To: <36aab5ae-e434-652b-d701-62493b7485bf@sconseil.fr> References: , <36aab5ae-e434-652b-d701-62493b7485bf@sconseil.fr> Message-ID: Isn't there an other way? I don't have a github account. Antigone ________________________________ De : AstroPy [astropy-bounces+antigone.lambert-huyghe=cea.fr at python.org] de la part de Simon Conseil [simon at sconseil.fr] Envoy? : lundi 26 ao?t 2019 14:22 ? : astropy at python.org Objet : Re: [AstroPy] Problem with the latest version of astropy and numpy The issue tracker is on github: https://github.com/astropy/astropy/issues/new Simon Le 26/08/2019 ? 12:58, LAMBERT-HUYGHE Antigone a ?crit : Hi, Ok, where can I send the bug report? I will construct the minimal example ASAP. Best, Antigone ________________________________ De : AstroPy [astropy-bounces+antigone.lambert-huyghe=cea.fr at python.org] de la part de Simon Conseil [simon at sconseil.fr] Envoy? : lundi 26 ao?t 2019 11:59 ? : astropy at python.org Objet : Re: [AstroPy] Problem with the latest version of astropy and numpy Hi, It is indeed weird that it tries to convert to a quantity if you are using Numpy arrays. There were significant changes in the convolution sub-package in Astropy 3.2 so this is probably worth a bug report, and ideally adding a minimal example to reproduce the issue (showing how you build the kernel). Best, Simon Le 26/08/2019 ? 09:24, LAMBERT-HUYGHE Antigone a ?crit : Hi, I re-installed previous versions, more precisely 3.0.4 for astropy and 1.16.4 for numpy. The things are going well, with no error, and the convolution is well done, for any size of map. So I'm sure it is due to new versions of astropy (or numpy). I don't understant why it should be a quantity, because I'm not using directly _result_as_quantity(), but astropy.convolution.convolve(), for which the doc is the following: convolve(array, kernel, boundary='fill', fill_value=0.0, nan_treatment='interpolate', normalize_kernel=True, mask=None, preserve_nan=False, normalization_zero_tol=1e-08) Parameters array NDData or numpy.ndarray or array-like The array to convolve. This should be a 1, 2, or 3-dimensional array or a list or a set of nested lists representing a 1, 2, or 3-dimensional array. If an NDData, the mask of the NDData will be used as the mask argument. kernel numpy.ndarray or Kernel The convolution kernel. The number of dimensions should match those for the array, and the dimensions should be odd in all directions. If a masked array, the masked values will be replaced by fill_value. [...] Returns result numpy.ndarray An array with the same dimensions and as the input array, convolved with kernel. The data type depends on the input array type. If array is a floating point type, then the return array keeps the same data type, otherwise the type is numpy.float. I don't understand why this function is now using _result_as_quantity(), from what I checked in the source code it is indirect use. But from the doc I can use numpy arrays as input for the map to convolve. Best, Antigone ________________________________ De : AstroPy [astropy-bounces+antigone.lambert-huyghe=cea.fr at python.org] de la part de Kenneth Anderson [kanderso at gemini.edu] Envoy? : vendredi 23 ao?t 2019 17:04 ? : Astronomical Python mailing list Objet : Re: [AstroPy] Problem with the latest version of astropy and numpy Hi Antigone, I cannot be sure how this problem arises for you, but what can be said is that an AttributeError thrown from the numpy object is way off base for that function. According the docstr on the _result_as_quantity(), the return object, i.e. the 'out' object, should be an astropy.units.Quantity object, not a numpy object. It is unclear where things got confused in the call stack: perhaps an incorrect object type was passed initially? You may want to absolutely ensure that this did work under the previous versions. And if so, then it would seem something is amiss in that astropy call stack. >From the docstr: --------------------- _result_as_quantity(self, result, unit, out): [ ... ] Parameters ---------- result : `~numpy.ndarray` or tuple of `~numpy.ndarray` Array(s) which need to be turned into quantity. unit : `~astropy.units.Unit` or None Unit for the quantities to be returned (or `None` if the result should not be a quantity). Should be tuple if result is a tuple. out : `~astropy.units.Quantity` or None Possible output quantity. Should be `None` or a tuple if result is a tuple. Returns ------- out : `~astropy.units.Quantity` With units set. salud, k _______________________________________________ AstroPy mailing list AstroPy at python.org https://mail.python.org/mailman/listinfo/astropy _______________________________________________ AstroPy mailing list AstroPy at python.org https://mail.python.org/mailman/listinfo/astropy -------------- next part -------------- An HTML attachment was scrubbed... URL: From aldcroft at head.cfa.harvard.edu Mon Aug 26 08:51:32 2019 From: aldcroft at head.cfa.harvard.edu (Aldcroft, Thomas) Date: Mon, 26 Aug 2019 08:51:32 -0400 Subject: [AstroPy] Problem with the latest version of astropy and numpy In-Reply-To: References: <36aab5ae-e434-652b-d701-62493b7485bf@sconseil.fr> Message-ID: Feel free to post the example here and a maintainer will put it on GitHub for you. Thanks! Tom On Mon, Aug 26, 2019 at 8:25 AM LAMBERT-HUYGHE Antigone < antigone.lambert-huyghe at cea.fr> wrote: > Isn't there an other way? I don't have a github account. > > Antigone > ------------------------------ > *De :* AstroPy [astropy-bounces+antigone.lambert-huyghe=cea.fr at python.org] > de la part de Simon Conseil [simon at sconseil.fr] > *Envoy? :* lundi 26 ao?t 2019 14:22 > *? :* astropy at python.org > *Objet :* Re: [AstroPy] Problem with the latest version of astropy and > numpy > > The issue tracker is on github: > > https://github.com/astropy/astropy/issues/new > > Simon > > > Le 26/08/2019 ? 12:58, LAMBERT-HUYGHE Antigone a ?crit : > > Hi, > > Ok, where can I send the bug report? I will construct the minimal example ASAP. > > Best, > Antigone > ________________________________ > De : AstroPy [astropy-bounces+antigone.lambert-huyghe=cea.fr at python.org] de la part de Simon Conseil [simon at sconseil.fr] > Envoy? : lundi 26 ao?t 2019 11:59 > ? : astropy at python.org > Objet : Re: [AstroPy] Problem with the latest version of astropy and numpy > > > Hi, > > It is indeed weird that it tries to convert to a quantity if you are using Numpy arrays. There were significant changes in the convolution sub-package in Astropy 3.2 so this is probably worth a bug report, and ideally adding a minimal example to reproduce the issue (showing how you build the kernel). > > Best, > > Simon > > Le 26/08/2019 ? 09:24, LAMBERT-HUYGHE Antigone a ?crit : > > Hi, > > I re-installed previous versions, more precisely 3.0.4 for astropy and 1.16.4 for numpy. The things are going well, with no error, and the convolution is well done, for any size of map. So I'm sure it is due to new versions of astropy (or numpy). > > I don't understant why it should be a quantity, because I'm not using directly _result_as_quantity(), but astropy.convolution.convolve(), for which the doc is the following: > > convolve(array, kernel, boundary='fill', fill_value=0.0, nan_treatment='interpolate', normalize_kernel=True, mask=None, preserve_nan=False, normalization_zero_tol=1e-08) > > Parameters > > array NDData or numpy.ndarray or array-like > > The array to convolve. This should be a 1, 2, or 3-dimensional array or a list or a set of nested lists representing a 1, 2, or 3-dimensional array. If an NDData , the mask of the NDData will be used as the mask argument. > > kernel numpy.ndarray or Kernel > > The convolution kernel. The number of dimensions should match those for the array, and the dimensions should be odd in all directions. If a masked array, the masked values will be replaced by fill_value. > > [...] > Returns > > result numpy.ndarray > > An array with the same dimensions and as the input array, convolved with kernel. The data type depends on the input array type. If array is a floating point type, then the return array keeps the same data type, otherwise the type is numpy.float. > > I don't understand why this function is now using _result_as_quantity(), from what I checked in the source code it is indirect use. But from the doc I can use numpy arrays as input for the map to convolve. > > Best, > > Antigone > ________________________________ > De : AstroPy [astropy-bounces+antigone.lambert-huyghe=cea.fr at python.org ] de la part de Kenneth Anderson [kanderso at gemini.edu ] > Envoy? : vendredi 23 ao?t 2019 17:04 > ? : Astronomical Python mailing list > Objet : Re: [AstroPy] Problem with the latest version of astropy and numpy > > Hi Antigone, > > I cannot be sure how this problem arises for you, but what can be said is that an AttributeError thrown from the numpy object is way off base for that function. According the docstr on the _result_as_quantity(), the return object, i.e. the 'out' object, should be an astropy.units.Quantity object, not a numpy object. > > It is unclear where things got confused in the call stack: perhaps an incorrect object type was passed initially? You may want to absolutely ensure that this did work under the previous versions. And if so, then it would seem something is amiss in that astropy call stack. > > From the docstr: > --------------------- > _result_as_quantity(self, result, unit, out): > [ ... ] > Parameters > ---------- > result : `~numpy.ndarray` or tuple of `~numpy.ndarray` > Array(s) which need to be turned into quantity. > unit : `~astropy.units.Unit` or None > Unit for the quantities to be returned (or `None` if the result > should not be a quantity). Should be tuple if result is a tuple. > out : `~astropy.units.Quantity` or None > Possible output quantity. Should be `None` or a tuple if result > is a tuple. > > Returns > ------- > out : `~astropy.units.Quantity` > With units set. > > salud, > k > > > > > > > > _______________________________________________ > AstroPy mailing listAstroPy at python.org https://mail.python.org/mailman/listinfo/astropy > > > _______________________________________________ > AstroPy mailing listAstroPy at python.orghttps://mail.python.org/mailman/listinfo/astropy > > _______________________________________________ > AstroPy mailing list > AstroPy at python.org > https://mail.python.org/mailman/listinfo/astropy > -------------- next part -------------- An HTML attachment was scrubbed... URL: From antigone.lambert-huyghe at cea.fr Mon Aug 26 09:16:47 2019 From: antigone.lambert-huyghe at cea.fr (LAMBERT-HUYGHE Antigone) Date: Mon, 26 Aug 2019 13:16:47 +0000 Subject: [AstroPy] Problem with the latest version of astropy and numpy In-Reply-To: References: <36aab5ae-e434-652b-d701-62493b7485bf@sconseil.fr> , Message-ID: So I report here the problem as a bug. Here is the minimal example of my problem (with the imports) : import astropy.units as u from astropy.convolution import convolve import numpy as np from astropy.io import fits from astropy.convolution import Gaussian2DKernel from copy import deepcopy #The aim is to convolve the map in the file file.fits from a resolution of 1.6 arcsec to 6 arcsec inhdu = fits.open('file.fits') fromfwhm = 1.6*u.arcsec tofwhm = 6*u.arcsec #calculate kernel size f2s = 2.*np.sqrt(2*np.log(2)) pixel_size = (abs(inhdu[0].header['CDELT1']) *u.deg).to('arcsec') #CDELT is a keyword in the header that gives the size of the pixel in an angular unit. kernel_sigma = np.sqrt( (tofwhm)**2 - (fromfwhm)**2 ) / pixel_size / f2s kernel = Gaussian2DKernel(stddev=kernel_sigma) result = convolve(inhdu[0].data, kernel, boundary = 'fill', fill_value = float('NaN'), preserve_nan=True) outhdu = hdudeepcopy(inhdu) outhdu[0].data = result outhdu.writeto(WriteTo, overwrite=True) And, as a reminder, here is the error that I had: ~/Bureau/Codes/python_lib/mylib/fits.py in fits_convolve(infits, fromfwhm, tofwhm, GaussianTrim, WriteTo, pixkey, pixkey_unit, returnHDU, verbose) 640 result[i, :, :] = convolve(plane, kernel, boundary = 'fill', fill_value = float('NaN'), preserve_nan=True) 641 else: --> 642 result = convolve(inhdu[0].data, kernel, boundary = 'fill', fill_value = float('NaN'), preserve_nan=True) 643 #result = convolve_fft(inhdu[0].data, kernel) 644 ~/.local/lib/python3.6/site-packages/astropy/nddata/decorators.py in wrapper(data, *args, **kwargs) 244 AstropyUserWarning) 245 --> 246 result = func(data, *args, **kwargs) 247 248 if unpack and repack: ~/.local/lib/python3.6/site-packages/astropy/convolution/convolve.py in convolve(array, kernel, boundary, fill_value, nan_treatment, normalize_kernel, mask, preserve_nan, normalization_zero_tol) 336 if normalize_kernel: 337 if not nan_interpolate: --> 338 result /= kernel_sum 339 else: 340 if nan_interpolate: ~/.local/lib/python3.6/site-packages/astropy/units/quantity.py in __array_ufunc__(self, function, method, *inputs, **kwargs) 473 return result 474 --> 475 return self._result_as_quantity(result, unit, out) 476 477 def _result_as_quantity(self, result, unit, out): ~/.local/lib/python3.6/site-packages/astropy/units/quantity.py in _result_as_quantity(self, result, unit, out) 512 # the output is of the correct Quantity subclass, as it was passed 513 # through check_output. --> 514 out._set_unit(unit) 515 return out 516 AttributeError: 'numpy.ndarray' object has no attribute '_set_unit' Thank you for all the answeres that I had here. -------------- next part -------------- An HTML attachment was scrubbed... URL: From simon at sconseil.fr Mon Aug 26 11:04:58 2019 From: simon at sconseil.fr (Simon Conseil) Date: Mon, 26 Aug 2019 17:04:58 +0200 Subject: [AstroPy] Problem with the latest version of astropy and numpy In-Reply-To: References: <36aab5ae-e434-652b-d701-62493b7485bf@sconseil.fr> Message-ID: <9e7c70e0-5986-52d3-a8d8-e9c9217ea476@sconseil.fr> https://github.com/astropy/astropy/issues/9168 As mentioned in the ticket, you use units for the kernel (kernel.array is a Quantity) so at least this explains why the crash happen in a quantity method. Simon Le 26/08/2019 ? 15:16, LAMBERT-HUYGHE Antigone a ?crit?: > So I report here the problem as a bug. > > Here is the minimal example of my problem (with the imports) : > > import astropy.units as u > from astropy.convolution import convolve > import numpy as np > from astropy.io import fits > from astropy.convolution import Gaussian2DKernel > from copy import deepcopy > > #The aim is to convolve the map in the file file.fits from a resolution of 1.6 arcsec to 6 arcsec > inhdu = fits.open('file.fits') > > fromfwhm = 1.6*u.arcsec > tofwhm = 6*u.arcsec > > #calculate kernel size > f2s = 2.*np.sqrt(2*np.log(2)) > > pixel_size = (abs(inhdu[0].header['CDELT1']) *u.deg).to('arcsec') > #CDELT is a keyword in the header that gives the size of the pixel in an angular unit. > > kernel_sigma = np.sqrt( (tofwhm)**2 - (fromfwhm)**2 ) / pixel_size / f2s > > kernel = Gaussian2DKernel(stddev=kernel_sigma) > > result = convolve(inhdu[0].data, kernel, boundary = 'fill', fill_value = float('NaN'), preserve_nan=True) > > outhdu = hdudeepcopy(inhdu) > outhdu[0].data = result > > outhdu.writeto(WriteTo, overwrite=True) > > And, as a reminder, here is the error that I had: > > ~/Bureau/Codes/python_lib/mylib/fits.py in fits_convolve(infits, fromfwhm, tofwhm, GaussianTrim, WriteTo, pixkey, pixkey_unit, returnHDU, verbose) > 640 result[i, :, :] = convolve(plane, kernel, boundary = 'fill', fill_value = float('NaN'), preserve_nan=True) > 641 else: > --> 642 result = convolve(inhdu[0].data, kernel, boundary = 'fill', fill_value = float('NaN'), preserve_nan=True) > 643 #result = convolve_fft(inhdu[0].data, kernel) > 644 > > ~/.local/lib/python3.6/site-packages/astropy/nddata/decorators.py in wrapper(data, *args, **kwargs) > 244 AstropyUserWarning) > 245 > --> 246 result = func(data, *args, **kwargs) > 247 > 248 if unpack and repack: > > ~/.local/lib/python3.6/site-packages/astropy/convolution/convolve.py in convolve(array, kernel, boundary, fill_value, nan_treatment, normalize_kernel, mask, preserve_nan, normalization_zero_tol) > 336 if normalize_kernel: > 337 if not nan_interpolate: > --> 338 result /= kernel_sum > 339 else: > 340 if nan_interpolate: > > ~/.local/lib/python3.6/site-packages/astropy/units/quantity.py in __array_ufunc__(self, function, method, *inputs, **kwargs) > 473 return result > 474 > --> 475 return self._result_as_quantity(result, unit, out) > 476 > 477 def _result_as_quantity(self, result, unit, out): > > ~/.local/lib/python3.6/site-packages/astropy/units/quantity.py in _result_as_quantity(self, result, unit, out) > 512 # the output is of the correct Quantity subclass, as it was passed > 513 # through check_output. > --> 514 out._set_unit(unit) > 515 return out > 516 > > AttributeError: 'numpy.ndarray' object has no attribute '_set_unit' > > Thank you for all the answeres that I had here. > > > _______________________________________________ > AstroPy mailing list > AstroPy at python.org > https://mail.python.org/mailman/listinfo/astropy -------------- next part -------------- An HTML attachment was scrubbed... URL: From antigone.lambert-huyghe at cea.fr Tue Aug 27 03:24:40 2019 From: antigone.lambert-huyghe at cea.fr (LAMBERT-HUYGHE Antigone) Date: Tue, 27 Aug 2019 07:24:40 +0000 Subject: [AstroPy] Problem with the latest version of astropy and numpy In-Reply-To: <9e7c70e0-5986-52d3-a8d8-e9c9217ea476@sconseil.fr> References: <36aab5ae-e434-652b-d701-62493b7485bf@sconseil.fr> , <9e7c70e0-5986-52d3-a8d8-e9c9217ea476@sconseil.fr> Message-ID: Ok, thank you very much. I didn't know that a kernel was a quantity. Antigone ________________________________ De : AstroPy [astropy-bounces+antigone.lambert-huyghe=cea.fr at python.org] de la part de Simon Conseil [simon at sconseil.fr] Envoy? : lundi 26 ao?t 2019 17:04 ? : astropy at python.org Objet : Re: [AstroPy] Problem with the latest version of astropy and numpy https://github.com/astropy/astropy/issues/9168 As mentioned in the ticket, you use units for the kernel (kernel.array is a Quantity) so at least this explains why the crash happen in a quantity method. Simon Le 26/08/2019 ? 15:16, LAMBERT-HUYGHE Antigone a ?crit : So I report here the problem as a bug. Here is the minimal example of my problem (with the imports) : import astropy.units as u from astropy.convolution import convolve import numpy as np from astropy.io import fits from astropy.convolution import Gaussian2DKernel from copy import deepcopy #The aim is to convolve the map in the file file.fits from a resolution of 1.6 arcsec to 6 arcsec inhdu = fits.open('file.fits') fromfwhm = 1.6*u.arcsec tofwhm = 6*u.arcsec #calculate kernel size f2s = 2.*np.sqrt(2*np.log(2)) pixel_size = (abs(inhdu[0].header['CDELT1']) *u.deg).to('arcsec') #CDELT is a keyword in the header that gives the size of the pixel in an angular unit. kernel_sigma = np.sqrt( (tofwhm)**2 - (fromfwhm)**2 ) / pixel_size / f2s kernel = Gaussian2DKernel(stddev=kernel_sigma) result = convolve(inhdu[0].data, kernel, boundary = 'fill', fill_value = float('NaN'), preserve_nan=True) outhdu = hdudeepcopy(inhdu) outhdu[0].data = result outhdu.writeto(WriteTo, overwrite=True) And, as a reminder, here is the error that I had: ~/Bureau/Codes/python_lib/mylib/fits.py in fits_convolve(infits, fromfwhm, tofwhm, GaussianTrim, WriteTo, pixkey, pixkey_unit, returnHDU, verbose) 640 result[i, :, :] = convolve(plane, kernel, boundary = 'fill', fill_value = float('NaN'), preserve_nan=True) 641 else: --> 642 result = convolve(inhdu[0].data, kernel, boundary = 'fill', fill_value = float('NaN'), preserve_nan=True) 643 #result = convolve_fft(inhdu[0].data, kernel) 644 ~/.local/lib/python3.6/site-packages/astropy/nddata/decorators.py in wrapper(data, *args, **kwargs) 244 AstropyUserWarning) 245 --> 246 result = func(data, *args, **kwargs) 247 248 if unpack and repack: ~/.local/lib/python3.6/site-packages/astropy/convolution/convolve.py in convolve(array, kernel, boundary, fill_value, nan_treatment, normalize_kernel, mask, preserve_nan, normalization_zero_tol) 336 if normalize_kernel: 337 if not nan_interpolate: --> 338 result /= kernel_sum 339 else: 340 if nan_interpolate: ~/.local/lib/python3.6/site-packages/astropy/units/quantity.py in __array_ufunc__(self, function, method, *inputs, **kwargs) 473 return result 474 --> 475 return self._result_as_quantity(result, unit, out) 476 477 def _result_as_quantity(self, result, unit, out): ~/.local/lib/python3.6/site-packages/astropy/units/quantity.py in _result_as_quantity(self, result, unit, out) 512 # the output is of the correct Quantity subclass, as it was passed 513 # through check_output. --> 514 out._set_unit(unit) 515 return out 516 AttributeError: 'numpy.ndarray' object has no attribute '_set_unit' Thank you for all the answeres that I had here. _______________________________________________ AstroPy mailing list AstroPy at python.org https://mail.python.org/mailman/listinfo/astropy -------------- next part -------------- An HTML attachment was scrubbed... URL: From gordon.b.dennis at gmail.com Tue Aug 27 08:13:04 2019 From: gordon.b.dennis at gmail.com (Gordon Dennis) Date: Tue, 27 Aug 2019 13:13:04 +0100 Subject: [AstroPy] Histogram problem in astropy tutorial Message-ID: <000001d55cd0$c7efeb80$57cfc280$@gmail.com> Hi everybody I'm having some difficulty with the example 'Galaxy mass' in the tutorial at http://learn.astropy.org/rst-tutorials/quantities.html?highlight=filtertutor ials These lines are to setup matplotlib: import matplotlib.pyplot as plt %matplotlib inline Spyder will not accept the second (i.e. %matplotlib inline) because, according to a Stack Overflow answer 'Line magics are only supported by the IPython command line. They cannot be used inside a script, because %something is not correct Python syntax'. Suggestion is to use exec(%matplotlib inline) This is accepted by the Python interpreter but doesn't work, i.e. the subsequent code plt.figure() plt.hist(v, bins='auto', histtype="step") plt.ylabel("N") . does not produce the histogram expected. The variable v is calculated earlier in the code. All the rest of the code works exactly as expected. I've added input statements to vary Reff and vmean in order to observe the effect of varying these parameters and the results from the code check out against results using a calculator. I'm using Spyder 3 on Windows 10, fully patched. Does anyone know of a way around this histogram problem? Best regards Gordon Dennis +44(0)1934 838096 / +44(0)7774628110 / Skype: gordon.dennis Sent from my Analytical Engine Description: analyticalEngine -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: image003.jpg Type: image/jpeg Size: 3301 bytes Desc: not available URL: From hulingyi1995 at yahoo.com.sg Tue Aug 27 09:55:36 2019 From: hulingyi1995 at yahoo.com.sg (Lingyi Hu) Date: Tue, 27 Aug 2019 21:55:36 +0800 Subject: [AstroPy] Histogram problem in astropy tutorial In-Reply-To: <000001d55cd0$c7efeb80$57cfc280$@gmail.com> References: <000001d55cd0$c7efeb80$57cfc280$@gmail.com> Message-ID: Hi Gordon, I believe you can do a normal plt.show() at the end of plotting to show the graph. Don't think you need the exec(%matplotlib inline) if you are not in ipython. I don't use Spyder but apparently there are some settings you can set in Spyder to make it work like a IPython notebook: https://stackoverflow.com/questions/23585126/how-do-i-get-interactive-plots-again-in-spyder-ipython-matplotlib Lingyi On Tue, Aug 27, 2019 at 8:13 PM Gordon Dennis wrote: > Hi everybody > > I'm having some difficulty with the example 'Galaxy mass' in the tutorial > at > http://learn.astropy.org/rst-tutorials/quantities.html?highlight=filtertutorials > > These lines are to setup matplotlib: > > import matplotlib.pyplot as plt > > %matplotlib inline > > Spyder will not accept the second (i.e. %matplotlib inline) because, > according to a Stack Overflow answer 'Line magics are only supported by the > IPython command line. They cannot be used inside a script, because > %something is not correct Python syntax'. > > Suggestion is to use > > exec(%matplotlib inline) > > This is accepted by the Python interpreter but doesn't work, i.e. the > subsequent code > > plt.figure() > > plt.hist(v, bins='auto', histtype="step") > > plt.ylabel("N") > > ? does not produce the histogram expected. The variable v is calculated > earlier in the code. > > > > All the rest of the code works exactly as expected. I've added input > statements to vary Reff and vmean in order to observe the effect of varying > these parameters and the results from the code check out against results > using a calculator. > > I?m using Spyder 3 on Windows 10, fully patched. > > Does anyone know of a way around this histogram problem? > > Best regards > > Gordon Dennis > > > > > > +44(0)1934 838096 / +44(0)7774628110 / Skype: gordon.dennis > > Sent from my Analytical Engine > > [image: Description: analyticalEngine] > > > _______________________________________________ > AstroPy mailing list > AstroPy at python.org > https://mail.python.org/mailman/listinfo/astropy > -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: image003.jpg Type: image/jpeg Size: 3301 bytes Desc: not available URL: From dstansby at gmail.com Tue Aug 27 10:10:28 2019 From: dstansby at gmail.com (David Stansby) Date: Tue, 27 Aug 2019 15:10:28 +0100 Subject: [AstroPy] Histogram problem in astropy tutorial In-Reply-To: <000001d55cd0$c7efeb80$57cfc280$@gmail.com> References: <000001d55cd0$c7efeb80$57cfc280$@gmail.com> Message-ID: Hi Gordon, If you're using Matplotlib in a normal python session then you don't need the '%matplotlib inline' command, but you will need to append 'plt.show()` to the end of your script to make the figure show up. Cheers, David On Tue, 27 Aug 2019 at 13:13, Gordon Dennis wrote: > Hi everybody > > I'm having some difficulty with the example 'Galaxy mass' in the tutorial > at > http://learn.astropy.org/rst-tutorials/quantities.html?highlight=filtertutorials > > These lines are to setup matplotlib: > > import matplotlib.pyplot as plt > > %matplotlib inline > > Spyder will not accept the second (i.e. %matplotlib inline) because, > according to a Stack Overflow answer 'Line magics are only supported by the > IPython command line. They cannot be used inside a script, because > %something is not correct Python syntax'. > > Suggestion is to use > > exec(%matplotlib inline) > > This is accepted by the Python interpreter but doesn't work, i.e. the > subsequent code > > plt.figure() > > plt.hist(v, bins='auto', histtype="step") > > plt.ylabel("N") > > ? does not produce the histogram expected. The variable v is calculated > earlier in the code. > > > > All the rest of the code works exactly as expected. I've added input > statements to vary Reff and vmean in order to observe the effect of varying > these parameters and the results from the code check out against results > using a calculator. > > I?m using Spyder 3 on Windows 10, fully patched. > > Does anyone know of a way around this histogram problem? > > Best regards > > Gordon Dennis > > > > > > +44(0)1934 838096 / +44(0)7774628110 / Skype: gordon.dennis > > Sent from my Analytical Engine > > [image: Description: analyticalEngine] > > > _______________________________________________ > AstroPy mailing list > AstroPy at python.org > https://mail.python.org/mailman/listinfo/astropy > -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: image003.jpg Type: image/jpeg Size: 3301 bytes Desc: not available URL: From gordon.b.dennis at gmail.com Tue Aug 27 15:22:25 2019 From: gordon.b.dennis at gmail.com (Gordon Dennis) Date: Tue, 27 Aug 2019 20:22:25 +0100 Subject: [AstroPy] AstroPy Digest, Vol 155, Issue 14 In-Reply-To: References: Message-ID: <001e01d55d0c$c2c74e50$4855eaf0$@gmail.com> Hi everyone A couple of people suggested the usual plt.show()after the third line, but that doesn't change anything I'm afraid - the histogram still doesn't work as the example shows. Anybody any other suggestions please?. Best regards Gordon -----Original Message----- From: AstroPy [mailto:astropy-bounces+gordon.b.dennis=gmail.com at python.org] On Behalf Of astropy-request at python.org Sent: Tuesday, August 27, 2019 15:11 To: astropy at python.org Subject: AstroPy Digest, Vol 155, Issue 14 Send AstroPy mailing list submissions to astropy at python.org To subscribe or unsubscribe via the World Wide Web, visit https://mail.python.org/mailman/listinfo/astropy or, via email, send a message with subject or body 'help' to astropy-request at python.org You can reach the person managing the list at astropy-owner at python.org When replying, please edit your Subject line so it is more specific than "Re: Contents of AstroPy digest..." Today's Topics: 1. Re: Histogram problem in astropy tutorial (Lingyi Hu) 2. Re: Histogram problem in astropy tutorial (David Stansby) ---------------------------------------------------------------------- Message: 1 Date: Tue, 27 Aug 2019 21:55:36 +0800 From: Lingyi Hu To: Astronomical Python mailing list Subject: Re: [AstroPy] Histogram problem in astropy tutorial Message-ID: Content-Type: text/plain; charset="utf-8" Hi Gordon, I believe you can do a normal plt.show() at the end of plotting to show the graph. Don't think you need the exec(%matplotlib inline) if you are not in ipython. I don't use Spyder but apparently there are some settings you can set in Spyder to make it work like a IPython notebook: https://stackoverflow.com/questions/23585126/how-do-i-get-interactive-plots- again-in-spyder-ipython-matplotlib Lingyi On Tue, Aug 27, 2019 at 8:13 PM Gordon Dennis < gordon.b.dennis at gmail.com> wrote: > Hi everybody > > I'm having some difficulty with the example 'Galaxy mass' in the > tutorial at > http://learn.astropy.org/rst-tutorials/quantities.html?highlight=filte > rtutorials > > These lines are to setup matplotlib: > > import matplotlib.pyplot as plt > > %matplotlib inline > > Spyder will not accept the second (i.e. %matplotlib inline) because, > according to a Stack Overflow answer 'Line magics are only supported > by the IPython command line. They cannot be used inside a script, > because %something is not correct Python syntax'. > > Suggestion is to use > > exec(%matplotlib inline) > > This is accepted by the Python interpreter but doesn't work, i.e. the > subsequent code > > plt.figure() > > plt.hist(v, bins='auto', histtype="step") > > plt.ylabel("N") > > ? does not produce the histogram expected. The variable v is > calculated earlier in the code. > > > > All the rest of the code works exactly as expected. I've added input > statements to vary Reff and vmean in order to observe the effect of > varying these parameters and the results from the code check out > against results using a calculator. > > I?m using Spyder 3 on Windows 10, fully patched. > > Does anyone know of a way around this histogram problem? > > Best regards > > Gordon Dennis > > > > > > +44(0)1934 838096 / +44(0)7774628110 / Skype: gordon.dennis > > Sent from my Analytical Engine > > [image: Description: analyticalEngine] > > > _______________________________________________ > AstroPy mailing list > AstroPy at python.org > https://mail.python.org/mailman/listinfo/astropy > -------------- next part -------------- An HTML attachment was scrubbed... URL: < http://mail.python.org/pipermail/astropy/attachments/20190827/32bd9a09/attac hment-0001.html> -------------- next part -------------- A non-text attachment was scrubbed... Name: image003.jpg Type: image/jpeg Size: 3301 bytes Desc: not available URL: < http://mail.python.org/pipermail/astropy/attachments/20190827/32bd9a09/attac hment-0001.jpg> ------------------------------ Message: 2 Date: Tue, 27 Aug 2019 15:10:28 +0100 From: David Stansby To: Astronomical Python mailing list Subject: Re: [AstroPy] Histogram problem in astropy tutorial Message-ID: Content-Type: text/plain; charset="utf-8" Hi Gordon, If you're using Matplotlib in a normal python session then you don't need the '%matplotlib inline' command, but you will need to append 'plt.show()` to the end of your script to make the figure show up. Cheers, David On Tue, 27 Aug 2019 at 13:13, Gordon Dennis < gordon.b.dennis at gmail.com> wrote: > Hi everybody > > I'm having some difficulty with the example 'Galaxy mass' in the > tutorial at > http://learn.astropy.org/rst-tutorials/quantities.html?highlight=filte > rtutorials > > These lines are to setup matplotlib: > > import matplotlib.pyplot as plt > > %matplotlib inline > > Spyder will not accept the second (i.e. %matplotlib inline) because, > according to a Stack Overflow answer 'Line magics are only supported > by the IPython command line. They cannot be used inside a script, > because %something is not correct Python syntax'. > > Suggestion is to use > > exec(%matplotlib inline) > > This is accepted by the Python interpreter but doesn't work, i.e. the > subsequent code > > plt.figure() > > plt.hist(v, bins='auto', histtype="step") > > plt.ylabel("N") > > ? does not produce the histogram expected. The variable v is > calculated earlier in the code. > > > > All the rest of the code works exactly as expected. I've added input > statements to vary Reff and vmean in order to observe the effect of > varying these parameters and the results from the code check out > against results using a calculator. > > I?m using Spyder 3 on Windows 10, fully patched. > > Does anyone know of a way around this histogram problem? > > Best regards > > Gordon Dennis > > > > > > +44(0)1934 838096 / +44(0)7774628110 / Skype: gordon.dennis > > Sent from my Analytical Engine > > [image: Description: analyticalEngine] > > > _______________________________________________ > AstroPy mailing list > AstroPy at python.org > https://mail.python.org/mailman/listinfo/astropy > -------------- next part -------------- An HTML attachment was scrubbed... URL: < http://mail.python.org/pipermail/astropy/attachments/20190827/c84c82ba/attac hment.html> -------------- next part -------------- A non-text attachment was scrubbed... Name: image003.jpg Type: image/jpeg Size: 3301 bytes Desc: not available URL: < http://mail.python.org/pipermail/astropy/attachments/20190827/c84c82ba/attac hment.jpg> ------------------------------ Subject: Digest Footer _______________________________________________ AstroPy mailing list AstroPy at python.org https://mail.python.org/mailman/listinfo/astropy ------------------------------ End of AstroPy Digest, Vol 155, Issue 14 **************************************** -------------- next part -------------- An HTML attachment was scrubbed... URL: From wtylergee at gmail.com Tue Aug 27 16:17:37 2019 From: wtylergee at gmail.com (Wilfred Tyler Gee) Date: Wed, 28 Aug 2019 06:17:37 +1000 Subject: [AstroPy] Histogram problem in astropy tutorial In-Reply-To: References: <000001d55cd0$c7efeb80$57cfc280$@gmail.com> Message-ID: Hi Gordon, Just to be clear, this is not a problem with the histogram but with the environment and how it is being called. Spyder is a different environment from a jupyter notebook and the tutorial is specifically using a notebook. That said, Spyder does (I believe) have a mechanism for plotting within the IDE itself. Most likely you just remove the line about the matplotlib magic. Cheers, On Wed, Aug 28, 2019, 00:11 David Stansby wrote: > Hi Gordon, > > If you're using Matplotlib in a normal python session then you don't need > the '%matplotlib inline' command, but you will need to append 'plt.show()` > to the end of your script to make the figure show up. > > Cheers, > David > > On Tue, 27 Aug 2019 at 13:13, Gordon Dennis > wrote: > >> Hi everybody >> >> I'm having some difficulty with the example 'Galaxy mass' in the tutorial >> at >> http://learn.astropy.org/rst-tutorials/quantities.html?highlight=filtertutorials >> >> These lines are to setup matplotlib: >> >> import matplotlib.pyplot as plt >> >> %matplotlib inline >> >> Spyder will not accept the second (i.e. %matplotlib inline) because, >> according to a Stack Overflow answer 'Line magics are only supported by the >> IPython command line. They cannot be used inside a script, because >> %something is not correct Python syntax'. >> >> Suggestion is to use >> >> exec(%matplotlib inline) >> >> This is accepted by the Python interpreter but doesn't work, i.e. the >> subsequent code >> >> plt.figure() >> >> plt.hist(v, bins='auto', histtype="step") >> >> plt.ylabel("N") >> >> ? does not produce the histogram expected. The variable v is calculated >> earlier in the code. >> >> >> >> All the rest of the code works exactly as expected. I've added input >> statements to vary Reff and vmean in order to observe the effect of varying >> these parameters and the results from the code check out against results >> using a calculator. >> >> I?m using Spyder 3 on Windows 10, fully patched. >> >> Does anyone know of a way around this histogram problem? >> >> Best regards >> >> Gordon Dennis >> >> >> >> >> >> +44(0)1934 838096 / +44(0)7774628110 / Skype: gordon.dennis >> >> Sent from my Analytical Engine >> >> [image: Description: analyticalEngine] >> >> >> _______________________________________________ >> AstroPy mailing list >> AstroPy at python.org >> https://mail.python.org/mailman/listinfo/astropy >> > _______________________________________________ > AstroPy mailing list > AstroPy at python.org > https://mail.python.org/mailman/listinfo/astropy > -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: image003.jpg Type: image/jpeg Size: 3301 bytes Desc: not available URL: