Skip to content

Commit

Permalink
Fixed Bug related to BasinNames
Browse files Browse the repository at this point in the history
  • Loading branch information
Li authored and Li committed Jan 8, 2018
1 parent f4e9cf6 commit 5024d67
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 14 deletions.
27 changes: 16 additions & 11 deletions demeter_w/DataReader/GCAMSupport.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ def proc_pop(infile, outfile_tot):
pop_tot = {}

for region in poptbl.keys():
stderr.write('[proc_pop]: processing region: %s\n' % region)
#stderr.write('[proc_pop]: processing region: %s\n' % region)
popvals = poptbl[region].split(',')
#benchmark = _gis2000[region]
#fpop = map(lambda x: str(1000*float(x)/benchmark), popvals)
Expand Down Expand Up @@ -273,8 +273,8 @@ def proc_wdlivestock(infilename, outfilename, rgnTotalFilename):
## read header line
fields = GCAMutil.rm_trailing_comma(infile.readline()).split(',')
nyear = len(fields) - 5
stdout.write('[proc_wdlivestock]: years: %s\n'%str(fields[4:-1]))
stdout.write('[proc_wdlivestock]: nyear: %d\n'%nyear)
#stdout.write('[proc_wdlivestock]: years: %s\n'%str(fields[4:-1]))
#stdout.write('[proc_wdlivestock]: nyear: %d\n'%nyear)

for line in infile:
line = GCAMutil.rm_trailing_comma(GCAMutil.scenariofix(line))
Expand Down Expand Up @@ -346,11 +346,16 @@ def proc_wdlivestock(infilename, outfilename, rgnTotalFilename):
try:
total_wd[region] = map(lambda tb,sh,pt,pg: tb+sh+pt+pg, total_bovine, sheepgoat, poultry[region], pig[region])
except TypeError:
stderr.write('[proc_wdlivestock]: bad table data for region = %s.\n' % region)
stderr.write('\ttotal_bovine: %s\n' % str(total_bovine))
stderr.write('\tsheepgoat: %s\n' % str(sheepgoat))
stderr.write('\tpoultry: %s\n' % str(poultry[region]))
stderr.write('\tpig: %s\n' % str(pig[region]))
# stderr.write('[proc_wdlivestock]: bad table data for region = %s.\n' % region)
# stderr.write('\ttotal_bovine: %s\n' % str(total_bovine))
# stderr.write('\tsheepgoat: %s\n' % str(sheepgoat))
# stderr.write('\tpoultry: %s\n' % str(poultry[region]))
# stderr.write('\tpig: %s\n' % str(pig[region]))
print('[proc_wdlivestock]: bad table data for region = %s.\n' % region)
print('\ttotal_bovine: %s\n' % str(total_bovine))
print('\tsheepgoat: %s\n' % str(sheepgoat))
print('\tpoultry: %s\n' % str(poultry[region]))
print('\tpig: %s\n' % str(pig[region]))
raise

## end of loop over regions
Expand Down Expand Up @@ -470,7 +475,7 @@ def proc_irr_share(infilename, outfile):
## end of file read

## We need to output this data, as well as using it for other calculations
stdout.write('irr share outfile: %s\n' % outfile)
#stdout.write('irr share outfile: %s\n' % outfile)
with open(outfile,"w") as outfile:
for region in _regions_ordered:
for aez in range(1,19):
Expand Down Expand Up @@ -533,7 +538,7 @@ def proc_ag_area(infilename, outfilename):
outfile.write(','.join(map(str,data)))
outfile.write('\n')

stdout.write('[proc_ag_area]: gcam_irr = %s\n' % gcam_irr)
#stdout.write('[proc_ag_area]: gcam_irr = %s\n' % gcam_irr)
return gcam_irr
## done with proc_ag_area

Expand Down Expand Up @@ -662,7 +667,7 @@ def proc_irr_area(infilename, outfilename):
outfile.write(','.join(map(str,data)))
outfile.write('\n')

stdout.write('[proc_irr_area]: gcam_irr = %s\n' % gcam_irr)
#stdout.write('[proc_irr_area]: gcam_irr = %s\n' % gcam_irr)
return gcam_irr

def read_gcam_irr_area(infilename):
Expand Down
8 changes: 8 additions & 0 deletions demeter_w/DataReader/GISReader.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,14 @@ def load_const_griddata(fn, headerNum=0, key=" "):
sys.exit(1)

data = GetArrayCSV(fn, headerNum)
all_zeros = not np.any(data)
if all_zeros:
try:
with open(fn, 'r') as f:
data = np.array(f.read().splitlines())
except:
pass


elif fn.endswith('.nc'):
if not os.path.isfile(fn):
Expand Down
6 changes: 5 additions & 1 deletion demeter_w/Utils/DataParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
def GetArrayCSV(filename, headerNum):
try:
f = open(filename, "rU")
data = numpy.genfromtxt(f, delimiter=",", skip_header=headerNum, filling_values="0")
a = numpy.__version__
if int(a.split('.')[1])>= 10:
data = numpy.genfromtxt(f, delimiter=",", skip_header=headerNum, filling_values="0")
else:
data = numpy.genfromtxt(f, delimiter=",", skiprows=headerNum, filling_values="0")
return data
f.close()
except IOError:
Expand Down
Git LFS file not shown

0 comments on commit 5024d67

Please sign in to comment.