Repository 'fits2tiff_astro_tool'
hg clone https://toolshed.g2.bx.psu.edu/repos/astroteam/fits2tiff_astro_tool

Changeset 0:8f94a9d810c2 (2025-07-18)
Commit message:
planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit 7be57c88cfb29c1bc1db2afbd42d3d80fcf42985
added:
fits2tiff.py
fits2tiff_astro_tool.xml
b
diff -r 000000000000 -r 8f94a9d810c2 fits2tiff.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/fits2tiff.py Fri Jul 18 14:13:15 2025 +0000
[
@@ -0,0 +1,84 @@
+#!/usr/bin/env python
+# coding: utf-8
+
+#!/usr/bin/env python
+
+# This script is generated with nb2galaxy
+
+# flake8: noqa
+
+import json
+import os
+import shutil
+
+import tifffile
+from astropy.io import fits
+
+file_input = "./input.fits"  # oda:POSIXPath; oda:label "Input file"
+input_hdu_no = 0  # oda:Integer; oda:label "Input HDU number"
+
+_galaxy_wd = os.getcwd()
+
+with open("inputs.json", "r") as fd:
+    inp_dic = json.load(fd)
+if "C_data_product_" in inp_dic.keys():
+    inp_pdic = inp_dic["C_data_product_"]
+else:
+    inp_pdic = inp_dic
+file_input = str(inp_pdic["file_input"])
+input_hdu_no = int(inp_pdic["input_hdu_no"])
+
+try:
+    hdul = fits.open(file_input)
+    data = hdul[input_hdu_no].data
+    header = hdul[input_hdu_no].header
+    data = data.astype(data.dtype.newbyteorder("="))
+except:
+    raise RuntimeError("The input file should have the FITS format.")
+
+image_out_path = "./output.tiff"
+tifffile.imwrite(image_out_path, data)
+
+dict_old = dict(header)
+dict_json = {}
+for key in dict_old.keys():
+    if key != "COMMENT":
+        dict_json[key] = dict_old[key]
+
+file_output = image_out_path
+header_json = dict_json
+
+# output gathering
+_galaxy_meta_data = {}
+_simple_outs = []
+_simple_outs.append(
+    ("out_fits2tiff_file_output", "file_output_galaxy.output", file_output)
+)
+_simple_outs.append(
+    ("out_fits2tiff_header_json", "header_json_galaxy.output", header_json)
+)
+
+try:
+    import numpy as np  # noqa: E402
+
+    _numpy_available = True
+except ImportError:
+    _numpy_available = False
+
+for _outn, _outfn, _outv in _simple_outs:
+    _galaxy_outfile_name = os.path.join(_galaxy_wd, _outfn)
+    if isinstance(_outv, str) and os.path.isfile(_outv):
+        shutil.move(_outv, _galaxy_outfile_name)
+        _galaxy_meta_data[_outn] = {"ext": "_sniff_"}
+    elif _numpy_available and isinstance(_outv, np.ndarray):
+        with open(_galaxy_outfile_name, "wb") as fd:
+            np.savez(fd, _outv)
+        _galaxy_meta_data[_outn] = {"ext": "npz"}
+    else:
+        with open(_galaxy_outfile_name, "w") as fd:
+            json.dump(_outv, fd)
+        _galaxy_meta_data[_outn] = {"ext": "expression.json"}
+
+with open(os.path.join(_galaxy_wd, "galaxy.json"), "w") as fd:
+    json.dump(_galaxy_meta_data, fd)
+print("*** Job finished successfully ***")
b
diff -r 000000000000 -r 8f94a9d810c2 fits2tiff_astro_tool.xml
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/fits2tiff_astro_tool.xml Fri Jul 18 14:13:15 2025 +0000
b
@@ -0,0 +1,48 @@
+<tool id="fits2tiff_astro_tool" name="fits2tiff" version="0.0.1+galaxy0" profile="24.0">
+  <requirements>
+    <requirement type="package" version="6.1.7">astropy</requirement>
+    <requirement type="package" version="2025.6.11">tifffile</requirement>
+    <requirement type="package" version="9.4.0">ipython</requirement>
+  </requirements>
+  <command detect_errors="exit_code">python '$__tool_directory__/fits2tiff.py'</command>
+  <environment_variables>
+    <environment_variable name="BASEDIR">$__tool_directory__</environment_variable>
+    <environment_variable name="GALAXY_TOOL_DIR">$__tool_directory__</environment_variable>
+  </environment_variables>
+  <configfiles>
+    <inputs name="inputs" filename="inputs.json" data_style="paths" />
+  </configfiles>
+  <inputs>
+    <param name="file_input" type="data" label="Input file" format="data" optional="false" />
+    <param name="input_hdu_no" type="integer" value="0" label="Input HDU number" optional="false" />
+  </inputs>
+  <outputs>
+    <data label="${tool.name} -&gt; fits2tiff file_output" name="out_fits2tiff_file_output" format="auto" from_work_dir="file_output_galaxy.output" />
+    <data label="${tool.name} -&gt; fits2tiff header_json" name="out_fits2tiff_header_json" format="auto" from_work_dir="header_json_galaxy.output" />
+  </outputs>
+  <tests>
+    <test expect_num_outputs="2">
+      <param name="file_input" location="https://gitlab.renkulab.io/astronomy/mmoda/fits2tiff/-/raw/425c43b8429eceea946865e1ba475aa82ad33a79/input.fits" />
+      <param name="input_hdu_no" value="0" />
+      <assert_stdout>
+        <has_text text="*** Job finished successfully ***" />
+      </assert_stdout>
+    </test>
+  </tests>
+  <help>This tool converts images stored in FITS files to TIFF format. If the
+FITS file contains multiple HDUs, the desired HDU index can be
+specified.
+
+**Important**: The image data itself is not altered during the
+conversion.
+
+In addition to the TIFF file, the tool also outputs a JSON file
+containing the metadata from the header of the selected FITS HDU.
+</help>
+  <citations>
+    <citation type="doi">10.1051/0004-6361/201322068</citation>
+    <citation type="doi">10.3847/1538-3881/aabc4f</citation>
+    <citation type="doi">10.3847/1538-4357/ac7c74</citation>
+    <citation type="doi">10.5281/zenodo.15645336</citation>
+  </citations>
+</tool>
\ No newline at end of file