<div dir="ltr"><div>Okay, I understand that the default behaviour for BZERO and BSCALE creates a floating point array because of the typical upconversion rules. However, I'm not clear about the data type for the special case where BZERO is an integer. In this case, it appears that BZERO is added first to the integer array before converting it to a floating point array, because BSCALE = 1.0 implies upconversion. Is this correct?</div><div><br></div><div>I do still think that the FITS standards document should be updated to account for the use of modern dynamically typed languages such as Python and Julia because they will be used more often in the future. It should be noted that users don't care what the data type of the array is as long as no precision is lost. If an image can be stored as a Float32 without losing precision, then it should. The user can convert it to a Float64 if needed or just let the code do the upconversion during a calculation. This is a more general programming approach than assuming that all FITS files are accessed and all calculations are done using a statically typed language. That is not the future.</div><div><br></div><div> -- Paul</div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Mar 11, 2024 at 5:41 PM William Pence <<a href="mailto:wdpence2000@yahoo.com">wdpence2000@yahoo.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="auto"><div dir="ltr"></div><div dir="ltr">I attempted to reply to Paul’s original question a couple days ago but it failed to get CCed back to FITSBITS. Here is an updated reply:</div><div dir="ltr"><br></div><div dir="ltr">The FITS standard explicitly defines the datatype of every keyword in the document, and in particular the BZERO keyword “SHALL contain a floating point number” (section 4.4.2.5). Note also that FITS follows the Fortran numerical notation, so in the case of floating point numbers the decimal point is optional if there is no fractional part to the number. In that case a floating point value is indistinguishable from an integer value (section 4.2.4).</div><div dir="ltr"><br></div><div dir="ltr">CFITSIO was designed to allow the calling C or Fortran program to specify whatever datatype it wants when reading data from a FITS file. Regardless of the intrinsic datatype of the data in the FITS file, CFITSIO will convert it on the fly to whatever the program requests. For example, even if a FITS image has an intrinsic 16-bit integer datatype, the application program may want the pixel values returned in a floating point array for further data processing. Similarly when writing data to a FITS file, CFITSIO will convert the datatype of the input data if necessary to conform to the FITS datatype. </div><div dir="ltr"><br></div><div dir="ltr">IMHO, it is unnecessary (and maybe even inappropriate) to make recommendations in the Standards document about how integer values should be converted to single or double floats in various circumstances. </div><div dir="ltr"><br></div><div dir="ltr">In regard to a couple suggestions that it may be time to update the FITS Standard document, note that the last update was recently completed in 2018, after a painstaking 2 year process lead by Malcolm Currie and Lucio Chiappetti. A summary of the mainly typographical changes is given in Appendix H.4. </div><div dir="ltr"><br></div><div dir="ltr">Since the time of the last update at least 3 relatively minor factual discrepancies in the document have been pointed out. Perhaps the FITS governing bodies should establish and maintain an Official Errata List. </div><div dir="ltr"><br></div><div dir="ltr">Bill</div><div dir="ltr"><br><blockquote type="cite">On Mar 11, 2024, at 1:39 PM, Seaman, Robert Lewis - (rseaman) via fitsbits <<a href="mailto:fitsbits@listmgr.nrao.edu" target="_blank">fitsbits@listmgr.nrao.edu</a>> wrote:<br><br></blockquote></div><blockquote type="cite"><div dir="ltr">
<div>
<p class="MsoNormal">Yes, don’t messed with unsigned integer support.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">No, don’t muck about with CFITSIO, but files generated by CFITSIO (and other packages) should be readable using your Julia code, and vice versa.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Rob<u></u><u></u></p>
<div style="border-top:none;border-right:none;border-left:none;border-bottom:1pt solid windowtext;padding:0in 0in 1pt">
<p class="MsoNormal" style="border:none;padding:0in"><u></u> <u></u></p>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<div id="m_-6143777266233789805mail-editor-reference-message-container">
<div>
<div>
<p class="MsoNormal" style="margin-left:0.5in">On 3/11/24, 10:26 AM, "Barrett, Paul" wrote:<u></u><u></u></p>
</div>
<p class="MsoNormal" style="margin-left:0.5in"><u></u> <u></u></p>
<div>
<div>
<p class="MsoNormal" style="margin-left:0.5in">I'm not sure I understand what you mean about UInt16 and UInt32 remaining integers. Do you mean for the special case? If yes, then they will remain integers.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:0.5in"><u></u> <u></u></p>
</div>
<p class="MsoNormal" style="margin-left:0.5in">I'm sorry, but I am not writing an interface to CFITSIO. If you want such an interface, then use the wrapped version.<u></u><u></u></p>
<div>
<p class="MsoNormal" style="margin-left:0.5in"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:0.5in"> -- Paul<u></u><u></u></p>
</div>
</div>
<p class="MsoNormal" style="margin-left:0.5in"><u></u> <u></u></p>
<div>
<div>
<p class="MsoNormal" style="margin-left:0.5in">On Mon, Mar 11, 2024 at 12:55 PM Seaman, Robert Lewis - (rseaman) <<a href="mailto:rseaman@arizona.edu" target="_blank">rseaman@arizona.edu</a>> wrote:<u></u><u></u></p>
</div>
<blockquote style="border-top:none;border-right:none;border-bottom:none;border-left:1pt solid rgb(204,204,204);padding:0in 0in 0in 6pt;margin-left:4.8pt;margin-right:0in">
<div>
<div>
<div>
<p class="MsoNormal" style="margin-left:0.5in">
Hi Paul,<u></u><u></u></p>
<p class="MsoNormal" style="margin-left:0.5in">
<u></u><u></u></p>
<p class="MsoNormal" style="margin-left:0.5in">
Just to be clear, the UInt16 and UInt32 would remain integers, right?<u></u><u></u></p>
<p class="MsoNormal" style="margin-left:0.5in">
<u></u><u></u></p>
<p class="MsoNormal" style="margin-left:0.5in">
Whether or not you review CFITSIO code, applications layered on your code versus on CFITSIO should interoperate. This is particularly true for tile compression (which your package should support).<u></u><u></u></p>
<p class="MsoNormal" style="margin-left:0.5in">
<u></u><u></u></p>
<p class="MsoNormal" style="margin-left:0.5in">
Rob<u></u><u></u></p>
<div style="border-top:none;border-right:none;border-left:none;border-bottom:1pt solid windowtext;padding:0in 0in 1pt">
<p class="MsoNormal" style="margin-left:0.5in">
<u></u><u></u></p>
</div>
<p class="MsoNormal" style="margin-left:0.5in">
<u></u><u></u></p>
<p class="MsoNormal" style="margin-left:0.5in">
<u></u><u></u></p>
<div id="m_-6143777266233789805m_6012079796170631538mail-editor-reference-message-container">
<div>
<div>
<p class="MsoNormal" style="margin-left:1in">
On 3/11/24, 9:01 AM, "Barrett, Paul" wrote:<u></u><u></u></p>
</div>
<p class="MsoNormal" style="margin-left:1in">
<u></u><u></u></p>
<div>
<p class="MsoNormal" style="margin-left:1in">
If the input array is a UInt8, then a Float64 output array is overkill. A Float32 array should work just fine. This provides sufficient precision while saving memory. So using this line of thought, I would think these mappings from integer input arrays to floating
point output arrays would be reasonable.<u></u><u></u></p>
<div>
<div>
<p class="MsoNormal" style="margin-left:1in">
<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:1in">
UInt8 => Float32<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:1in">
Int16 => Float32<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:1in">
Int32 => Float64<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:1in">
Int64 => Float64<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:1in">
<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:1in">
By explicitly specifying this in the documentation, you would save future developers some time. They would not have to decipher how best to implement the code as I have done. Note that Julia does type inference, like Python, unless the developer specifies otherwise.
If BSCALE looks like an integer, because there is no decimal point, then Julia will interpret this as an integer, unless I coerce it to a float. I'm just confirming that this is what I should do using the above mappings.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:1in">
<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:1in">
I'm trying to support whatever the standard specifies. Being explicit would make this easier for me. I would prefer not to have to wade into the CFITSIO code to do so and I don't think other developers should have to do so too.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:1in">
<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:1in">
-- Paul<u></u><u></u></p>
</div>
</div>
</div>
<p class="MsoNormal" style="margin-left:1in">
<u></u><u></u></p>
<div>
<div>
<p class="MsoNormal" style="margin-left:1in">
On Sun, Mar 10, 2024 at 12:17 PM Seaman, Robert Lewis - (rseaman) <<a href="mailto:rseaman@arizona.edu" target="_blank">rseaman@arizona.edu</a>> wrote:<u></u><u></u></p>
</div>
<blockquote style="border-top:none;border-right:none;border-bottom:none;border-left:1pt solid rgb(204,204,204);padding:0in 0in 0in 6pt;margin:5pt 0in 5pt 4.8pt">
<div>
<div>
<div>
<p class="MsoNormal" style="margin-left:1in">
Hi Paul,<u></u><u></u></p>
<p class="MsoNormal" style="margin-left:1in">
<u></u><u></u></p>
<div id="m_-6143777266233789805m_6012079796170631538m_-8264937793714063958m_2825591748467855562mail-editor-reference-message-container">
<div>
<div>
<p class="MsoNormal" style="margin-left:1.5in">
<i>I'm writing a FITS package for the Julia programming language. I have a question about the output type of the image when BZERO is an integer value. The documentation implies that the output image should be a floating point type because the BSCALE value is
a float. Is this correct? If yes, then I recommend stating this explicitly in the FITS standard documentation. I also recommend suggesting the appropriate output type depending on the input type, e.g., UInt8 => Float32, Int16 => Float32, etc.</i><u></u><u></u></p>
<div>
<div>
<div>
<div>
<p class="MsoNormal" style="margin-left:1.5in">
<i> </i><u></u><u></u></p>
<p class="MsoNormal" style="margin-left:1in">
Yes, that is the ancient implication of BSCALE. This carries over to lossy tile compression, too, which is a very fancy BSCALE operation if you look at it sideways.<u></u><u></u></p>
<p class="MsoNormal" style="margin-left:1in">
<u></u><u></u></p>
<p class="MsoNormal" style="margin-left:1in">
Undoubtedly there are other pending tweaks to the docs. This is hard to avoid with esoteric standards, especially perhaps if they survive through multiple generations of other contingent computer technologies.<u></u><u></u></p>
<p class="MsoNormal" style="margin-left:1in">
<u></u><u></u></p>
<p class="MsoNormal" style="margin-left:1in">
I’m not sure I understand your last sentence. Could you provide a table of the mappings you think should apply?<u></u><u></u></p>
<p class="MsoNormal" style="margin-left:1in">
<u></u><u></u></p>
<p class="MsoNormal" style="margin-left:1in">
To first order, other languages and libraries should start with the CFITSIO source for appropriate usage (or to suggest differently). One recommendation is that all FITS packages support tile compression.<u></u><u></u></p>
<p class="MsoNormal" style="margin-left:1in">
<u></u><u></u></p>
<p class="MsoNormal" style="margin-left:1in">
Rob Seaman<u></u><u></u></p>
<p class="MsoNormal" style="margin-left:1in">
Lunar and Planetary Laboratory<u></u><u></u></p>
<p class="MsoNormal" style="margin-left:1in">
University of Arizona<u></u><u></u></p>
<p class="MsoNormal" style="margin-left:1in">
<u></u><u></u></p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</blockquote>
</div>
</div>
</div>
</div>
</div>
</div>
</blockquote>
</div>
</div>
</div>
</div>
<span>_______________________________________________</span><br><span>fitsbits mailing list</span><br><span><a href="mailto:fitsbits@listmgr.nrao.edu" target="_blank">fitsbits@listmgr.nrao.edu</a></span><br><span><a href="https://listmgr.nrao.edu/mailman/listinfo/fitsbits" target="_blank">https://listmgr.nrao.edu/mailman/listinfo/fitsbits</a></span><br></div></blockquote></div></blockquote></div>