<commit_before>import pdb
import numpy as np
from utils import black
from utils import loggen
from astropy.cosmology import FlatLambdaCDM
import astropy.units as u
from lmfit import Parameters, minimize, fit_report

L_sun = 3.839e26 # W
c = 299792458.0 # m/s

def find_nearest_index(array_in,value):
	ng = len(value)
	#idx = (np.abs(array_in-value)).argmin()
	idx = (np.abs(array_in-np.reshape(value,(ng,1)))).argmin(axis=1)
	return idx

def sed(p, nu_in, T, betain, alphain): 
	'''
	#m = [A, T, Beta, Alpha] - return SED (array) in Jy
	#P[0] = A
	#P[1] = T
	#P[2] = Beta
	#P[3] = Alpha
	'''
	v = p.valuesdict()
	A0= v['Ain']
	A=np.asarray(A0)
	#T = v['Tin']
	#betain = v['betain']
	#alphain = v['alphain']
	ng = np.size(A)

	ns = len(nu_in)
	base = 2.0 * (6.626)**(-2.0 - betain - alphain) * (1.38)**(3. + betain + alphain) / (2.99792458)**2.0
	expo = 34.0 * (2.0 + betain + alphain) - 23.0 * (3.0 + betain + alphain) - 16.0 + 26.0
	K = base * 10.0**expo
	w_num = A * K * (T * (3.0 + betain + alphain))**(3.0 + betain + alphain) 
	w_den = (np.exp(3.0 + betain + alphain) - 1.0)
	w_div = w_num/w_den 
	nu_cut = (3.0 + betain + alphain) * 0.208367e11 * T

	graybody = np.reshape(A,(ng,1)) * nu_in**np.reshape(betain,(ng,1)) * black(nu_in, T) / 1000.0 
	powerlaw = np.reshape(w_div,(ng,1)) * nu_in**np.reshape(-1.0 * betain,(ng,1))
	graybody[np.where(nu_in >= np.reshape(nu_cut,(ng,1)))]=powerlaw[np.where(nu_in >= np.reshape(nu_cut,(ng,1)))]

	return graybody

def sedint(p, nu_in, Lir, T, betain, alphain): 
	'''
	#m = [A, T, Beta, Alpha] - return integrated SED flux (one number) in Jy x Hz
	#P[0] = A
	#P[1] = T
	#P[2] = Beta
	#P[3] = Alpha
	'''

	v = p.valuesdict()
	A0 = v['Ain']
	A=np.asarray(A0)
	#pdb.set_trace()
	#T = v['Tin']
	#betain = v['betain']
	#alphain = v['alphain']


	#print 'A is ' + str(A)
	ns = len(nu_in)
	#pdb.set_trace()
	ng = np.size(A)
	base = 2.0 * (6.626)**(-2.0 - betain - alphain) * (1.38)**(3. + betain + alphain) / (2.99792458)**2.0
	expo = 34.0 * (2.0 + betain + alphain) - 23.0 * (3.0 + betain + alphain) - 16.0 + 26.0
	K = base * 10.0**expo
	w_num = A * K * (T * (3.0 + betain + alphain))**(3.0 + betain + alphain) 
	w_den = (np.exp(3.0 + betain + alphain) - 1.0)
	w_div = w_num/w_den 
	nu_cut = (3.0 + betain + alphain) * 0.208367e11 * T
	
	#nu_cut_ind = find_nearest_index(nu_in,nu_cut)

	graybody = np.reshape(A,(ng,1)) * nu_in**np.reshape(betain,(ng,1)) * black(nu_in, T) / 1000.0 
	powerlaw = np.reshape(w_div,(ng,1)) * nu_in**np.reshape(-1.0 * betain,(ng,1))
	graybody[np.where(nu_in >= np.reshape(nu_cut,(ng,1)))]=powerlaw[np.where(nu_in >= np.reshape(nu_cut,(ng,1)))]

	#pdb.set_trace()

	dnu = nu_in[1:ns] - nu_in[0:ns-1]
	dnu = np.append(dnu[0],dnu)

	return np.ravel([np.sum(graybody * dnu, axis=1) - Lir]) 

def sedint2(p, nu_in, Lir, ng): # m = [A, T, Beta, Alpha] - return integrated SED flux (one number) in Jy x Hz
	#P[0] = A
	#P[1] = T
	#P[2] = Beta
	#P[3] = Alpha

	v = p.valuesdict()
	A = v['Ain']
	T = v['Tin']
	betain = v['betain']
	alphain = v['alphain']


	print 'A is ' + str(A)
	ns = len(nu_in)
	#ng = len(A)
	base = 2.0 * (6.626)**(-2.0 - betain - alphain) * (1.38)**(3. + betain + alphain) / (2.99792458)**2.0
	expo = 34.0 * (2.0 + betain + alphain) - 23.0 * (3.0 + betain + alphain) - 16.0 + 26.0
	K = base * 10.0**expo
	w_num = A * K * (T * (3.0 + betain + alphain))**(3.0 + betain + alphain) 
	w_den = (np.exp(3.0 + betain + alphain) - 1.0)
	w_div = w_num/w_den 
	nu_cut = (3.0 + betain + alphain) * 0.208367e11 * T
	
	#nu_cut_ind = find_nearest_index(nu_in,nu_cut)

	graybody = np.reshape(A,(ng,1)) * nu_in**np.reshape(betain,(ng,1)) * black(nu_in, T) / 1000.0 
	powerlaw = np.reshape(w_div,(ng,1)) * nu_in**np.reshape(-1.0 * betain,(ng,1))
	graybody[np.where(nu_in >= np.reshape(nu_cut,(ng,1)))]=powerlaw[np.where(nu_in >= np.reshape(nu_cut,(ng,1)))]<commit_msg>changed some betain to alphain<commit_after>import pdb
import numpy as np
from utils import black
from utils import loggen
from astropy.cosmology import FlatLambdaCDM
import astropy.units as u
from lmfit import Parameters, minimize, fit_report

L_sun = 3.839e26 # W
c = 299792458.0 # m/s

def find_nearest_index(array_in,value):
	ng = len(value)
	#idx = (np.abs(array_in-value)).argmin()
	idx = (np.abs(array_in-np.reshape(value,(ng,1)))).argmin(axis=1)
	return idx

def sed(p, nu_in, T, betain, alphain): 
	'''
	#m = [A, T, Beta, Alpha] - return SED (array) in Jy
	#P[0] = A
	#P[1] = T
	#P[2] = Beta
	#P[3] = Alpha
	'''
	v = p.valuesdict()
	A0= v['Ain']
	A=np.asarray(A0)
	#T = v['Tin']
	#betain = v['betain']
	#alphain = v['alphain']
	ng = np.size(A)

	ns = len(nu_in)
	base = 2.0 * (6.626)**(-2.0 - betain - alphain) * (1.38)**(3. + betain + alphain) / (2.99792458)**2.0
	expo = 34.0 * (2.0 + betain + alphain) - 23.0 * (3.0 + betain + alphain) - 16.0 + 26.0
	K = base * 10.0**expo
	w_num = A * K * (T * (3.0 + betain + alphain))**(3.0 + betain + alphain) 
	w_den = (np.exp(3.0 + betain + alphain) - 1.0)
	w_div = w_num/w_den 
	nu_cut = (3.0 + betain + alphain) * 0.208367e11 * T

	graybody = np.reshape(A,(ng,1)) * nu_in**np.reshape(betain,(ng,1)) * black(nu_in, T) / 1000.0 
	powerlaw = np.reshape(w_div,(ng,1)) * nu_in**np.reshape(-1.0 * alphain,(ng,1))
	graybody[np.where(nu_in >= np.reshape(nu_cut,(ng,1)))]=powerlaw[np.where(nu_in >= np.reshape(nu_cut,(ng,1)))]

	return graybody

def sedint(p, nu_in, Lir, T, betain, alphain): 
	'''
	#m = [A, T, Beta, Alpha] - return integrated SED flux (one number) in Jy x Hz
	#P[0] = A
	#P[1] = T
	#P[2] = Beta
	#P[3] = Alpha
	'''

	v = p.valuesdict()
	A0 = v['Ain']
	A=np.asarray(A0)
	#pdb.set_trace()
	#T = v['Tin']
	#betain = v['betain']
	#alphain = v['alphain']


	#print 'A is ' + str(A)
	ns = len(nu_in)
	#pdb.set_trace()
	ng = np.size(A)
	base = 2.0 * (6.626)**(-2.0 - betain - alphain) * (1.38)**(3. + betain + alphain) / (2.99792458)**2.0
	expo = 34.0 * (2.0 + betain + alphain) - 23.0 * (3.0 + betain + alphain) - 16.0 + 26.0
	K = base * 10.0**expo
	w_num = A * K * (T * (3.0 + betain + alphain))**(3.0 + betain + alphain) 
	w_den = (np.exp(3.0 + betain + alphain) - 1.0)
	w_div = w_num/w_den 
	nu_cut = (3.0 + betain + alphain) * 0.208367e11 * T
	
	#nu_cut_ind = find_nearest_index(nu_in,nu_cut)

	graybody = np.reshape(A,(ng,1)) * nu_in**np.reshape(betain,(ng,1)) * black(nu_in, T) / 1000.0 
	powerlaw = np.reshape(w_div,(ng,1)) * nu_in**np.reshape(-1.0 * alphain,(ng,1))
	graybody[np.where(nu_in >= np.reshape(nu_cut,(ng,1)))]=powerlaw[np.where(nu_in >= np.reshape(nu_cut,(ng,1)))]

	#pdb.set_trace()

	dnu = nu_in[1:ns] - nu_in[0:ns-1]
	dnu = np.append(dnu[0],dnu)

	return np.ravel([np.sum(graybody * dnu, axis=1) - Lir]) 

def sedint2(p, nu_in, Lir, ng): # m = [A, T, Beta, Alpha] - return integrated SED flux (one number) in Jy x Hz
	#P[0] = A
	#P[1] = T
	#P[2] = Beta
	#P[3] = Alpha

	v = p.valuesdict()
	A = v['Ain']
	T = v['Tin']
	betain = v['betain']
	alphain = v['alphain']


	print 'A is ' + str(A)
	ns = len(nu_in)
	#ng = len(A)
	base = 2.0 * (6.626)**(-2.0 - betain - alphain) * (1.38)**(3. + betain + alphain) / (2.99792458)**2.0
	expo = 34.0 * (2.0 + betain + alphain) - 23.0 * (3.0 + betain + alphain) - 16.0 + 26.0
	K = base * 10.0**expo
	w_num = A * K * (T * (3.0 + betain + alphain))**(3.0 + betain + alphain) 
	w_den = (np.exp(3.0 + betain + alphain) - 1.0)
	w_div = w_num/w_den 
	nu_cut = (3.0 + betain + alphain) * 0.208367e11 * T
	
	#nu_cut_ind = find_nearest_index(nu_in,nu_cut)

	graybody = np.reshape(A,(ng,1)) * nu_in**np.reshape(betain,(ng,1)) * black(nu_in, T) / 1000.0 
	powerlaw = np.reshape(w_div,(ng,1)) * nu_in**np.reshape(-1.0 * alphain,(ng,1))
	graybody[np.where(nu_in >= np.reshape(nu_cut,(ng,1)))]=powerlaw[np.where(nu_in >= np.reshape(nu_cut,(ng,1)))]
{'fraction_non_alphanumeric': 0.21932794998697577, 'fraction_numerical': 0.06824693930711123, 'mean_word_length': 3.5197174808711007, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '599196', 'n_tokens_mistral': 4083, 'n_tokens_neox': 3782, 'n_words': 745}