﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	severity	resolution	keywords	cc
1032	psFitsImageWrite BSCALE/BZERO needs some work	eugene	Paul Price	"There are a few issues going on in psFitsImage.c that need to be cleaned up.  I have disabled a bit of code with #if(0) until these are resolved.

Currently, it looks like the steps for CFITSIO output are as follows:

* the file is opened for write
* compression options are applied to the fits pointer with psFitsCompressionApply
* the ps-specific float type is written if selected, otherwise:

(I get a little lost in the options at this point : are these next two steps only for float types?)
* a new value for BZERO and BSCALE are determined based on the data range (confusingly, this is applied for write, but not update?)
or,
* the old values of BZERO and BSCALE (from the header?) are applied.

* the image has random fuzz added to it (if input is float and output is int type)

The problems:

1) the user needs the option of control over BZERO and BSCALE.  for example, you may know that the realistic dynamic range of the output image is (say, 0 to 100k).  The autoscaling trick can be very dangerous because of division by near-zero values.  

2) the user needs more control over the application of the fuzz when converting from float to int.  It is necessary (or useful at least) to apply the fuzz when writing a float-valued image out as an int, but in some cases, you have an image being carried as a float which is actually an int: using ppImage or ppMerge to manipulate masks, for example.  In that case, you want the hard edge transition from one int value to the next.

Also, I find this code very confusing.  I think it does not help that the steps are nested rather than sequential.  So, for example rather than define a function 'convertImageWrite' that calls two possible write functions, one of which calls the other, I would rather see these as isolated steps, eg:

scaleImage
convertImage
writeImage

the way these are laid out, you cannot tell by looking at the top level what is going on: you need to keep too many of the separate functions in your head at once."	enhancement	closed	high		fits	unspecified	minor	fixed		
