Guest User

Untitled

a guest
Jun 20th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. # Start by storing model names in an array. This keeps order, but prolly not important
  2. models = [ 'casa', 'lpj', 'jules', 'middle_aged_glamour_model']
  3.  
  4. # The year list that you are going to loop over
  5. years = np.arange ( 1990, 2011 )
  6.  
  7. # Model variables for each model
  8. # You need to keep each list in the order they appear in the output. That's fairly important.
  9. model_var = { 'casa':[ 'doy','NEE', 'NPP'], 'lpj':['year', 'doy','NEE', "GPP"], \
  10. 'doy',middle_aged_glamour_model']=[ 'doy','you','dont','wanna_know'] }
  11. # Initialise the output "object". It's an empty dictionary
  12. # if you need multiple treatments, define two model outputs and add an extra external loop.
  13. model_outputs = {}
  14. for model in models: # loop over models
  15. model_outputs [ model ] = {}
  16. # The container will be a dictionary with keys given by model names. Nice for plot names and stuff
  17. for year in years: # loop over years
  18. # Each year is stored as its own key. If years are integers, else convert into integers
  19. model_outputs [ model ][ year ] = {} # empty dictionary again...
  20. retval = run_model ( model, year ) # Model run, retval is a tuple or an array or whatever
  21. i = 2 # retval [0] is year, retval[1] is doys, retval[2]... retval[N] is data arrays
  22. # Loop over model variables (remember they are in order?) and add dictionary entries
  23. for vari in model_var [ model ]:
  24. # now the entry in the dictionary is an array (usually of length 365) with the parameters
  25. # of interest. I am assuming that retval looks like this
  26. # retval = ( year, doy_arr, param1_arr, param2_arr, ... )
  27. # year is an integer
  28. # doy_arr is a numpy array of eg. int16
  29. # param1_arrX are arrays of the same shape as doy_arr storing the daily values of the parameters
  30. model_outputs[ model][year][vari] = retval[i]
  31. i = i + 1
  32. model_outputs[ model][year]['doy'] = retval[1]
  33.  
  34. # So you can look at the NPP from LPJ in 2004 as model_outputs['lpj'][2004]['NPP'], a numpy array
Add Comment
Please, Sign In to add comment