def filter_label_saveToFile(image_features_dict, db_path, noaa_data):
	'''
	Filters image AR assingments to NOAA AR labels,
	Labels image AR with NOAA AR labels or with generate labels,
	Saves final image features to file

	Input: image_features_dict, dictionary
		   keys are image active region numbers
		   values are active region features i.e. centroids, flux, 
	Output: None
	'''
	print "running get_noaa_and_image_centroids..."
	my_cents, noaa_cents_labels = get_noaa_and_image_centroids(image_features_dict, noaa_data)
	# Assinge extracted AR to NOAA AR if dist between any 2 is less than 5 degrees
	# this will return one-to-many parings, if they exist 
	print "running get_shortest_distance_pair..."
	shortest_dist_pairs = extract_image_features.get_shortest_distance_pair(my_cents, noaa_cents_labels)

	
	# returns one-to-one pairs with the shortest distance between them
	# {noaa_ar: [{Image_ar : dist}]
	print "running check_repeating_noaa_assignments..."
	clean_ar_assignments = extract_image_features.check_repeating_noaa_assignments(shortest_dist_pairs)

	print "running filter_extra_active_region_assignments..."
	clean_feat_object = Centroid_Labeling.filter_extra_active_region_assignments(image_features_dict, 
																				 clean_ar_assignments)

	#return my_cents, noaa_cents, shortest_dist_pairs, clean_ar_assignments, clean_feat_object
	print "running save_features_to_file..."
	Centroid_Labeling.save_features_to_file(db_path, clean_feat_object)
def get_noaa_and_image_centroids(image_features_dict, noaa_data):
	'''
	Output: noaa_cents_labels, tuple
			my_cents, nested lists
	'''
	
	# For Local Series Computing, uncomment function 
	#noaa_data = load_noaa_data()
	
	
	# Cluster/Parallel computing 
	# noaa_data will have already been pushed  into each engine
	noaa_cents_labels_sameDay, \
	noaa_cents_labels_prevDay=\
	Centroid_Labeling.get_currentDay_previusDay_noaa_activeRegions(image_features_dict, noaa_data)

	_, hour, minute = image_features_dict["image_time"].split(":")

	# check if image occured in 1st or 2nd half of the day 
	if int(hour) >= 12:
		noaa_cents_labels = noaa_cents_labels_sameDay
	else:
		noaa_cents_labels = noaa_cents_labels_prevDay

	my_cents = extract_image_features.get_image_active_region_centroids(image_features_dict, split_centroids = False)
	
	return my_cents, noaa_cents_labels