Advertisement
bigyan

so_20017267

Nov 16th, 2013
330
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.86 KB | None | 0 0
  1. __author__ = 'bigyan'
  2.  
  3. import re
  4. import numpy as np
  5.  
  6. startBinValue = 5060
  7. endBinValue = 5176
  8. binSize = 0.1
  9.  
  10. bins = np.arange(startBinValue, endBinValue, binSize)
  11.  
  12. x = []  # Column 1: HJD
  13. y = []  # Column 2: Tamuz-corrected magnitude
  14. numLine = 0
  15. with open("/Users/bigyan/Downloads/sample_data.txt") as file:
  16.     for line in file:
  17.         numLine += 1
  18.         line = line.strip()
  19.         if numLine >= 111:
  20.             data = [colValue for colValue in re.split(" +", line) if len(colValue) > 0]
  21.             x.append(float(data[0]))
  22.             y.append(float(data[1]))
  23.  
  24. x_binned = np.digitize(x, bins)
  25. y_numpyArray = np.array(y)
  26. y_means = np.array([
  27.     y_numpyArray[x_binned == i].mean()
  28.     if len(y_numpyArray[x_binned == i]) > 0
  29.     else 0
  30.     for i in range(1, len(bins))])
  31. binnedData = [(bins[i], bins[i + 1], y_means[i]) for i in range(len(y_means))]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement