Ejemplo n.º 1
0
        pos1 = ax1[ii].get_position()
        pos2 = [pos1.x0+0.008+(ii-1)*0.008, pos1.y0, pos1.width, pos1.height]
        ax1[ii].set_position(pos2)
    plt.show()



if __name__ == "__main__":
    args = parser.parse_args()
    if args.filename.rstrip()[-5:] == '.json':
        args.filename = args.filename[:-5]
    elif args.filename.rstrip()[-4:] == '.npz':
        args.filename = args.filename[:-4]

    # load parameters
    params = Run.Params()
    params.file_read_chg(args.filename)
    dom_len = params.domain_info[1]*2 + 1

    # load model result
    modelsol = []
    with np.load(args.filename+'.npz') as npz_obj:
        days = npz_obj['days']
        # some code here to make loading robust to both COO and CSR.
        CSR = False
        for day in days:
            V = npz_obj[str(day)+'_data']
            if CSR:
                indices = npz_obj[str(day)+'_ind']
                indptr = npz_obj[str(day)+'_indptr']
                modelsol.append(sparse.csr_matrix((V,indices,indptr),
Ejemplo n.º 2
0
def main(argv):
    '''Function for plotting a previous result.

    The first argument in the list should be the location of a simulation file.
    '''
    try:
        filename = argv[0]
    except IndexError:
        print(
            'Please pass the filename you wish to load as an argument, e.g.:')
        print('python Plot_Result.py output/filename')
        return
    if filename.rstrip()[-5:] == '.json':
        filename = filename[:-5]
    elif filename.rstrip()[-4:] == '.npz':
        filename = filename[:-4]

    # load parameters
    params = Run.Params()
    params.file_read_chg(filename)

    dom_len = params.domain_info[1] * 2 + 1

    # load data
    modelsol = []
    with np.load(filename + '.npz') as npz_obj:
        days = npz_obj['days']
        for day in days:
            V = npz_obj[str(day) + '_data']
            # Solution should be reconstructed as CSR sparse
            indices = npz_obj[str(day) + '_ind']
            indptr = npz_obj[str(day) + '_indptr']
            modelsol.append(
                sparse.csr_matrix((V, indices, indptr),
                                  shape=(dom_len, dom_len)))

    LOCINFO_LOADED = False
    print('----------------Model result visualizations----------------')
    while True:
        val = input(
            '\nEnter a day number to plot, ' + 'or "all" to plot all.\n' +
            '"save" or "s" and then a number will save that day to file.\n' +
            '? will provide a list of plottable day numbers.\n' +
            '"vid" will output a video (requires FFmpeg or menconder).\n' +
            '"fields" will load data for plotting sentinel field outlines.\n' +
            'Or enter q to quit:')
        val = val.strip()
        if val == '':
            continue
        elif val == '?':
            print(*list(range(1, len(days) + 1)))
        elif val.lower() == 'q' or val.lower() == 'quit':
            break
        elif val.lower() == 'a' or val.lower() == 'all':
            # plot_all wants a list of values. pass a view into ordered dict
            if LOCINFO_LOADED:
                plot_all(modelsol, params, locinfo=locinfo)
            else:
                plot_all(modelsol, params)
        elif val.lower() == 'vid':
            if LOCINFO_LOADED:
                create_mp4(modelsol, params, filename, locinfo=locinfo)
            else:
                create_mp4(modelsol, params, filename)
        elif val.lower() == 'fields':
            try:
                from Data_Import import LocInfo
                locinfo = LocInfo(params.dataset, params.coord,
                                  params.domain_info)
                LOCINFO_LOADED = True
                print('\nSentinel field locations loaded.')
            except:
                print('\nCould not load sentinel field data.')
                print(sys.exc_info()[0])
                continue
        elif val[0] == 's':
            try:
                if val[:4] == 'save':
                    val = int(val[4:].strip())
                else:
                    val = int(val[1:].strip())
            except ValueError:
                print('\nCould not convert {} to an integer.'.format(val))
                continue
            try:
                if LOCINFO_LOADED:
                    plot(modelsol[val - 1],
                         val,
                         params,
                         saveonly=filename,
                         locinfo=locinfo)
                else:
                    plot(modelsol[val - 1], val, params, saveonly=filename)
            except IndexError:
                print("\n{} is out of the simulation's range.".format(val))
                print("Possible entries are: " +
                      str(list(range(1,
                                     len(days) + 1)))[1:-1] + '.')
                continue
        else:
            try:
                if LOCINFO_LOADED:
                    plot(modelsol[int(val) - 1], val, params, locinfo=locinfo)
                else:
                    plot(modelsol[int(val) - 1], val, params)
            except KeyError:
                print('\nDay {0} not found.'.format(val))
            except ValueError:
                print('\nInput {} not understood.'.format(val))
                continue
            except IndexError:
                print("\n{} is out of the simulation's range.".format(val))
                print("Possible entries are: " +
                      str(list(range(1,
                                     len(days) + 1)))[1:-1] + '.')
                continue