def pixel_format(data, wavelength, center=670.9659, lower=0.4, upper=0.4, ftype='flux'): """Changes the data from read into a machine learning format. This function is for machine learning over pixels. Parameters ---------- data : dict Flux data from the read functions. The outermost keys are the stellar parameters for the models. The next keys are the lithium abundances. The innermost keys are 'flux' which retreives the NLTE flux or 'fluxl' which retreives the LTE flux. All data must be located at the same wavelength points. wavelength : List[Real] or 1darray The wavelengths that correspond to the data. From read.get_wavelengths(). center : Real, optional The center of the wavelengths where the cut should be taken, in the same units as the wavelength. The 3 lithium lines are centered at 610.5298, 670.9659, and 812.8606 nm in the Balder results. upper : Real, optional The amount to go above the center when taking the cut, in the same units as the wavelength. lower : Real, optional The amount to go below the center when taking the cut, in the same units as the wavelength. ftype : str, optional Which type of flux to convert from the data. Accepted options are: 'flux' for NLTE or 'fluxl' for LTE. Returns ------- Xy : tuple of 2darrays The X and y data sets in the form (X, y). X contains [num of objects x num of parameters], and y contains [num of objects x num of pixels]. """ y = [] X = [] for row in list(data): # stellar parameters t, g, m = row model = data[t, g, m] ys = [ tools.cut(wavelength, model[li][ftype], center=center, upper=upper, lower=lower)[1] for li in list(model) ] # lithium abundances X.extend([[t, g, m, li] for li in list(model)]) y.extend(ys) Xy = (np.array(X), np.array(y)) return Xy
def test_case3(self): assert_array_eq( tools.cut([608, 609, 610, 612, 614], [-9, 1, 203, 40, 1], center=610.5298, upper=3, lower=0), [[612], [40]])
def test_case2(self): assert_array_eq( tools.cut([810, 812, 813, 816, 818, 819], [0, 1, 2, 3, 4, 5], center=812.8606, upper=1, lower=2), [[812, 813], [1, 2]])
def test_case1(self): assert_array_eq( tools.cut([660, 669, 671, 680, 690], [1, -3, -6, 0, 2]), [[669, 671, 680], [-3, -6, 0]])
def test_inc_edge(self): assert_array_eq( tools.cut([1, 2, 3, 4], [4, 5, 6, 7], center=2, upper=1, lower=1), [[1, 2, 3], [4, 5, 6]])
def test_empty(self): assert_array_eq(tools.cut([], []), np.array([[], []]))