Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implemented using bscale for storing std #77

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions RMS/CompressionCy.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,9 @@ def compressFrames(np.ndarray[INT8_TYPE_t, ndim=3] frames, int deinterlace_order
# Subtract average squared sum of all values (acc*mean = acc*acc/frames_num_minus_four)
var -= acc*mean

# Compute the standard deviation
var = <unsigned int> sqrt(var/frames_num_minus_five)
# Compute 10 times the standard deviation (to keep one decimal when rounding to uint8)
# In FFbin and FFfits, the standard deviation is divided by 10 again
var = <unsigned int> (10 * sqrt(var/frames_num_minus_five))

# Make sure that the stddev is not 0, to prevent divide by zero afterwards
if var == 0:
Expand All @@ -174,4 +175,4 @@ def compressFrames(np.ndarray[INT8_TYPE_t, ndim=3] frames, int deinterlace_order
ftp_array[3, y, x] = var


return ftp_array, fieldsum[:frames_num*deinterlace_multiplier]
return ftp_array, fieldsum[:frames_num*deinterlace_multiplier]
3 changes: 1 addition & 2 deletions RMS/Formats/FFbin.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def write(ff, directory, filename, version=2):
arr[0] = ff.maxpixel
arr[1] = ff.maxframe
arr[2] = ff.avepixel
arr[3] = ff.stdpixel
arr[3] = np.round(0.1 * ff.stdpixel)

# Extract only the number from the camera code
camno_num = int(re.findall('\d+', str(ff.camno))[0])
Expand Down Expand Up @@ -172,4 +172,3 @@ def write(ff, directory, filename, version=2):

# Write image arrays
arr.tofile(fid)

2 changes: 1 addition & 1 deletion RMS/Formats/FFfile.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
""" Functions for reading/writing FF files with respet to the rheir format (.bin for .fits). """
""" Functions for reading/writing FF files with respect to their format (.bin for .fits). """


from __future__ import print_function, division, absolute_import
Expand Down
9 changes: 7 additions & 2 deletions RMS/Formats/FFfits.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ def write(ff, directory, filename):

Arguments:
ff: [ff bin struct] FF bin file loaded in the FF structure
In this FF structure, the standard deviation is an uint8 with ten
times the actual value
directory: [str] path to the directory where the file will be written
filename: [str] name of the file which will be written

Expand Down Expand Up @@ -115,7 +117,10 @@ def write(ff, directory, filename):
maxpixel_hdu = fits.ImageHDU(ff.maxpixel, name='MAXPIXEL')
maxframe_hdu = fits.ImageHDU(ff.maxframe, name='MAXFRAME')
avepixel_hdu = fits.ImageHDU(ff.avepixel, name='AVEPIXEL')
stdpixel_hdu = fits.ImageHDU(ff.stdpixel, name='STDPIXEL')
stdpixel_hdu = fits.ImageHDU(0.1 * ff.stdpixel, name='STDPIXEL')
# Set BSCALE in fits metadata, so FITS readers will understand the scaling and
# return e.g. 4.3 when the number 43 is stored as uint8
stdpixel_hdu.scale('uint8', bscale=0.1)

# Create the primary part
prim = fits.PrimaryHDU(header=head)
Expand Down Expand Up @@ -152,7 +157,7 @@ def write(ff, directory, filename):

maxpixel = np.zeros((ht, wid), dtype=np.uint8)
avepixel = np.zeros((ht, wid), dtype=np.uint8) + 10
stdpixel = np.zeros((ht, wid), dtype=np.uint8) + 20
stdpixel = np.zeros((ht, wid), dtype=np.uint8) + 201 # Scaled by 10, so this represents 20.1
maxframe = np.zeros((ht, wid), dtype=np.uint8) + 30

ff.array = np.stack([maxpixel, maxframe, avepixel, stdpixel], axis=0)
Expand Down