Beispiel #1
0
def iterate_valid_targets(config, impacts=None, verbose=True):
    root = config['results-root']
    verbose = verbose or config.get('verbose', False)

    do_montecarlo = config.get('do-montecarlo', False)
    do_rcp_only = config.get('only-rcp', None)
    do_iam_only = config.get('only-iam', None)
    do_targetsubdirs = config.get('targetsubdirs', None)
    checks = config.get('checks', None)

    allmodels = config['only-models'] if config.get('only-models',
                                                    'all') != 'all' else None

    if do_targetsubdirs:
        iterator = results.iterate_targetdirs(root, do_targetsubdirs)
    elif do_montecarlo == 'both':
        iterator = results.iterate_both(root)
    elif do_montecarlo:
        iterator = results.iterate_montecarlo(root)
    else:
        iterator = results.iterate_batch(root, 'median')
        # Logic for a given directory
        #if root[-1] == '/':
        #    root = root[0:-1]
        #iterator = results.iterate_batch(*os.path.split(root))

    observations = 0
    message_on_none = "No target directories."
    for batch, rcp, model, iam, ssp, targetdir in iterator:
        message_on_none = "No valid target directories."

        if checks is not None and not results.directory_contains(
                targetdir, checks):
            if verbose:
                print targetdir, "missing", checks
            continue

        if do_rcp_only and rcp != do_rcp_only:
            print targetdir, "not", do_rcp_only
            continue
        if do_iam_only and iam != do_iam_only:
            print targetdir, "not", do_iam_only
            continue
        if allmodels is not None and model not in allmodels:
            print targetdir, "not in", allmodels
            continue

        if impacts is None:
            observations += 1
            yield batch, rcp, model, iam, ssp, targetdir
        else:
            # Check that at least one of the impacts is here
            for impact in impacts:
                if impact + ".nc4" in os.listdir(targetdir):
                    observations += 1
                    yield batch, rcp, model, iam, ssp, targetdir
                    break

    if observations == 0:
        print message_on_none
Beispiel #2
0
def iterate_valid_targets(config, impacts, verbose=True):
    root = config['results-root']
    do_montecarlo = config['do-montecarlo']
    do_adaptation = config['do-adaptation'] == True
    batches = range(config['batches']) if isinstance(
        config['batches'], int) else config['batches']
    allmodels = config['only-models'] if config.get('only-models',
                                                    'all') != 'all' else None
    checks = config['checks']
    do_rcp_only = config['only-rcp']
    do_realization_only = config['only-realization']
    batch_presuffix = config.get('batch-presuffix', False)
    suffix = get_suffix(config)

    if do_adaptation:
        prefix = 'batch-adapt-'
        if batch_presuffix:
            prefix += batch_presuffix + '-'
        batches = map(lambda i: prefix + str(i), batches)

    if do_montecarlo:
        iterator = results.iterate_montecarlo(root, batches=batches)
    else:
        if root[-1] == '/':
            root = root[0:-1]
        iterator = results.iterate_batch(*os.path.split(root))

    for (batch, rcp, model, realization, pvals, targetdir) in iterator:
        if checks is not None and not results.directory_contains(
                targetdir, checks):
            if verbose:
                print targetdir, "missing", checks
            continue

        if do_rcp_only and rcp != do_rcp_only:
            print targetdir, "not", do_rcp_only
            continue
        if do_realization_only and realization != do_realization_only:
            print targetdir, "not", do_realization_only
            continue
        if allmodels is not None and model not in allmodels:
            print targetdir, "not in", allmodels
            continue

        if impacts is None:
            yield (batch, rcp, model, realization, pvals, targetdir)
            continue

        # Check that at least one of the impacts is here
        for impact in impacts:
            if impact + suffix + ".tar.gz" in os.listdir(targetdir):
                yield (batch, rcp, model, realization, pvals, targetdir)
                break
Beispiel #3
0
def iterate_valid_targets(config, impacts, verbose=True):
    root = config['results-root']
    do_montecarlo = config['do-montecarlo']
    do_adaptation = config['do-adaptation'] == True
    batches = range(config['batches']) if isinstance(config['batches'], int) else config['batches']
    allmodels = config['only-models'] if config.get('only-models', 'all') != 'all' else None
    checks = config['checks']
    do_rcp_only = config['only-rcp']
    do_realization_only = config['only-realization']
    batch_presuffix = config.get('batch-presuffix', False)
    suffix = get_suffix(config)

    if do_adaptation:
        prefix = 'batch-adapt-'
        if batch_presuffix:
            prefix += batch_presuffix + '-'
        batches = map(lambda i: prefix + str(i), batches)

    if do_montecarlo:
        iterator = results.iterate_montecarlo(root, batches=batches)
    else:
        if root[-1] == '/':
            root = root[0:-1]
        iterator = results.iterate_batch(*os.path.split(root))

    for (batch, rcp, model, realization, pvals, targetdir) in iterator:
        if checks is not None and not results.directory_contains(targetdir, checks):
            if verbose:
                print targetdir, "missing", checks
            continue

        if do_rcp_only and rcp != do_rcp_only:
            print targetdir, "not", do_rcp_only
            continue
        if do_realization_only and realization != do_realization_only:
            print targetdir, "not", do_realization_only
            continue
        if allmodels is not None and model not in allmodels:
            print targetdir, "not in", allmodels
            continue

        # Check that at least one of the impacts is here
        for impact in impacts:
            if impact + suffix + ".tar.gz" in os.listdir(targetdir):
                yield (batch, rcp, model, realization, pvals, targetdir)
                continue
Beispiel #4
0
def iterate_valid_targets(config, impacts=None, verbose=True):
    root = config['results-root']

    do_montecarlo = config['do-montecarlo']
    do_rcp_only = config.get('only-rcp', None)
    checks = config.get('checks', None)

    allmodels = config['only-models'] if config.get('only-models',
                                                    'all') != 'all' else None

    if do_montecarlo:
        iterator = results.iterate_montecarlo(root)
    else:
        iterator = results.iterate_batch(root, 'median')
        # Logic for a given directory
        #if root[-1] == '/':
        #    root = root[0:-1]
        #iterator = results.iterate_batch(*os.path.split(root))

    for batch, rcp, model, iam, ssp, targetdir in iterator:
        if checks is not None and not results.directory_contains(
                targetdir, checks):
            if verbose:
                print targetdir, "missing", checks
            continue

        if do_rcp_only and rcp != do_rcp_only:
            print targetdir, "not", do_rcp_only
            continue
        if allmodels is not None and model not in allmodels:
            print targetdir, "not in", allmodels
            continue

        if impacts is None:
            yield batch, rcp, model, iam, ssp, targetdir
        else:
            # Check that at least one of the impacts is here
            for impact in impacts:
                if impact + ".nc4" in os.listdir(targetdir):
                    yield batch, rcp, model, iam, ssp, targetdir
                    break
Beispiel #5
0
            else:
                complete += 1

    sys.stdout = stdout_

    return complete, missingness, incomplete, toaggregate, stream.getvalue()


models = [
    'global_interaction_gmfd', 'global_interaction_no_popshare_gmfd'
]  # 'global_interaction_best', 'global_interaction_no_popshare_best',
variations = ['', '_comatose', '_dumb', '-histclim', '-costs']
aggregated = ['-aggregated', '-levels']

print "Mortality Median 2:"
iterator = results.iterate_batch(
    "/shares/gcp/outputs/mortality/impacts-pharaoh2", 'median')
complete, missingness, incomplete, toaggregate, output4 = count_results(
    iterator, mortality.allmodels.check_doit)

print complete, missingness, incomplete, toaggregate

print "Mortality Monte Carlo 2:"
iterator = results.iterate_montecarlo(
    "/shares/gcp/outputs/mortality/impacts-pharaoh2")
complete, missingness, incomplete, toaggregate, output3 = count_results(
    iterator, mortality.allmodels.check_doit)
print complete, missingness, incomplete, toaggregate

print "Mortality Median:"
iterator = results.iterate_batch(
    "/shares/gcp/outputs/mortality/impacts-pharaoh", 'median')

if do_fast:
    checks.do_skip_check = True

print(('C', 'M', 'I', 'A'))

models = [
    'global_interaction_Tmean-POLY-4-AgeSpec-' + cohort
    for cohort in ['young', 'older', 'oldest', 'combined']
]
variations = ['', '-noadapt', '-incadapt', '-histclim', '-costs']
aggregated = ['-aggregated', '-levels']

print("4th-order Polynomial Median:")
iterator = results.iterate_batch(
    "/shares/gcp/outputs/mortality/impacts-harvester", 'median')
complete, missingness, incomplete, toaggregate, output4 = count_results(
    iterator, mortality.allmodels.check_doit)
print((complete, missingness, incomplete, toaggregate))

print(output4)

print("4th-order Polynomial Monte Carlo:")
iterator = results.iterate_montecarlo(
    "/shares/gcp/outputs/mortality/impacts-harvester")
complete, missingness, incomplete, toaggregate, output3 = count_results(
    iterator, mortality.allmodels.check_doit)
print((complete, missingness, incomplete, toaggregate))

models = [
    'global_interaction_Tmean-CSpline-LS-AgeSpec-' + cohort
Beispiel #7
0
def iterate_valid_targets(root, config, impacts=None, verbose=True):
    verbose = verbose or config.get('verbose', False)

    do_montecarlo = config.get('do-montecarlo', False)
    do_rcp_only = config.get('only-rcp', None)
    do_iam_only = config.get('only-iam', None)
    do_targetsubdirs = config.get('targetsubdirs', None)
    do_batchdir = config.get('batchdir', 'median')
    checks = config.get('checks', None)
    dirtree = config.get('dirtree', 'normal')

    allmodels = config['only-models'] if config.get('only-models',
                                                    'all') != 'all' else None

    if dirtree == 'climate-only':

        def get_iterator():
            for alldirs in results.recurse_directories(root, 2):
                yield ['pest', alldirs[0], alldirs[1], 'NA', 'NA', alldirs[2]]

        iterator = get_iterator()
    elif do_targetsubdirs:
        iterator = results.iterate_targetdirs(root, do_targetsubdirs)
    elif do_montecarlo == 'both':
        iterator = results.iterate_both(root)
    elif do_montecarlo:
        iterator = results.iterate_montecarlo(root)
    else:
        iterator = results.iterate_batch(root, do_batchdir)
        # Logic for a given directory
        #if root[-1] == '/':
        #    root = root[0:-1]
        #iterator = results.iterate_batch(*os.path.split(root))

    observations = 0
    message_on_none = "No target directories."
    for batch, rcp, model, iam, ssp, targetdir in iterator:
        message_on_none = "No valid target directories."

        if checks is not None and not results.directory_contains(
                targetdir, checks):
            if verbose:
                print targetdir, "missing", checks
            continue

        if do_rcp_only and rcp != do_rcp_only:
            print targetdir, "not", do_rcp_only
            continue
        if do_iam_only and iam != do_iam_only:
            print targetdir, "not", do_iam_only
            continue
        if allmodels is not None and model not in allmodels:
            print targetdir, "not in", allmodels
            continue

        if impacts is None:
            if is_parallel_deltamethod(config):
                dmpath = get_deltamethod_path(targetdir, config)
                if isinstance(dmpath, dict):
                    allthere = True
                    for name in dmpath:
                        if not os.path.isdir(dmpath[name]):
                            print "deltamethod", dmpath[name], "missing 1"
                            allthere = False
                            break
                    if allthere:
                        observations += 1
                        yield batch, rcp, model, iam, ssp, targetdir
                elif os.path.isdir(dmpath):
                    observations += 1
                    yield batch, rcp, model, iam, ssp, targetdir
                elif verbose:
                    print "deltamethod", get_deltamethod_path(
                        targetdir, config), "missing 2"
            else:
                observations += 1
                yield batch, rcp, model, iam, ssp, targetdir
        else:
            # Check that at least one of the impacts is here
            for impact in impacts:
                if impact + ".nc4" in os.listdir(multipath(targetdir, impact)):
                    if is_parallel_deltamethod(config):
                        if isinstance(targetdir, dict):
                            dmpath = os.path.join(
                                multipath(
                                    get_deltamethod_path(targetdir, config),
                                    impact), impact + ".nc4")
                            if not os.path.isfile(dmpath):
                                print "deltamethod", dmpath, "missing 3"
                                continue
                        elif not os.path.isfile(
                                os.path.join(targetdir, impact + ".nc4")):
                            print "deltamethod", dmpath, "missing 4"
                            continue
                    observations += 1
                    yield batch, rcp, model, iam, ssp, targetdir
                    break

    if observations == 0:
        print message_on_none