|
| 1 | +#!/usr/bin/env python |
| 2 | + |
| 3 | +import os |
| 4 | +import util |
| 5 | +import util.input |
| 6 | +import util.param |
| 7 | +import util.runmask |
| 8 | +import util.config |
| 9 | +import commentjson |
| 10 | + |
| 11 | + |
| 12 | +verbose = True |
| 13 | + |
| 14 | +#Print expected config file path |
| 15 | +#Load expected config file |
| 16 | +assumed_config_file = "config/config.js" |
| 17 | +print("Loading " + assumed_config_file) |
| 18 | +with open(assumed_config_file) as config_file: |
| 19 | + config = commentjson.load(config_file) |
| 20 | + |
| 21 | + |
| 22 | +#Extract and display input file path prefixes (excluding parameter files |
| 23 | +# and output_spec) |
| 24 | +input_filepaths = util.config.get_input_paths(assumed_config_file) |
| 25 | +path_prefixes = [] |
| 26 | +for filepath in input_filepaths: |
| 27 | + prefix = os.path.dirname(filepath) |
| 28 | + if prefix not in path_prefixes: |
| 29 | + path_prefixes.append(prefix) |
| 30 | +print("*********************************************************") |
| 31 | +print("|", len(path_prefixes), "input path prefixes specified:") |
| 32 | +for prefix in path_prefixes: |
| 33 | + print("|", prefix) |
| 34 | +print("*********************************************************") |
| 35 | + |
| 36 | + |
| 37 | +#Check that all input files specified in the config file exist (excluding |
| 38 | +# parameter files and output_spec) |
| 39 | +#We are not using the following method because that checks a whole |
| 40 | +# directory, which would not allow individually different input paths |
| 41 | +#util.input.check_input_set_existence(input directory) |
| 42 | +missing_files = [path for path in input_filepaths if not os.path.exists(path)] |
| 43 | +if len(missing_files) > 0: |
| 44 | + star_len = len(max(missing_files, key=len)) + 4 |
| 45 | + star_str = '*' * star_len |
| 46 | + |
| 47 | + print(star_str) |
| 48 | + print("| Missing input files:") |
| 49 | + print("|", *missing_files) |
| 50 | + print(star_str) |
| 51 | +else: |
| 52 | + print("***********************************") |
| 53 | + print("| All specified input files exist |") |
| 54 | + print("***********************************") |
| 55 | + |
| 56 | + |
| 57 | +#Find total count of active cells |
| 58 | +#The call to cell_count will also flag invalid values |
| 59 | +mask_info = util.runmask.cell_count(config['IO']['runmask_file'], verbose) |
| 60 | +invalid_values = {value:count for value,count in mask_info.items() if value not in [0,1]} |
| 61 | + |
| 62 | +print("*********************************************************") |
| 63 | +print("| Active cells in run mask:", mask_info[1]) |
| 64 | +print("| Inactive cells in run mask:", mask_info[0]) |
| 65 | +print("| Other values:", invalid_values) |
| 66 | +print("*********************************************************") |
| 67 | + |
| 68 | + |
| 69 | +#Check that all CMT values specified in the input vegetation file |
| 70 | +# have a parameterization in the parameter files. |
| 71 | +input_CMTs = util.input.get_vegtypes(config['IO']['veg_class_file'], verbose) |
| 72 | +print("Input veg types:", *input_CMTs.keys(), sep=', ') |
| 73 | +print("input veg counts:", *input_CMTs.values(), sep=', ') |
| 74 | +print(input_CMTs) |
| 75 | + |
| 76 | +param_CMTs = util.param.get_available_CMTs(config['IO']['parameter_dir']) |
| 77 | +print("Param CMTs:", param_CMTs) |
| 78 | + |
| 79 | +unparameterized_CMTs = [x for x in input_CMTs.keys() if x not in param_CMTs] |
| 80 | + |
| 81 | +if len(unparameterized_CMTs) > 0: |
| 82 | + print("There are CMTs in the veg file that have no parameterization") |
| 83 | + print(unparameterized_CMTs) |
| 84 | + print("Check that these are masked out by the run mask or set to\ |
| 85 | + different values before running.") |
| 86 | +else: |
| 87 | + print("************************************************") |
| 88 | + print("| All input CMTs exist in the parameter files. |") |
| 89 | + print("| Please ensure that all are calibrated. |") |
| 90 | + print("************************************************") |
| 91 | + |
| 92 | + |
0 commit comments