if crystal_age_d != "No Data":
                                for age_d in db.sandbox.find(
                                    {"_id": ObjectId(crystal_age_d)}):
                                    age_u = convert(age_d)
                                    Te_batch_d = str(
                                        age_d.get(criteria, "No Data"))
                                    if Te_batch_d == Only:
                                        Found_Crystals.append(z_str + " " +
                                                              Te_batch_d)

#Printing all of the relevant crystals to the textfile specified by the user the length of the containing the data is also printed
#for trouble shooting purposes (e.g. if one searches for crystals from any batch 984 should be returned
print(len(Found_Crystals))
f = open(output, "w")
f.write("\n".join(map(lambda x: str(x), Found_Crystals)))
f.close()

#The next half of this script compares the data from the searched crystals to their DAQ data
with open(isotope) as h_f:
    for line in h_f:
        (key_1, val_1, val_2) = line.split()
        dict_a[int(key_1)] = val_1
        dict_b[int(key_1)] = val_2

        with open(output) as g_f:
            for lane in g_f:
                (val_f, val_g, val_h, batch) = lane.split()
                Rank = Rank_Mapping[int(val_f)]
                Tower = Tower_Mapping[int(val_h)]
                if val_g == "hearts":
                    Channel = (str((int(Tower) - 1) * (52) + (1 - 1) * (13) +