Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
lee1043 committed Nov 28, 2017
1 parent c44b1d9 commit 78920fc
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 45 deletions.
19 changes: 8 additions & 11 deletions src/python/devel/mean_climate_maps/lib/plot_map_4panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,22 +133,20 @@ def plot_4panel(canvas,
plot_title.string = '['+units+']'
plot_title.height = 17

plot_title.x = .90
plot_title.x = .5
plot_title.y = .49
canvas.plot(plot_title) # next to top colorbar

plot_title.x = .90
plot_title.x = .5
plot_title.y = .075
canvas.plot(plot_title) # next to bottom colorbar

# Logos ---
# PCMDI
#logo2 = vcs.utils.Logo('/work/lee1043/cdat/pmp/mean_climate_maps/lib/160915_PCMDI_logo-oblong_377x300px.png')
logo2 = vcs.utils.Logo('/work/lee1043/cdat/pmp/mean_climate_maps/lib/PCMDILogo_200x65px_72dpi.png')
#logo2.x = .06
logo2 = vcs.utils.Logo('../../../../../share/pcmdi/PCMDILogo_200x65px_72dpi.png')
logo2.x = .9
#logo2.y = .03
logo2.y = .96
logo2.y = .04
#logo2.y = .96
#logo2.width = logo2.source_width * .3
#logo2.height = logo2.source_height * .3
logo2.width = logo2.source_width
Expand All @@ -164,13 +162,12 @@ def plot_4panel(canvas,
#logo3.plot(canvas)

# New CDAT
logo_CDAT = vcs.utils.Logo('../lib/171101_doutriaux1_CDATLogo_1707x878px-300dpi.jpg')
logo_CDAT = vcs.utils.Logo('../../../../../share/pcmdi/CDATLogo_200x70px_72dpi.png')
logo_CDAT.x = .06
logo_CDAT.y = .018
logo_CDAT.width = logo_CDAT.source_width * .08
logo_CDAT.height = logo_CDAT.source_height * .08
logo_CDAT.width = logo_CDAT.source_width
logo_CDAT.height = logo_CDAT.source_height
logo_CDAT.plot(canvas)


#-------------------------------------------------
# Drop output as image file (--- vector image?)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import vcs
import cdms2, cdutil
import cdms2, cdutil, genutil
import MV2
import sys,os
import json
Expand All @@ -9,14 +9,46 @@
import EzTemplate
import collections

#debug = True
debug = False
#----------------------------------------------------------------------------
def remove_zonal_mean(d):
d_zm = cdutil.averager(d,axis='x')
d,d_zm = genutil.grower(d,d_zm) # Matching dimension for subtraction
d = MV2.subtract(d, d_zm)
return d

def remove_annual_mean(ds, d):
d_am = cdutil.YEAR.climatology(d)
ds = MV2.subtract(ds, d_am)
return ds
#----------------------------------------------------------------------------
debug = True
#debug = False

#OgridAsCommon = True
OgridAsCommon = False # In case if OBS has higher resolution than models AND all models already have been processed to have same grid

#----------------------------------------------------------------------------
option = 1

if option == 1:
RemoveZonalMean = False
RemoveAnnualMean = False
odir = 'clim'
elif option == 2:
RemoveZonalMean = True
RemoveAnnualMean = False
odir = 'climmzm'
elif option == 3:
RemoveZonalMean = False
RemoveAnnualMean = True
odir = 'climmtm'

#----------------------------------------------------------------------------

era = 'cmip5'
exp = 'historical'
#exp = 'amip'
#exp = 'picontrol'

m = 'crunchy'

Expand All @@ -28,6 +60,7 @@

#plots_outdir = '/work/gleckler1/processed_data/clim_plots/'
plots_outdir = '/work/lee1043/cdat/pmp/clim_plots/' ## FOR TEST -jwlee
plots_outdir = './test'

# Load the obs dictionary
#fjson = open(
Expand All @@ -36,7 +69,7 @@
# "share",
# "pmp",
# "obs_info_dictionary.json"))
fjson = open('/export_backup/lee1043/git/pcmdi_metrics/doc/obs_info_dictionary.json') ## FOR TEST -jwlee
fjson = open('/export_backup/lee1043/git/pcmdi_metrics_master/pcmdi_metrics/doc/obs_info_dictionary.json') ## FOR TEST -jwlee
obs_dic = json.loads(fjson.read())
fjson.close()

Expand All @@ -48,6 +81,7 @@
# MOD path
mpathin = '/work/gleckler1/processed_data/metrics_package/interpolated_model_clims_historical/global/cmip5.MOD.historical.r1i1p1.mo.Amon.VAR.ver-1.1980-2005.interpolated.linear.2.5x2.5.global.AC.nc'

#----------------------------------------------------------------------------
# Log file
import datetime
now = datetime.datetime.now()
Expand All @@ -63,7 +97,7 @@
for sub in subs:
po = po + '/' + sub
try:
os.mkdir(po)
os.makedirs(po)
except:
pass

Expand All @@ -86,6 +120,7 @@
'colormap': 'band_12', # 'default_1', 'dvbluered'
'colormap_diff': 'band_6', # 'bl_to_darkred'
'isofill': 'AMIP_pr',
'isofill_mzm': 'pr_anom1_bw1',
'isofill_diff': 'pr_anom1_bw1', ## BUT, HARD-CODED!!
},
'prw': {
Expand All @@ -96,6 +131,7 @@
'colormap': 'band_12', # 'default_1', 'dvbluered'
'colormap_diff': 'band_6', # 'bl_to_darkred'
'isofill': 'AMIP_prw',
'isofill_mzm': 'pr_anom1_bw1',
'isofill_diff': 'pr_anom1_bw1', ## BUT, HARD-CODED!!
},
'psl': {
Expand All @@ -106,6 +142,7 @@
'colormap': 'default_1', # 'dvbluered'
'colormap_diff': 'bl_to_darkred',
'isofill': 'AMIP_psl',
'isofill_mzm': 'AMIP_psldif',
'isofill_diff': 'AMIP_psldif',
},
'rltcre': {
Expand All @@ -116,6 +153,7 @@
'colormap': 'default_1', # 'dvbluered'
'colormap_diff': 'bl_to_darkred',
'isofill': 'rlt_clim', ## BUT, HARD-CODED!!
'isofill_mzm': 'AMIP_rlta',
'isofill_diff': 'AMIP_rlta',
},
'rlut': {
Expand All @@ -126,6 +164,7 @@
'colormap': 'default_1', # 'dvbluered'
'colormap_diff': 'bl_to_darkred',
'isofill': 'AMIP_rlt',
'isofill_mzm': 'AMIP_rlta',
'isofill_diff': 'AMIP_rlta',
},
'rstcre': {
Expand All @@ -136,6 +175,7 @@
'colormap': 'default_1', # 'dvbluered'
'colormap_diff': 'bl_to_darkred',
'isofill': 'AMIP_rls',
'isofill_mzm': 'AMIP_rlta',
'isofill_diff': 'AMIP_rlta',
},
'tas': {
Expand All @@ -146,6 +186,7 @@
'colormap': 'default_1', # 'band_8', 'default_1', 'dvbluered'
'colormap_diff': 'band_6', #'bl_to_darkred',
'isofill': 'AMIP_tas',
'isofill_mzm': 'AMIP_tasvar',
'isofill_diff': 'AMIP_tasvar', ## BUT, HARD-CODED!!
},
'ta-200': {
Expand All @@ -156,6 +197,7 @@
'colormap': 'default_1', # 'band_8', 'default_1', 'dvbluered'
'colormap_diff': 'band_6', #'bl_to_darkred',
'isofill': 'AMIP_ta200',
'isofill_mzm': 'AMIP_ta200var',
'isofill_diff': 'AMIP_ta200var', ## BUT, HARD-CODED!!
'level': 20000 # Pa
},
Expand All @@ -167,6 +209,7 @@
'colormap': 'default_1', # 'band_8', 'default_1', 'dvbluered'
'colormap_diff': 'band_6', #'bl_to_darkred',
'isofill': 'AMIP_ta850', ## BUT, HARD-CODED (because of bug in given levels: two 1e20s at the end..)
'isofill_mzm': 'AMIP_ta850var',
'isofill_diff': 'AMIP_ta850var', ## BUT, HARD-CODED!!
'level': 85000 # Pa
},
Expand All @@ -178,6 +221,7 @@
'colormap': 'default_1', # 'band_8', 'default_1', 'dvbluered'
'colormap_diff': 'band_6', #'bl_to_darkred',
'isofill': 'AMIP_u200',
'isofill_mzm': 'AMIP_u200var',
'isofill_diff': 'AMIP_u200var', ## BUT, HARD-CODED!!
'level': 20000 # Pa
},
Expand All @@ -189,6 +233,7 @@
'colormap': 'default_1', # 'band_8', 'default_1', 'dvbluered'
'colormap_diff': 'band_6', #'bl_to_darkred',
'isofill': 'AMIP_u850', ## BUT, HARD-CODED (because of bug in given levels: two 1e20s at the end..)
'isofill_mzm': 'AMIP_u850var',
'isofill_diff': 'AMIP_u200var', ## BUT, HARD-CODED!!
'level': 85000 # Pa
},
Expand All @@ -200,6 +245,7 @@
'colormap': 'default_1', # 'band_8', 'default_1', 'dvbluered'
'colormap_diff': 'band_6', #'bl_to_darkred',
'isofill': 'AMIP_v200',
'isofill_mzm': 'AMIP_v200var',
'isofill_diff': 'AMIP_v200var', ## BUT, HARD-CODED!!
'level': 20000 # Pa
},
Expand All @@ -211,6 +257,7 @@
'colormap': 'default_1', # 'band_8', 'default_1', 'dvbluered'
'colormap_diff': 'band_6', #'bl_to_darkred',
'isofill': 'AMIP_v850', ## BUT, HARD-CODED (because of bug in given levels: two 1e20s at the end..)
'isofill_mzm': 'AMIP_v850var',
'isofill_diff': 'AMIP_v200var', ## BUT, HARD-CODED!!
'level': 85000 # Pa
},
Expand All @@ -222,36 +269,26 @@
'colormap': 'default_1', # 'band_8', 'default_1', 'dvbluered'
'colormap_diff': 'band_6', #'bl_to_darkred',
'isofill': 'AMIP_zg500',
'isofill_mzm': 'AMIP_zg500var',
'isofill_diff': 'AMIP_zg500var', ## BUT, HARD-CODED!!?
'level': 50000 # Pa
},
}

vars = var_dic.keys()

#vars = ['pr','rlut','tas','rt']
#vars = ['tas']
#vars = ['rlut']
#vars = ['prw']
#vars = ['psl']
#vars = ['rltcre']
#vars = ['rstcre']
#vars = ['ta-200']
#vars = ['ta-850']
#vars = ['ua-200']
#vars = ['ua-850']
#vars = ['va-200', 'va-850']
vars = ['zg-500']
#vars = ['pr']
#vars = ['prw','psl']
#vars = ['rlut', 'rltcre', 'rstcre']
#vars = ['tas', 'ta-200', 'ta-850']
#vars = ['ua-200', 'ua-850', 'va-200', 'va-850']
#vars = ['zg-500']

seasons = ['djf', 'mam', 'jja', 'son']

if debug:
#vars = ['pr']
#vars = ['tas']
#vars = ['pr', 'tas']
#vars = ['rlt']
vars = ['pr']
seasons = ['djf']
#seasons = ['djf', 'mam', 'jja', 'son']

##################################################################################
# Open VCS canvas and load color maps
Expand All @@ -272,6 +309,11 @@
for var in vars:
var_long_name = var_dic[var]['var_long_name']

if RemoveZonalMean is True: var_long_name = var_long_name + ""

if RemoveZonalMean or RemoveAnnualMean:
var_dic[var]['isofill'] = var_dic[var]['isofill_mzm']

#==============================================================================
# Observation
#------------------------------------------------------------------------------
Expand All @@ -292,6 +334,8 @@
else:
do = fo(var, longitude=(0,360), latitude=(-90,90))

cdutil.setTimeBoundsMonthly(do)

fo.close()

# Missing data maskout (temporary, for special case: prw, RSS, no data over land nor ice)
Expand All @@ -302,16 +346,23 @@

ogrid = do.getGrid()

# Adjust Units
if var_dic[var]['units_adjust'][0]:
operator = var_dic[var]['units_adjust'][1]
number = var_dic[var]['units_adjust'][2]
do = getattr(MV2,operator)(do, number)

# Seasonal climatology of observation
obs = {}
for season in seasons:

obs[season] = pcmdi_metrics.pcmdi.seasonal_mean.compute(do,season)

# Adjust Units
if var_dic[var]['units_adjust'][0]:
operator = var_dic[var]['units_adjust'][1]
number = var_dic[var]['units_adjust'][2]
obs[season] = getattr(MV2,operator)(obs[season], number)
if RemoveZonalMean:
obs[season] = remove_zonal_mean(obs[season])

if RemoveAnnualMean:
obs[season] = remove_annual_mean(obs[season], do)

#==============================================================================
# Models
Expand All @@ -329,6 +380,7 @@

if debug:
mods = mods[0:3] # FOR TEST -jwlee
mods = mods[0:1] # FOR TEST -jwlee

# Dictionary for save fields
fld = {} # Model's climatology field
Expand Down Expand Up @@ -362,6 +414,12 @@
else:
dm = fm(var, longitude=(0,360), latitude=(-90,90))

# Adjust units
if var_dic[var]['units_adjust'][0]:
dm = getattr(MV2,operator)(dm, number)

cdutil.setTimeBoundsMonthly(dm)

fm.close()

#print 'calc', var, season, mod
Expand Down Expand Up @@ -390,9 +448,13 @@
# Seasonal climatology
fld[mod][season] = pcmdi_metrics.pcmdi.seasonal_mean.compute(dm,season)

# Adjust units
if var_dic[var]['units_adjust'][0]:
fld[mod][season] = getattr(MV2,operator)(fld[mod][season], number)
# Zonal Mean Remove?
if RemoveZonalMean:
fld[mod][season] = remove_zonal_mean(fld[mod][season])

# Annual Mean Remove?
if RemoveAnnualMean:
fld[mod][season] = remove_annual_mean(fld[mod][season], dm)

# Regrid to observational grid
fld_regrid = fld[mod][season].regrid(refgrid, regridTool='regrid2', mkCyclic=True)
Expand Down Expand Up @@ -420,9 +482,10 @@
#------------------------------------------------------------------------------
# Create 4 panel plots: model, obs, model-obs, mmm-obs
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
pout = plots_outdir + '/' + era + '/' + exp + '/' + '/clim/' + var
pout = plots_outdir + '/' + era + '/' + exp + '/' + odir + '/' + var

try:
os.mkdir(pout)
os.makedirs(pout)
except:
pass

Expand All @@ -435,11 +498,12 @@
time1 = time.time() # Time checker

plot_4panel(canvas,
var_dic,
var, var_long_name, units, season,
mod,
fld[mod][season], obs[season],
dif[mod][season], mmm_dif[season],
output_file_name)
output_file_name,option)

time2 = time.time() # Time checker
timec = time2 - time1
Expand Down

7 comments on commit 78920fc

@lee1043
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@durack1 code for mean plot updated

pr access1-0_djf

@durack1
Copy link
Collaborator

Choose a reason for hiding this comment

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

@lee1043 great, these look sharp to me!

Can you merge #519, so we have these files in all the installs?

@gleckler1
Copy link
Contributor

@gleckler1 gleckler1 commented on 78920fc Nov 28, 2017 via email

Choose a reason for hiding this comment

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

@lee1043
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@durack1 Have less idea how to merge branch to branch, so manually copied logo png files to this branch

@lee1043
Copy link
Contributor Author

@lee1043 lee1043 commented on 78920fc Nov 28, 2017

Choose a reason for hiding this comment

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

@gleckler1 diff maps are identical just because this is a test plot for checking how logos are looking (thus no iterating throughout all models). No worries.

@durack1
Copy link
Collaborator

Choose a reason for hiding this comment

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

@lee1043 if you can just point your browser to #519 and press the "Merge pull request" button down the bottom, that will pull these changes into master and voila!

@lee1043
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@durack1 Thanks, done.

Please sign in to comment.