Exemplo n.º 1
0
def connect_external_flow(ini_file='connect_external_flow.ini'):
    """
    * Objective
      to link the location of external flows to the river network by transforming the initially non-channel cells into channel cells
      ar_lambda is modified (value from 0 to 1) ar_n_c is modified the value of the new channel cells are taken equal to the nearest existing channel cell
    """
    ### READ THE INI FILE ###
    config.read(ini_file)
    print 'Read the file ', ini_file
    ##~~~~~~ file_in ~~~~~~##
    file_in = config.get('file_in', 'file_in')
    ##~~~~~~ file_out ~~~~~~##
    file_out = config.get('file_out', 'file_out')

    ##~~~~~~ external_flow ~~~~~~##
    Xext_flow = config.getfloat('external_flow', 'Xext_flow')
    Yext_flow = config.getfloat('external_flow', 'Yext_flow')

    ##~~~~~~ flags ~~~~~~##
    nb_param = config.getfloat('flags', 'nb_param')

    #Reading of parameter file
    print 'Reading parameter file'
    ar_cell_label,ar_coorx,ar_coory,ar_lambda,ar_Xc,ar_dam,ar_tan_beta,ar_tan_beta_channel,ar_L,ar_Ks,\
    ar_theta_r,ar_theta_s,ar_n_o,ar_n_c,\
    ar_cell_down,ar_pVs_t0,ar_Vo_t0,ar_Qc_t0,ar_kc\
    =pm.read_cell_parameters(file_in)

    print 'Connect external flows to the network'
    ar_lambda, ar_n_c = link_channel_cell(ar_cell_label, ar_coorx, ar_coory,
                                          ar_lambda, ar_cell_down, ar_n_c,
                                          Xext_flow, Yext_flow)

    #~~~~~~Write parameter file~~~~~~#
    tab_param = np.zeros((len(ar_cell_label), nb_param))
    tab_param[:, 0] = ar_cell_label
    tab_param[:, 1] = ar_coorx
    tab_param[:, 2] = ar_coory
    tab_param[:, 3] = ar_lambda
    tab_param[:, 4] = ar_Xc
    tab_param[:, 5] = ar_dam
    tab_param[:, 6] = ar_tan_beta
    tab_param[:, 7] = ar_tan_beta_channel
    tab_param[:, 8] = ar_L
    tab_param[:, 9] = ar_Ks
    tab_param[:, 10] = ar_theta_r
    tab_param[:, 11] = ar_theta_s
    tab_param[:, 12] = ar_n_o
    tab_param[:, 13] = ar_n_c
    tab_param[:, 14] = ar_cell_down
    tab_param[:, 15] = ar_pVs_t0
    tab_param[:, 16] = ar_Vo_t0
    tab_param[:, 17] = ar_Qc_t0
    tab_param[:, 18] = ar_kc

    np.savetxt(file_out, tab_param)
Exemplo n.º 2
0
def connect_external_flow(ini_file='connect_external_flow.ini'):
    """
    * Objective
      to link the location of external flows to the river network by transforming the initially non-channel cells into channel cells
      ar_lambda is modified (value from 0 to 1) ar_n_c is modified the value of the new channel cells are taken equal to the nearest existing channel cell
    """
    ### READ THE INI FILE ###
    config.read(ini_file)
    print('Read the file ',ini_file)
    ##~~~~~~ file_in ~~~~~~##
    file_in=config.get('file_in','file_in')
    ##~~~~~~ file_out ~~~~~~##
    file_out=config.get('file_out','file_out')

    ##~~~~~~ external_flow ~~~~~~##
    Xext_flow=config.getfloat('external_flow','Xext_flow')
    Yext_flow=config.getfloat('external_flow','Yext_flow')

    ##~~~~~~ flags ~~~~~~##
    nb_param=config.getfloat('flags','nb_param')

    #Reading of parameter file
    print('Reading parameter file')
    ar_cell_label,ar_coorx,ar_coory,ar_lambda,ar_Xc,ar_dam,ar_tan_beta,ar_tan_beta_channel,ar_L,ar_Ks,\
    ar_theta_r,ar_theta_s,ar_n_o,ar_n_c,\
    ar_cell_down,ar_pVs_t0,ar_Vo_t0,ar_Qc_t0,ar_kc\
    =pm.read_cell_parameters(file_in)

    print('Connect external flows to the network')
    ar_lambda,ar_n_c=link_channel_cell(ar_cell_label,ar_coorx,ar_coory,ar_lambda,ar_cell_down,ar_n_c,Xext_flow,Yext_flow)

    #~~~~~~Write parameter file~~~~~~#
    tab_param=np.zeros((len(ar_cell_label),nb_param))
    tab_param[:,0]=ar_cell_label
    tab_param[:,1]=ar_coorx
    tab_param[:,2]=ar_coory
    tab_param[:,3]=ar_lambda
    tab_param[:,4]=ar_Xc
    tab_param[:,5]=ar_dam
    tab_param[:,6]=ar_tan_beta
    tab_param[:,7]=ar_tan_beta_channel
    tab_param[:,8]=ar_L
    tab_param[:,9]=ar_Ks
    tab_param[:,10]=ar_theta_r
    tab_param[:,11]=ar_theta_s
    tab_param[:,12]=ar_n_o
    tab_param[:,13]=ar_n_c
    tab_param[:,14]=ar_cell_down
    tab_param[:,15]=ar_pVs_t0
    tab_param[:,16]=ar_Vo_t0
    tab_param[:,17]=ar_Qc_t0
    tab_param[:,18]=ar_kc

    np.savetxt(file_out, tab_param)
Exemplo n.º 3
0
def run(ini_file='plot_soil_moisture_maps.ini'):

    config.read(ini_file)
    print 'Read the file ',ini_file

    file_global_param=config.get('files','file_global_param')
    file_cell_param=config.get('files','file_cell_param')
    file_sim=config.get('files','file_sim')

    path_out=config.get('paths','path_out')

    fac_L=config.getfloat('calib_params','fac_L')
    fac_Ks=config.getfloat('calib_params','fac_Ks')
    fac_n_o=config.getfloat('calib_params','fac_n_o')
    fac_n_c=config.getfloat('calib_params','fac_n_c')

    t1=config.getfloat('flags','t1')
    t2=config.getfloat('flags','t2')
    variable=config.getfloat('flags','variable')

    ##~~~~~~PROGRAM~~~~~##
    # Create the folder if it doesn't exist
    ut.check_folder_exist(path_out)

    #~~~~Read Global parameters file
    X,Dt,alpha_s,alpha_o,alpha_c,A_thres,W_min,W_max\
      =pm.read_global_parameters(file_global_param)
    #~~~~Read Cell parameters file
    ar_cell_label, ar_coorx, \
    ar_coory, ar_lambda, \
    ar_Xc, ar_dam, \
    ar_tan_beta, ar_tan_beta_channel, \
    ar_L0, ar_Ks0, \
    ar_theta_r, ar_theta_s, \
    ar_n_o0, ar_n_c0, \
    ar_cell_down, ar_pVs_t0, \
    ar_Vo_t0, ar_Qc_t0, \
    ar_kc, psi_b, lamda = pm.read_cell_parameters(file_cell_param)
    #~~~~Number of cell in the catchment
    nb_cell=len(ar_cell_label)
    #~~~~Computation of cell order
    ar_label_sort=pm.sort_cell(ar_cell_label,ar_cell_down)
    #~~~~Computation of upcells
    li_cell_up=pm.direct_up_cell(ar_cell_label,ar_cell_down,ar_label_sort)
    #~~~~Computation of drained area
    ar_A_drained=pm.drained_area(ar_label_sort,li_cell_up,X)
    #~~~~Modifies the values of the parameters
    ar_L=ar_L0*fac_L
    ar_Ks=ar_Ks0*fac_Ks
    ar_n_o=ar_n_o0*fac_n_o
    ar_n_c=ar_n_c0*fac_n_c
    #~~~~Computation of model parameters from physical parameters
    ar_Vsm, ar_b_s, ar_b_o, ar_W, ar_b_c\
      =pm.compute_cell_param(X,ar_Xc,Dt,alpha_s,alpha_o,alpha_c,nb_cell,\
                              A_thres,W_max,W_min,\
                              ar_lambda,ar_tan_beta,ar_tan_beta_channel,ar_L,\
                              ar_Ks,ar_theta_r,ar_theta_s,ar_n_o,ar_n_c,\
                              ar_A_drained)

    #Read of data from the outputs of TOPKAPI in hdf5 format
    ndar_Vs=np.array(ut.read_one_array_hdf(file_sim,'/Soil/','V_s'))

    #Assign the variables
    if variable==1:
        im_out=os.path.join(path_out, 'field_Vs_')
        tab=ndar_Vs
    elif variable==2:
        im_out=os.path.join(path_out, 'field_Vo_')
        tab=ndar_Vo
    elif variable==3:
        im_out=os.path.join(path_out, 'field_Vo_bin_')
        tab=ndar_Vo
        tab[tab>0]=1.
    elif variable==4:
        im_out=os.path.join(path_out, 'field_SSI_')
        tab=ndar_Vs/ar_Vsm*100.

    # Plot the maps
    for t in np.arange(int(t1),int(t2+1)):
        print 'Map time-step ', t
        image_out=im_out+ut.string(t,len(str(t2)))+'.png'
        field_map_ndar(tab,t,ar_coorx,ar_coory,X,image_out,variable)
Exemplo n.º 4
0
def run(ini_file='plot_soil_moisture_maps.ini'):

    config.read(ini_file)
    print('Read the file ',ini_file)

    file_global_param=config.get('files','file_global_param')
    file_cell_param=config.get('files','file_cell_param')
    file_sim=config.get('files','file_sim')

    path_out=config.get('paths','path_out')

    fac_L=config.getfloat('calib_params','fac_L')
    fac_Ks=config.getfloat('calib_params','fac_Ks')
    fac_n_o=config.getfloat('calib_params','fac_n_o')
    fac_n_c=config.getfloat('calib_params','fac_n_c')

    t1=config.getfloat('flags','t1')
    t2=config.getfloat('flags','t2')
    variable=config.getfloat('flags','variable')

    ##~~~~~~PROGRAM~~~~~##
    # Create the folder if it doesn't exist
    ut.check_folder_exist(path_out)

    #~~~~Read Global parameters file
    X,Dt,alpha_s,alpha_o,alpha_c,A_thres,W_min,W_max\
      =pm.read_global_parameters(file_global_param)
    #~~~~Read Cell parameters file
    ar_cell_label, ar_coorx, \
    ar_coory, ar_lambda, \
    ar_Xc, ar_dam, \
    ar_tan_beta, ar_tan_beta_channel, \
    ar_L0, ar_Ks0, \
    ar_theta_r, ar_theta_s, \
    ar_n_o0, ar_n_c0, \
    ar_cell_down, ar_pVs_t0, \
    ar_Vo_t0, ar_Qc_t0, \
    ar_kc, psi_b, lamda = pm.read_cell_parameters(file_cell_param)
    #~~~~Number of cell in the catchment
    nb_cell=len(ar_cell_label)
    #~~~~Computation of cell order
    ar_label_sort=pm.sort_cell(ar_cell_label,ar_cell_down)
    #~~~~Computation of upcells
    li_cell_up=pm.direct_up_cell(ar_cell_label,ar_cell_down,ar_label_sort)
    #~~~~Computation of drained area
    ar_A_drained=pm.drained_area(ar_label_sort,li_cell_up,X)
    #~~~~Modifies the values of the parameters
    ar_L=ar_L0*fac_L
    ar_Ks=ar_Ks0*fac_Ks
    ar_n_o=ar_n_o0*fac_n_o
    ar_n_c=ar_n_c0*fac_n_c
    #~~~~Computation of model parameters from physical parameters
    ar_Vsm, ar_b_s, ar_b_o, ar_W, ar_b_c\
      =pm.compute_cell_param(X,ar_Xc,Dt,alpha_s,alpha_o,alpha_c,nb_cell,\
                              A_thres,W_max,W_min,\
                              ar_lambda,ar_tan_beta,ar_tan_beta_channel,ar_L,\
                              ar_Ks,ar_theta_r,ar_theta_s,ar_n_o,ar_n_c,\
                              ar_A_drained)

    #Read of data from the outputs of TOPKAPI in hdf5 format
    ndar_Vs=np.array(ut.read_one_array_hdf(file_sim,'Soil','V_s'))

    #Assign the variables
    if variable==1:
        im_out=os.path.join(path_out, 'field_Vs_')
        tab=ndar_Vs
    elif variable==2:
        im_out=os.path.join(path_out, 'field_Vo_')
        tab=ndar_Vo
    elif variable==3:
        im_out=os.path.join(path_out, 'field_Vo_bin_')
        tab=ndar_Vo
        tab[tab>0]=1.
    elif variable==4:
        im_out=os.path.join(path_out, 'field_SSI_')
        tab=ndar_Vs/ar_Vsm*100.

    # Plot the maps
    for t in np.arange(int(t1),int(t2+1)):
        print('Map time-step ', t)
        image_out=im_out+ut.string(t,len(str(t2)))+'.png'
        field_map_ndar(tab,t,ar_coorx,ar_coory,X,image_out,variable)
Exemplo n.º 5
0
def mean_simuVsi(ini_file='mean_simuVsi.ini'):
    """
    * Objective

    """

    ### READ THE INI FILE ###
    config.read(ini_file)
    print('Read the file ',ini_file)

    ##~~~~~~ file_in ~~~~~~##
    file_in=config.get('file_in','file_in')
    file_in_global=config.get('file_in','file_in_global')
    file_h5=config.get('file_in','file_h5')

    ##~~~~~~ file_out ~~~~~~##
    file_out=config.get('file_out','file_out')

    ##~~~~~~ variables ~~~~~~##
    mean_pVs_t0=config.getfloat('variables','mean_pVs_t0')
    fac_L_simu=config.getfloat('variables','fac_L_simu')
    fac_Ks_simu=config.getfloat('variables','fac_Ks_simu')
    fac_n_o_simu=config.getfloat('variables','fac_n_o_simu')
    fac_n_c_simu=config.getfloat('variables','fac_n_c_simu')

    ##~~~~~~ flags ~~~~~~##
    nb_param=config.getfloat('flags','nb_param')

    #--Read and compute the parameters to have the values of parameter and ar_Vsm
    #~~~~Read Global parameters file
    print('Pretreatment of input data')
    #~~~~Read Global parameters file
    X,Dt,alpha_s,alpha_o,alpha_c,A_thres,W_min,W_max\
      =pm.read_global_parameters(file_in_global)
    #~~~~Read Cell parameters file
    ar_cell_label,ar_coorx,ar_coory,ar_lambda,ar_Xc,ar_dam,ar_tan_beta,ar_tan_beta_channel,ar_L,ar_Ks,\
    ar_theta_r,ar_theta_s,ar_n_o,ar_n_c,\
    ar_cell_down,ar_pVs_t0,ar_Vo_t0,ar_Qc_t0,ar_kc\
        =pm.read_cell_parameters(file_in)
    #~~~~Number of cell in the catchment
    nb_cell=len(ar_cell_label)
    #~~~~Computation of cell order
    ar_label_sort=pm.sort_cell(ar_cell_label,ar_cell_down)
    #~~~~Computation of upcells
    li_cell_up=pm.direct_up_cell(ar_cell_label,ar_cell_down,ar_label_sort)
    #~~~~Computation of drained area
    ar_A_drained=pm.drained_area(ar_label_sort,li_cell_up,X)
    #~~~~Modifies the values of the parameters
    ar_L1=ar_L*fac_L_simu
    ar_Ks1=ar_Ks*fac_Ks_simu
    ar_n_o1=ar_n_o*fac_n_o_simu
    ar_n_c1=ar_n_c*fac_n_c_simu
    #~~~~Computation of model parameters from physical parameters
    ar_Vsm, ar_b_s, ar_b_o, ar_W, ar_b_c\
      =pm.compute_cell_param(X,ar_Xc,Dt,alpha_s,alpha_o,alpha_c,nb_cell,\
                              A_thres,W_max,W_min,\
                              ar_lambda,ar_tan_beta,ar_tan_beta_channel,ar_L1,\
                              ar_Ks1,ar_theta_r,ar_theta_s,ar_n_o1,ar_n_c1,\
                              ar_A_drained)

    #Read the soil volume file
    ndar_Vs=np.array(ut.read_one_array_hdf(file_h5,'Soil','V_s'))

    #Read the file of catchment saturation rates
    ndar_Vs_sat=ndar_Vs/ar_Vsm*100.
    tab_rate=np.average(ndar_Vs_sat,axis=1)
    tab_rate_sort=np.sort(tab_rate)
    indice_sort=np.argsort(tab_rate)

    #Look for the rate closest to the expected mean value
    if mean_pVs_t0<tab_rate_sort[0]:
        ind=0
        print('mean_pVs_t0 expected:', mean_pVs_t0,'effective:',tab_rate_sort[0])
    elif mean_pVs_t0>tab_rate_sort[-1]:
        ind=-1
        print('mean_pVs_t0 expected:', mean_pVs_t0,' effective',tab_rate_sort[-1])
    else:
        loop=True
        i=-1
        while loop:
            i=i+1
            if mean_pVs_t0>=tab_rate_sort[i] and mean_pVs_t0<tab_rate_sort[i+1]:
                ind=i
                loop=False
                print('mean_pVs_t0 expected:', mean_pVs_t0,' effective:',tab_rate_sort[i])

    ind_end=indice_sort[ind]
    print(ind,ind_end)
    ar_Vs=ndar_Vs[ind_end,:]
    ar_Vsi=ar_Vs/ar_Vsm*100.
    print(ar_Vsi)
    ar_pVs_t0=ar_Vsi

    #~~~~~~Write parameter file~~~~~~#
    tab_param=np.zeros((len(ar_cell_label),nb_param))

    tab_param[:,0]=ar_cell_label
    tab_param[:,1]=ar_coorx
    tab_param[:,2]=ar_coory
    tab_param[:,3]=ar_lambda
    tab_param[:,4]=ar_Xc
    tab_param[:,5]=ar_dam
    tab_param[:,6]=ar_tan_beta
    tab_param[:,7]=ar_tan_beta_channel
    tab_param[:,8]=ar_L
    tab_param[:,9]=ar_Ks
    tab_param[:,10]=ar_theta_r
    tab_param[:,11]=ar_theta_s
    tab_param[:,12]=ar_n_o
    tab_param[:,13]=ar_n_c
    tab_param[:,14]=ar_cell_down
    tab_param[:,15]=ar_pVs_t0
    tab_param[:,16]=ar_Vo_t0
    tab_param[:,17]=ar_Qc_t0
    tab_param[:,18]=ar_kc

    np.savetxt(file_out, tab_param)
Exemplo n.º 6
0
def initial_pVs_Vo_Qc_from_simu(ini_file='initial_pVs_Vo_Qc_from_simu.ini'):
    """
    * Objective

     """
    ### READ THE INI FILE ###
    config.read(ini_file)
    print('Read the file ',ini_file)

    ##~~~~~~ file_in ~~~~~~##
    file_in=config.get('file_in','file_in')
    file_in_global=config.get('file_in','file_in_global')
    file_h5=config.get('file_in','file_h5')

    ##~~~~~~ file_out ~~~~~~##
    file_out=config.get('file_out','file_out')

    ##~~~~~~ variables ~~~~~~##
    time_step=config.getint('variables','time_step')
    fac_L_simu=config.getfloat('variables','fac_L_simu')
    fac_Ks_simu=config.getfloat('variables','fac_Ks_simu')
    fac_n_o_simu=config.getfloat('variables','fac_n_o_simu')
    fac_n_c_simu=config.getfloat('variables','fac_n_c_simu')

    ##~~~~~~ flags ~~~~~~##
    nb_param=config.getfloat('flags','nb_param')

    #--Read and compute the parameters to have the values of parameter and ar_Vsm
    #~~~~Read Global parameters file
    #~~~~Read Global parameters file
    X,Dt,alpha_s,alpha_o,alpha_c,A_thres,W_min,W_max\
      =pm.read_global_parameters(file_in_global)
    #~~~~Read Cell parameters file
    ar_cell_label,ar_coorx,ar_coory,ar_lambda,ar_Xc,ar_dam,ar_tan_beta,ar_tan_beta_channel,ar_L,ar_Ks,\
    ar_theta_r,ar_theta_s,ar_n_o,ar_n_c,\
    ar_cell_down,ar_pVs_t0,ar_Vo_t0,ar_Qc_t0,ar_kc\
        =pm.read_cell_parameters(file_in)
    #~~~~Number of cell in the catchment
    nb_cell=len(ar_cell_label)
    #~~~~Computation of cell order
    ar_label_sort=pm.sort_cell(ar_cell_label,ar_cell_down)
    #~~~~Computation of upcells
    li_cell_up=pm.direct_up_cell(ar_cell_label,ar_cell_down,ar_label_sort)
    #~~~~Computation of drained area
    ar_A_drained=pm.drained_area(ar_label_sort,li_cell_up,X)
    #~~~~Modifies the values of the parameters
    ar_L1=ar_L*fac_L_simu
    ar_Ks1=ar_Ks*fac_Ks_simu
    ar_n_o1=ar_n_o*fac_n_o_simu
    ar_n_c1=ar_n_c*fac_n_c_simu
    #~~~~Computation of model parameters from physical parameters
    ar_Vsm, ar_b_s, ar_b_o, ar_W, ar_b_c\
      =pm.compute_cell_param(X,ar_Xc,Dt,alpha_s,alpha_o,alpha_c,nb_cell,\
                              A_thres,W_max,W_min,\
                              ar_lambda,ar_tan_beta,ar_tan_beta_channel,ar_L1,\
                              ar_Ks1,ar_theta_r,ar_theta_s,ar_n_o1,ar_n_c1,\
                              ar_A_drained)

    #Read the soil volume file
    ndar_Vs=np.array(ut.read_one_array_hdf(file_h5,'Soil','V_s'))
    #Read the overland volume file
    ndar_Vo=np.array(ut.read_one_array_hdf(file_h5,'Overland','V_o'))
    #Read the channel dischargefile
    ndar_Qc=np.array(ut.read_one_array_hdf(file_h5,'Channel','Qc_out'))

    ar_Vs=ndar_Vs[time_step,:]
    ar_pVs_t0=ar_Vs/ar_Vsm*100.
    ar_Vo_t0=ndar_Vo[time_step,:]
    ar_Qc_t0=ndar_Qc[time_step,:]


    #~~~~~~Write parameter file~~~~~~#
    tab_param=np.zeros((len(ar_cell_label),nb_param))

    tab_param[:,0]=ar_cell_label
    tab_param[:,1]=ar_coorx
    tab_param[:,2]=ar_coory
    tab_param[:,3]=ar_lambda
    tab_param[:,4]=ar_Xc
    tab_param[:,5]=ar_dam
    tab_param[:,6]=ar_tan_beta
    tab_param[:,7]=ar_tan_beta_channel
    tab_param[:,8]=ar_L
    tab_param[:,9]=ar_Ks
    tab_param[:,10]=ar_theta_r
    tab_param[:,11]=ar_theta_s
    tab_param[:,12]=ar_n_o
    tab_param[:,13]=ar_n_c
    tab_param[:,14]=ar_cell_down
    tab_param[:,15]=ar_pVs_t0
    tab_param[:,16]=ar_Vo_t0
    tab_param[:,17]=ar_Qc_t0
    tab_param[:,18]=ar_kc

    np.savetxt(file_out, tab_param)
Exemplo n.º 7
0
def new_param(ini_file='new_param.ini'):
    """
    * Objective
        Modifies the param file by multiplying some variables (L, Ks, n_o,n_c)
        or replacing by a given new value for the initial level of reservoir in percent
    * Input
      - file_in: parameter file to be modified
      - the other parameters are assigned by default and have to be changed according to user's choice.
    * Output
      - file_out: new parameter file
    """
    ### READ THE INI FILE ###
    config.read(ini_file)
    print('Read the file ',ini_file)
    ##~~~~~~ file_in ~~~~~~##
    file_in=config.get('file_in','file_in')
    ##~~~~~~ file_out ~~~~~~##
    file_out=config.get('file_out','file_out')

    ##~~~~~~ factor_values ~~~~~##
    fac_L=config.getfloat('factor_values','fac_L')
    fac_Ks=config.getfloat('factor_values','fac_KS')
    fac_n_o=config.getfloat('factor_values','fac_n_o')
    fac_n_c=config.getfloat('factor_values','fac_n_c')

    ##~~~~~~ new_initial_values ~~~~~##
    new_pVs_t0=config.getfloat('new_initial_values','new_pVs_t0')
    new_Vo_t0=config.getfloat('new_initial_values','new_Vo_t0')
    new_Qc_t0=config.getfloat('new_initial_values','new_Qc_t0')

    ##~~~~~~ flags ~~~~~~##
    nb_param=config.getfloat('flags','nb_param')

    #Reading of parameter file
    print('Reading parameter file')
    ar_cell_label,ar_coorx,ar_coory,ar_lambda,ar_Xc,ar_dam,ar_tan_beta,ar_tan_beta_channel,ar_L,ar_Ks,\
    ar_theta_r,ar_theta_s,ar_n_o,ar_n_c,\
    ar_cell_down,ar_pVs_t0,ar_Vo_t0,ar_Qc_t0,ar_kc\
    =pm.read_cell_parameters(file_in)

    #~~~~~~Change in parameters~~~~~~#
    #Multiplying factors for L, Ks, n_o and n_c
    if fac_L!=1.:
        print('Change L')
        ar_L=ar_L*fac_L
    if fac_Ks!=1.:
        print('Change Ks')
        ar_Ks=ar_Ks*fac_Ks
    if fac_n_o!=1.:
        print('Change n_o')
        ar_n_o=ar_n_o*fac_n_o
    if fac_n_c!=1.:
        print('Change n_c')
        ar_n_c=ar_n_c*fac_n_c
    #New values for pVs_t0, Vo_t0 and Qc_t0
    if new_pVs_t0!=ar_pVs_t0[0]:
        print('Change pVs_t0')
        ar_pVs_t0=ar_pVs_t0*0.+new_pVs_t0
    if new_Vo_t0!=ar_Vo_t0[0]:
        print('Change pVs_t0')
        ar_Vo_t0=ar_Vo_t0*0.+new_Vo_t0
    if new_Qc_t0!=ar_Qc_t0[0]:
        print('Change pVc_t0')
        ar_Qc_t0=ar_Qc_t0*0.+new_Qc_t0

    #~~~~~~Write parameter file~~~~~~#
    tab_param=np.zeros((len(ar_cell_label),nb_param))
    tab_param[:,0]=ar_cell_label
    tab_param[:,1]=ar_coorx
    tab_param[:,2]=ar_coory
    tab_param[:,3]=ar_lambda
    tab_param[:,4]=ar_Xc
    tab_param[:,5]=ar_dam
    tab_param[:,6]=ar_tan_beta
    tab_param[:,7]=ar_tan_beta_channel
    tab_param[:,8]=ar_L
    tab_param[:,9]=ar_Ks
    tab_param[:,10]=ar_theta_r
    tab_param[:,11]=ar_theta_s
    tab_param[:,12]=ar_n_o
    tab_param[:,13]=ar_n_c
    tab_param[:,14]=ar_cell_down
    tab_param[:,15]=ar_pVs_t0
    tab_param[:,16]=ar_Vo_t0
    tab_param[:,17]=ar_Qc_t0
    tab_param[:,18]=ar_kc

    np.savetxt(file_out, tab_param)
Exemplo n.º 8
0
def zero_slope_management(ini_file='zero_slope_management.ini'):
    """Fix zero slopes

    Correct the cell and channel slopes to avoid situations with zero
    slopes. Water cannot drain downstream in these cases and the ODE's
    fail.

    Parameters
    ----------
    ini_file : string
        The name and full path to an ini file containing the required
        configuration.

    Returns
    -------
    Nothing

    """

    ##================================##
    ##  Read the input file (*.ini)   ##
    ##================================##
    config.read(ini_file)
    print('Read the file ',ini_file)
    ##~~~~~~~~~~~ input files ~~~~~~~~~~~##
    #Param
    file_cell_param=config.get('input_files','file_cell_param')
    file_cell_param_out=config.get('output_files','file_cell_param_out')
    ##~~~~~~ numerical_values ~~~~~~##
    nb_param=config.getfloat('numerical_values','nb_param')
    X=config.getfloat('numerical_values','X')

    ##============================##
    ## Pretreatment of input data ##
    ##============================##
    print('Pretreatment of input data')
    #~~~~Read Cell parameters file
    ar_cell_label, ar_coorx, ar_coory, \
    ar_lambda, ar_Xc, ar_dam, ar_tan_beta, \
    ar_tan_beta_channel, ar_L, ar_Ks, ar_theta_r, \
    ar_theta_s, ar_n_o, ar_n_c, ar_cell_down, ar_pVs_t0, ar_Vo_t0, \
    ar_Qc_t0, ar_kc, psi_b, lamda = pm.read_cell_parameters(file_cell_param)

    #~~~~Number of cell in the catchment
    nb_cell=len(ar_cell_label)
    #~~~~Computation of cell order
    ar_label_sort=pm.sort_cell(ar_cell_label,ar_cell_down)

    print('Treatment of cell slopes')
    #Adjust the outlet slope if equal to zero
    if ar_tan_beta[ar_label_sort[-1]]==0:
        ar_tan_beta[ar_label_sort[-1]]=1./X

    for cell1 in ar_label_sort:
        print(cell1)
        cell=np.where(ar_cell_label==cell1)[0][0]

        li_label_path=[cell]
        li_slope_path=[ar_tan_beta[cell]]

        down_cell=ar_cell_down[cell]

        # Extract the arrays of (i) all cells in the path
        # (ar_label_path) (ii) all corresponding slopes
        # (ar_slope_path)
        while down_cell>-1:
            li_label_path.append(down_cell)
            li_slope_path.append(ar_tan_beta[down_cell])
            down_cell=ar_cell_down[down_cell]
        ar_label_path=np.array(li_label_path)
        ar_slope_path=np.array(li_slope_path)

        # Go into the slope vector to detect the series of zero slopes
        # The method first consists of creating an array containing
        # the index of begining and end of zero series

        # Example: ar_slope_path=np.array([1, 2, 0, 0, 1, 0, 1, 0, 0, 0, 0])
        #--> ar_ind_start=array([2,5,7])
        #--> ar_ind_end=array([4,6,-1])
        li_ind_start=[]
        li_ind_end=[]
        #print(len(ar_slope_path), np.where(ar_slope_path==0.))
        for i in np.arange(len(ar_slope_path)):
            if i==0:
                if ar_slope_path[i]==0.:
                    li_ind_start.append(i)
            elif i==np.arange(len(ar_slope_path))[-1]:
                if ar_slope_path[i]==0. and ar_slope_path[i-1]==0.:
                    li_ind_end.append(-1)
                if ar_slope_path[i]!=0. and ar_slope_path[i-1]==0.:
                    li_ind_end.append(i)
            else:
                if ar_slope_path[i]==0. and ar_slope_path[i-1]!=0:
                    li_ind_start.append(i)
                if ar_slope_path[i]!=0. and ar_slope_path[i-1]==0.:
                    li_ind_end.append(i)
        ar_ind_start=np.array(li_ind_start,int)
        ar_ind_end=np.array(li_ind_end,int)
        if len(ar_ind_start)-len(ar_ind_end)!=0:
            print('problem length')
            print('ar_ind_start:',len(ar_ind_start),'ar_ind_end:',len(ar_ind_end))
            print(ar_ind_start)
            print(ar_ind_end)
            stop
        a=ar_ind_end-ar_ind_start
        if len(np.where(a<0)[0])!=0:
            print('problem index')
            stop

        #Then the slope are changed according to the defined index arrays
        if len(ar_ind_start)>0:
            print('Number of sections with zero slopes:',len(ar_ind_start))
        for i in np.arange(len(ar_ind_start)):
            #Compute the length of the zero path
            if ar_ind_end[i]!=-1:
                length_path=ar_ind_end[i]-ar_ind_start[i]
            else:
                length_path=len(ar_slope_path)-ar_ind_start[i]
            #Compute the corresponding slope
            slope=1./(length_path*X)
            #Replace the values of slope in the initial ar_tan_beta
            #select the cell labels
            ar_label_cell_zero=ar_label_path[ar_ind_start[i]:ar_ind_end[i]]
            #select the cell index (if different from the label)
            ar_ind_cell_zero=np.array(ar_label_cell_zero,int)
            n=-1
            for label in ar_label_cell_zero:
                n=n+1
                ind=np.where(ar_cell_label==label)[0][0]
                ar_ind_cell_zero[n]=ind

            #Change the values
            ar_tan_beta[ar_ind_cell_zero]=slope

    print('Treatment of channel slopes')
    #Adjust the outlet slope if equal to zero
    if ar_tan_beta_channel[ar_label_sort[-1]]==0:
        ar_tan_beta_channel[ar_label_sort[-1]]=1./X

    for cell1 in ar_label_sort:
        print(cell1)
        cell=np.where(ar_cell_label==cell1)[0][0]

        li_label_path=[cell]
        li_slope_path=[ar_tan_beta_channel[cell]]

        down_cell=ar_cell_down[cell]

        # Extract the arrays of (i) all cells in the path
        # (ar_label_path) (ii) all corresponding slopes
        # (ar_slope_path)
        while down_cell>-1:
            li_label_path.append(down_cell)
            li_slope_path.append(ar_tan_beta_channel[down_cell])
            down_cell=ar_cell_down[down_cell]
        ar_label_path=np.array(li_label_path)
        ar_slope_path=np.array(li_slope_path)

        # Go into the slope vector to detect the series of zero slopes
        # The method first consists of creating an array containing
        # the index of begining and end of zero series

        # Example: ar_slope_path=np.array([1, 2, 0, 0, 1, 0, 1, 0, 0, 0, 0])
        #--> ar_ind_start=array([2,5,7])
        #--> ar_ind_end=array([4,6,-1])
        li_ind_start=[]
        li_ind_end=[]
        #print(len(ar_slope_path), np.where(ar_slope_path==0.))
        for i in np.arange(len(ar_slope_path)):
            if i==0:
                if ar_slope_path[i]==0.:
                    li_ind_start.append(i)
            elif i==np.arange(len(ar_slope_path))[-1]:
                if ar_slope_path[i]==0. and ar_slope_path[i-1]==0.:
                    li_ind_end.append(-1)
                if ar_slope_path[i]!=0. and ar_slope_path[i-1]==0.:
                    li_ind_end.append(i)
            else:
                if ar_slope_path[i]==0. and ar_slope_path[i-1]!=0:
                    li_ind_start.append(i)
                if ar_slope_path[i]!=0. and ar_slope_path[i-1]==0.:
                    li_ind_end.append(i)
        ar_ind_start=np.array(li_ind_start,int)
        ar_ind_end=np.array(li_ind_end,int)
        if len(ar_ind_start)-len(ar_ind_end)!=0:
            print('problem length')
            print('ar_ind_start:',len(ar_ind_start),'ar_ind_end:',len(ar_ind_end))
            print(ar_ind_start)
            print(ar_ind_end)
            stop
        a=ar_ind_end-ar_ind_start
        if len(np.where(a<0)[0])!=0:
            print('problem index')
            stop

        # Then the slope are changed according to the defined index
        # arrays
        if len(ar_ind_start)>0:
            print('Number of sections with zero slopes:',len(ar_ind_start))
        for i in np.arange(len(ar_ind_start)):
            # Compute the length of the zero path
            if ar_ind_end[i]!=-1:
                length_path=ar_ind_end[i]-ar_ind_start[i]
            else:
                length_path=len(ar_slope_path)-ar_ind_start[i]
            # Compute the corresponding slope
            slope=1./(length_path*X)
            # Replace the values of slope in the initial
            # ar_tan_beta_channel select the cell labels
            ar_label_cell_zero=ar_label_path[ar_ind_start[i]:ar_ind_end[i]]
            # Select the cell index (if different from the label)
            ar_ind_cell_zero=np.array(ar_label_cell_zero,int)
            n=-1
            for label in ar_label_cell_zero:
                n=n+1
                ind=np.where(ar_cell_label==label)[0][0]
                ar_ind_cell_zero[n]=ind

            # Change the values
            ar_tan_beta_channel[ar_ind_cell_zero]=slope

    # Write parameter file
    param_table = np.zeros((len(ar_cell_label),nb_param))
    param_table[:,0] = ar_cell_label
    param_table[:,1] = ar_coorx
    param_table[:,2] = ar_coory
    param_table[:,3] = ar_lambda
    param_table[:,4] = ar_Xc
    param_table[:,5] = ar_dam
    param_table[:,6] = ar_tan_beta
    param_table[:,7] = ar_tan_beta_channel
    param_table[:,8] = ar_L
    param_table[:,9] = ar_Ks
    param_table[:,10] = ar_theta_r
    param_table[:,11] = ar_theta_s
    param_table[:,12] = ar_n_o
    param_table[:,13] = ar_n_c
    param_table[:,14] = ar_cell_down
    param_table[:,15] = ar_pVs_t0
    param_table[:,16] = ar_Vo_t0
    param_table[:,17] = ar_Qc_t0
    param_table[:,18] = ar_kc
    param_table[:,19] = psi_b
    param_table[:,20] = lamda

    format = '%d %f %f %d %f %d %f %f %f %f %f %f %f %f %d %f %f %f %f %f %f'
    np.savetxt(file_cell_param_out, param_table, fmt=format)
Exemplo n.º 9
0
def subcatch(ini_file='subcatch.ini'):
    """
    Create a subcatchment parameter file.

    Extract a subcatchment parameter file from an existing parameter
    file by defining the location of the sub-catchment outlet. The
    closest channel cell to the given coordinates is selected by
    default, based on a nearest neighbour search.

    A new parameter file for the subcatchment is written and a plot of
    the full catchment showing the location of the derived
    subcatchment is also produced.

    Parameters
    ----------
    ini_file : string
        The name of the ini file that specifies the input and output files,
        coordinates of the subcatchment outlet, the number of parameters and
        the grid dimension.

    Returns
    -------
    Nothing

    Notes
    -----
    This function creates a parameter file where the cell numbering doesn't
    follow the conventional North to South and West to East ordering. The
    cells are labelled in order from the outlet to the most distant upstream
    cell.

    """
    config.read(ini_file)
    print('Read the file ', ini_file)

    file_in = config.get('file_in', 'file_in')

    file_out = config.get('file_out', 'file_out')

    picture_out = config.get('picture_out', 'picture_out')

    Xoutlet = config.getfloat('coord_outlet', 'Xoutlet')
    Youtlet = config.getfloat('coord_outlet', 'Youtlet')

    nb_param = config.getfloat('flags', 'nb_param')
    X = config.getfloat('flags', 'X')

    #Reading of parameter file
    print('Reading parameter file')
    ar_cell_label, ar_coorx, ar_coory, ar_lambda, ar_Xc, ar_dam, ar_tan_beta, \
    ar_tan_beta_channel, ar_L, ar_Ks, ar_theta_r, ar_theta_s, ar_n_o, ar_n_c, \
    ar_cell_down, ar_pVs_t0, ar_Vo_t0, ar_Qc_t0, ar_kc \
    = pm.read_cell_parameters(file_in)

    #Search for the cell close to the coordinates
    print('Search for the outlet cell')
    cell_outlet = find_cell_coordinates(ar_cell_label, Xoutlet,
                                        Youtlet, ar_coorx, ar_coory, ar_lambda)

    #Search for the catchment cells
    print('Search for the catchment cells')
    subcatch_label = all_up_cell(cell_outlet, ar_cell_down, ar_cell_label)

    #Select the subcatchmnent parameters
    print('Select the subcatchmnent parameters')
    tab_param = np.zeros((len(subcatch_label),nb_param))
    new_label = np.arange(len(subcatch_label))

    tab_param[:,0] = new_label#ar_cell_label[subcatch_label]
    tab_param[:,1] = ar_coorx[subcatch_label]
    tab_param[:,2] = ar_coory[subcatch_label]
    tab_param[:,3] = ar_lambda[subcatch_label]
    tab_param[:,4] = ar_Xc[subcatch_label]
    tab_param[:,5] = ar_dam[subcatch_label]
    tab_param[:,6] = ar_tan_beta[subcatch_label]
    tab_param[:,7] = ar_tan_beta_channel[subcatch_label]
    tab_param[:,8] = ar_L[subcatch_label]
    tab_param[:,9] = ar_Ks[subcatch_label]
    tab_param[:,10] = ar_theta_r[subcatch_label]
    tab_param[:,11] = ar_theta_s[subcatch_label]
    tab_param[:,12] = ar_n_o[subcatch_label]
    tab_param[:,13] = ar_n_c[subcatch_label]
    for i in range(len(subcatch_label)):
        if i == 0:
            tab_param[i,14] = -9999.0
        else:
            ind = np.where(ar_cell_label[subcatch_label]
                           == ar_cell_down[subcatch_label][i])

            tab_param[i,14] = new_label[ind]

    tab_param[:,15]=ar_pVs_t0[subcatch_label]
    tab_param[:,16]=ar_Vo_t0[subcatch_label]
    tab_param[:,17]=ar_Qc_t0[subcatch_label]
    tab_param[:,18]=ar_kc[subcatch_label]

    #~~~~~~Write parameter file~~~~~~#
    np.savetxt(file_out, tab_param)

    ar_image=ar_cell_label*0.
    ar_image[subcatch_label]=1.
    ar_image[ar_lambda==1.]=10.
    ar_image[cell_outlet]=5.
    field_map(ar_image, ar_coorx, ar_coory, X, picture_out, 'Subcatchment')
Exemplo n.º 10
0

#if __name__ == '__main__':
##~~~~~~~~~~~ INPUTS FILES ~~~~~~~~~~~##
file_cell_param='E:/post_doc/liebenbergsvlei/topkapi_model_Oct07/parameters/cell_parameter/8D/slope_GIS_channel/cell_param_Vsi100.0_slope.dat'
file_global_param='E:/post_doc/liebenbergsvlei/topkapi_model_Oct07/parameters/global_parameter/global_param_Wmin5.0_Wmax40.0.dat'
path_out='E:/post_doc/liebenbergsvlei/topkapi_model_Oct07/parameters/cell_parameter/8D/slope_GIS_channel/'

#~~~~Read Global parameters file
X,Dt,alpha_s,alpha_o,alpha_c,A_thres,W_min,W_max\
  =pm.read_global_parameters(file_global_param)
#~~~~Read Cell parameters file
ar_cell_label,ar_coorx,ar_coory,ar_lambda,ar_Xc,ar_dam,ar_tan_beta,ar_tan_beta_channel,ar_L,ar_Ks,\
ar_theta_r,ar_theta_s,ar_n_o,ar_n_c,\
ar_cell_down,ar_pVs_t0,ar_Vo_t0,ar_Qc_t0,ar_kc\
    =pm.read_cell_parameters(file_cell_param)

#Lambda
image_out=path_out+'field_lambda.png'
field_map(ar_lambda,ar_coorx,ar_coory,X,image_out,'Channel cells',max_val=max(ar_lambda))
#ar_Xc
image_out=path_out+'field_Xc.png'
field_map(ar_Xc,ar_coorx,ar_coory,X,image_out,'Channel length',max_val=max(ar_Xc))
#Ks
image_out=path_out+'field_KS.png'
field_map(ar_Ks,ar_coorx,ar_coory,X,image_out,'Ks',max_val=max(ar_Ks))
#Slopes
image_out=path_out+'field_tan_beta.png'
field_map(ar_tan_beta,ar_coorx,ar_coory,X,image_out,r'$Slope \ tan(\beta)$',max_val=max(ar_tan_beta))
#Slopes zero
image_out=path_out+'field_tan_beta_zero.png'
Exemplo n.º 11
0
def mean_simuVsi(ini_file='mean_simuVsi.ini'):
    """
    * Objective

    """

    ### READ THE INI FILE ###
    config.read(ini_file)
    print 'Read the file ', ini_file

    ##~~~~~~ file_in ~~~~~~##
    file_in = config.get('file_in', 'file_in')
    file_in_global = config.get('file_in', 'file_in_global')
    file_h5 = config.get('file_in', 'file_h5')

    ##~~~~~~ file_out ~~~~~~##
    file_out = config.get('file_out', 'file_out')

    ##~~~~~~ variables ~~~~~~##
    mean_pVs_t0 = config.getfloat('variables', 'mean_pVs_t0')
    fac_L_simu = config.getfloat('variables', 'fac_L_simu')
    fac_Ks_simu = config.getfloat('variables', 'fac_Ks_simu')
    fac_n_o_simu = config.getfloat('variables', 'fac_n_o_simu')
    fac_n_c_simu = config.getfloat('variables', 'fac_n_c_simu')

    ##~~~~~~ flags ~~~~~~##
    nb_param = config.getfloat('flags', 'nb_param')

    #--Read and compute the parameters to have the values of parameter and ar_Vsm
    #~~~~Read Global parameters file
    print 'Pretreatment of input data'
    #~~~~Read Global parameters file
    X,Dt,alpha_s,alpha_o,alpha_c,A_thres,W_min,W_max\
      =pm.read_global_parameters(file_in_global)
    #~~~~Read Cell parameters file
    ar_cell_label,ar_coorx,ar_coory,ar_lambda,ar_Xc,ar_dam,ar_tan_beta,ar_tan_beta_channel,ar_L,ar_Ks,\
    ar_theta_r,ar_theta_s,ar_n_o,ar_n_c,\
    ar_cell_down,ar_pVs_t0,ar_Vo_t0,ar_Qc_t0,ar_kc\
        =pm.read_cell_parameters(file_in)
    #~~~~Number of cell in the catchment
    nb_cell = len(ar_cell_label)
    #~~~~Computation of cell order
    ar_label_sort = pm.sort_cell(ar_cell_label, ar_cell_down)
    #~~~~Computation of upcells
    li_cell_up = pm.direct_up_cell(ar_cell_label, ar_cell_down, ar_label_sort)
    #~~~~Computation of drained area
    ar_A_drained = pm.drained_area(ar_label_sort, li_cell_up, X)
    #~~~~Modifies the values of the parameters
    ar_L1 = ar_L * fac_L_simu
    ar_Ks1 = ar_Ks * fac_Ks_simu
    ar_n_o1 = ar_n_o * fac_n_o_simu
    ar_n_c1 = ar_n_c * fac_n_c_simu
    #~~~~Computation of model parameters from physical parameters
    ar_Vsm, ar_b_s, ar_b_o, ar_W, ar_b_c\
      =pm.compute_cell_param(X,ar_Xc,Dt,alpha_s,alpha_o,alpha_c,nb_cell,\
                              A_thres,W_max,W_min,\
                              ar_lambda,ar_tan_beta,ar_tan_beta_channel,ar_L1,\
                              ar_Ks1,ar_theta_r,ar_theta_s,ar_n_o1,ar_n_c1,\
                              ar_A_drained)

    #Read the soil volume file
    ndar_Vs = np.array(ut.read_one_array_hdf(file_h5, '/Soil/', 'V_s'))

    #Read the file of catchment saturation rates
    ndar_Vs_sat = ndar_Vs / ar_Vsm * 100.
    tab_rate = np.average(ndar_Vs_sat, axis=1)
    tab_rate_sort = np.sort(tab_rate)
    indice_sort = np.argsort(tab_rate)

    #Look for the rate closest to the expected mean value
    if mean_pVs_t0 < tab_rate_sort[0]:
        ind = 0
        print 'mean_pVs_t0 expected:', mean_pVs_t0, 'effective:', tab_rate_sort[
            0]
    elif mean_pVs_t0 > tab_rate_sort[-1]:
        ind = -1
        print 'mean_pVs_t0 expected:', mean_pVs_t0, ' effective', tab_rate_sort[
            -1]
    else:
        loop = True
        i = -1
        while loop:
            i = i + 1
            if mean_pVs_t0 >= tab_rate_sort[i] and mean_pVs_t0 < tab_rate_sort[
                    i + 1]:
                ind = i
                loop = False
                print 'mean_pVs_t0 expected:', mean_pVs_t0, ' effective:', tab_rate_sort[
                    i]

    ind_end = indice_sort[ind]
    print ind, ind_end
    ar_Vs = ndar_Vs[ind_end, :]
    ar_Vsi = ar_Vs / ar_Vsm * 100.
    print ar_Vsi
    ar_pVs_t0 = ar_Vsi

    #~~~~~~Write parameter file~~~~~~#
    tab_param = np.zeros((len(ar_cell_label), nb_param))

    tab_param[:, 0] = ar_cell_label
    tab_param[:, 1] = ar_coorx
    tab_param[:, 2] = ar_coory
    tab_param[:, 3] = ar_lambda
    tab_param[:, 4] = ar_Xc
    tab_param[:, 5] = ar_dam
    tab_param[:, 6] = ar_tan_beta
    tab_param[:, 7] = ar_tan_beta_channel
    tab_param[:, 8] = ar_L
    tab_param[:, 9] = ar_Ks
    tab_param[:, 10] = ar_theta_r
    tab_param[:, 11] = ar_theta_s
    tab_param[:, 12] = ar_n_o
    tab_param[:, 13] = ar_n_c
    tab_param[:, 14] = ar_cell_down
    tab_param[:, 15] = ar_pVs_t0
    tab_param[:, 16] = ar_Vo_t0
    tab_param[:, 17] = ar_Qc_t0
    tab_param[:, 18] = ar_kc

    np.savetxt(file_out, tab_param)
Exemplo n.º 12
0
def initial_pVs_Vo_Qc_from_simu(ini_file='initial_pVs_Vo_Qc_from_simu.ini'):
    """
    * Objective

     """
    ### READ THE INI FILE ###
    config.read(ini_file)
    print 'Read the file ', ini_file

    ##~~~~~~ file_in ~~~~~~##
    file_in = config.get('file_in', 'file_in')
    file_in_global = config.get('file_in', 'file_in_global')
    file_h5 = config.get('file_in', 'file_h5')

    ##~~~~~~ file_out ~~~~~~##
    file_out = config.get('file_out', 'file_out')

    ##~~~~~~ variables ~~~~~~##
    time_step = config.getint('variables', 'time_step')
    fac_L_simu = config.getfloat('variables', 'fac_L_simu')
    fac_Ks_simu = config.getfloat('variables', 'fac_Ks_simu')
    fac_n_o_simu = config.getfloat('variables', 'fac_n_o_simu')
    fac_n_c_simu = config.getfloat('variables', 'fac_n_c_simu')

    ##~~~~~~ flags ~~~~~~##
    nb_param = config.getfloat('flags', 'nb_param')

    #--Read and compute the parameters to have the values of parameter and ar_Vsm
    #~~~~Read Global parameters file
    #~~~~Read Global parameters file
    X,Dt,alpha_s,alpha_o,alpha_c,A_thres,W_min,W_max\
      =pm.read_global_parameters(file_in_global)
    #~~~~Read Cell parameters file
    ar_cell_label,ar_coorx,ar_coory,ar_lambda,ar_Xc,ar_dam,ar_tan_beta,ar_tan_beta_channel,ar_L,ar_Ks,\
    ar_theta_r,ar_theta_s,ar_n_o,ar_n_c,\
    ar_cell_down,ar_pVs_t0,ar_Vo_t0,ar_Qc_t0,ar_kc\
        =pm.read_cell_parameters(file_in)
    #~~~~Number of cell in the catchment
    nb_cell = len(ar_cell_label)
    #~~~~Computation of cell order
    ar_label_sort = pm.sort_cell(ar_cell_label, ar_cell_down)
    #~~~~Computation of upcells
    li_cell_up = pm.direct_up_cell(ar_cell_label, ar_cell_down, ar_label_sort)
    #~~~~Computation of drained area
    ar_A_drained = pm.drained_area(ar_label_sort, li_cell_up, X)
    #~~~~Modifies the values of the parameters
    ar_L1 = ar_L * fac_L_simu
    ar_Ks1 = ar_Ks * fac_Ks_simu
    ar_n_o1 = ar_n_o * fac_n_o_simu
    ar_n_c1 = ar_n_c * fac_n_c_simu
    #~~~~Computation of model parameters from physical parameters
    ar_Vsm, ar_b_s, ar_b_o, ar_W, ar_b_c\
      =pm.compute_cell_param(X,ar_Xc,Dt,alpha_s,alpha_o,alpha_c,nb_cell,\
                              A_thres,W_max,W_min,\
                              ar_lambda,ar_tan_beta,ar_tan_beta_channel,ar_L1,\
                              ar_Ks1,ar_theta_r,ar_theta_s,ar_n_o1,ar_n_c1,\
                              ar_A_drained)

    #Read the soil volume file
    ndar_Vs = np.array(ut.read_one_array_hdf(file_h5, '/Soil/', 'V_s'))
    #Read the overland volume file
    ndar_Vo = np.array(ut.read_one_array_hdf(file_h5, '/Overland/', 'V_o'))
    #Read the channel dischargefile
    ndar_Qc = np.array(ut.read_one_array_hdf(file_h5, '/Channel/', 'Qc_out'))

    ar_Vs = ndar_Vs[time_step, :]
    ar_pVs_t0 = ar_Vs / ar_Vsm * 100.
    ar_Vo_t0 = ndar_Vo[time_step, :]
    ar_Qc_t0 = ndar_Qc[time_step, :]

    #~~~~~~Write parameter file~~~~~~#
    tab_param = np.zeros((len(ar_cell_label), nb_param))

    tab_param[:, 0] = ar_cell_label
    tab_param[:, 1] = ar_coorx
    tab_param[:, 2] = ar_coory
    tab_param[:, 3] = ar_lambda
    tab_param[:, 4] = ar_Xc
    tab_param[:, 5] = ar_dam
    tab_param[:, 6] = ar_tan_beta
    tab_param[:, 7] = ar_tan_beta_channel
    tab_param[:, 8] = ar_L
    tab_param[:, 9] = ar_Ks
    tab_param[:, 10] = ar_theta_r
    tab_param[:, 11] = ar_theta_s
    tab_param[:, 12] = ar_n_o
    tab_param[:, 13] = ar_n_c
    tab_param[:, 14] = ar_cell_down
    tab_param[:, 15] = ar_pVs_t0
    tab_param[:, 16] = ar_Vo_t0
    tab_param[:, 17] = ar_Qc_t0
    tab_param[:, 18] = ar_kc

    np.savetxt(file_out, tab_param)
Exemplo n.º 13
0
def new_param(ini_file='new_param.ini'):
    """
    * Objective
        Modifies the param file by multiplying some variables (L, Ks, n_o,n_c)
        or replacing by a given new value for the initial level of reservoir in percent
    * Input
      - file_in: parameter file to be modified
      - the other parameters are assigned by default and have to be changed according to user's choice.
    * Output
      - file_out: new parameter file
    """
    ### READ THE INI FILE ###
    config.read(ini_file)
    print 'Read the file ', ini_file
    ##~~~~~~ file_in ~~~~~~##
    file_in = config.get('file_in', 'file_in')
    ##~~~~~~ file_out ~~~~~~##
    file_out = config.get('file_out', 'file_out')

    ##~~~~~~ factor_values ~~~~~##
    fac_L = config.getfloat('factor_values', 'fac_L')
    fac_Ks = config.getfloat('factor_values', 'fac_KS')
    fac_n_o = config.getfloat('factor_values', 'fac_n_o')
    fac_n_c = config.getfloat('factor_values', 'fac_n_c')

    ##~~~~~~ new_initial_values ~~~~~##
    new_pVs_t0 = config.getfloat('new_initial_values', 'new_pVs_t0')
    new_Vo_t0 = config.getfloat('new_initial_values', 'new_Vo_t0')
    new_Qc_t0 = config.getfloat('new_initial_values', 'new_Qc_t0')

    ##~~~~~~ flags ~~~~~~##
    nb_param = config.getfloat('flags', 'nb_param')

    #Reading of parameter file
    print 'Reading parameter file'
    ar_cell_label,ar_coorx,ar_coory,ar_lambda,ar_Xc,ar_dam,ar_tan_beta,ar_tan_beta_channel,ar_L,ar_Ks,\
    ar_theta_r,ar_theta_s,ar_n_o,ar_n_c,\
    ar_cell_down,ar_pVs_t0,ar_Vo_t0,ar_Qc_t0,ar_kc\
    =pm.read_cell_parameters(file_in)

    #~~~~~~Change in parameters~~~~~~#
    #Multiplying factors for L, Ks, n_o and n_c
    if fac_L != 1.:
        print 'Change L'
        ar_L = ar_L * fac_L
    if fac_Ks != 1.:
        print 'Change Ks'
        ar_Ks = ar_Ks * fac_Ks
    if fac_n_o != 1.:
        print 'Change n_o'
        ar_n_o = ar_n_o * fac_n_o
    if fac_n_c != 1.:
        print 'Change n_c'
        ar_n_c = ar_n_c * fac_n_c
    #New values for pVs_t0, Vo_t0 and Qc_t0
    if new_pVs_t0 != ar_pVs_t0[0]:
        print 'Change pVs_t0'
        ar_pVs_t0 = ar_pVs_t0 * 0. + new_pVs_t0
    if new_Vo_t0 != ar_Vo_t0[0]:
        print 'Change pVs_t0'
        ar_Vo_t0 = ar_Vo_t0 * 0. + new_Vo_t0
    if new_Qc_t0 != ar_Qc_t0[0]:
        print 'Change pVc_t0'
        ar_Qc_t0 = ar_Qc_t0 * 0. + new_Qc_t0

    #~~~~~~Write parameter file~~~~~~#
    tab_param = np.zeros((len(ar_cell_label), nb_param))
    tab_param[:, 0] = ar_cell_label
    tab_param[:, 1] = ar_coorx
    tab_param[:, 2] = ar_coory
    tab_param[:, 3] = ar_lambda
    tab_param[:, 4] = ar_Xc
    tab_param[:, 5] = ar_dam
    tab_param[:, 6] = ar_tan_beta
    tab_param[:, 7] = ar_tan_beta_channel
    tab_param[:, 8] = ar_L
    tab_param[:, 9] = ar_Ks
    tab_param[:, 10] = ar_theta_r
    tab_param[:, 11] = ar_theta_s
    tab_param[:, 12] = ar_n_o
    tab_param[:, 13] = ar_n_c
    tab_param[:, 14] = ar_cell_down
    tab_param[:, 15] = ar_pVs_t0
    tab_param[:, 16] = ar_Vo_t0
    tab_param[:, 17] = ar_Qc_t0
    tab_param[:, 18] = ar_kc

    np.savetxt(file_out, tab_param)
Exemplo n.º 14
0
def zero_slope_management(ini_file='zero_slope_management.ini'):
    """Fix zero slopes

    Correct the cell and channel slopes to avoid situations with zero
    slopes. Water cannot drain downstream in these cases and the ODE's
    fail.

    Parameters
    ----------
    ini_file : string
        The name and full path to an ini file containing the required
        configuration.

    Returns
    -------
    Nothing

    """

    ##================================##
    ##  Read the input file (*.ini)   ##
    ##================================##
    config.read(ini_file)
    print 'Read the file ', ini_file
    ##~~~~~~~~~~~ input files ~~~~~~~~~~~##
    #Param
    file_cell_param = config.get('input_files', 'file_cell_param')
    file_cell_param_out = config.get('output_files', 'file_cell_param_out')
    ##~~~~~~ numerical_values ~~~~~~##
    nb_param = config.getfloat('numerical_values', 'nb_param')
    X = config.getfloat('numerical_values', 'X')

    ##============================##
    ## Pretreatment of input data ##
    ##============================##
    print 'Pretreatment of input data'
    #~~~~Read Cell parameters file
    ar_cell_label, ar_coorx, ar_coory, \
    ar_lambda, ar_Xc, ar_dam, ar_tan_beta, \
    ar_tan_beta_channel, ar_L, ar_Ks, ar_theta_r, \
    ar_theta_s, ar_n_o, ar_n_c, ar_cell_down, ar_pVs_t0, ar_Vo_t0, \
    ar_Qc_t0, ar_kc, psi_b, lamda = pm.read_cell_parameters(file_cell_param)

    #~~~~Number of cell in the catchment
    nb_cell = len(ar_cell_label)
    #~~~~Computation of cell order
    ar_label_sort = pm.sort_cell(ar_cell_label, ar_cell_down)

    print 'Treatment of cell slopes'
    #Adjust the outlet slope if equal to zero
    if ar_tan_beta[ar_label_sort[-1]] == 0:
        ar_tan_beta[ar_label_sort[-1]] = 1. / X

    for cell1 in ar_label_sort:
        print cell1
        cell = np.where(ar_cell_label == cell1)[0][0]

        li_label_path = [cell]
        li_slope_path = [ar_tan_beta[cell]]

        down_cell = ar_cell_down[cell]

        # Extract the arrays of (i) all cells in the path
        # (ar_label_path) (ii) all corresponding slopes
        # (ar_slope_path)
        while down_cell > -1:
            li_label_path.append(down_cell)
            li_slope_path.append(ar_tan_beta[down_cell])
            down_cell = ar_cell_down[down_cell]
        ar_label_path = np.array(li_label_path)
        ar_slope_path = np.array(li_slope_path)

        # Go into the slope vector to detect the series of zero slopes
        # The method first consists of creating an array containing
        # the index of begining and end of zero series

        # Example: ar_slope_path=np.array([1, 2, 0, 0, 1, 0, 1, 0, 0, 0, 0])
        #--> ar_ind_start=array([2,5,7])
        #--> ar_ind_end=array([4,6,-1])
        li_ind_start = []
        li_ind_end = []
        #print len(ar_slope_path), np.where(ar_slope_path==0.)
        for i in np.arange(len(ar_slope_path)):
            if i == 0:
                if ar_slope_path[i] == 0.:
                    li_ind_start.append(i)
            elif i == np.arange(len(ar_slope_path))[-1]:
                if ar_slope_path[i] == 0. and ar_slope_path[i - 1] == 0.:
                    li_ind_end.append(-1)
                if ar_slope_path[i] != 0. and ar_slope_path[i - 1] == 0.:
                    li_ind_end.append(i)
            else:
                if ar_slope_path[i] == 0. and ar_slope_path[i - 1] != 0:
                    li_ind_start.append(i)
                if ar_slope_path[i] != 0. and ar_slope_path[i - 1] == 0.:
                    li_ind_end.append(i)
        ar_ind_start = np.array(li_ind_start, int)
        ar_ind_end = np.array(li_ind_end, int)
        if len(ar_ind_start) - len(ar_ind_end) != 0:
            print 'problem length'
            print 'ar_ind_start:', len(ar_ind_start), 'ar_ind_end:', len(
                ar_ind_end)
            print ar_ind_start
            print ar_ind_end
            stop
        a = ar_ind_end - ar_ind_start
        if len(np.where(a < 0)[0]) != 0:
            print 'problem index'
            stop

        #Then the slope are changed according to the defined index arrays
        if len(ar_ind_start) > 0:
            print 'Number of sections with zero slopes:', len(ar_ind_start)
        for i in np.arange(len(ar_ind_start)):
            #Compute the length of the zero path
            if ar_ind_end[i] != -1:
                length_path = ar_ind_end[i] - ar_ind_start[i]
            else:
                length_path = len(ar_slope_path) - ar_ind_start[i]
            #Compute the corresponding slope
            slope = 1. / (length_path * X)
            #Replace the values of slope in the initial ar_tan_beta
            #select the cell labels
            ar_label_cell_zero = ar_label_path[ar_ind_start[i]:ar_ind_end[i]]
            #select the cell index (if different from the label)
            ar_ind_cell_zero = np.array(ar_label_cell_zero, int)
            n = -1
            for label in ar_label_cell_zero:
                n = n + 1
                ind = np.where(ar_cell_label == label)[0][0]
                ar_ind_cell_zero[n] = ind

            #Change the values
            ar_tan_beta[ar_ind_cell_zero] = slope

    print 'Treatment of channel slopes'
    #Adjust the outlet slope if equal to zero
    if ar_tan_beta_channel[ar_label_sort[-1]] == 0:
        ar_tan_beta_channel[ar_label_sort[-1]] = 1. / X

    for cell1 in ar_label_sort:
        print cell1
        cell = np.where(ar_cell_label == cell1)[0][0]

        li_label_path = [cell]
        li_slope_path = [ar_tan_beta_channel[cell]]

        down_cell = ar_cell_down[cell]

        # Extract the arrays of (i) all cells in the path
        # (ar_label_path) (ii) all corresponding slopes
        # (ar_slope_path)
        while down_cell > -1:
            li_label_path.append(down_cell)
            li_slope_path.append(ar_tan_beta_channel[down_cell])
            down_cell = ar_cell_down[down_cell]
        ar_label_path = np.array(li_label_path)
        ar_slope_path = np.array(li_slope_path)

        # Go into the slope vector to detect the series of zero slopes
        # The method first consists of creating an array containing
        # the index of begining and end of zero series

        # Example: ar_slope_path=np.array([1, 2, 0, 0, 1, 0, 1, 0, 0, 0, 0])
        #--> ar_ind_start=array([2,5,7])
        #--> ar_ind_end=array([4,6,-1])
        li_ind_start = []
        li_ind_end = []
        #print len(ar_slope_path), np.where(ar_slope_path==0.)
        for i in np.arange(len(ar_slope_path)):
            if i == 0:
                if ar_slope_path[i] == 0.:
                    li_ind_start.append(i)
            elif i == np.arange(len(ar_slope_path))[-1]:
                if ar_slope_path[i] == 0. and ar_slope_path[i - 1] == 0.:
                    li_ind_end.append(-1)
                if ar_slope_path[i] != 0. and ar_slope_path[i - 1] == 0.:
                    li_ind_end.append(i)
            else:
                if ar_slope_path[i] == 0. and ar_slope_path[i - 1] != 0:
                    li_ind_start.append(i)
                if ar_slope_path[i] != 0. and ar_slope_path[i - 1] == 0.:
                    li_ind_end.append(i)
        ar_ind_start = np.array(li_ind_start, int)
        ar_ind_end = np.array(li_ind_end, int)
        if len(ar_ind_start) - len(ar_ind_end) != 0:
            print 'problem length'
            print 'ar_ind_start:', len(ar_ind_start), 'ar_ind_end:', len(
                ar_ind_end)
            print ar_ind_start
            print ar_ind_end
            stop
        a = ar_ind_end - ar_ind_start
        if len(np.where(a < 0)[0]) != 0:
            print 'problem index'
            stop

        # Then the slope are changed according to the defined index
        # arrays
        if len(ar_ind_start) > 0:
            print 'Number of sections with zero slopes:', len(ar_ind_start)
        for i in np.arange(len(ar_ind_start)):
            # Compute the length of the zero path
            if ar_ind_end[i] != -1:
                length_path = ar_ind_end[i] - ar_ind_start[i]
            else:
                length_path = len(ar_slope_path) - ar_ind_start[i]
            # Compute the corresponding slope
            slope = 1. / (length_path * X)
            # Replace the values of slope in the initial
            # ar_tan_beta_channel select the cell labels
            ar_label_cell_zero = ar_label_path[ar_ind_start[i]:ar_ind_end[i]]
            # Select the cell index (if different from the label)
            ar_ind_cell_zero = np.array(ar_label_cell_zero, int)
            n = -1
            for label in ar_label_cell_zero:
                n = n + 1
                ind = np.where(ar_cell_label == label)[0][0]
                ar_ind_cell_zero[n] = ind

            # Change the values
            ar_tan_beta_channel[ar_ind_cell_zero] = slope

    # Write parameter file
    param_table = np.zeros((len(ar_cell_label), nb_param))
    param_table[:, 0] = ar_cell_label
    param_table[:, 1] = ar_coorx
    param_table[:, 2] = ar_coory
    param_table[:, 3] = ar_lambda
    param_table[:, 4] = ar_Xc
    param_table[:, 5] = ar_dam
    param_table[:, 6] = ar_tan_beta
    param_table[:, 7] = ar_tan_beta_channel
    param_table[:, 8] = ar_L
    param_table[:, 9] = ar_Ks
    param_table[:, 10] = ar_theta_r
    param_table[:, 11] = ar_theta_s
    param_table[:, 12] = ar_n_o
    param_table[:, 13] = ar_n_c
    param_table[:, 14] = ar_cell_down
    param_table[:, 15] = ar_pVs_t0
    param_table[:, 16] = ar_Vo_t0
    param_table[:, 17] = ar_Qc_t0
    param_table[:, 18] = ar_kc
    param_table[:, 19] = psi_b
    param_table[:, 20] = lamda

    format = '%d %f %f %d %f %d %f %f %f %f %f %f %f %f %d %f %f %f %f %f %f'
    np.savetxt(file_cell_param_out, param_table, fmt=format)
Exemplo n.º 15
0
def subcatch(ini_file='subcatch.ini'):
    """
    Create a subcatchment parameter file.

    Extract a subcatchment parameter file from an existing parameter
    file by defining the location of the sub-catchment outlet. The
    closest channel cell to the given coordinates is selected by
    default, based on a nearest neighbour search.

    A new parameter file for the subcatchment is written and a plot of
    the full catchment showing the location of the derived
    subcatchment is also produced.

    Parameters
    ----------
    ini_file : string
        The name of the ini file that specifies the input and output files,
        coordinates of the subcatchment outlet, the number of parameters and
        the grid dimension.

    Returns
    -------
    Nothing

    Notes
    -----
    This function creates a parameter file where the cell numbering doesn't
    follow the conventional North to South and West to East ordering. The
    cells are labelled in order from the outlet to the most distant upstream
    cell.

    """
    config.read(ini_file)
    print 'Read the file ', ini_file

    file_in = config.get('file_in', 'file_in')

    file_out = config.get('file_out', 'file_out')

    picture_out = config.get('picture_out', 'picture_out')

    Xoutlet = config.getfloat('coord_outlet', 'Xoutlet')
    Youtlet = config.getfloat('coord_outlet', 'Youtlet')

    nb_param = config.getfloat('flags', 'nb_param')
    X = config.getfloat('flags', 'X')

    #Reading of parameter file
    print 'Reading parameter file'
    ar_cell_label, ar_coorx, ar_coory, ar_lambda, ar_Xc, ar_dam, ar_tan_beta, \
    ar_tan_beta_channel, ar_L, ar_Ks, ar_theta_r, ar_theta_s, ar_n_o, ar_n_c, \
    ar_cell_down, ar_pVs_t0, ar_Vo_t0, ar_Qc_t0, ar_kc \
    = pm.read_cell_parameters(file_in)

    #Search for the cell close to the coordinates
    print 'Search for the outlet cell'
    cell_outlet = find_cell_coordinates(ar_cell_label, Xoutlet, Youtlet,
                                        ar_coorx, ar_coory, ar_lambda)

    #Search for the catchment cells
    print 'Search for the catchment cells'
    subcatch_label = all_up_cell(cell_outlet, ar_cell_down, ar_cell_label)

    #Select the subcatchmnent parameters
    print 'Select the subcatchmnent parameters'
    tab_param = np.zeros((len(subcatch_label), nb_param))
    new_label = np.arange(len(subcatch_label))

    tab_param[:, 0] = new_label  #ar_cell_label[subcatch_label]
    tab_param[:, 1] = ar_coorx[subcatch_label]
    tab_param[:, 2] = ar_coory[subcatch_label]
    tab_param[:, 3] = ar_lambda[subcatch_label]
    tab_param[:, 4] = ar_Xc[subcatch_label]
    tab_param[:, 5] = ar_dam[subcatch_label]
    tab_param[:, 6] = ar_tan_beta[subcatch_label]
    tab_param[:, 7] = ar_tan_beta_channel[subcatch_label]
    tab_param[:, 8] = ar_L[subcatch_label]
    tab_param[:, 9] = ar_Ks[subcatch_label]
    tab_param[:, 10] = ar_theta_r[subcatch_label]
    tab_param[:, 11] = ar_theta_s[subcatch_label]
    tab_param[:, 12] = ar_n_o[subcatch_label]
    tab_param[:, 13] = ar_n_c[subcatch_label]
    for i in range(len(subcatch_label)):
        if i == 0:
            tab_param[i, 14] = -9999.0
        else:
            ind = np.where(ar_cell_label[subcatch_label] ==
                           ar_cell_down[subcatch_label][i])

            tab_param[i, 14] = new_label[ind]

    tab_param[:, 15] = ar_pVs_t0[subcatch_label]
    tab_param[:, 16] = ar_Vo_t0[subcatch_label]
    tab_param[:, 17] = ar_Qc_t0[subcatch_label]
    tab_param[:, 18] = ar_kc[subcatch_label]

    #~~~~~~Write parameter file~~~~~~#
    np.savetxt(file_out, tab_param)

    ar_image = ar_cell_label * 0.
    ar_image[subcatch_label] = 1.
    ar_image[ar_lambda == 1.] = 10.
    ar_image[cell_outlet] = 5.
    field_map(ar_image, ar_coorx, ar_coory, X, picture_out, 'Subcatchment')
Exemplo n.º 16
0

#if __name__ == '__main__':
##~~~~~~~~~~~ INPUTS FILES ~~~~~~~~~~~##
file_cell_param = 'E:/post_doc/liebenbergsvlei/topkapi_model_Oct07/parameters/cell_parameter/8D/slope_GIS_channel/cell_param_Vsi100.0_slope.dat'
file_global_param = 'E:/post_doc/liebenbergsvlei/topkapi_model_Oct07/parameters/global_parameter/global_param_Wmin5.0_Wmax40.0.dat'
path_out = 'E:/post_doc/liebenbergsvlei/topkapi_model_Oct07/parameters/cell_parameter/8D/slope_GIS_channel/'

#~~~~Read Global parameters file
X,Dt,alpha_s,alpha_o,alpha_c,A_thres,W_min,W_max\
  =pm.read_global_parameters(file_global_param)
#~~~~Read Cell parameters file
ar_cell_label,ar_coorx,ar_coory,ar_lambda,ar_Xc,ar_dam,ar_tan_beta,ar_tan_beta_channel,ar_L,ar_Ks,\
ar_theta_r,ar_theta_s,ar_n_o,ar_n_c,\
ar_cell_down,ar_pVs_t0,ar_Vo_t0,ar_Qc_t0,ar_kc\
    =pm.read_cell_parameters(file_cell_param)

#Lambda
image_out = path_out + 'field_lambda.png'
field_map(ar_lambda,
          ar_coorx,
          ar_coory,
          X,
          image_out,
          'Channel cells',
          max_val=max(ar_lambda))
#ar_Xc
image_out = path_out + 'field_Xc.png'
field_map(ar_Xc,
          ar_coorx,
          ar_coory,