Hello, Please help...
I am currently stuck with a problem for my project, I need to take a median from data using numpy.
I will walk you through how I wanted this code to work. Some parts are labeled with different file.py cause they are in different files.
In my main.py code:
if o.mediancalib: <this is an option parse and not really relevant>
mediancount = 0
while mediancount < maxfilecount: <To ensure all files have been accumlated and appended into spectra>
median.accumulate(ysignal)
mediancount += 1
ysignal_m = median.calibrate(ysignal) To take out the calibrated y signal.
else:
ysignal_m = ysignal <For when you dont want the median calibrated>
The main issue appears to be in here, in my calibration class.
class MedianCalibration:
def init(self):
self.spectra = [] # Setup the spectra list to append
def accumulate(self, ysignal):
self.spectra.append(ysignal) # here is where every files ysignal data should be
def calculate(self):
spectra_array = np.array(self.spectra) # Create a numpy array of the appended spectra data
median_array = np.median(spectra_array, axis=0) # Create the median array from the appended spectra data
return median_array # Return the median array
def calibrate(self, ysignal): # as far as I have tested the issue begins in here
median_array = self.calculate() # calculate the median array
ysignal_m = ysignal - median_array # subtract the median array from the y data <For some reason the first values that are appended get removed from this line this causes my plot to have a zeroed out line instead of actual data>
ysignal_m -= np.mean(ysignal_m)
return ysignal_m