Question on GILDAS/CLASS and Python

147 views
Skip to first unread message

49j...@gmail.com

unread,
Feb 3, 2021, 2:48:27 PM2/3/21
to Society of Amateur Radio Astronomers
Wolfgang, the Python FITS program you sent me sometime back has been really useful, and I have made some modifications to it over time.  One of those modifications, for example, the attachment below shows the current FITS Header produced by the program. The other attachment, from a different day, shows the plot of all the FITS files on that day.  The "read_fits.class" attachment shows the script that reads all the FITS files collected over a time period.  One of the lines in that script is " modify system eq" which allows the Header to display RA and DEC in place of "l" and "b".  I don't have any problem with putting RA and DEC into the Header, but I can't figure out how to get Python to populate the RA and DEC parts of the Header that displays with the plot.  In short, I would like to have a plot display that shows the RA and DEC for the start of the plot.  I hope I haven't made this confusing.  As always, thanks for your help.
Screenshot from 2021-01-27 15-30-17.png
Screenshot from 2021-01-30 14-53-31.png
process1.class

fasleitung3

unread,
Feb 6, 2021, 1:47:06 PM2/6/21
to sara...@googlegroups.com
Jack,
Most likely the issue is that we are using different keyworks in the fits header than what CLASS would recognize. I have not figured out myself. I will go ahead and try to find somebody who might know.
A workaround might be to get access to the FITS header elements from within CLASS other than those which are printed out as standard. I have not done this myself, but here is what I found. It is only part of the solution but maybe you can work from there.
On page 28, Importing data from outside world, III Other fits files you will find a class command sequence which gives access to all header elements. f% will list all header lines, but you can also specify which element you want. Maybe that is a way to eventually get it printed as well.
I will keep you advised if I find anything out. 
Wolfgang


Am Mittwoch, den 03.02.2021, 11:48 -0800 schrieb 49j...@gmail.com:
Wolfgang, the Python FITS program you sent me sometime back has been really useful, and I have made some modifications to it over time.  One of those modifications, for example, the attachment below shows the current FITS Header produced by the program. The other attachment, from a different day, shows the plot of all the FITS files on that day.  The "read_fits.class" attachment shows the script that reads all the FITS files collected over a time period.  One of the lines in that script is " modify system eq" which allows the Header to display RA and DEC in place of "l" and "b".  I don't have any problem with putting RA and DEC into the Header, but I can't figure out how to get Python to populate the RA and DEC parts of the Header that displays with the plot.  In short, I would like to have a plot display that shows the RA and DEC for the start of the plot.  I hope I haven't made this confusing.  As always, thanks for your help.

--
--
You received this message because you are subscribed to the Google
Groups "Society of Amateur Radio Astronomers" group.
To post to this group, send email to sara...@googlegroups.com
To unsubscribe from this group, send email to
sara-list-...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/sara-list?hl=en
---
You received this message because you are subscribed to the Google Groups "Society of Amateur Radio Astronomers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sara-list+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sara-list/8b7bdddb-0ea5-4892-adeb-fe86066fde01n%40googlegroups.com.

Jack Lobingier

unread,
Feb 8, 2021, 10:32:20 AM2/8/21
to sara...@googlegroups.com
Wolfgang, thank you for your response.  With that information I have been able to do the following:

>fits read 3m_Lime-H1_spec_2549.fits
>modify system eq*
>define fits f 3m_Lime-H1_spec_2549.fits
>modify position f%crval2 f%crval3
>pl

When you run this in CLASS it will place the RA and DEC values into the plot header.  Because the crval2 and crval3 are written into the fits header file by your python program I should be able to modify the @ read_fits.class script to write the RA and DEC values to all the files as they are read into CLASS.  The only problem is that I don't know what the correct syntax is to modify the @ read_fits.class script.  Other than the GILDAS people, do you know anyone who could tell me how to do that?  Thank you for the continued help.

Jack

3m_Lime-H1_spec_2549.fits
read_fits.class

fasleitung3

unread,
Feb 8, 2021, 11:19:35 AM2/8/21
to sara...@googlegroups.com
Jack, this is an interesting piece of information. I will certainly use this as will.
As far as the read_fits.class script is concerned, this was not attached to your previous mail. You sent a process1.class which seems to be a different thing.
Can you send your read_fits script as well so that I can think about how to modify it?
I am in contact with people at the university of Bonn who do a lot with class. This is where I can ask.
Best regards,
Wolfgang

Jack Lobingier

unread,
Feb 8, 2021, 1:58:37 PM2/8/21
to sara...@googlegroups.com
Sorry Wolfgang, I must have attached the wrong script.  Here is the correct one.

Jack

read_fits.class

49j...@gmail.com

unread,
Feb 13, 2021, 8:54:45 PM2/13/21
to Society of Amateur Radio Astronomers
Wolfgang, through trial and error I have been able to modify the 'read_fits_test' Class script to add the RA and DEC to the FITS database and plots.  The only drawback is that it will only do 250 files at a time.  Do to the limitation in doing attachments I can't send the FITS files that produced the below screenshots and database, but I will be glad to post them on Google Drive, or somewhere else for your use.  I am really not knowledgeable of Class/SIC programming, so if you or your friends at the University can find a less limiting way of adding RA and DEC, from the individual FITS files, to the database that would be wonderful.  Thanks again for your help. 

Jack
read_fits_test.class
Screenshot from 2021-02-13 08-34-24.png
process1_test.class
Screenshot from 2021-02-13 08-33-36.png

Jack Lobingier

unread,
Feb 13, 2021, 9:12:39 PM2/13/21
to sara...@googlegroups.com
Wolfgang, after looking at the available options for sending the FITS files used in the previous post, I find that standard tar compression would allow me to send the data, so here are the FITS files that when run with the previously attached class scripts will produce the previously sent plots.  The limit of 250 FITS files is because of the ~250 limit of a single variable in SIC.  Hopefully you or your friends at the University will be able to recommend a better way to do this that does not have this limitation.  Thanks again.

Jack

You received this message because you are subscribed to a topic in the Google Groups "Society of Amateur Radio Astronomers" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sara-list/ypsbHRY2Fs8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sara-list+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sara-list/3431c14a-ee75-4778-ab7b-4514089d51cbn%40googlegroups.com.
FITS_data.tar.xz

fasleitung3

unread,
Feb 14, 2021, 9:46:07 AM2/14/21
to sara...@googlegroups.com
Jack,
I have not heard back from the University yet about how to properly put the coordinates in the header.
In the meantime, I have looked at the header of a FITS file where things work (from Onsala). I have tried to create it in the same way, but it did not work for me. There must be something subtle which I have not figured out yet.
I have attached this FITS file and one of our FITS file where I believe it i have done it in the same way. Maybe it is just something stupid, but so far I cannot find it.
Best regards,
Wolfgang
latest.fits
spectrum_24612.fits

fasleitung3

unread,
Feb 17, 2021, 11:38:24 AM2/17/21
to sara...@googlegroups.com
Hi Jack,
Finally! I found a way to write the coordinates into the fits file in such a way that CLASS does understand it.
It is not the header alone, but it also has something to do with the structure of the actual data. Here is the story, the example is for galactic coordinates:
You define one axis (as before) holding your spectrum such as:

hdu.header.append(('CTYPE1','FREQ','Type of x') , end=True)
hdu.header.append(('CRVAL1',0,'Frequency offset') , end=True)
hdu.header.append(('CDELT1',channelwidth,'Frequency resolution per channel') , end=True)
hdu.header.append(('CRPIX1',CRPIX1,'Number of reference channel') , end=True)

Then you define a second axis for the galacitc longitude, "Lon" being the variable holding your longitude
hdu.header.append(('CTYPE2','GLON','Galactic Longitude') , end=True)
hdu.header.append(('CRPIX2',0), end=True)
hdu.header.append(('CRVAL2',Lon,'Galactic Longitude') , end=True)
hdu.header.append(('CDELT2',1.0), end=True)
hdu.header.append(('CUNIT2','DEGREE','Galactic Longitude') , end=True)

Then you define a third axis for the galacitc latitude, "Lat" being the variable holding your latitude

hdu.header.append(('CTYPE3','GLAT','Galactic Latitude') , end=True)
hdu.header.append(('CRPIX3',0), end=True)
hdu.header.append(('CRVAL3',Lat,'Galactic Latitude') , end=True)
hdu.header.append(('CDELT3',1.0), end=True)
hdu.header.append(('CUNIT3','DEGREE','Galactic Latitude') , end=True)

This is pretty much along the lines of what we did before. The trick is, that CLASS understands this only if the data is actually a three dimensional array. So you need to make your spectrum (which in this example is a numpy array called u) to be three-dimensional. This can be done by just adding empty dimensions by:
u=u[np.newaxis, :]
u=u[np.newaxis, :]

You can then use thus u to create your HDU.

All this seems to be a bit strange at first glance. However, I suppose one could have more than one spectrum from different locations in a single fits file and then it starts making sense.
I hope this gets you going to where you want to be.
Best regards,
Wolfgang



Am Mittwoch, den 03.02.2021, 11:48 -0800 schrieb 49j...@gmail.com:
Wolfgang, the Python FITS program you sent me sometime back has been really useful, and I have made some modifications to it over time.  One of those modifications, for example, the attachment below shows the current FITS Header produced by the program. The other attachment, from a different day, shows the plot of all the FITS files on that day.  The "read_fits.class" attachment shows the script that reads all the FITS files collected over a time period.  One of the lines in that script is " modify system eq" which allows the Header to display RA and DEC in place of "l" and "b".  I don't have any problem with putting RA and DEC into the Header, but I can't figure out how to get Python to populate the RA and DEC parts of the Header that displays with the plot.  In short, I would like to have a plot display that shows the RA and DEC for the start of the plot.  I hope I haven't made this confusing.  As always, thanks for your help. --

fasleitung3

unread,
Feb 17, 2021, 12:26:02 PM2/17/21
to sara...@googlegroups.com
Just as an addition:
Instead of galactic coordinates you can also use equatorial coordinates, just change the definition of the axis into RA and DEC.

Wolfgang

49j...@gmail.com

unread,
Feb 19, 2021, 11:23:09 AM2/19/21
to Society of Amateur Radio Astronomers
Wolfgang, thank you very much for the modifications you sent me.  I'm not the most informed when it comes to using numpy, and as you can see from the below attachments, after I made what I thought were the correct modifications to the Python, I appear to have a multidimensional error when the FITS file tries to write out.  Also, do I need to change the Header parameter NAXIS to something other than 1?  Thanks again for your help.

Jack
Screenshot from 2021-02-19 10-08-16.png
Screenshot from 2021-02-19 10-11-27.png

49j...@gmail.com

unread,
Feb 19, 2021, 12:01:53 PM2/19/21
to Society of Amateur Radio Astronomers
Wolfgang, all worked out, I had the newaxis commands before instead of after the 'u' write command.  Also, NAXIS shows 3 now.  Works great, your the best, thanks again.

Jack

49j...@gmail.com

unread,
Feb 19, 2021, 9:41:06 PM2/19/21
to Society of Amateur Radio Astronomers
Wolfgang, sorry to bother you again, but I have noticed a problem and maybe you have a solution.  The Python program passes decimal hours to CRVAL2 and decimal degrees to CRVAL3.  The CLASS plot header displays the Declination correctly, but the RA is completely wrong..  However, if I use the CLASS modify position command with decimal hours and degrees, it shows fine in the CLASS header plot.  I will continue to work on it, but if you have any ideas please let me know.  Best regards.

Jack

Jack Lobingier

unread,
Feb 20, 2021, 12:08:47 PM2/20/21
to sara...@googlegroups.com
Wolfgang, once again I sent my last email too soon, as I have fixed the problem.  In the future I will spend more time working it before I send something your way.  As always, thanks for all the help.

Jack

--
--
You received this message because you are subscribed to the Google
Groups "Society of Amateur Radio Astronomers" group.
To post to this group, send email to sara...@googlegroups.com
To unsubscribe from this group, send email to
sara-list-...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/sara-list?hl=en
---
You received this message because you are subscribed to the Google Groups "Society of Amateur Radio Astronomers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sara-list+...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages