From sflarkin at ucsc.edu Wed Apr 3 16:12:13 2019 From: sflarkin at ucsc.edu (Sean Larkin) Date: Wed, 3 Apr 2019 13:12:13 -0700 Subject: [AstroPy] Question about Table Comments Message-ID: Hello all, I have a question about the astropy.table comments attribute. I am generating an table of the x, y, z and vx, vy, vz coordinates of particles in a simulation to write to an ascii file to feed to another program for analysis. The code I am using for this is as follows: a_line = 'a = ' + scale_factor comment = {'comments':[a_line]} data = Table([x, y, z, vx, vy, vz, ids], names=['x', 'y', 'z', 'vx', 'vy', 'vz', 'id'], meta=comment) ascii.write(data, output=file_name) The ascii file is written properly, with a format like: # a = 0.21019612252712247 x y z vx vy vz id 4.112212871731752 3.778579779058581 4.11872852936419 -34.907225443016664 91.54097555566668 -140.89939877648789 0 4.112980377762908 3.778162574506875 4.1175911771358455 -35.195479563640525 91.50465485499448 -141.87647535372412 1 However, the program I am using expects comments in the form of : #a = 0.21019612252712247 I am wondering if there is a way in astropy to remove the space between the # and a in the comment when the file is written, or if there is another way to add a comment like line of the above formatting. Thank for your time and consideration! -------------- next part -------------- An HTML attachment was scrubbed... URL: From derek at astro.physik.uni-goettingen.de Wed Apr 3 16:25:44 2019 From: derek at astro.physik.uni-goettingen.de (Derek Homeier) Date: Wed, 3 Apr 2019 22:25:44 +0200 Subject: [AstroPy] Question about Table Comments In-Reply-To: References: Message-ID: On 3 Apr 2019, at 10:12 pm, Sean Larkin wrote: > > I have a question about the astropy.table comments attribute. I am generating an table of the x, y, z and vx, vy, vz coordinates of particles in a simulation to write to an ascii file to feed to another program for analysis. The code I am using for this is as follows: > > a_line = 'a = ' + scale_factor > comment = {'comments':[a_line]} > > data = Table([x, y, z, vx, vy, vz, ids], names=['x', 'y', 'z', 'vx', 'vy', 'vz', 'id'], meta=comment) > > ascii.write(data, output=file_name) > > The ascii file is written properly, with a format like: > > # a = 0.21019612252712247 > x y z vx vy vz id > 4.112212871731752 3.778579779058581 4.11872852936419 -34.907225443016664 91.54097555566668 -140.89939877648789 0 > 4.112980377762908 3.778162574506875 4.1175911771358455 -35.195479563640525 91.50465485499448 -141.87647535372412 1 > > However, the program I am using expects comments in the form of : > > #a = 0.21019612252712247 > > I am wondering if there is a way in astropy to remove the space between the # and a in the comment when the file is written, or if there is another way to add a comment like line of the above formatting. > Have you tried to explicitly specify ascii.write(data, output=file_name, comment=?#?) ? For me this is overriding the default write_comment=?# ?. Cheers, Derek From sflarkin at ucsc.edu Wed Apr 3 16:32:55 2019 From: sflarkin at ucsc.edu (Sean Larkin) Date: Wed, 3 Apr 2019 13:32:55 -0700 Subject: [AstroPy] Question about Table Comments In-Reply-To: References: Message-ID: I had not tried that. I had initially tried: ascii.write(data, output=file_name, comment=?#a = ...?) believing that the comment in the ascii.write command was the same as in the Table command. Thank you for the clarification, now it works exactly as desired. Thank you so much for the quick help! On Wed, Apr 3, 2019 at 1:26 PM Derek Homeier < derek at astro.physik.uni-goettingen.de> wrote: > On 3 Apr 2019, at 10:12 pm, Sean Larkin wrote: > > > > I have a question about the astropy.table comments attribute. I am > generating an table of the x, y, z and vx, vy, vz coordinates of particles > in a simulation to write to an ascii file to feed to another program for > analysis. The code I am using for this is as follows: > > > > a_line = 'a = ' + scale_factor > > comment = {'comments':[a_line]} > > > > data = Table([x, y, z, vx, vy, vz, ids], names=['x', 'y', 'z', 'vx', > 'vy', 'vz', 'id'], meta=comment) > > > > ascii.write(data, output=file_name) > > > > The ascii file is written properly, with a format like: > > > > # a = 0.21019612252712247 > > x y z vx vy vz id > > 4.112212871731752 3.778579779058581 4.11872852936419 -34.907225443016664 > 91.54097555566668 -140.89939877648789 0 > > 4.112980377762908 3.778162574506875 4.1175911771358455 > -35.195479563640525 91.50465485499448 -141.87647535372412 1 > > > > However, the program I am using expects comments in the form of : > > > > #a = 0.21019612252712247 > > > > I am wondering if there is a way in astropy to remove the space between > the # and a in the comment when the file is written, or if there is another > way to add a comment like line of the above formatting. > > > Have you tried to explicitly specify ascii.write(data, output=file_name, > comment=?#?) ? > For me this is overriding the default write_comment=?# ?. > > Cheers, > Derek > > > _______________________________________________ > AstroPy mailing list > AstroPy at python.org > https://mail.python.org/mailman/listinfo/astropy > -------------- next part -------------- An HTML attachment was scrubbed... URL: From adrianmpw at gmail.com Tue Apr 16 11:58:00 2019 From: adrianmpw at gmail.com (Adrian Price-Whelan) Date: Tue, 16 Apr 2019 08:58:00 -0700 Subject: [AstroPy] Gala v1.0 released Message-ID: Gala is an Astropy affiliated package for Galactic dynamics. Most of its functionality centers around implementations of gravitational potential models, numerical orbit integration, stellar stream modeling, and nonlinear dynamics, and all works natively with astropy.units and astropy.coordinates. You can read more about Gala and see examples and tutorials in the documentation: http://gala.adrian.pw/en/stable/ v1.0 contains many new features, including: - great circle coordinate frames that work with astropy coordinates - new potential models, including MWPotential2014 from galpy - SCF (basis function expansion) flexible potential representations - new stellar stream coordinate frames You can read more about these new features in the What's New documentation: http://gala.adrian.pw/en/stable/whatsnew/1.0.html To install or update the latest version (v1.0), you can use conda or pip. For example: conda install -c conda-forge astro-gala or pip install astro-gala Please report and issues or suggest new features through the issue tracker on GitHub: https://github.com/adrn/gala/issues thanks! - Adrian -- Adrian M. Price-Whelan Lyman Spitzer, Jr. Postdoctoral Fellow Princeton University http://adrn.github.io From hessman at astro.physik.uni-goettingen.de Wed Apr 17 09:43:56 2019 From: hessman at astro.physik.uni-goettingen.de (Frederic V. Hessman) Date: Wed, 17 Apr 2019 15:43:56 +0200 Subject: [AstroPy] HDU to Table Message-ID: <1444AA35-E9B5-45F5-99FC-E2CFA5941D80@astro.physik.uni-goettingen.de> There's the convenience function astropy.io.fits.table_to_hdu (astropy.table.Table) -> astropy.io.fits.BinTableHDU but where's astropy.io.fits.hdu_to_table(astropy.io.fits.BinTableHDU) -> astropy.table.Table ? Surely people are writing AND reading binary tables.....! I want to dump IFU spectra into a single FITS binary table file and then easily read them back in again. My internet searches haven't yielded anything equivalent. Of course, one can write the reverse conversion (one can write anything/everything), but this should be a standard FITS/Table function. Rick ------------------------------------------------------------------------------------------------ Dr. Frederic V. Hessman Hessman at Astro.physik.Uni-Goettingen.DE Institut f?r Astrophysik Tel. +49-551-39-5052 Friedrich-Hund-Platz 1 Fax +49-551-39-5043 37077 Goettingen Room F04-133 http://www.Astro.physik.Uni-Goettingen.de/~hessman ------------------------------------------------------------------------------------------------- MONET: a MOnitoring NEtwork of Telescopes http://monet.Uni-Goettingen.de ------------------------------------------------------------------------------------------------- From bjw at as.arizona.edu Wed Apr 17 12:51:48 2019 From: bjw at as.arizona.edu (Benjamin Weiner) Date: Wed, 17 Apr 2019 09:51:48 -0700 Subject: [AstroPy] AstroPy Digest, Vol 151, Issue 3 In-Reply-To: References: Message-ID: Hello Rick, You should be able to read a FITS binary table with something like: from astropy.io import fits hdulist = fits.open('myfilename.fits') mydata = hdu[1].data # makes a table from the data in extension 1 This is covered in the astropy.io.fits documentation at http://docs.astropy.org/en/stable/io/fits/ Cheers, Ben Weiner Date: Wed, 17 Apr 2019 15:43:56 +0200 > From: "Frederic V. Hessman" > To: astropy at python.org > Subject: [AstroPy] HDU to Table > > There's the convenience function > > astropy.io.fits.table_to_hdu (astropy.table.Table) -> > astropy.io.fits.BinTableHDU > > but where's > > astropy.io.fits.hdu_to_table(astropy.io.fits.BinTableHDU) -> > astropy.table.Table ? > > Surely people are writing AND reading binary tables.....! I want to > dump IFU spectra into a single FITS binary table file and then easily read > them back in again. > > My internet searches haven't yielded anything equivalent. Of course, one > can write the reverse conversion (one can write anything/everything), but > this should be a standard FITS/Table function. > > Rick > > > ------------------------------------------------------------------------------------------------ > Dr. Frederic V. Hessman Hessman at Astro.physik.Uni-Goettingen.DE > Institut f?r Astrophysik Tel. +49-551-39-5052 > Friedrich-Hund-Platz 1 Fax +49-551-39-5043 > 37077 Goettingen Room F04-133 > http://www.Astro.physik.Uni-Goettingen.de/~hessman > > ------------------------------------------------------------------------------------------------- > MONET: a MOnitoring NEtwork of Telescopes > http://monet.Uni-Goettingen.de > > ------------------------------------------------------------------------------------------------- > > -- Benjamin Weiner Staff Scientist / Associate Astronomer, MMT / Steward Observatory bjw at as.arizona.edu http://mingus.mmto.arizona.edu/~bjw/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From bjw at as.arizona.edu Wed Apr 17 12:52:53 2019 From: bjw at as.arizona.edu (Benjamin Weiner) Date: Wed, 17 Apr 2019 09:52:53 -0700 Subject: [AstroPy] AstroPy Digest, Vol 151, Issue 3 In-Reply-To: References: Message-ID: Ugh, I mistyped a variable name, my example should be hdulist = fits.open('myfilename.fits') mydata = hdulist[1].data # makes a table from the data in extension 1 On Wed, Apr 17, 2019 at 9:51 AM Benjamin Weiner wrote: > Hello Rick, > > You should be able to read a FITS binary table with something like: > > from astropy.io import fits > hdulist = fits.open('myfilename.fits') > mydata = hdu[1].data # makes a table from the data in extension 1 > > This is covered in the astropy.io.fits documentation at > http://docs.astropy.org/en/stable/io/fits/ > > Cheers, > Ben Weiner > > Date: Wed, 17 Apr 2019 15:43:56 +0200 >> From: "Frederic V. Hessman" >> To: astropy at python.org >> Subject: [AstroPy] HDU to Table >> >> There's the convenience function >> >> astropy.io.fits.table_to_hdu (astropy.table.Table) -> >> astropy.io.fits.BinTableHDU >> >> but where's >> >> astropy.io.fits.hdu_to_table(astropy.io.fits.BinTableHDU) -> >> astropy.table.Table ? >> >> Surely people are writing AND reading binary tables.....! I want to >> dump IFU spectra into a single FITS binary table file and then easily read >> them back in again. >> >> My internet searches haven't yielded anything equivalent. Of course, one >> can write the reverse conversion (one can write anything/everything), but >> this should be a standard FITS/Table function. >> >> Rick >> >> >> ------------------------------------------------------------------------------------------------ >> Dr. Frederic V. Hessman Hessman at Astro.physik.Uni-Goettingen.DE >> Institut f?r Astrophysik Tel. +49-551-39-5052 >> Friedrich-Hund-Platz 1 Fax +49-551-39-5043 >> 37077 Goettingen Room F04-133 >> http://www.Astro.physik.Uni-Goettingen.de/~hessman >> >> ------------------------------------------------------------------------------------------------- >> MONET: a MOnitoring NEtwork of Telescopes >> http://monet.Uni-Goettingen.de >> >> ------------------------------------------------------------------------------------------------- >> >> > -- > Benjamin Weiner > Staff Scientist / Associate Astronomer, MMT / Steward Observatory > bjw at as.arizona.edu > http://mingus.mmto.arizona.edu/~bjw/ > -- Benjamin Weiner Staff Scientist / Associate Astronomer, MMT / Steward Observatory bjw at as.arizona.edu http://mingus.mmto.arizona.edu/~bjw/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From deil.christoph at googlemail.com Wed Apr 17 13:41:20 2019 From: deil.christoph at googlemail.com (Christoph Deil) Date: Wed, 17 Apr 2019 19:41:20 +0200 Subject: [AstroPy] AstroPy Digest, Vol 151, Issue 3 In-Reply-To: References: Message-ID: Hi Rick, if you want a astropy.table.Table object, use Table.read. You can pass it a filename, but you can also pass an astropy.io .fits.BinTableHDU object, If for some reason you already have it in memory. I agree it?s weird that Table.read does this, adding a astropy.io.fits.hdu_to_table function would make this easier to discover. Maybe file an issue with Astropy with that suggestion? Christoph > On 17. Apr 2019, at 18:52, Benjamin Weiner wrote: > > Ugh, I mistyped a variable name, my example should be > hdulist = fits.open('myfilename.fits') > mydata = hdulist[1].data # makes a table from the data in extension 1 > > > > On Wed, Apr 17, 2019 at 9:51 AM Benjamin Weiner > wrote: > Hello Rick, > > You should be able to read a FITS binary table with something like: > > from astropy.io import fits > hdulist = fits.open('myfilename.fits') > mydata = hdu[1].data # makes a table from the data in extension 1 > > This is covered in the astropy.io.fits documentation at http://docs.astropy.org/en/stable/io/fits/ > > Cheers, > Ben Weiner > > Date: Wed, 17 Apr 2019 15:43:56 +0200 > From: "Frederic V. Hessman" > > To: astropy at python.org > Subject: [AstroPy] HDU to Table > > There's the convenience function > > astropy.io.fits.table_to_hdu (astropy.table.Table) -> astropy.io.fits.BinTableHDU > > but where's > > astropy.io.fits.hdu_to_table(astropy.io.fits.BinTableHDU) -> astropy.table.Table ? > > Surely people are writing AND reading binary tables.....! I want to dump IFU spectra into a single FITS binary table file and then easily read them back in again. > > My internet searches haven't yielded anything equivalent. Of course, one can write the reverse conversion (one can write anything/everything), but this should be a standard FITS/Table function. > > Rick > > ------------------------------------------------------------------------------------------------ > Dr. Frederic V. Hessman Hessman at Astro.physik.Uni-Goettingen.DE > Institut f?r Astrophysik Tel. +49-551-39-5052 > Friedrich-Hund-Platz 1 Fax +49-551-39-5043 > 37077 Goettingen Room F04-133 > http://www.Astro.physik.Uni-Goettingen.de/~hessman > ------------------------------------------------------------------------------------------------- > MONET: a MOnitoring NEtwork of Telescopes > http://monet.Uni-Goettingen.de > ------------------------------------------------------------------------------------------------- > > > -- > Benjamin Weiner > Staff Scientist / Associate Astronomer, MMT / Steward Observatory > bjw at as.arizona.edu > http://mingus.mmto.arizona.edu/~bjw/ > > > -- > Benjamin Weiner > Staff Scientist / Associate Astronomer, MMT / Steward Observatory > bjw at as.arizona.edu > http://mingus.mmto.arizona.edu/~bjw/ > _______________________________________________ > AstroPy mailing list > AstroPy at python.org > https://mail.python.org/mailman/listinfo/astropy -------------- next part -------------- An HTML attachment was scrubbed... URL: From ivvv68 at gmail.com Wed Apr 17 14:32:16 2019 From: ivvv68 at gmail.com (Ivan Valtchanov) Date: Wed, 17 Apr 2019 20:32:16 +0200 Subject: [AstroPy] AstroPy Digest, Vol 151, Issue 3 In-Reply-To: References: Message-ID: Hi Christoph, You cannot use BinTableHDU to create an astropy.tableTable object. When you try to do this you get this error: table = Table(hdu[1]) Data type not allowed to init Table But this one works, table = Table(hdu[1].data) although I don't think it's documented in astropy.table docs. I could not find it easily. Cheers, Ivan On Wed, 17 Apr 2019 at 19:41, Christoph Deil wrote: > Hi Rick, > > if you want a astropy.table.Table object, use Table.read. > > You can pass it a filename, but you can also pass an astropy.io.fits.BinTableHDU > object, > If for some reason you already have it in memory. > > I agree it?s weird that Table.read does this, adding a > astropy.io.fits.hdu_to_table function would make this easier to discover. > Maybe file an issue with Astropy with that suggestion? > > Christoph > > On 17. Apr 2019, at 18:52, Benjamin Weiner wrote: > > Ugh, I mistyped a variable name, my example should be > hdulist = fits.open('myfilename.fits') > mydata = hdulist[1].data # makes a table from the data in extension 1 > > > > On Wed, Apr 17, 2019 at 9:51 AM Benjamin Weiner > wrote: > >> Hello Rick, >> >> You should be able to read a FITS binary table with something like: >> >> from astropy.io import fits >> hdulist = fits.open('myfilename.fits') >> mydata = hdu[1].data # makes a table from the data in extension 1 >> >> This is covered in the astropy.io.fits documentation at >> http://docs.astropy.org/en/stable/io/fits/ >> >> Cheers, >> Ben Weiner >> >> Date: Wed, 17 Apr 2019 15:43:56 +0200 >>> From: "Frederic V. Hessman" >>> To: astropy at python.org >>> Subject: [AstroPy] HDU to Table >>> >>> There's the convenience function >>> >>> astropy.io.fits.table_to_hdu (astropy.table.Table) -> >>> astropy.io.fits.BinTableHDU >>> >>> but where's >>> >>> astropy.io.fits.hdu_to_table(astropy.io.fits.BinTableHDU) -> >>> astropy.table.Table ? >>> >>> Surely people are writing AND reading binary tables.....! I want to >>> dump IFU spectra into a single FITS binary table file and then easily read >>> them back in again. >>> >>> My internet searches haven't yielded anything equivalent. Of course, >>> one can write the reverse conversion (one can write anything/everything), >>> but this should be a standard FITS/Table function. >>> >>> Rick >>> >>> >>> ------------------------------------------------------------------------------------------------ >>> Dr. Frederic V. Hessman Hessman at Astro.physik.Uni-Goettingen.DE >>> Institut f?r Astrophysik Tel. +49-551-39-5052 >>> Friedrich-Hund-Platz 1 Fax +49-551-39-5043 >>> 37077 Goettingen Room F04-133 >>> http://www.Astro.physik.Uni-Goettingen.de/~hessman >>> >>> >>> ------------------------------------------------------------------------------------------------- >>> MONET: a MOnitoring NEtwork of Telescopes >>> http://monet.Uni-Goettingen.de >>> >>> ------------------------------------------------------------------------------------------------- >>> >>> >> -- >> Benjamin Weiner >> Staff Scientist / Associate Astronomer, MMT / Steward Observatory >> bjw at as.arizona.edu >> http://mingus.mmto.arizona.edu/~bjw/ >> > > > -- > Benjamin Weiner > Staff Scientist / Associate Astronomer, MMT / Steward Observatory > bjw at as.arizona.edu > http://mingus.mmto.arizona.edu/~bjw/ > _______________________________________________ > 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 derek at astro.physik.uni-goettingen.de Wed Apr 17 14:52:23 2019 From: derek at astro.physik.uni-goettingen.de (Derek Homeier) Date: Wed, 17 Apr 2019 20:52:23 +0200 Subject: [AstroPy] AstroPy Digest - HDU to Table In-Reply-To: References: Message-ID: <3D4ED4C0-C264-42BE-AD3F-25E33101A41F@astro.physik.uni-goettingen.de> On 17 Apr 2019, at 7:41 pm, Christoph Deil wrote: > > if you want a astropy.table.Table object, use Table.read. > > You can pass it a filename, but you can also pass an astropy.io.fits.BinTableHDU object, > If for some reason you already have it in memory. > > I agree it?s weird that Table.read does this, adding a astropy.io.fits.hdu_to_table function would make this easier to discover. > Maybe file an issue with Astropy with that suggestion? > Two small clarifications: direct Table initialisation requires the `data` part, e.g. astropy.table.Table(binhdu.data) but it still preserves structure and column names of the FITS table. If in addition you want to keep the complete header information, you need to explicitly pass it to the table.meta data, i.e. astropy.table.Table(binhdu.data, meta=binhdu.header) so you may say this still requires a wrapper, but it?s a pretty thin one. For reading from file I have to add that my understanding of the documentation http://docs.astropy.org/en/stable/io/unified.html#keywords "The FITS keywords associated with an HDU table are represented in the meta ordered dictionary attribute of a Table. ? is actually that Table.read(?filename.fits?, [hdu=n]) should do this automatically, but in fact, just like Table() without the meta keyword it ends up with an empty dictionary in table.meta. This looks indeed like a real issue (either fix the documentation, or better, implement the functionality it describes). Cheers, Derek From derek at astro.physik.uni-goettingen.de Wed Apr 17 18:41:40 2019 From: derek at astro.physik.uni-goettingen.de (Derek Homeier) Date: Thu, 18 Apr 2019 00:41:40 +0200 Subject: [AstroPy] AstroPy Digest - HDU to Table In-Reply-To: <3D4ED4C0-C264-42BE-AD3F-25E33101A41F@astro.physik.uni-goettingen.de> References: <3D4ED4C0-C264-42BE-AD3F-25E33101A41F@astro.physik.uni-goettingen.de> Message-ID: On 17 Apr 2019, at 8:52 pm, Derek Homeier wrote: > > On 17 Apr 2019, at 7:41 pm, Christoph Deil wrote: >> >> if you want a astropy.table.Table object, use Table.read. >> >> You can pass it a filename, but you can also pass an astropy.io.fits.BinTableHDU object, >> If for some reason you already have it in memory. >> >> I agree it?s weird that Table.read does this, adding a astropy.io.fits.hdu_to_table function would make this easier to discover. >> Maybe file an issue with Astropy with that suggestion? >> > Two small clarifications: direct Table initialisation requires the `data` part, e.g. > > astropy.table.Table(binhdu.data) > > but it still preserves structure and column names of the FITS table. If in addition you want to keep > the complete header information, you need to explicitly pass it to the table.meta data, i.e. > > astropy.table.Table(binhdu.data, meta=binhdu.header) > > so you may say this still requires a wrapper, but it?s a pretty thin one. > > For reading from file I have to add that my understanding of the documentation > http://docs.astropy.org/en/stable/io/unified.html#keywords > "The FITS keywords associated with an HDU table are represented in the meta ordered dictionary attribute of a Table. ? > > is actually that Table.read(?filename.fits?, [hdu=n]) should do this automatically, but in fact, > just like Table() without the meta keyword it ends up with an empty dictionary in table.meta. > I stand corrected here: Table.read() does store the header cards in the meta attribute, after stripping the functional keywords defining the table itself and a couple of other blacklisted cards - which just happened to be *all* of the cards in some of the test files in the distribution. In contrast, this works as expected: >>> chandra = Table.read('https://github.com/astropy/astropy/blob/master/astropy/io/fits/tests/data/chandra_time.fits?raw=true?) >>> chandra.meta['TITLE'] Multiwavelength Characterization of Candidate Black Holes in Nearby Dwarf Galaxies Cheers, Derek From derek at astro.physik.uni-goettingen.de Wed Apr 17 19:13:53 2019 From: derek at astro.physik.uni-goettingen.de (Derek Homeier) Date: Thu, 18 Apr 2019 01:13:53 +0200 Subject: [AstroPy] AstroPy Digest, Vol 151, Issue 3 In-Reply-To: References: Message-ID: <4586D712-70EA-4984-8C54-906D4B2813B2@astro.physik.uni-goettingen.de> On 17 Apr 2019, at 8:32 pm, Ivan Valtchanov wrote: > > You cannot use BinTableHDU to create an astropy.tableTable object. When you try to do this you get this error: > > table = Table(hdu[1]) > > Data type not allowed to init Table > > But this one works, > > table = Table(hdu[1].data) > > although I don't think it's documented in astropy.table docs. I could not find it easily. > Actually you can pass the BinTableHDU object to the read() function instead of a file, which will properly handle the rest (including filling the table.meta information), and that?s probably what Christoph referred to: table = Table.read(hdu[1]) But it certainly looks like a peculiar egg; Happy Easter! Derek From hessman at astro.physik.uni-goettingen.de Thu Apr 18 03:44:04 2019 From: hessman at astro.physik.uni-goettingen.de (Frederic V. Hessman) Date: Thu, 18 Apr 2019 09:44:04 +0200 Subject: [AstroPy] AstroPy Digest, Vol 151, Issue 5 In-Reply-To: References: Message-ID: Thanks for the various tips... > But this one works, > > table = Table(hdu[1].data) > > although I don't think it's documented in astropy.table docs. > I could not find it easily. > > Cheers, > Ivan > Two small clarifications: direct Table initialisation requires the `data` part, e.g. > > astropy.table.Table(binhdu.data) > > but it still preserves structure and column names of the FITS table. Aha! This is because np.ndarray has dtype.names! However, this doesn't transfer the metadata... > If in addition you want to keep > the complete header information, you need to explicitly pass it to the table.meta data, i.e. > > astropy.table.Table(binhdu.data, meta=binhdu.header) > > so you may say this still requires a wrapper, but it?s a pretty thin one. I agree - this is the way to go for now. THAT thin a wrapper for a single HDU->Table conversion would be elegant but is otherwise unnecessary. However, mutiple table in a multiple HDU list require more work and it would be nice to have a wrapper for that. It would be good to have this mentioned in the docs, something like ---------------------------------------------------------------------------------------------------------------------------------------- The equivalent reverse conversion for complex HDUList's (multiple tables in one FITS binary table file) tables = hdulist_to_tables (hdul) is easily achieved by explicitly passing both the data and the metadata to Table(): import astropy.io.fits from astropy.table import Table def hdulist_to_tables (hdul) : tables = [] for i in range(1,len(hdul)) : hdu = hdul[i] t = Table (data=hdu.data, meta=hdu.header) tables.append(t) return tables ---------------------------------------------------------------------------------------------------------------------------------------- > I stand corrected here: Table.read() does store the header cards in the meta attribute, > after stripping the functional keywords defining the table itself and a couple of other blacklisted > cards - which just happened to be *all* of the cards in some of the test files in the distribution. > In contrast, this works as expected: > >>>> chandra = Table.read('https://github.com/astropy/astropy/blob/master/astropy/io/fits/tests/data/chandra_time.fits?raw=true?) >>>> chandra.meta['TITLE'] >>>> Multiwavelength Characterization of Candidate Black Holes in Nearby Dwarf Galaxies OK, so I wrote the test script http://www.astro.physik.uni-goettingen.de/~hessman/misc/HDUList_to_Table_test.py which creates different multiple table HDULists from scratch, writes them to files (for a Table.read({filename}) comparison), and reads the last table into a Table using t = Table.read (hdul,hdu=n) (hdul is the HDUList, n is the total number of HDU's; hdu=0 is the PrimaryHDU) and this appears to work: the correct table is converted. However, I get FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`. from ._conv import register_converters as _register_converters the first time and WARNING: hdu= was not specified but multiple tables are present, reading in first available table (hdu=1) [astropy.io.fits.connect] for n > 2 (i.e. more than one table), even though "hdu=" _was_ specified and the correct HDU is converted; the "first available table" is NOT read. A small bug in the irrelevant warning. Thus, for now ---------------------------------------------------------------------------------------------------------------------------------------- or by using the hdu= argument of Table.read(): def hdulist_to_tables (hdul) : tables = [] for i in range(1,len(hdul)) : t = Table.read (hdul, hdu=i) tables.append(t) return tables and ignoring the warning that hdu= was not specified and that the first HDU was used (Version XXXX and earlier). ---------------------------------------------------------------------------------------------------------------------------------------- Rick ------------------------------------------------------------------------------------------------ Dr. Frederic V. Hessman Hessman at Astro.physik.Uni-Goettingen.DE Institut f?r Astrophysik Tel. +49-551-39-5052 Friedrich-Hund-Platz 1 Fax +49-551-39-5043 37077 Goettingen Room F04-133 http://www.Astro.physik.Uni-Goettingen.de/~hessman ------------------------------------------------------------------------------------------------- MONET: a MOnitoring NEtwork of Telescopes http://monet.Uni-Goettingen.de ------------------------------------------------------------------------------------------------- From derek at astro.physik.uni-goettingen.de Thu Apr 18 08:35:11 2019 From: derek at astro.physik.uni-goettingen.de (Derek Homeier) Date: Thu, 18 Apr 2019 14:35:11 +0200 Subject: [AstroPy] AstroPy Digest: HDU to Table In-Reply-To: References: Message-ID: Hi Rick, > > I agree - this is the way to go for now. THAT thin a wrapper for a single HDU->Table conversion would be elegant but is otherwise unnecessary. However, mutiple table in a multiple HDU list require more work and it would be nice to have a wrapper for that. It would be good to have this mentioned in the docs, something like > > ---------------------------------------------------------------------------------------------------------------------------------------- > The equivalent reverse conversion for complex HDUList's (multiple tables in one FITS binary table file) > > tables = hdulist_to_tables (hdul) > > is easily achieved by explicitly passing both the data and the metadata to Table(): > for the docs it would probably be best to recommend the ?trick? using Table.read() below. > > OK, so I wrote the test script > > http://www.astro.physik.uni-goettingen.de/~hessman/misc/HDUList_to_Table_test.py > > which creates different multiple table HDULists from scratch, writes them to files (for a Table.read({filename}) comparison), and reads the last table into a Table using > > t = Table.read (hdul,hdu=n) > > (hdul is the HDUList, n is the total number of HDU's; hdu=0 is the PrimaryHDU) and this appears to work: the correct table is converted. However, I get > > FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`. > from ._conv import register_converters as _register_converters > > the first time and > Hmm, don?t see that FutureWarning with Astropy 3.1.2 + Numpy 1.14.5 - in fact I could not find that code line anywhere in the astropy or numpy tree. > WARNING: hdu= was not specified but multiple tables are present, reading in first available table (hdu=1) [astropy.io.fits.connect] > > for n > 2 (i.e. more than one table), even though "hdu=" _was_ specified and the correct HDU is converted; the "first available table" is NOT read. A small bug in the irrelevant warning. > But the ?hdu= was not specified? warning (correctly) follows the reading from file, and that is is opening the first extension - looks all correct to me. I tested with all extensions in hdul (extending your last lines a bit): ... t = Table.read ('test.fits',format='fits') t.info print (' * y-sum of table:',np.sum(t['y'])) print (' * Creating a table from default (first) table in HDUList ?') t = Table.read (hdul) t.info print (' * y-sum of table:',np.sum(t['y'])) print (' * Creating a table from the each table in HDUList using hdu= argument ...') for i in range(1, n+1) : t = Table.read (hdul,hdu=i) t.info print (' * HDU {:d} - {:s}: y-sum of table: {:f}'.format(i, t.meta['OBJNAME'], np.sum(t['y']))) ? * Creating a table from the file... WARNING: hdu= was not specified but multiple tables are present, reading in first available table (hdu=1) [astropy.io.fits.connect] * y-sum of table: 55.0 * Creating a table from default (first) table in HDUList ... * y-sum of table: 55.0 * Creating a table from the each table in HDUList using hdu= argument ... * HDU 1 - data_0: y-sum of table: 55.000000 * HDU 2 - data_1: y-sum of table: 550.000000 * Test using 3 HDUs... * y-sum of table: 55.0 * y-sum of table: 550.0 * y-sum of table: 5500.0 * Storing in file... * Creating a table from the file... * y-sum of table: 55.0 * Creating a table from default (first) table in HDUList ... * y-sum of table: 55.0 * Creating a table from the each table in HDUList using hdu= argument ... * HDU 1 - data_0: y-sum of table: 55.000000 * HDU 2 - data_1: y-sum of table: 550.000000 * HDU 3 - data_2: y-sum of table: 5500.000000 Creating lists of table is thus straightforward; and as `table_to_hdu()` does not provide any more specific functionality here either, I rather don?t think it needs to be further discussed in the docs. At a minimum probably a paragraph should be added to the end of the `Reading` section noting that in addition to the file-like objects mentioned in http://docs.astropy.org/en/stable/io/unified.html Table.read() accepts an HDU or HDUList object as input ?file? (with the ?hdu=? kwarg functioning accordingly in the latter case). Cheers, Derek From algorithm059 at gmail.com Thu Apr 4 04:41:24 2019 From: algorithm059 at gmail.com (Rohit Kapoor) Date: Thu, 04 Apr 2019 08:41:24 -0000 Subject: [AstroPy] Introduction and query regarding installation Message-ID: Hello all! I am using Anaconda distribution and have created a virtual environment named space. I just installed astropy in that environment and configured it's developer version as per the instructions given here . When I run the conda list command on the terminal i get the output as shown in the image. I installed astropy's developer version using pip in the conda environment where astropy was already installed using conda. Also i ran the command: "python setup.py test" and it gave me a positive result and no errors. So i just want to confirm if the installation is complete. Thank you -Rohit -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: Selection_002.png Type: image/png Size: 131335 bytes Desc: not available URL: