Skip to content

Commit

Permalink
Merge pull request #70 from PtyLab/binning
Browse files Browse the repository at this point in the history
Added a binning function
  • Loading branch information
wfeschen authored Feb 4, 2025
2 parents 90a0447 + 49ce701 commit b2c5ae1
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions PtyLab/ExperimentalData/ExperimentalData.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,25 @@ def cropCenter(self, size):
self.ptychogram = self.ptychogram[..., startx: startx + size, startx: startx + size]
# self._setData()

def binData(self, binning):
'''
:param binning: Binning parameter (int, e.g. 2)
:return:
'''
Ndp = self.ptychogram.shape[0]
Ny = self.ptychogram.shape[1]
Nx = self.ptychogram.shape[2]

ptychogram_temp = np.copy(self.ptychogram)
self.ptychogram = np.zeros((Ndp, Ny // binning, Nx // binning))

# Loop through all dp
for i in range(Ndp):
temp = ptychogram_temp[i]
reshaped_temp = temp.reshape(Ny // binning, binning, Nx // binning, binning)
temp_binning = reshaped_temp.mean(axis=(1, 3))
self.ptychogram[i] = np.copy(temp_binning)

def setOrientation(self, orientation, force_contiguous=True):
"""
Sets the correct orientation. This function follows the ptypy convention.
Expand Down

0 comments on commit b2c5ae1

Please sign in to comment.