According to the CF convention, lambert conformal projection can have one or two standard parallels. Iris seems to work fine with the case of two, but if there is only one standard parallel, the conversion to a cartopy crs fails in iris.coord_systems.as_cartopy_crs:799 with a tuple index out of range error.
Hi @larsbarring, thanks for taking the time to report this.
Would it be possible for you to provide an example, with traceback, and also mention the version of iris that you're using.
Thanks!
Hi @bjlittle @larsbarring ,
I reproduced the issue with the attached code. In lambert_test.zip you will find a minimal data file together with the program reproducing the error and the log from running it.
The traceback reads
Traceback (most recent call last):
File "./lambert_test.py", line 14, in <module>
main()
File "./lambert_test.py", line 10, in main
qplt.pcolormesh(c)
File "/home/sm_klazi/.conda/envs/esmvaltool/lib/python3.6/site-packages/iris/quickplot.py", line 241, in pcolormesh
result = iplt.pcolormesh(cube, *args, **kwargs)
File "/home/sm_klazi/.conda/envs/esmvaltool/lib/python3.6/site-packages/iris/plot.py", line 1041, in pcolormesh
result = _draw_2d_from_bounds('pcolormesh', cube, *args, **kwargs)
File "/home/sm_klazi/.conda/envs/esmvaltool/lib/python3.6/site-packages/iris/plot.py", line 267, in _draw_2d_from_bounds
cube, plot_defn, *args, **kwargs)
File "/home/sm_klazi/.conda/envs/esmvaltool/lib/python3.6/site-packages/iris/plot.py", line 744, in _map_common
kwargs)
File "/home/sm_klazi/.conda/envs/esmvaltool/lib/python3.6/site-packages/iris/plot.py", line 659, in _ensure_cartopy_axes_and_determine_kwargs
cartopy_proj = cs.as_cartopy_projection()
File "/home/sm_klazi/.conda/envs/esmvaltool/lib/python3.6/site-packages/iris/coord_systems.py", line 823, in as_cartopy_projection
return self.as_cartopy_crs()
File "/home/sm_klazi/.conda/envs/esmvaltool/lib/python3.6/site-packages/iris/coord_systems.py", line 799, in as_cartopy_crs
max_lat = lats[0] if abs(lats[0]) > abs(lats[1]) else lats[1]
IndexError: tuple index out of range
So it is a problem in converting the coordinate system to a cartopy crs, that manifests itself in iris.plot.
Cheers
Klaus
The LambertConformal coordinate system defined in iris is capable of being constructed with a single standard parallel (secant latitude) but the method to convert to cartopy CRS still assumes we have a 2-tuple. The check below is what is causing the exception:
The check is used when computing the sign of the cutoff for the projection. The check could be modified to choose max_lat = lats[0] if there is only 1 standard parallel, or use the current check if there are 2, for example:
if len(lats) == 2:
max_lat = lats[0] if abs(lats[0]) > abs(lats[1]) else lats[1]
else:
max_lat = lats[0]
Closed by #3231 pushed onto the 2.2.x branch.