ossama-othman / MaRC

MaRC - Map Reprojections and Conversions
GNU Lesser General Public License v2.1
1 stars 0 forks source link

Incorrect data auto-offset for LONGITUDE maps. #42

Closed ossama-othman closed 6 years ago

ossama-othman commented 6 years ago

The automatic data scaling feature (#37) introduced in v0.9.9 incorrectly calculates the offset for data with a positive range of values.

For example, MaRC uses a longitude data range of [0, 360]. The scale for LONGITUDE maps is calculated correctly but the offset is not. Assuming a map with 16 bit signed integer data is being plotted, the maximum value is 32767. The LONGITUDE map data will be scaled by 100 with an offset of 0, making the maximum plotted data value 36000, which is larger than the largest 16 bit signed integer 32767. The result is longitude values greater than 327 degrees end up being dropped from the map. The offset value should have been -18000, for example, to shift the map value into the chosen integer range of values, i.e. [0, 360] scaled by 100 and offset -18000 results in map data in the range [-18000, 18000] which is well within the 16 bit signed integer data range [-32768, 32767]. In this case, the corresponding FITS BSCALE and BZERO values needed to convert from the map value to the physical value would be 0.01 and 180, respectively.

This problem only occurs when creating a LONGITUDE integer typed map plane containing scaled longitude values larger than a certain value (e.g. larger than 32767 in 16 bit signed integer maps). Floating point maps don't exhibit this problem.