Ejemplo n.º 1
0
def merge_and_normalize(
    outputdir='out',
    eventsdat='events.dat',
    overwrite_datafiles=True):
    
    # find all output files
    from mcni.components.outputs import n_mcsamples_files, mcs_sum
    import glob, os
    filename = eventsdat
    pattern = os.path.join(outputdir, '*', filename)
    eventdatfiles = glob.glob(pattern)
    n_mcsamples = n_mcsamples_files(outputdir)
    assert len(eventdatfiles) == n_mcsamples, \
        "neutron storage files %s does not match #mcsample files %s" %(
        len(eventdatfiles), n_mcsamples)
    if not eventdatfiles:
        return

    # output
    out = os.path.join(outputdir, eventsdat)
    if overwrite_datafiles:
        if os.path.exists(out):
            os.remove(out)
    # merge
    from mccomponents.detector import mergeEventFiles
    mergeEventFiles(eventdatfiles, out)
    
    # load number_of_mc_samples
    mcs = mcs_sum(outputdir)
    # normalize
    from mccomponents.detector import normalizeEventFile
    normalizeEventFile(out, mcs)
    return
Ejemplo n.º 2
0
def merge_and_normalize(filename, outputs_dir, overwrite_datafiles=True):
    """merge_and_normalize('scattered-neutrons', 'out')
    """
    # find all output files
    from mcni.components.outputs import n_mcsamples_files, mcs_sum
    import glob, os

    pattern = os.path.join(outputs_dir, "*", filename)
    nsfiles = glob.glob(pattern)
    n_mcsamples = n_mcsamples_files(outputs_dir)
    assert len(nsfiles) == n_mcsamples, "neutron storage files %s does not match #mcsample files %s" % (
        len(nsfiles),
        n_mcsamples,
    )
    if not nsfiles:
        return None, None

    # output
    out = os.path.join(outputs_dir, filename)
    if overwrite_datafiles:
        if os.path.exists(out):
            os.remove(out)
    # merge
    from mcni.neutron_storage import merge

    merge(nsfiles, out)

    # number of neutron events totaly in the neutron file
    from mcni.neutron_storage.idf_usenumpy import count

    nevts = count(out)

    # load number_of_mc_samples
    mcs = mcs_sum(outputs_dir)

    # normalization factor. this is a bit tricky!!!
    nfactor = mcs / nevts

    # normalize
    from mcni.neutron_storage import normalize

    normalize(out, nfactor)
    return
Ejemplo n.º 3
0
    def _merge_and_normalize(self):
        # XXX: should rewrite using mcni.neutron_storage.merge_and_normalize
        outdir = self.simulation_context.outputdir

        # find all output files
        from mcni.components.outputs import n_mcsamples_files, mcs_sum
        import glob, os
        filename = self.path
        pattern = os.path.join(outdir, '*', filename)
        nsfiles = glob.glob(pattern)
        n_mcsamples = n_mcsamples_files(outdir)
        assert len(nsfiles) == n_mcsamples, \
            "neutron storage files %s does not match #mcsample files %s" %(
            len(nsfiles), n_mcsamples)
        if not nsfiles:
            return None, None

        # output
        out = os.path.join(outdir, self.path)
        if self.overwrite_datafiles:
            if os.path.exists(out):
                os.remove(out)
        # merge
        from mcni.neutron_storage import merge
        merge(nsfiles, out)

        # number of neutron events totaly in the neutron file
        from mcni.neutron_storage.idf_usenumpy import count
        nevts = count(out)

        # load number_of_mc_samples
        mcs = mcs_sum(outdir)

        # normalization factor. this is a bit tricky!!!
        nfactor = mcs / nevts

        # normalize
        from mcni.neutron_storage import normalize
        normalize(out, nfactor)
        return
Ejemplo n.º 4
0
    def _merge_and_normalize(self):
        # XXX: should rewrite using mcni.neutron_storage.merge_and_normalize
        outdir = self.simulation_context.outputdir

        # find all output files
        from mcni.components.outputs import n_mcsamples_files, mcs_sum
        import glob, os
        filename = self.path
        pattern = os.path.join(outdir, '*', filename)
        nsfiles = glob.glob(pattern)
        n_mcsamples = n_mcsamples_files(outdir)
        assert len(nsfiles) == n_mcsamples, \
            "neutron storage files %s does not match #mcsample files %s" %(
            len(nsfiles), n_mcsamples)
        if not nsfiles:
            return None, None
        
        # output
        out = os.path.join(outdir, self.path)
        if self.overwrite_datafiles:
            if os.path.exists(out):
                os.remove(out)
        # merge
        from mcni.neutron_storage import merge
        merge(nsfiles, out)
        
        # number of neutron events totaly in the neutron file
        from mcni.neutron_storage.idf_usenumpy import count
        nevts = count(out)

        # load number_of_mc_samples
        mcs = mcs_sum(outdir)

        # normalization factor. this is a bit tricky!!!
        nfactor = mcs/nevts
        
        # normalize
        from mcni.neutron_storage import normalize
        normalize(out, nfactor)
        return
Ejemplo n.º 5
0
def merge_and_normalize(filename, outputs_dir, overwrite_datafiles=True):
    """merge_and_normalize('scattered-neutrons', 'out')
    """
    # find all output files
    from mcni.components.outputs import n_mcsamples_files, mcs_sum
    import glob, os
    pattern = os.path.join(outputs_dir, '*', filename)
    nsfiles = glob.glob(pattern)
    n_mcsamples = n_mcsamples_files(outputs_dir)
    assert len(nsfiles) == n_mcsamples, \
        "neutron storage files %s does not match #mcsample files %s" %(
        len(nsfiles), n_mcsamples)
    if not nsfiles:
        return None, None

    # output
    out = os.path.join(outputs_dir, filename)
    if overwrite_datafiles:
        if os.path.exists(out):
            os.remove(out)
    # merge
    from mcni.neutron_storage import merge
    merge(nsfiles, out)

    # number of neutron events totaly in the neutron file
    from mcni.neutron_storage.idf_usenumpy import count
    nevts = count(out)

    # load number_of_mc_samples
    mcs = mcs_sum(outputs_dir)

    # normalization factor. this is a bit tricky!!!
    nfactor = mcs / nevts

    # normalize
    from mcni.neutron_storage import normalize
    normalize(out, nfactor)
    return