def getErrorFields(level, month, year, yearOffset, stash, latPnt=None, lonPnt=None):
"""this loads the relevant data to return an error field
Positional arguments:
level -- filed level number
month -- run month
year -- run year
yearOffset -- the '1860' initialisation date i.e. the offset to convert from naming year to actual year
stash -- the stash code. 101 for sea temp, 102 for salinity
latPnts -- optional arg for the lat grid point number to load
lonPnts -- optional arg for the lon grid point number to load
"""
analPath = '/project/decadal2/nrobin/ocean_anal/temp/' # path to data analysed with correlation alogrythm. Expects anomoly
truthPath = '/project/decadal2/haddi/HadGEM2/control/ocean/2_5deg/' # path to the 'truth' monthy averages (not anomoly)
truthClimatologyPath = '/project/decadal2/haddi/HadGEM2/control/ocean/climate/' # path to the 'truth' climatology(used with above to calc anomoly
truthLevel = I.load_raw(truthPath+str(stash)+'_'+str(year+yearOffset)+'%02d'%month+'.pp')[int(level)] # at all levels
if stash==101: # get the climatalogical average and analysed field for the correct variable
analAnomaly = I.load_cube(analPath+'pot_anal_'+str(year)+'%02d'%month+'%02d'%level+'.pp') # this also formats the relevant single digit integers to two digit strings
truthClimateLevel = I.load_raw(truthClimatologyPath+'pot_2334_2389_'+'%02d'%month+'.pp')[int(level)]
elif stash==102:
analAnomaly = I.load_cube(analPath+'sal_anal_'+str(year)+'%02d'%month+str(level)+'.pp') # this also formats the relevant single digit integers to two digit strings
truthClimateLevel = I.load_raw(truthClimatologyPath+'sal_2334_2389_'+'%02d'%month+'.pp')[int(level)]
else:
print "Not an appropriate stash number"
if latPnt!=None and lonPnt!=None:
thisAnalAnomaly = analAnomaly[latPnt][lonPnt]
truthAnomaly = imaths.subtract(truthLevel[latPnt][lonPnt], truthClimateLevel[latPnt][lonPnt]) # get the truth field expressed as an anomoly
errorField = imaths.subtract(thisAnalAnomaly, truthAnomaly) # calculates the difference between the anomalies
return [errorField, truthAnomaly, thisAnalAnomaly] # returns the error field
else:
truthAnomaly = imaths.subtract(truthLevel, truthClimateLevel) # get the truth field expressed as an anomoly
errorField = imaths.subtract(analAnomaly, truthAnomaly) # calculates the difference between the anomalies
return [errorField, truthAnomaly, analAnomaly] # returns the error fieldanalPath+'pot_anal_'+str(year)+'%02d'%month+'%02d'%level+'.pp''%spot_anal_%d%02d%02d.pp' % (analPath, year, month, level)'{}pot_anal_{}{:02d}{:02d}.pp'.format(analPath, year, month, level)thisAnalAnomaly.collapsed(['longitude', 'latitude'], analysis.MEAN)