out_directory = args.output_directory survey_filepath = args.survey_filepath convert_coords = args.convert_coords.lower() == 'true' plant_spacing = float(args.plant_spacing) field_num_start = int(args.field_num_start) rows = unpickle_stage4_output(input_filepath) print 'Loaded {} rows'.format(len(rows)) if len(rows) == 0: sys.exit(ExitReason.no_rows) rows = sorted(rows, key=lambda r: r.number) items = number_serpentine(rows, field_num_start) print 'Found {} items in rows.'.format(len(items)) codes = [item for item in items if 'code' in item.type.lower()] plants = [item for item in items if 'plant' in item.type.lower()] print '{} are codes and {} are plants.'.format(len(codes), len(plants)) # Now that plants are found calculate their field coordinates based on codes. calculate_field_positions_and_range(rows, codes, plants) # Shouldn't be necessary, but do it anyway. print 'Sorting items by number within field.' items = sorted(items, key=lambda item: item.number_within_field)
warn_about_bad_group_lengths(groups, plant_spacing) # KLM - not reliable since not all numbers were actually planted #warn_about_missing_single_codes(single_code_ids) warn_about_missing_single_code_lengths(single_segments, plant_spacing) if not os.path.exists(out_directory): os.makedirs(out_directory) # Write averaged results out to file. import time from src.processing.export_results import export_results from src.util.numbering import number_serpentine avg_results_filename = time.strftime("_results_averaged-%Y%m%d-%H%M%S.csv") avg_results_filepath = os.path.join(out_directory, avg_results_filename) sorted_rows = sorted(rows, key=lambda r: r.number) items = number_serpentine(sorted_rows) export_results(items, [], avg_results_filepath) print 'Output codes to {}'.format(avg_results_filepath) # extra_ids = ['123', '302', '488', '645', '647'] # extra_groups = [group for group in groups if group.id in extra_ids] # for group in extra_groups: # length = group.length # # expected_plants = length / plant_spacing # print "Group ID {} has {} expected plants".format(group.id, expected_plants)