changeset 0:01fbfdf7d10f draft

planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools/astropytools commit 1ed262b482599b257c6b323b154bee2412265dbf-dirty
author astroteam
date Thu, 22 Jun 2023 19:39:08 +0000
parents
children 59311d1525e1
files fits2table.xml generate_cmaps.py static/images/legacysurvey_image.png test-data/WFPC2u5780205r_c0fx.fits test-data/fitsinfo.out test-data/fitstable.csv test-data/fitstable.tsv test-data/legacysurvey_image.fits test-data/legacysurvey_image.png
diffstat 9 files changed, 108 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/fits2table.xml	Thu Jun 22 19:39:08 2023 +0000
@@ -0,0 +1,90 @@
+<tool id="astropy_fits2csv" name="astropy fits2csv" version="0.1.0+galaxy0" profile="21.05">
+    <requirements>
+        <requirement type="package" version="5.2.2">astropy</requirement>
+    </requirements>
+    <command detect_errors="exit_code"><![CDATA[
+        python '$py_script_file' 
+    ]]></command>
+
+    <configfiles>
+        <configfile name="py_script_file">
+from astropy.io import fits
+from astropy.table import Table
+
+if '$output_format' == 'csv':
+    output_separator = ','
+elif '$output_format' == 'tabular':
+    output_separator = '\t'
+else:
+    raise ValueError('Unknown output format: ' + '$output_format')
+
+with fits.open("$input_fits", memmap=True) as hdu_list:
+
+    # select the HDU you want
+    hdu = hdu_list[$hdu]
+    
+    # read into an astropy Table object
+    table = Table(hdu.data)
+
+    # write to a CSV file
+    table.write('$output', delimiter=output_separator, format='ascii', overwrite=True)
+        </configfile>
+    </configfiles>
+
+    <inputs>
+        <param type="data" name="input_fits" format="fits" label="FITS file to dump"/>
+        <param type="integer" name="hdu"  value="1" min="1" label="Select input HDU number"/>
+        <param type="select" name="output_format" label="Output format">
+            <option value="tabular" selected="true">tabular, tab-separated values</option>
+            <option value="csv">CSV, coma-separated values</option>
+        </param>
+    </inputs>
+    <outputs>
+        <data name="output" format="tabular">
+            <change_format>
+                <when input="output_separator" value="," format="csv" />
+            </change_format>
+        </data>
+    </outputs>
+    <tests>
+        <test>
+            <param name="input_fits" value="WFPC2u5780205r_c0fx.fits"/>
+            <param name="hdu" value="1"/>
+            <param name="output_format" value="csv"/>
+            <output name="output" file="fitstable.csv"/>
+        </test>
+        <test>
+            <param name="input_fits" value="WFPC2u5780205r_c0fx.fits"/>
+            <param name="hdu" value="1"/>
+            <param name="output_format" value="tabular"/>
+            <output name="output" file="fitstable.tsv"/>
+        </test>
+    </tests>
+    <help><![CDATA[
+Extract a text table (CSV, SSV, or TSV) from FITS file HDU Table. Resulting CSV file can be used by many existing Galaxy tools and visualisation plugins.
+
+---------
+
+**Example:**
+
+For example, here is the output for on of the sample fits files, https://fits.gsfc.nasa.gov/samples/WFPC2u5780205r_c0fx.fits
+
+
+.. code-block::
+
+    CRVAL1	CRVAL2	CRPIX1	CRPIX2	CD1_1	CD1_2	CD2_1	CD2_2	DATAMIN	DATAMAX	MIR_REVR	ORIENTAT	FILLCNT	ERRCNT	FPKTTIME	LPKTTIME	CTYPE1	CTYPE2	DETECTOR	DEZERO	BIASEVEN	BIASODD	GOODMIN	GOODMAX	DATAMEAN	GPIXELS	SOFTERRS	CALIBDEF	STATICD	ATODSAT	DATALOST	BADPIXEL	OVERLAP	PHOTMODE	PHOTFLAM	PHOTZPT	PHOTPLAM	PHOTBW	MEDIAN	MEDSHADO	HISTWIDE	SKEWNESS	MEANC10	MEANC25	MEANC50	MEANC100	MEANC200	MEANC300	BACKGRND
+    182.6311886308	39.39633673411	420.0	424.5	-1.06704e-06	-1.25958e-05	-1.26016e-05	1.06655e-06	-73.19537	3777.701	T	-85.16	0	0	51229.798573999986	51229.798742000006	RA---TAN	DEC--TAN	1	316.6452	316.6715	316.6189	-5.064006	2552.17	0.4182382	632387	0	1466	0	16	0	0	0	WFPC2,1,A2D7,LRF#4877.0,,CAL	3.44746e-16	-21.1	4884.258	20.20996	-0.175651	-0.121681	1.033711	-1.983727	0.12958	0.3129676	0.4577668	0.3916293	0.3115222	0.3295493	-0.3676353
+    182.6255233634	39.41214313815	423.5	414.0	-2.75605e-05	2.08221e-06	2.08021e-06	2.75871e-05	-19.95751	3740.623	T	4.31638	0	0	51229.798742000006	51229.79891000002	RA---TAN	DEC--TAN	2	354.0573	354.0761	354.0386	-3.379329	3720.573	0.6385469	631340	0	2072	0	25	0	0	0	WFPC2,2,A2D7,LRF#4877.0,,CAL	3.382652e-16	-21.1	4884.261	20.20992	-0.1896807	-0.1899146	1.053666	-1.947547	0.2564496	0.1057321	0.9952926	0.8409855	0.6534808	0.5836062	0.2101429
+    182.6523792305	39.410944281389995	436.0	424.5	2.23913e-06	2.75426e-05	2.75684e-05	-2.23704e-06	-58.53249	3282.136	T	94.6434	0	0	51229.79891000002	51229.799078	RA---TAN	DEC--TAN	3	306.6676	306.6541	306.681	-3.713645	3282.136	0.5217843	633259	0	1551	0	7	0	0	0	WFPC2,3,A2D7,LRF#4877.0,,CAL	3.372288e-16	-21.1	4884.255	20.21006	0.01109185	0.06184989	1.003236	28.21703	1.669304	0.3472891	0.327215	0.6145074	0.7027547	0.5681439	0.4761558
+    182.650022355	39.38946044168	423.0	421.0	2.75358e-05	-2.50931e-06	-2.50689e-06	-2.75624e-05	-72.41166	3420.24	T	-174.798	0	0	51229.799079	51229.79924599999	RA---TAN	DEC--TAN	4	311.7072	311.7648	311.6496	-3.289304	3420.24	0.7084697	628289	0	1816	0	57	0	0	0	WFPC2,4,A2D7,LRF#4877.0,,CAL	3.46466e-16	-21.1	4884.256	20.20999	-0.06813275	-0.03253493	0.9846212	-4.591252	0.1359666	0.04015671	0.1129934	1.897491	0.9687142	1.05377	0.3466465
+
+
+This tool is a simple script based on Astropy package. See `astropy help <https://docs.astropy.org/en/latest/io/fits/>`_
+for further documentation. 
+    ]]></help>
+    <citations>
+        <citation type="doi">
+            10.3847/1538-4357/ac7c74
+        </citation>
+    </citations>
+</tool>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/generate_cmaps.py	Thu Jun 22 19:39:08 2023 +0000
@@ -0,0 +1,5 @@
+from matplotlib import pyplot as plt
+
+cmaps = sorted(m for m in plt.cm.datad if not m.endswith("_r"))
+
+print("\n".join([f'<option value="{cm}">{cm}</option>' for cm in cmaps]))
Binary file static/images/legacysurvey_image.png has changed
Binary file test-data/WFPC2u5780205r_c0fx.fits has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test-data/fitsinfo.out	Thu Jun 22 19:39:08 2023 +0000
@@ -0,0 +1,3 @@
+No.    Name      Ver    Type      Cards   Dimensions   Format
+  0  PRIMARY       1 PrimaryHDU     262   (200, 200, 4)   float32   
+  1  u5780205r_cvt.c0h.tab    1 TableHDU       353   4R x 49C   [D25.17, D25.17, E15.7, E15.7, E15.7, E15.7, E15.7, E15.7, E15.7, E15.7, A1, E15.7, I12, I12, D25.17, D25.17, A8, A8, I12, E15.7, E15.7, E15.7, E15.7, E15.7, E15.7, I12, I12, I12, I12, I12, I12, I12, I12, A48, E15.7, E15.7, E15.7, E15.7, E15.7, E15.7, E15.7, E15.7, E15.7, E15.7, E15.7, E15.7, E15.7, E15.7, E15.7]   
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test-data/fitstable.csv	Thu Jun 22 19:39:08 2023 +0000
@@ -0,0 +1,5 @@
+CRVAL1,CRVAL2,CRPIX1,CRPIX2,CD1_1,CD1_2,CD2_1,CD2_2,DATAMIN,DATAMAX,MIR_REVR,ORIENTAT,FILLCNT,ERRCNT,FPKTTIME,LPKTTIME,CTYPE1,CTYPE2,DETECTOR,DEZERO,BIASEVEN,BIASODD,GOODMIN,GOODMAX,DATAMEAN,GPIXELS,SOFTERRS,CALIBDEF,STATICD,ATODSAT,DATALOST,BADPIXEL,OVERLAP,PHOTMODE,PHOTFLAM,PHOTZPT,PHOTPLAM,PHOTBW,MEDIAN,MEDSHADO,HISTWIDE,SKEWNESS,MEANC10,MEANC25,MEANC50,MEANC100,MEANC200,MEANC300,BACKGRND
+182.6311886308,39.39633673411,420.0,424.5,-1.06704e-06,-1.25958e-05,-1.26016e-05,1.06655e-06,-73.19537,3777.701,T,-85.16,0,0,51229.798573999986,51229.798742000006,RA---TAN,DEC--TAN,1,316.6452,316.6715,316.6189,-5.064006,2552.17,0.4182382,632387,0,1466,0,16,0,0,0,"WFPC2,1,A2D7,LRF#4877.0,,CAL",3.44746e-16,-21.1,4884.258,20.20996,-0.175651,-0.121681,1.033711,-1.983727,0.12958,0.3129676,0.4577668,0.3916293,0.3115222,0.3295493,-0.3676353
+182.6255233634,39.41214313815,423.5,414.0,-2.75605e-05,2.08221e-06,2.08021e-06,2.75871e-05,-19.95751,3740.623,T,4.31638,0,0,51229.798742000006,51229.79891000002,RA---TAN,DEC--TAN,2,354.0573,354.0761,354.0386,-3.379329,3720.573,0.6385469,631340,0,2072,0,25,0,0,0,"WFPC2,2,A2D7,LRF#4877.0,,CAL",3.382652e-16,-21.1,4884.261,20.20992,-0.1896807,-0.1899146,1.053666,-1.947547,0.2564496,0.1057321,0.9952926,0.8409855,0.6534808,0.5836062,0.2101429
+182.6523792305,39.410944281389995,436.0,424.5,2.23913e-06,2.75426e-05,2.75684e-05,-2.23704e-06,-58.53249,3282.136,T,94.6434,0,0,51229.79891000002,51229.799078,RA---TAN,DEC--TAN,3,306.6676,306.6541,306.681,-3.713645,3282.136,0.5217843,633259,0,1551,0,7,0,0,0,"WFPC2,3,A2D7,LRF#4877.0,,CAL",3.372288e-16,-21.1,4884.255,20.21006,0.01109185,0.06184989,1.003236,28.21703,1.669304,0.3472891,0.327215,0.6145074,0.7027547,0.5681439,0.4761558
+182.650022355,39.38946044168,423.0,421.0,2.75358e-05,-2.50931e-06,-2.50689e-06,-2.75624e-05,-72.41166,3420.24,T,-174.798,0,0,51229.799079,51229.79924599999,RA---TAN,DEC--TAN,4,311.7072,311.7648,311.6496,-3.289304,3420.24,0.7084697,628289,0,1816,0,57,0,0,0,"WFPC2,4,A2D7,LRF#4877.0,,CAL",3.46466e-16,-21.1,4884.256,20.20999,-0.06813275,-0.03253493,0.9846212,-4.591252,0.1359666,0.04015671,0.1129934,1.897491,0.9687142,1.05377,0.3466465
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test-data/fitstable.tsv	Thu Jun 22 19:39:08 2023 +0000
@@ -0,0 +1,5 @@
+CRVAL1	CRVAL2	CRPIX1	CRPIX2	CD1_1	CD1_2	CD2_1	CD2_2	DATAMIN	DATAMAX	MIR_REVR	ORIENTAT	FILLCNT	ERRCNT	FPKTTIME	LPKTTIME	CTYPE1	CTYPE2	DETECTOR	DEZERO	BIASEVEN	BIASODD	GOODMIN	GOODMAX	DATAMEAN	GPIXELS	SOFTERRS	CALIBDEF	STATICD	ATODSAT	DATALOST	BADPIXEL	OVERLAP	PHOTMODE	PHOTFLAM	PHOTZPT	PHOTPLAM	PHOTBW	MEDIAN	MEDSHADO	HISTWIDE	SKEWNESS	MEANC10	MEANC25	MEANC50	MEANC100	MEANC200	MEANC300	BACKGRND
+182.6311886308	39.39633673411	420.0	424.5	-1.06704e-06	-1.25958e-05	-1.26016e-05	1.06655e-06	-73.19537	3777.701	T	-85.16	0	0	51229.798573999986	51229.798742000006	RA---TAN	DEC--TAN	1	316.6452	316.6715	316.6189	-5.064006	2552.17	0.4182382	632387	0	1466	0	16	0	0	0	WFPC2,1,A2D7,LRF#4877.0,,CAL	3.44746e-16	-21.1	4884.258	20.20996	-0.175651	-0.121681	1.033711	-1.983727	0.12958	0.3129676	0.4577668	0.3916293	0.3115222	0.3295493	-0.3676353
+182.6255233634	39.41214313815	423.5	414.0	-2.75605e-05	2.08221e-06	2.08021e-06	2.75871e-05	-19.95751	3740.623	T	4.31638	0	0	51229.798742000006	51229.79891000002	RA---TAN	DEC--TAN	2	354.0573	354.0761	354.0386	-3.379329	3720.573	0.6385469	631340	0	2072	0	25	0	0	0	WFPC2,2,A2D7,LRF#4877.0,,CAL	3.382652e-16	-21.1	4884.261	20.20992	-0.1896807	-0.1899146	1.053666	-1.947547	0.2564496	0.1057321	0.9952926	0.8409855	0.6534808	0.5836062	0.2101429
+182.6523792305	39.410944281389995	436.0	424.5	2.23913e-06	2.75426e-05	2.75684e-05	-2.23704e-06	-58.53249	3282.136	T	94.6434	0	0	51229.79891000002	51229.799078	RA---TAN	DEC--TAN	3	306.6676	306.6541	306.681	-3.713645	3282.136	0.5217843	633259	0	1551	0	7	0	0	0	WFPC2,3,A2D7,LRF#4877.0,,CAL	3.372288e-16	-21.1	4884.255	20.21006	0.01109185	0.06184989	1.003236	28.21703	1.669304	0.3472891	0.327215	0.6145074	0.7027547	0.5681439	0.4761558
+182.650022355	39.38946044168	423.0	421.0	2.75358e-05	-2.50931e-06	-2.50689e-06	-2.75624e-05	-72.41166	3420.24	T	-174.798	0	0	51229.799079	51229.79924599999	RA---TAN	DEC--TAN	4	311.7072	311.7648	311.6496	-3.289304	3420.24	0.7084697	628289	0	1816	0	57	0	0	0	WFPC2,4,A2D7,LRF#4877.0,,CAL	3.46466e-16	-21.1	4884.256	20.20999	-0.06813275	-0.03253493	0.9846212	-4.591252	0.1359666	0.04015671	0.1129934	1.897491	0.9687142	1.05377	0.3466465
Binary file test-data/legacysurvey_image.fits has changed
Binary file test-data/legacysurvey_image.png has changed