Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ConfSoilMoisture.py and some edits in Variable.py and ilamblib.py #44

Draft
wants to merge 18 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 80 additions & 6 deletions bin/ilamb-run
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,11 @@ def InitializeModels(model_root,models=[],verbose=False,filter="",regex="",model
if log: logger.debug("[%s]" % mname,format_exc())
continue
M.append(m)

max_model_name_len = max(max_model_name_len,len(mname))
break
M = sorted(M,key=lambda m: m.name.upper())

# assign unique colors
clrs = il.GenerateDistinctColors(len(M))
for m in M:
Expand Down Expand Up @@ -248,6 +249,68 @@ def MatchRelationshipConfrontation(C):
found = True
return C

def MatchSensitivityConfrontation(C):
# YW
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove the #YW comments here. Your name will be associated with this PR and thus we will always know who to blame :D

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

"""Match sensitivity strings to confrontation longnames

We allow for sensitivity maps to be studied by specifying the
sensitivity longname in the configure file. This routine loops
over all defined sensitivity maps and finds the matching
confrontation.

Parameters
----------
C : list of ILAMB.Confrontation.Confrontation
the confrontation list

Returns
-------
C : list of ILAMB.Confrontation.Confrontation
the same list with sensitivity maps linked to confrontations.
"""
for c in C:
if not hasattr(c, "sensitivities"): continue
if c.sensitivities is None: continue
for i,longname in enumerate(c.sensitivities):
found = False
for cor in C:
if longname.lower() == cor.longname.lower():
c.sensitivities[i] = cor
found = True
return C

"""
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove these lines, thanks for noticing that the function isn't needed. It seems like I got rid of it at some point.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

# YW: Appears to duplicate MatchRelationshipConfrontation
def MatchConfrontation(C):
""" """Match relationship strings to confrontation longnames

We allow for relationships to be studied by specifying the
confrontation longname in the configure file. This routine loops
over all defined relationships and finds the matching
confrontation. (NOTE: this really belongs inside the Scoreboard
object)

Parameters
----------
C : list of ILAMB.Confrontation.Confrontation
the confrontation list

Returns
-------
C : list of ILAMB.Confrontation.Confrontation
the same list with relationships linked to confrontations
""" """
for c in C:
if c.relationships is None: continue
for i,longname in enumerate(c.relationships):
found = False
for cor in C:
if longname.lower() == cor.longname.lower():
c.relationships[i] = cor
found = True
return C
"""

def FilterConfrontationList(C,match_list):
"""Filter the confrontation list

Expand Down Expand Up @@ -303,8 +366,8 @@ def BuildLocalWorkList(M,C,skip_cache=False):
for c in C:
for m in M:
if skip_cache:
# if we want to skip we have to check that it is complete

# if we want to skip we have to check that it is complete
fname = os.path.join(c.output_path,"%s_%s.nc" % (c.name,m.name))
complete = False
if os.path.isfile(fname):
Expand Down Expand Up @@ -346,6 +409,7 @@ def BuildLocalWorkList(M,C,skip_cache=False):

return localW


def WorkConfront(W,verbose=False,clean=False):
"""Performs the confrontation analysis

Expand Down Expand Up @@ -378,7 +442,7 @@ def WorkConfront(W,verbose=False,clean=False):

# try to run the confrontation
try:
t0 = time.time()
t0 = time.time()
c.confront(m)
dt = time.time()-t0
proc[rank] += dt
Expand All @@ -393,7 +457,8 @@ def WorkConfront(W,verbose=False,clean=False):
logger.debug("[%s][%s]\n%s" % (c.longname,m.name,format_exc()))
if verbose:
print((" {0:>%d} {1:<%d} %s%s%s" % (maxCL,maxML,FAIL,ex.__class__.__name__,ENDC)).format(c.longname,m.name))



def WorkPost(M,C,W,S,verbose=False,skip_plots=False):
"""Performs the post-processing

Expand Down Expand Up @@ -428,6 +493,9 @@ def WorkPost(M,C,W,S,verbose=False,skip_plots=False):
proc[rank] += dt
if verbose:
dt = datetime.timedelta(seconds=max(1,int(np.round(dt))))
print((" {0:>%d} {1:<%d} %sCompleted%s {2:>8}" % (maxCL,maxML,OK,ENDC)).format(c.longname,m.name,str(dt)))


print((" {0:>%d} {1:<%d} %sCompleted%s {2:>8}" % (maxCL,maxML,OK,ENDC)).format(c.longname,m.name,str(dt)))
sys.stdout.flush()
except Exception as ex:
Expand All @@ -438,7 +506,7 @@ def WorkPost(M,C,W,S,verbose=False,skip_plots=False):
sys.stdout.flush()

sys.stdout.flush(); comm.Barrier()

for i,c in enumerate(C):
try:
c.compositePlots()
Expand Down Expand Up @@ -487,6 +555,7 @@ class MPIFileHandler(logging.FileHandler):

def _open(self):
stream = MPI.File.Open( self.comm, self.baseFilename, self.mode )

stream.Set_atomicity(True)
return stream

Expand Down Expand Up @@ -611,6 +680,7 @@ if args.model_setup is None:
models_path=args.build_dir[0])
else:
M = ParseModelSetup(args.model_setup[0],args.models,not args.quiet,filter=args.filter[0],models_path=args.build_dir[0])

if rank == 0 and not args.quiet: print("\nParsing config file %s...\n" % args.config[0])
S = Scoreboard(args.config[0],
regions = args.regions,
Expand All @@ -622,7 +692,10 @@ S = Scoreboard(args.config[0],
mem_per_pair = args.mem_per_pair,
run_title = args.run_title,
rmse_score_basis = args.rmse_score_basis)

C = MatchRelationshipConfrontation(S.list())
C = MatchSensitivityConfrontation(C)

if len(args.study_limits) == 2:
args.study_limits[1] += 1
for c in C: c.study_limits = (np.asarray(args.study_limits)-1850)*365.
Expand Down Expand Up @@ -662,6 +735,7 @@ if rank==0 and not args.quiet: print("\nRunning model-confrontation pairs...\n")
sys.stdout.flush(); comm.Barrier()

W = BuildLocalWorkList(M,C,skip_cache=True)

WorkConfront(W,not args.quiet,args.clean)

sys.stdout.flush(); comm.Barrier()
Expand Down
2 changes: 1 addition & 1 deletion src/ILAMB/ConfAlbedo.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class ConfAlbedo(Confrontation):
def __init__(self,**keywords):
super(ConfAlbedo,self).__init__(**keywords)
self.derived = "rsus / rsds"

def stageData(self,m):

energy_threshold = float(self.keywords.get("energy_threshold",10))
Expand Down
7 changes: 6 additions & 1 deletion src/ILAMB/ConfIOMB.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,12 @@ def stageData(self,m):
# part of the expression to look at the time
info = ""
possible = [self.variable,] + self.alternate_vars
if self.derived is not None: possible += [str(s) for s in sympify(self.derived).free_symbols]
if self.derived is not None:
if isinstance(self.derived, list):
for dr in self.derived:
possible += [str(s) for s in sympify(dr).free_symbols]
else:
possible += [str(s) for s in sympify(self.derived).free_symbols]
vname = [v for v in possible if v in m.variables.keys()]
if len(vname) == 0:
logger.debug("[%s] Could not find [%s] in the model results" % (self.name,",".join(possible)))
Expand Down
8 changes: 6 additions & 2 deletions src/ILAMB/ConfNBP.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
import numpy as np
import os,glob

def SpaceLabels(y,ymin,maxit=1000):
def SpaceLabels(y,ymin,maxit=1000):
if len(y) == 1:
return y

for j in range(maxit):
dy = np.diff(y)
for i in range(1,y.size-1):
Expand Down Expand Up @@ -267,13 +270,14 @@ def NBPplot(V,vmin,vmax,colors,fname):
Y = np.asarray(Y); L = np.asarray(L)
ind = np.argsort(Y)
Y = Y[ind]; L = L[ind]

fig = plt.figure(figsize=(11.8,5.8))
ax = fig.add_subplot(1,1,1,position=[0.06,0.06,0.8,0.92])
data_range = vmax-vmin
fig_height = fig.get_figheight()
font_size = 10
dy = 0.05*data_range

y = SpaceLabels(Y.copy(),data_range/fig_height*font_size/50.)
v = V["Benchmark"]
for i in range(L.size):
Expand Down
Loading