Esempio n. 1
0
    def load(self, path):
        nuclides_path = os.path.join(path, 'nuclides.txt')
        nuclides_file = open(nuclides_path, "U")

        lines = nuclides_file.readlines()

        nuclides_file.close()

        lines = [line.strip() for line in lines]
        lines = [line for line in lines if line != '']

        while len(lines) > 0:
            try:
                begin_index  = lines.index('BEGIN NUCLIDE')
                end_required = lines.index('END REQUIRED')
                end_optional = lines.index('END OPTIONAL')
                nuclide = Nuclide(lines[begin_index+1])
                for i in range(begin_index+3, end_required):
                    nuclide.add_required(lines[i])
                for i in range(end_required+2, end_optional):
                    nuclide.add_optional(lines[i])
                self.add(nuclide)
                del lines[begin_index:end_optional+2]
            except:
                pass
Esempio n. 2
0
    def load(self, path):
        nuclides_path = os.path.join(path, "nuclides.txt")
        nuclides_file = open(nuclides_path, "U")

        line = nuclides_file.readline().strip()
        while line != "":
            while line != "END NUCLIDE":
                nuclide = Nuclide()
                nuclide.load(nuclides_file)
                self.add(nuclide)
                line = nuclides_file.readline().strip()
            line = nuclides_file.readline().strip()
        nuclides_file.close()
Esempio n. 3
0
def inheritancePossible():
    """
    Checks whether it is possible for the oldest sample to in fact be the product of
    inheritance (based on saturation constraints), both from the youngest sample and
    from the mean.
    """
    
    name = 'amount of inheritance required to explain spread is possible'
    oldest = calculations.calcMaxSample(__getAge())
    
    if Nuclide.stable(oldest['nuclide']):
        return SimResult(confidence.Confidence(confidence.Applic.ct, confidence.Validity.accept),
                         name, 'nuclide is stable', 'nuclide is ' + str(oldest['nuclide']))
    
    saturation = 3.0 / Nuclide.decay[oldest['nuclide']] 

    spread = oldest[__getAge()] - calculations.calcMin(__getAge())
    if spread < saturation:
        return SimResult(confidence.Confidence(confidence.Applic.ct, confidence.Validity.sound),
                         name, 'total spread of ' + str(spread) + 
                         ' is less than saturation age of about ' + str(saturation), 
                         'saturation: ' + str(saturation) + ', spread: ' + str(spread))
    
    spread = oldest[__getAge()] - calculations.calcMean(__getAge())
    if spread < saturation:
        return SimResult(confidence.Confidence(confidence.Applic.dt, confidence.Validity.sound),
                         name, 'total amount > mean age of ' + str(spread) + 
                         ' is less than saturation age of about ' + str(saturation), 
                         'saturation: ' + str(saturation) + ', spread: ' + str(spread))
        
    return SimResult(confidence.Confidence(confidence.Applic.cf, confidence.Validity.sound),
                     name, 'spread in ages is impossible via inheritance', 
                     'saturation (about): ' + str(saturation) + ', spread: ' + str(spread))
Esempio n. 4
0
def applyExperiment():
    names = experiments.names()
    calibrated = []

    for name in names:
        exp = experiments.get(name)
        if exp.is_calibrated():
            calibrated.append(exp)

    if len(calibrated) == 0:
        print "There are no calibrated experiments."
        print
        return

    calibrated_names = [item["name"] for item in calibrated]

    print "============================================"
    print "Select an experiment to apply:              "
    print
    print_choices(calibrated_names)
    print

    exp = None
    while exp == None:
        try:
            exp = select_item(calibrated)
        except Exception:
            print "ACE: Invalid Selection. Try Again."

    sets = []
    names = samples.names()
    for name in names:
        sample_set = samples.get(name)
        if sample_set.get_nuclide() == exp["nuclide"]:
            sets.append(sample_set)

    print
    print "Select a sample set to process:"
    print
    print_choices([set.get_name() for set in sets])

    sample_set = None
    while sample_set == None:
        try:
            sample_set = select_item(sets)
        except Exception:
            print "ACE: Invalid Selection. Try Again."

    w = workflows.get(exp["dating"])
    print "Retrieved Workflow"
    print

    w.set_factors(factors)
    w.set_collections(collections)
    w.set_nuclides(nuclides)

    print "Configured Workflow"
    print

    print "Preparing Sample Data...",
    ids = sample_set.ids()
    current_samples = []
    for id in ids:
        sample = sample_set.get(id)
        sample.set_experiment(exp["name"])
        current_samples.append(sample)
    print "Done."
    print

    print "Dating Samples"
    print

    w.execute(exp, current_samples)

    print "Cleaning Samples"
    print
    nuclide_ALL      = nuclides.get("ALL")
    nuclide_specific = nuclides.get(exp["nuclide"])

    atts_current = []
    atts_current.extend(nuclide_ALL.required_atts())
    atts_current.extend(nuclide_ALL.optional_atts())
    atts_current.extend(nuclide_specific.required_atts())
    atts_current.extend(nuclide_specific.optional_atts())
    atts_current.extend(Nuclide.output_atts())

    for s in current_samples:
        atts = s.properties()
        for att in atts:
            if not att in atts_current:
                del s[att]

    output_name = "results/%s_%s.csv" % (sample_set.get_name(), exp["name"])
    output_name = output_name.replace(" ", "_")
    print "Saving Results to %s" % (output_name),

    output = []
    output.append(atts_current)

    for s in current_samples:
        values = []
        for key in atts_current:
            values.append(s[key])
        output.append(values)
    

    f = open(output_name, "w")
    w = csv.writer(f)
    w.writerows(output)
    f.close()

    print "Done."
Esempio n. 5
0
def applyExperiment():
    names = experiments.names()
    calibrated = []

    for name in names:
        exp = experiments.get(name)
        if exp.is_calibrated():
            calibrated.append(exp)

    if len(calibrated) == 0:
        print "There are no calibrated experiments."
        print
        return

    calibrated_names = [item["name"] for item in calibrated]

    print "============================================"
    print "Select an experiment to apply:              "
    print
    print_choices(calibrated_names)
    print

    exp = None
    while exp == None:
        try:
            exp = select_item(calibrated)
        except Exception:
            print "ACE: Invalid Selection. Try Again."

    sets = []
    names = samples.names()
    for name in names:
        sample_set = samples.get(name)
        if sample_set.get_nuclide() == exp["nuclide"]:
            sets.append(sample_set)

    print
    print "Select a sample set to process:"
    print
    print_choices([set.get_name() for set in sets])

    sample_set = None
    while sample_set == None:
        try:
            sample_set = select_item(sets)
        except Exception:
            print "ACE: Invalid Selection. Try Again."

    w = workflows.get(exp["dating"])
    print "Retrieved Workflow"
    print

    w.set_factors(factors)
    w.set_collections(collections)
    w.set_nuclides(nuclides)

    print "Configured Workflow"
    print

    print "Preparing Sample Data...",
    ids = sample_set.ids()
    current_samples = []
    for id in ids:
        sample = sample_set.get(id)
        sample.set_experiment(exp["name"])
        current_samples.append(sample)
    print "Done."
    print

    print "Dating Samples"
    print

    w.execute(exp, current_samples)

    print "Cleaning Samples"
    print
    nuclide_ALL = nuclides.get("ALL")
    nuclide_specific = nuclides.get(exp["nuclide"])

    atts_current = []
    atts_current.extend(nuclide_ALL.required_atts())
    atts_current.extend(nuclide_ALL.optional_atts())
    atts_current.extend(nuclide_specific.required_atts())
    atts_current.extend(nuclide_specific.optional_atts())
    atts_current.extend(Nuclide.output_atts())

    for s in current_samples:
        atts = s.properties()
        for att in atts:
            if not att in atts_current:
                del s[att]

    output_name = "results/%s_%s.csv" % (sample_set.get_name(), exp["name"])
    output_name = output_name.replace(" ", "_")
    print "Saving Results to %s" % (output_name),

    output = []
    output.append(atts_current)

    for s in current_samples:
        values = []
        for key in atts_current:
            values.append(s[key])
        output.append(values)

    f = open(output_name, "w")
    w = csv.writer(f)
    w.writerows(output)
    f.close()

    print "Done."