Ejemplo n.º 1
0
#!/usr/local/anaconda/bin/python
''' This scripts prepares a xmask file for Lohmann routine, using consistant method as in the inverse routing method (i.e., using haversine formula) '''

import numpy as np
import argparse
import my_functions

parser = argparse.ArgumentParser()
parser.add_argument("--cfg", type=str, help="config file for this script")
args = parser.parse_args()
cfg = my_functions.read_config(args.cfg)

#========================================================#
# Calculate xmask (i.e., flow distance)
#========================================================#
flow_distance = my_functions.generate_xmask_for_route(
    cfg['INPUT']['fdir_path'])

#========================================================#
# Write to file
#========================================================#
f = open(cfg['OUTPUT']['output_xmask_path'], 'w')
#--- Write header lines (copy from flow direction file) ---#
f_fdir = open(cfg['INPUT']['fdir_path'], 'r')
for i in range(6):
    line = f_fdir.readline().rstrip("\n")  # read from flow direction file
    f.write(line + "\n")
f_fdir.close()
#--- Write xmask values ---#
for i in range(len(flow_distance)):
    for j in range(len(flow_distance[0])):
#!/usr/local/anaconda/bin/python

''' This script reads in VIC output and convert to initial runoff field guess for inverse routing input '''

import numpy as np
import pandas as pd
import datetime as dt
import argparse
import my_functions

parser = argparse.ArgumentParser()
parser.add_argument("--cfg", type=str,  help="config file for this script")
args = parser.parse_args()
cfg = my_functions.read_config(args.cfg)

start_date = dt.datetime(cfg['PARAM']['start_date'][0], \
                         cfg['PARAM']['start_date'][1], \
                         cfg['PARAM']['start_date'][2])
end_date = dt.datetime(cfg['PARAM']['end_date'][0], \
                         cfg['PARAM']['end_date'][1], \
                         cfg['PARAM']['end_date'][2])

#=====================================================#
# Read in flow direction file
#=====================================================#
#----- Read header file -----#
ncols, nrows, xllcorner, yllcorner, cellsize, NODATA_value = \
    my_functions.read_GIS_ascii_header(cfg['INPUT']['fdir_header_path'])
#----- Read flow direction file -----#
fdir = np.loadtxt(cfg['INPUT']['fdir_path'], dtype=int)
Ejemplo n.º 3
0
#!/usr/local/anaconda/bin/python

# This script generates a flow and an energy file (in the format of RBM input)

import numpy as np
import sys
import datetime as dt
import pandas as pd
import xray
import gc
import my_functions

cfg = my_functions.read_config(sys.argv[1])  # Read config file

#====================================================#
# Parameter loading from config file
#====================================================#
# [INPUT]
# Routing station file - output from 'prepare_RBM_param.py'
route_station_file = cfg['INPUT']['route_station_file']
# VIC output nc file - energy
vic_output_energy_nc = cfg['INPUT']['vic_output_energy_nc']

# [RBM_OPTIONS]
# RBM start and end date (dt.date)
start_date = dt.date(cfg['RBM_OPTIONS']['start_date'][0], \
                         cfg['RBM_OPTIONS']['start_date'][1], \
                         cfg['RBM_OPTIONS']['start_date'][2])
end_date = dt.date(cfg['RBM_OPTIONS']['end_date'][0], \
                         cfg['RBM_OPTIONS']['end_date'][1], \
                         cfg['RBM_OPTIONS']['end_date'][2])
Ejemplo n.º 4
0
#!/usr/local/anaconda/bin/python

# This script generates a flow and an energy file (in the format of RBM input)

import numpy as np
import sys
import datetime as dt
import pandas as pd
import xray
import gc
import my_functions

cfg = my_functions.read_config(sys.argv[1])  # Read config file

#====================================================#
# Parameter loading from config file
#====================================================#
# [INPUT]
# Routing station file - output from 'prepare_RBM_param.py'
route_station_file = cfg['INPUT']['route_station_file']
# VIC output nc file - energy
vic_output_energy_nc = cfg['INPUT']['vic_output_energy_nc']

# [RBM_OPTIONS]
# RBM start and end date (dt.date)
start_date = dt.date(cfg['RBM_OPTIONS']['start_date'][0], \
                         cfg['RBM_OPTIONS']['start_date'][1], \
                         cfg['RBM_OPTIONS']['start_date'][2])
end_date = dt.date(cfg['RBM_OPTIONS']['end_date'][0], \
                         cfg['RBM_OPTIONS']['end_date'][1], \
                         cfg['RBM_OPTIONS']['end_date'][2])
Ejemplo n.º 5
0
#!/usr/local/anaconda/bin/python

import sys
import numpy as np
import xray
import datetime as dt
import pandas as pd
import matplotlib.pyplot as plt
import os
import my_functions

# Read in config file
cfg = my_functions.read_config(sys.argv[1])

# Process dates
start_date_to_run = dt.datetime(cfg['PARAM']['start_date_to_run'][0], \
                                cfg['PARAM']['start_date_to_run'][1], \
                                cfg['PARAM']['start_date_to_run'][2], 12, 0)
end_date_to_run = dt.datetime(cfg['PARAM']['end_date_to_run'][0], \
                              cfg['PARAM']['end_date_to_run'][1], \
                              cfg['PARAM']['end_date_to_run'][2], 12, 0)

#====================================================================#
# Load dam information and network information
#====================================================================#
#=== Load dam info ===#
df_dam_info = pd.read_csv(cfg['DAM_INFO']['dam_info_csv'])
#=== Load network info ===@
ds_network = xray.open_dataset(cfg['NETWORK']['route_nc'])
da_flowdir = ds_network['Flow_Direction']
da_flowdis = ds_network['Flow_Distance']