def main():
    parser = build_parser()
    options = parser.parse_args()
    if options.subset:
        subset = int(options.subset)
    else:
        subset = (- 1)
    print(options.session)
    if options.session:
        with open(os.path.join('Sessions', options.session), 'r') as f:
            session = json.load(f)
    else:
        with open(DEFAULT_SESSION, 'r') as f:
            session = json.load(f)
    file_path = session['file_path']
    if ('output_file' in session):
        output_file = session['output_file']
    else:
        output_file = ''
    if ('output_file_root' in session):
        output_file_root = session['output_file_root']
    else:
        output_file_root = ''
    if (not (output_file or output_file_root)):
        raise ValueError('output_file or output_file_root must be defined in session file.')
    manual_peak_selection = session['manual_peak_selection']
    known_family = session['known_family']
    chemistry = session['chemistry']
    diffraction = session['diffraction']
    print('file inputs')
    print(output_file)
    print(output_file_root)
    mode = ''
    if diffraction:
        if chemistry:
            mode = 'DiffChem'
        else:
            mode = 'DiffOnly'
    elif chemistry:
        raise ValueError('Running chemistry only predictions is currently not implemented')
    else:
        raise ValueError('Invalid prediction type. Either diffraction or chemistry must be enabled')
    if (known_family and (known_family == 'yes')):
        print('known family')
        crystal_family = session['crystal_family']
        prediction_per_level[0] = 1
    else:
        crystal_family = None
    if session['user_info']:
        with open(session['user_info'], 'r') as f:
            user_info = json.load(f)
    else:
        with open(DEFAULT_USER, 'r') as f:
            user_info = json.load(f)
    with open(session['server_info'], 'r') as f:
        server_info = json.load(f)
    if server_info['URL']:
        url = server_info['URL']
    else:
        raise ValueError('you need to have the server URL provided to you')
    chem_vec = cf.check_for_chemistry(session)
    print(file_path)
    print('---starting loop--')
    if os.path.isdir(file_path):
        print('loading files from directory')
        file_paths = []
        for (dirpath, dirnames, fpath) in os.walk(file_path):
            for path in fpath:
                if (not (path[0] == '.')):
                    file_paths.append(os.path.join(dirpath, path))
        print('found {} files to load.'.format(len(file_paths)))
    else:
        file_paths = [file_path]
    if (not os.path.exists('Results')):
        os.makedirs('Results')
    print(file_paths)
    for f_path in file_paths:
        print('loading data from {}'.format(f_path))
        (image_data, scale) = ClientSide2.Load_Profile(f_path)
        print('I successfully loaded the data')
        print(options.figures_only)
        print(options.data_only)
        froot = os.path.splitext(os.path.basename(f_path))[0]
        if output_file_root:
            outfile = ((('Results/' + output_file_root) + froot) + '.json')
            outfile_2 = ((('Results/' + output_file_root) + froot) + '_peaks.json')
        else:
            output_file_root = ''
            [outroot, ext] = os.path.splitext(output_file)
            if (not (ext == '.json')):
                output_file = (outroot + '.json')
                output_file_2 = (outroot + '_peaks.json')
            outfile = ('Results/' + output_file)
            outfile_2 = ('Results/' + output_file_2)
        if options.figures_only:
            print('Only creating figures')
            with open(outfile, 'r') as fp:
                guesses = json.load(fp)
        else:
            if diffraction:
                (peak_locs, peaks_h) = ClientSide2.Find_Peaks(image_data, scale, **FILTER_SETTINGS)
                if manual_peak_selection:
                    peak_locs = cf.choose_peaks(peak_locs, peaks_h)
            else:
                peak_locs = []
                peaks_h = []
            if (len(peak_locs['d_spacing']) > 25):
                print('\n\n======================================================')
                print((('there are ' + str(len(peak_locs['d_spacing']))) + ' peaks, which is too many.'))
                print(f_path)
                print('======================================================\n\n')
                continue
            (common_peaks, guesses) = combination_peaks(peak_locs, chem_vec, mode, froot, crystal_family, user_info, url, prediction_per_level, subset, num_peaks)
            guesses['pk_d_spacing'] = peak_locs['d_spacing'].tolist()
            guesses['pk_vec'] = peak_locs['vec']
            print(guesses)
            with open(outfile, 'w') as fp:
                json.dump(guesses, fp)
            with open(outfile_2, 'w') as fp:
                json.dump(common_peaks, fp)
        if options.data_only:
            print('skipping figures')
        else:
            make_figures(guesses, crystal_family, (output_file_root + froot))
def main():
    parser = build_parser()
    options = parser.parse_args()
    if options.subset:
        subset = int(options.subset)
    else:
        subset = (- 1)
    print(options.session)
    if options.session:
        with open(os.path.join('Sessions', options.session), 'r') as f:
            session = json.load(f)
    else:
        with open(DEFAULT_SESSION, 'r') as f:
            session = json.load(f)
    file_path = session['file_path']
    if ('output_file' in session):
        output_file = session['output_file']
    else:
        output_file = 
    if ('output_file_root' in session):
        output_file_root = session['output_file_root']
    else:
        output_file_root = 
    if (not (output_file or output_file_root)):
        raise ValueError('output_file or output_file_root must be defined in session file.')
    manual_peak_selection = session['manual_peak_selection']
    known_family = session['known_family']
    chemistry = session['chemistry']
    diffraction = session['diffraction']
    print('file inputs')
    print(output_file)
    print(output_file_root)
    mode = 
    if diffraction:
        if chemistry:
            mode = 'DiffChem'
        else:
            mode = 'DiffOnly'
    elif chemistry:
        raise ValueError('Running chemistry only predictions is currently not implemented')
    else:
        raise ValueError('Invalid prediction type. Either diffraction or chemistry must be enabled')
    if (known_family and (known_family == 'yes')):
        print('known family')
        crystal_family = session['crystal_family']
        prediction_per_level[0] = 1
    else:
        crystal_family = None
    if session['user_info']:
        with open(session['user_info'], 'r') as f:
            user_info = json.load(f)
    else:
        with open(DEFAULT_USER, 'r') as f:
            user_info = json.load(f)
    with open(session['server_info'], 'r') as f:
        server_info = json.load(f)
    if server_info['URL']:
        url = server_info['URL']
    else:
        raise ValueError('you need to have the server URL provided to you')
    chem_vec = cf.check_for_chemistry(session)
    print(file_path)
    print('---starting loop--')
    if os.path.isdir(file_path):
        print('loading files from directory')
        file_paths = []
        for (dirpath, dirnames, fpath) in os.walk(file_path):
            for path in fpath:
                if (not (path[0] == '.')):
                    file_paths.append(os.path.join(dirpath, path))
        print('found {} files to load.'.format(len(file_paths)))
    else:
        file_paths = [file_path]
    if (not os.path.exists('Results')):
        os.makedirs('Results')
    print(file_paths)
    for f_path in file_paths:
        print('loading data from {}'.format(f_path))
        (image_data, scale) = ClientSide2.Load_Profile(f_path)
        print('I successfully loaded the data')
        print(options.figures_only)
        print(options.data_only)
        froot = os.path.splitext(os.path.basename(f_path))[0]
        if output_file_root:
            outfile = ((('Results/' + output_file_root) + froot) + '.json')
            outfile_2 = ((('Results/' + output_file_root) + froot) + '_peaks.json')
        else:
            output_file_root = 
            [outroot, ext] = os.path.splitext(output_file)
            if (not (ext == '.json')):
                output_file = (outroot + '.json')
                output_file_2 = (outroot + '_peaks.json')
            outfile = ('Results/' + output_file)
            outfile_2 = ('Results/' + output_file_2)
        if options.figures_only:
            print('Only creating figures')
            with open(outfile, 'r') as fp:
                guesses = json.load(fp)
        else:
            if diffraction:
                (peak_locs, peaks_h) = ClientSide2.Find_Peaks(image_data, scale, **FILTER_SETTINGS)
                if manual_peak_selection:
                    peak_locs = cf.choose_peaks(peak_locs, peaks_h)
            else:
                peak_locs = []
                peaks_h = []
            if (len(peak_locs['d_spacing']) > 25):
                print('\n\n======================================================')
                print((('there are ' + str(len(peak_locs['d_spacing']))) + ' peaks, which is too many.'))
                print(f_path)
                print('======================================================\n\n')
                continue
            (common_peaks, guesses) = combination_peaks(peak_locs, chem_vec, mode, froot, crystal_family, user_info, url, prediction_per_level, subset, num_peaks)
            guesses['pk_d_spacing'] = peak_locs['d_spacing'].tolist()
            guesses['pk_vec'] = peak_locs['vec']
            print(guesses)
            with open(outfile, 'w') as fp:
                json.dump(guesses, fp)
            with open(outfile_2, 'w') as fp:
                json.dump(common_peaks, fp)
        if options.data_only:
            print('skipping figures')
        else:
            make_figures(guesses, crystal_family, (output_file_root + froot))