import sys
from herschel_correlations import load_data, save_data, swap_lines

#all correlations with a specific line 
#setting line1 of result to the target line, for ease of sorting the final result
def line_correlations(data, targetline, threshold):
	correlations = []
	for cor in data:
		if cor['line1'] == targetline:
			correlations.append(cor)
		elif cor['line2'] == targetline:
			cor2 = swap_lines(cor)
			correlations.append(cor2)
	return correlations


if __name__ == "__main__":
	if len(sys.argv) != 4:
		print "line_correlations.py correlations_file target_line threshold"
	else:
		correlations_file = sys.argv[1]
		target_line = sys.argv[2]
		threshold = float(sys.argv[3])
		data = load_data(correlations_file)
		corr = line_correlations(data, target_line, threshold)
		save_data(corr, target_line + "_correlations" +  ".csv")	
#command-line utility for comparing like lines from Herschel data, 
#i.e. lines that both start with the same prefix
#this requires all correlations to have been already computed, in herschel_correlations.py
import sys
import numpy as np
from herschel_correlations import load_data, save_data


#syntax: correlations file, the prefix, then the cutoff threshold 
#(i.e. if you only care about things with a correlation above 0.9)
#gets correlations of similar lines against each other (i.e. CO vs other CO lines)
#just iterating through data file
def compare_like_lines(data, prefix, threshold):
	correlations = []
	for cor in data:
		if cor['line1'].startswith(prefix) and cor['line2'].startswith(prefix) and np.abs(cor['r']) > threshold:
			correlations.append(cor)
	return correlations

if __name__ == "__main__":
	if len(sys.argv) != 4:
		print "compare_like_lines.py correlations_file prefix threshold"
	else:
		correlations_file = sys.argv[1]
		prefix = sys.argv[2]
		threshold = float(sys.argv[3])
		data = load_data(correlations_file)
		corr = compare_like_lines(data, prefix, threshold)
		save_data(corr, prefix + "_lines.csv")

#command-line utility for comparing different lines from Herschel data, 
#i.e. lines that both start with differnt prefixes
#this requires all correlations to have been already computed, in herschel_correlations.py
import sys
from herschel_correlations import load_data, save_data, swap_lines

#find all correlations between lines starting with prefix 1 and prefix 2
#re-arranging lines so that prefix1 is in first line column, prefix2
def compare_prefixes(data, prefix1, prefix2, threshold):
	correlations = []
	for cor in data:
		if cor['line1'].startswith(prefix1) and cor['line2'].startswith(prefix2):
			correlations.append(cor)
		elif cor['line2'].startswith(prefix1) and cor['line1'].startswith(prefix2):
			correlations.append(swap_lines(cor))
	return correlations

if __name__ == "__main__":
	if len(sys.argv) != 5:
		print "compare_prefixes.py correlations_file prefix1 prefix2 threshold"
	else:
		correlations_file = sys.argv[1]
		prefix1 = sys.argv[2]
		prefix2 = sys.argv[3]
		threshold = float(sys.argv[4])
		data = load_data(correlations_file)
		corr = compare_prefixes(data, prefix1, prefix2, threshold)
		save_data(corr, prefix1 + "_" + prefix2 +  ".csv")	
Example #4
0
#i.e. lines that both start with the same prefix
#this requires all correlations to have been already computed, in herschel_correlations.py
import sys
import numpy as np
from herschel_correlations import load_data, save_data


#syntax: correlations file, the prefix, then the cutoff threshold
#(i.e. if you only care about things with a correlation above 0.9)
#gets correlations of similar lines against each other (i.e. CO vs other CO lines)
#just iterating through data file
def compare_like_lines(data, prefix, threshold):
    correlations = []
    for cor in data:
        if cor['line1'].startswith(prefix) and cor['line2'].startswith(
                prefix) and np.abs(cor['r']) > threshold:
            correlations.append(cor)
    return correlations


if __name__ == "__main__":
    if len(sys.argv) != 4:
        print "compare_like_lines.py correlations_file prefix threshold"
    else:
        correlations_file = sys.argv[1]
        prefix = sys.argv[2]
        threshold = float(sys.argv[3])
        data = load_data(correlations_file)
        corr = compare_like_lines(data, prefix, threshold)
        save_data(corr, prefix + "_lines.csv")
import sys
from herschel_correlations import load_data, save_data, swap_lines


#all correlations with a specific line
#setting line1 of result to the target line, for ease of sorting the final result
def line_correlations(data, targetline, threshold):
    correlations = []
    for cor in data:
        if cor['line1'] == targetline:
            correlations.append(cor)
        elif cor['line2'] == targetline:
            cor2 = swap_lines(cor)
            correlations.append(cor2)
    return correlations


if __name__ == "__main__":
    if len(sys.argv) != 4:
        print "line_correlations.py correlations_file target_line threshold"
    else:
        correlations_file = sys.argv[1]
        target_line = sys.argv[2]
        threshold = float(sys.argv[3])
        data = load_data(correlations_file)
        corr = line_correlations(data, target_line, threshold)
        save_data(corr, target_line + "_correlations" + ".csv")