3 from basic_plot_functions
import scatterMapFields
4 from copy
import deepcopy
6 import modelsp_utils
as modelUtils
9 initDate =
'2018041500'
10 mapCentralLongitude = 0.
12 imageFileExtension =
'png'
15 testVariables = [
'theta',
'qv',
'uReconstructZonal']
19 referenceCase =
'barycentric'
26 'weightMethod':
'barycentric',
30 'weightMethod':
'pbarycentric',
38 'weightMethod':
'unstinterp',
49 'directory':
'/glade/p/mmm/parc/liuz/pandac_common/120km_GFSANA',
53 'directory':
'/glade/p/mmm/parc/liuz/pandac_common/30km_GFSANA',
63 for meshName, conf
in meshConfigs.items():
64 gridFiles[meshName] = modelUtils.getGridFile(initDate,
65 conf[
'directory'], conf[
'nCells'],
67 meshLatDeg[meshName], meshLonDeg[meshName] = modelUtils.readGrid(gridFile=gridFiles[meshName])
68 meshLat[meshName] = meshLatDeg[meshName] * np.pi / 180.0
69 meshLon[meshName] = meshLonDeg[meshName] * np.pi / 180.0
72 'coarse': meshLonDeg[
'coarse'],
73 'fine': meshLonDeg[
'fine'],
76 'coarse': meshLatDeg[
'coarse'],
77 'fine': meshLatDeg[
'fine'],
102 for testVariable
in testVariables:
103 meshField[testVariable] = {}
104 for meshName, conf
in meshConfigs.items():
105 meshField[testVariable][meshName] = \
106 modelUtils.varRead(testVariable, gridFiles[meshName])[:,testLevel]
109 'coarse': meshField[testVariable][
'coarse']
112 print(
'Plotting coarse field: '+testVariable)
113 scatterMapFields(lons, lats, fields,
'original_coarse_'+testVariable+
'_l'+str(testLevel)+
'.'+imageFileExtension,
114 cLon = mapCentralLongitude,
115 markers = markers, sizes = sizes,
119 minAbsNormError[testVariable] = np.NaN
120 maxAbsNormError[testVariable] = np.NaN
122 minAbsError[testVariable] = np.NaN
123 maxAbsError[testVariable] = np.NaN
125 minBias[testVariable] = np.NaN
126 maxBias[testVariable] = np.NaN
129 absNormErrorFields = {}
132 for caseName, case
in weightCases.items():
133 weightMethod = case[
'weightMethod']
134 print(
'Testing caseName = '+caseName)
135 print(
'generating weights for interpolating from coarse to fine mesh')
137 nInterpPoints = case[
'nInterpPoints'],
138 weightMethod = weightMethod,
139 calculateDiagnostics =
True)
140 coarse2fine.initWeights(meshLon[
'fine'], meshLat[
'fine'])
142 print(
'generating weights for interpolating from fine to coarse mesh')
144 nInterpPoints = case[
'nInterpPoints'],
145 weightMethod = weightMethod,
146 calculateDiagnostics =
True)
147 fine2coarse.initWeights(meshLon[
'coarse'], meshLat[
'coarse'])
149 if 'barycentric' in caseName:
150 print(
'plotting barycentric combination used, triangle area, and determinant')
151 fields[
'coarse'] = fine2coarse.combinationUsed
152 scatterMapFields(lons, lats, fields, caseName+
'_combinationUsedCoarse.'+imageFileExtension,
153 cLon = mapCentralLongitude,
155 markers = markers, sizes = sizes,
158 fields[
'coarse'] = fine2coarse.triangleArea
159 scatterMapFields(lons, lats, fields, caseName+
'_triangleAreaCoarse.'+imageFileExtension,
160 cLon = mapCentralLongitude,
161 cmap =
'gist_rainbow',
162 markers = markers, sizes = sizes,
165 fields[
'coarse'] = fine2coarse.determinant
166 scatterMapFields(lons, lats, fields, caseName+
'_determinantCoarse.'+imageFileExtension,
167 cLon = mapCentralLongitude,
168 markers = markers, sizes = sizes,
171 fields[
'coarse'] = fine2coarse.ycoord
172 scatterMapFields(lons, lats, fields, caseName+
'_ycoordCoarse.'+imageFileExtension,
173 cLon = mapCentralLongitude,
174 markers = markers, sizes = sizes, cbarType =
'Log',
177 fields[
'coarse'] = fine2coarse.aspectRatio
178 scatterMapFields(lons, lats, fields, caseName+
'_aspectRatioCoarse.'+imageFileExtension,
179 cLon = mapCentralLongitude,
180 markers = markers, sizes = sizes,
185 fields[
'fine'] = coarse2fine.combinationUsed
186 scatterMapFields(lons, lats, fields, caseName+
'_combinationUsedFine.'+imageFileExtension,
187 cLon = mapCentralLongitude,
189 markers = markers, sizes = sizes,
192 fields[
'fine'] = coarse2fine.triangleArea
193 scatterMapFields(lons, lats, fields, caseName+
'_triangleAreaFine.'+imageFileExtension,
194 cLon = mapCentralLongitude,
195 cmap =
'gist_rainbow',
196 markers = markers, sizes = sizes,
199 fields[
'fine'] = coarse2fine.determinant
200 scatterMapFields(lons, lats, fields, caseName+
'_determinantFine.'+imageFileExtension,
201 cLon = mapCentralLongitude,
202 markers = markers, sizes = sizes,
205 fields[
'fine'] = coarse2fine.ycoord
206 scatterMapFields(lons, lats, fields, caseName+
'_ycoordFine.'+imageFileExtension,
207 cLon = mapCentralLongitude,
208 markers = markers, sizes = sizes, cbarType =
'Log',
211 fields[
'fine'] = coarse2fine.aspectRatio
212 scatterMapFields(lons, lats, fields, caseName+
'_aspectRatioFine.'+imageFileExtension,
213 cLon = mapCentralLongitude,
214 markers = markers, sizes = sizes,
219 absNormErrorFields[caseName] = {}
220 absErrorFields[caseName] = {}
221 biasFields[caseName] = {}
223 meanAbsNormError[caseName] = {}
224 meanAbsError[caseName] = {}
225 meanBias[caseName] = {}
228 for testVariable
in testVariables:
229 print(
'Interpolating and calculating errors for testVariable = '+testVariable)
230 coarse2fineField = coarse2fine.apply(meshField[testVariable][
'coarse'])
231 coarse2fine2coarseField = fine2coarse.apply(coarse2fineField)
241 absNormErrorFields[caseName][testVariable] = \
242 np.divide(np.abs(coarse2fine2coarseField - meshField[testVariable][
'coarse']), np.abs(meshField[testVariable][
'coarse']))
243 minAbsNormError_ = np.min(absNormErrorFields[caseName][testVariable])
244 maxAbsNormError_ = np.max(absNormErrorFields[caseName][testVariable])
245 print(minAbsNormError_, maxAbsNormError_)
246 minAbsNormError[testVariable] = np.nanmin([minAbsNormError_, minAbsNormError[testVariable]])
247 maxAbsNormError[testVariable] = np.nanmax([maxAbsNormError_, maxAbsNormError[testVariable]])
249 meanAbsNormError[caseName][testVariable] = np.nanmean(absNormErrorFields[caseName][testVariable])
251 absErrorFields[caseName][testVariable] = \
252 np.abs(coarse2fine2coarseField - meshField[testVariable][
'coarse'])
253 minAbsError_ = np.min(absErrorFields[caseName][testVariable])
254 maxAbsError_ = np.max(absErrorFields[caseName][testVariable])
255 print(minAbsError_, maxAbsError_)
256 minAbsError[testVariable] = np.nanmin([minAbsError_, minAbsError[testVariable]])
257 maxAbsError[testVariable] = np.nanmax([maxAbsError_, maxAbsError[testVariable]])
259 meanAbsError[caseName][testVariable] = np.nanmean(absErrorFields[caseName][testVariable])
261 biasFields[caseName][testVariable] = \
262 coarse2fine2coarseField - meshField[testVariable][
'coarse']
263 minBias_ = np.min(biasFields[caseName][testVariable])
264 maxBias_ = np.max(biasFields[caseName][testVariable])
265 print(minBias_, maxBias_)
266 minBias[testVariable] = np.nanmin([minBias_, minBias[testVariable]])
267 maxBias[testVariable] = np.nanmax([maxBias_, maxBias[testVariable]])
269 meanBias[caseName][testVariable] = np.nanmean(biasFields[caseName][testVariable])
271 print(
'meanAbsNormError = ', meanAbsNormError)
272 print(
'meanAbsError = ', meanAbsError)
273 print(
'meanBias = ', meanBias)
276 for caseName, case
in weightCases.items():
277 for testVariable
in testVariables:
278 print(
'Plotting error metrics for caseName = '+caseName+
' and testVariable = '+testVariable)
280 weightMethod = case[
'weightMethod']
281 fields[
'coarse'] = absNormErrorFields[caseName][testVariable]
282 scatterMapFields(lons, lats, fields, caseName+
'_NormalizedAbsError_coarse2fine2coarse_'+testVariable+
'_l'+str(testLevel)+
'.'+imageFileExtension,
283 cLon = mapCentralLongitude,
285 dmin = 1.e-8, dmax = 1.0,
286 cmap =
'gist_rainbow',
287 markers = markers, sizes = sizes, cbarType =
'Log',
291 fields[
'coarse'] = absErrorFields[caseName][testVariable]
292 scatterMapFields(lons, lats, fields, caseName+
'_AbsError_coarse2fine2coarse_'+testVariable+
'_l'+str(testLevel)+
'.'+imageFileExtension,
293 cLon = mapCentralLongitude,
294 dmin = minAbsError[testVariable], dmax = maxAbsError[testVariable],
295 cmap =
'gist_rainbow',
296 markers = markers, sizes = sizes, cbarType =
'Log',
300 dd = np.max([minBias[testVariable], maxBias[testVariable]])
301 fields[
'coarse'] = biasFields[caseName][testVariable]
302 scatterMapFields(lons, lats, fields, caseName+
'_Bias_coarse2fine2coarse_'+testVariable+
'_l'+str(testLevel)+
'.'+imageFileExtension,
303 cLon = mapCentralLongitude,
304 dmin = -dd, dmax = dd,
306 markers = markers, sizes = sizes, cbarType =
'SymLog',
310 if caseName != referenceCase:
311 fields[
'coarse'] = absNormErrorFields[caseName][testVariable] - absNormErrorFields[referenceCase][testVariable]
312 scatterMapFields(lons, lats, fields, caseName+
'-'+referenceCase+
'_NormalizedAbsError_coarse2fine2coarse_'+testVariable+
'_l'+str(testLevel)+
'.'+imageFileExtension,
313 cLon = mapCentralLongitude,
314 dmin = -0.1, dmax = 0.1,
316 markers = markers, sizes = sizes, cbarType =
'SymLog',
320 referenceAbsError = deepcopy(absErrorFields[referenceCase][testVariable])
321 referenceAbsError[referenceAbsError == 0.0] = 1.e-16*meshField[testVariable][
'coarse'][referenceAbsError == 0.0]
323 caseAbsError = deepcopy(absErrorFields[caseName][testVariable])
324 caseAbsError[caseAbsError == 0.0] = 1.e-16*meshField[testVariable][
'coarse'][caseAbsError == 0.0]
326 fields[
'coarse'] = np.divide(caseAbsError, referenceAbsError)
327 scatterMapFields(lons, lats, fields, caseName+
'DIV'+referenceCase+
'_AbsError_coarse2fine2coarse_'+testVariable+
'_l'+str(testLevel)+
'.'+imageFileExtension,
328 cLon = mapCentralLongitude,
329 dmin = 1.e-3, dmax = 1.e3,
331 markers = markers, sizes = sizes, cbarType =
'Log',
def scatterMapFields(lons, lats, fields, filename, minLon=-180., maxLon=180., minLat=-90., maxLat=90., cLon=None, projection='default', dmin=None, dmax=None, markers={}, sizes={}, cmap='gist_ncar', cbarType=None, c={}, logVLim=1.e-12)