#πŸ”’ Appending for Median Calibration

5 messages Β· Page 1 of 1 (latest)

burnt sun
#

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
remote knollBOT
#

@burnt sun

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

zinc crater
remote knollBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.