Python iris NetCDF time gone awry

432 views Asked by At

Something seems to have gone wrong between yesterday and today. I’m wondering if you might be able to help? This is all running Python using iris.

Basically when I ran my code yesterday I got the first graph here, but today I get the second: enter image description here enter image description here

If I run just one of the CORDEX models (blue line) and one of the observed data (black) on their own, you can see they both run but the cordex model seems to have something funny going on with its time. enter image description here enter image description here

So I printed the time coordinates for each I get the following for the CORDEX model

DimCoord([netcdftime._netcdftime.DatetimeNoLeap(1989, 1, 16, 12, 0, 0, 0, 4, 16),
       netcdftime._netcdftime.DatetimeNoLeap(1989, 2, 15, 0, 0, 0, 0, 6, 46),
       netcdftime._netcdftime.DatetimeNoLeap(1989, 3, 16, 12, 0, 0, 0, 0, 75),
       netcdftime._netcdftime.DatetimeNoLeap(1989, 4, 16, 0, 0, 0, 0, 3, 106),
       netcdftime._netcdftime.DatetimeNoLeap(1989, 5, 16, 12, 0, 0, 0, 5, 136),
       netcdftime._netcdftime.DatetimeNoLeap(1989, 6, 16, 0, 0, 0, 0, 1, 167),
       netcdftime._netcdftime.DatetimeNoLeap(1989, 7, 16, 12, 0, 0, 0, 3, 197),
       netcdftime._netcdftime.DatetimeNoLeap(1989, 8, 16, 12, 0, 0, 0, 6, 228),
       netcdftime._netcdftime.DatetimeNoLeap(1989, 9, 16, 0, 0, 0, 0, 2, 259),
       netcdftime._netcdftime.DatetimeNoLeap(1989, 10, 16, 12, 0, 0, 0, 4, 289),
       netcdftime._netcdftime.DatetimeNoLeap(1989, 11, 16, 0, 0, 0, 0, 0, 320),
       netcdftime._netcdftime.DatetimeNoLeap(1989, 12, 16, 12, 0, 0, 0, 2, 350),
       netcdftime._netcdftime.DatetimeNoLeap(1990, 1, 16, 12, 0, 0, 0, 5, 16),
       netcdftime._netcdftime.DatetimeNoLeap(1990, 2, 15, 0, 0, 0, 0, 0, 46),
       netcdftime._netcdftime.DatetimeNoLeap(1990, 3, 16, 12, 0, 0, 0, 1, 75),
       netcdftime._netcdftime.DatetimeNoLeap(1990, 4, 16, 0, 0, 0, 0, 4, 106),
       netcdftime._netcdftime.DatetimeNoLeap(1990, 5, 16, 12, 0, 0, 0, 6, 136),
       netcdftime._netcdftime.DatetimeNoLeap(1990, 6, 16, 0, 0, 0, 0, 2, 167),
       netcdftime._netcdftime.DatetimeNoLeap(1990, 7, 16, 12, 0, 0, 0, 4, 197),
       netcdftime._netcdftime.DatetimeNoLeap(1990, 8, 16, 12, 0, 0, 0, 0, 228),
       netcdftime._netcdftime.DatetimeNoLeap(1990, 9, 16, 0, 0, 0, 0, 3, 259),
       netcdftime._netcdftime.DatetimeNoLeap(1990, 10, 16, 12, 0, 0, 0, 5, 289),
       netcdftime._netcdftime.DatetimeNoLeap(1990, 11, 16, 0, 0, 0, 0, 1, 320),
       netcdftime._netcdftime.DatetimeNoLeap(1990, 12, 16, 12, 0, 0, 0, 3, 350),
       netcdftime._netcdftime.DatetimeNoLeap(1991, 1, 16, 12, 0, 0, 0, 6, 16),
       netcdftime._netcdftime.DatetimeNoLeap(1991, 2, 15, 0, 0, 0, 0, 1, 46),
       netcdftime._netcdftime.DatetimeNoLeap(1991, 3, 16, 12, 0, 0, 0, 2, 75),
       netcdftime._netcdftime.DatetimeNoLeap(1991, 4, 16, 0, 0, 0, 0, 5, 106),
       netcdftime._netcdftime.DatetimeNoLeap(1991, 5, 16, 12, 0, 0, 0, 0, 136),
       netcdftime._netcdftime.DatetimeNoLeap(1991, 6, 16, 0, 0, 0, 0, 3, 167),
       netcdftime._netcdftime.DatetimeNoLeap(1991, 7, 16, 12, 0, 0, 0, 5, 197),
       netcdftime._netcdftime.DatetimeNoLeap(1991, 8, 16, 12, 0, 0, 0, 1, 228),
       netcdftime._netcdftime.DatetimeNoLeap(1991, 9, 16, 0, 0, 0, 0, 4, 259),
       netcdftime._netcdftime.DatetimeNoLeap(1991, 10, 16, 12, 0, 0, 0, 6, 289),
       netcdftime._netcdftime.DatetimeNoLeap(1991, 11, 16, 0, 0, 0, 0, 2, 320),
       netcdftime._netcdftime.DatetimeNoLeap(1991, 12, 16, 12, 0, 0, 0, 4, 350),
       netcdftime._netcdftime.DatetimeNoLeap(1992, 1, 16, 12, 0, 0, 0, 0, 16),
       netcdftime._netcdftime.DatetimeNoLeap(1992, 2, 15, 0, 0, 0, 0, 2, 46),
       netcdftime._netcdftime.DatetimeNoLeap(1992, 3, 16, 12, 0, 0, 0, 3, 75),
       netcdftime._netcdftime.DatetimeNoLeap(1992, 4, 16, 0, 0, 0, 0, 6, 106),
       netcdftime._netcdftime.DatetimeNoLeap(1992, 5, 16, 12, 0, 0, 0, 1, 136),
       netcdftime._netcdftime.DatetimeNoLeap(1992, 6, 16, 0, 0, 0, 0, 4, 167),
       netcdftime._netcdftime.DatetimeNoLeap(1992, 7, 16, 12, 0, 0, 0, 6, 197),
       netcdftime._netcdftime.DatetimeNoLeap(1992, 8, 16, 12, 0, 0, 0, 2, 228),
       netcdftime._netcdftime.DatetimeNoLeap(1992, 9, 16, 0, 0, 0, 0, 5, 259),
       netcdftime._netcdftime.DatetimeNoLeap(1992, 10, 16, 12, 0, 0, 0, 0, 289),
       netcdftime._netcdftime.DatetimeNoLeap(1992, 11, 16, 0, 0, 0, 0, 3, 320),
       netcdftime._netcdftime.DatetimeNoLeap(1992, 12, 16, 12, 0, 0, 0, 5, 350),
       netcdftime._netcdftime.DatetimeNoLeap(1993, 1, 16, 12, 0, 0, 0, 1, 16),
       netcdftime._netcdftime.DatetimeNoLeap(1993, 2, 15, 0, 0, 0, 0, 3, 46),
       netcdftime._netcdftime.DatetimeNoLeap(1993, 3, 16, 12, 0, 0, 0, 4, 75),
       netcdftime._netcdftime.DatetimeNoLeap(1993, 4, 16, 0, 0, 0, 0, 0, 106),
       netcdftime._netcdftime.DatetimeNoLeap(1993, 5, 16, 12, 0, 0, 0, 2, 136),
       netcdftime._netcdftime.DatetimeNoLeap(1993, 6, 16, 0, 0, 0, 0, 5, 167),
       netcdftime._netcdftime.DatetimeNoLeap(1993, 7, 16, 12, 0, 0, 0, 0, 197),
       netcdftime._netcdftime.DatetimeNoLeap(1993, 8, 16, 12, 0, 0, 0, 3, 228),
       netcdftime._netcdftime.DatetimeNoLeap(1993, 9, 16, 0, 0, 0, 0, 6, 259),
       netcdftime._netcdftime.DatetimeNoLeap(1993, 10, 16, 12, 0, 0, 0, 1, 289),
       netcdftime._netcdftime.DatetimeNoLeap(1993, 11, 16, 0, 0, 0, 0, 4, 320),
       netcdftime._netcdftime.DatetimeNoLeap(1993, 12, 16, 12, 0, 0, 0, 6, 350),
       netcdftime._netcdftime.DatetimeNoLeap(1994, 1, 16, 12, 0, 0, 0, 2, 16),
       netcdftime._netcdftime.DatetimeNoLeap(1994, 2, 15, 0, 0, 0, 0, 4, 46),
       netcdftime._netcdftime.DatetimeNoLeap(1994, 3, 16, 12, 0, 0, 0, 5, 75),
       netcdftime._netcdftime.DatetimeNoLeap(1994, 4, 16, 0, 0, 0, 0, 1, 106),
       netcdftime._netcdftime.DatetimeNoLeap(1994, 5, 16, 12, 0, 0, 0, 3, 136),
       netcdftime._netcdftime.DatetimeNoLeap(1994, 6, 16, 0, 0, 0, 0, 6, 167),
       netcdftime._netcdftime.DatetimeNoLeap(1994, 7, 16, 12, 0, 0, 0, 1, 197),
       netcdftime._netcdftime.DatetimeNoLeap(1994, 8, 16, 12, 0, 0, 0, 4, 228),
       netcdftime._netcdftime.DatetimeNoLeap(1994, 9, 16, 0, 0, 0, 0, 0, 259),
       netcdftime._netcdftime.DatetimeNoLeap(1994, 10, 16, 12, 0, 0, 0, 2, 289),
       netcdftime._netcdftime.DatetimeNoLeap(1994, 11, 16, 0, 0, 0, 0, 5, 320),
       netcdftime._netcdftime.DatetimeNoLeap(1994, 12, 16, 12, 0, 0, 0, 0, 350),
       netcdftime._netcdftime.DatetimeNoLeap(1995, 1, 16, 12, 0, 0, 0, 3, 16),
       netcdftime._netcdftime.DatetimeNoLeap(1995, 2, 15, 0, 0, 0, 0, 5, 46),
       netcdftime._netcdftime.DatetimeNoLeap(1995, 3, 16, 12, 0, 0, 0, 6, 75),
       netcdftime._netcdftime.DatetimeNoLeap(1995, 4, 16, 0, 0, 0, 0, 2, 106),
       netcdftime._netcdftime.DatetimeNoLeap(1995, 5, 16, 12, 0, 0, 0, 4, 136),
       netcdftime._netcdftime.DatetimeNoLeap(1995, 6, 16, 0, 0, 0, 0, 0, 167),
       netcdftime._netcdftime.DatetimeNoLeap(1995, 7, 16, 12, 0, 0, 0, 2, 197),
       netcdftime._netcdftime.DatetimeNoLeap(1995, 8, 16, 12, 0, 0, 0, 5, 228),
       netcdftime._netcdftime.DatetimeNoLeap(1995, 9, 16, 0, 0, 0, 0, 1, 259),
       netcdftime._netcdftime.DatetimeNoLeap(1995, 10, 16, 12, 0, 0, 0, 3, 289),
       netcdftime._netcdftime.DatetimeNoLeap(1995, 11, 16, 0, 0, 0, 0, 6, 320),
       netcdftime._netcdftime.DatetimeNoLeap(1995, 12, 16, 12, 0, 0, 0, 1, 350),
       netcdftime._netcdftime.DatetimeNoLeap(1996, 1, 16, 12, 0, 0, 0, 4, 16),
       netcdftime._netcdftime.DatetimeNoLeap(1996, 2, 15, 0, 0, 0, 0, 6, 46),
       netcdftime._netcdftime.DatetimeNoLeap(1996, 3, 16, 12, 0, 0, 0, 0, 75),
       netcdftime._netcdftime.DatetimeNoLeap(1996, 4, 16, 0, 0, 0, 0, 3, 106),
       netcdftime._netcdftime.DatetimeNoLeap(1996, 5, 16, 12, 0, 0, 0, 5, 136),
       netcdftime._netcdftime.DatetimeNoLeap(1996, 6, 16, 0, 0, 0, 0, 1, 167),
       netcdftime._netcdftime.DatetimeNoLeap(1996, 7, 16, 12, 0, 0, 0, 3, 197),
       netcdftime._netcdftime.DatetimeNoLeap(1996, 8, 16, 12, 0, 0, 0, 6, 228),
       netcdftime._netcdftime.DatetimeNoLeap(1996, 9, 16, 0, 0, 0, 0, 2, 259),
       netcdftime._netcdftime.DatetimeNoLeap(1996, 10, 16, 12, 0, 0, 0, 4, 289),
       netcdftime._netcdftime.DatetimeNoLeap(1996, 11, 16, 0, 0, 0, 0, 0, 320),
       netcdftime._netcdftime.DatetimeNoLeap(1996, 12, 16, 12, 0, 0, 0, 2, 350),
       netcdftime._netcdftime.DatetimeNoLeap(1997, 1, 16, 12, 0, 0, 0, 5, 16),
       netcdftime._netcdftime.DatetimeNoLeap(1997, 2, 15, 0, 0, 0, 0, 0, 46),
       netcdftime._netcdftime.DatetimeNoLeap(1997, 3, 16, 12, 0, 0, 0, 1, 75),
       netcdftime._netcdftime.DatetimeNoLeap(1997, 4, 16, 0, 0, 0, 0, 4, 106),
       netcdftime._netcdftime.DatetimeNoLeap(1997, 5, 16, 12, 0, 0, 0, 6, 136),
       netcdftime._netcdftime.DatetimeNoLeap(1997, 6, 16, 0, 0, 0, 0, 2, 167),
       netcdftime._netcdftime.DatetimeNoLeap(1997, 7, 16, 12, 0, 0, 0, 4, 197),
       netcdftime._netcdftime.DatetimeNoLeap(1997, 8, 16, 12, 0, 0, 0, 0, 228),
       netcdftime._netcdftime.DatetimeNoLeap(1997, 9, 16, 0, 0, 0, 0, 3, 259),
       netcdftime._netcdftime.DatetimeNoLeap(1997, 10, 16, 12, 0, 0, 0, 5, 289),
       netcdftime._netcdftime.DatetimeNoLeap(1997, 11, 16, 0, 0, 0, 0, 1, 320),
       netcdftime._netcdftime.DatetimeNoLeap(1997, 12, 16, 12, 0, 0, 0, 3, 350),
       netcdftime._netcdftime.DatetimeNoLeap(1998, 1, 16, 12, 0, 0, 0, 6, 16),
       netcdftime._netcdftime.DatetimeNoLeap(1998, 2, 15, 0, 0, 0, 0, 1, 46),
       netcdftime._netcdftime.DatetimeNoLeap(1998, 3, 16, 12, 0, 0, 0, 2, 75),
       netcdftime._netcdftime.DatetimeNoLeap(1998, 4, 16, 0, 0, 0, 0, 5, 106),
       netcdftime._netcdftime.DatetimeNoLeap(1998, 5, 16, 12, 0, 0, 0, 0, 136),
       netcdftime._netcdftime.DatetimeNoLeap(1998, 6, 16, 0, 0, 0, 0, 3, 167),
       netcdftime._netcdftime.DatetimeNoLeap(1998, 7, 16, 12, 0, 0, 0, 5, 197),
       netcdftime._netcdftime.DatetimeNoLeap(1998, 8, 16, 12, 0, 0, 0, 1, 228),
       netcdftime._netcdftime.DatetimeNoLeap(1998, 9, 16, 0, 0, 0, 0, 4, 259),
       netcdftime._netcdftime.DatetimeNoLeap(1998, 10, 16, 12, 0, 0, 0, 6, 289),
       netcdftime._netcdftime.DatetimeNoLeap(1998, 11, 16, 0, 0, 0, 0, 2, 320),
       netcdftime._netcdftime.DatetimeNoLeap(1998, 12, 16, 12, 0, 0, 0, 4, 350),
       netcdftime._netcdftime.DatetimeNoLeap(1999, 1, 16, 12, 0, 0, 0, 0, 16),
       netcdftime._netcdftime.DatetimeNoLeap(1999, 2, 15, 0, 0, 0, 0, 2, 46),
       netcdftime._netcdftime.DatetimeNoLeap(1999, 3, 16, 12, 0, 0, 0, 3, 75),
       netcdftime._netcdftime.DatetimeNoLeap(1999, 4, 16, 0, 0, 0, 0, 6, 106),
       netcdftime._netcdftime.DatetimeNoLeap(1999, 5, 16, 12, 0, 0, 0, 1, 136),
       netcdftime._netcdftime.DatetimeNoLeap(1999, 6, 16, 0, 0, 0, 0, 4, 167),
       netcdftime._netcdftime.DatetimeNoLeap(1999, 7, 16, 12, 0, 0, 0, 6, 197),
       netcdftime._netcdftime.DatetimeNoLeap(1999, 8, 16, 12, 0, 0, 0, 2, 228),
       netcdftime._netcdftime.DatetimeNoLeap(1999, 9, 16, 0, 0, 0, 0, 5, 259),
       netcdftime._netcdftime.DatetimeNoLeap(1999, 10, 16, 12, 0, 0, 0, 0, 289),
       netcdftime._netcdftime.DatetimeNoLeap(1999, 11, 16, 0, 0, 0, 0, 3, 320),
       netcdftime._netcdftime.DatetimeNoLeap(1999, 12, 16, 12, 0, 0, 0, 5, 350),
       netcdftime._netcdftime.DatetimeNoLeap(2000, 1, 16, 12, 0, 0, 0, 1, 16),
       netcdftime._netcdftime.DatetimeNoLeap(2000, 2, 15, 0, 0, 0, 0, 3, 46),
       netcdftime._netcdftime.DatetimeNoLeap(2000, 3, 16, 12, 0, 0, 0, 4, 75),
       netcdftime._netcdftime.DatetimeNoLeap(2000, 4, 16, 0, 0, 0, 0, 0, 106),
       netcdftime._netcdftime.DatetimeNoLeap(2000, 5, 16, 12, 0, 0, 0, 2, 136),
       netcdftime._netcdftime.DatetimeNoLeap(2000, 6, 16, 0, 0, 0, 0, 5, 167),
       netcdftime._netcdftime.DatetimeNoLeap(2000, 7, 16, 12, 0, 0, 0, 0, 197),
       netcdftime._netcdftime.DatetimeNoLeap(2000, 8, 16, 12, 0, 0, 0, 3, 228),
       netcdftime._netcdftime.DatetimeNoLeap(2000, 9, 16, 0, 0, 0, 0, 6, 259),
       netcdftime._netcdftime.DatetimeNoLeap(2000, 10, 16, 12, 0, 0, 0, 1, 289),
       netcdftime._netcdftime.DatetimeNoLeap(2000, 11, 16, 0, 0, 0, 0, 4, 320),
       netcdftime._netcdftime.DatetimeNoLeap(2000, 12, 16, 12, 0, 0, 0, 6, 350),
       netcdftime._netcdftime.DatetimeNoLeap(2001, 1, 16, 12, 0, 0, 0, 2, 16),
       netcdftime._netcdftime.DatetimeNoLeap(2001, 2, 15, 0, 0, 0, 0, 4, 46),
       netcdftime._netcdftime.DatetimeNoLeap(2001, 3, 16, 12, 0, 0, 0, 5, 75),
       netcdftime._netcdftime.DatetimeNoLeap(2001, 4, 16, 0, 0, 0, 0, 1, 106),
       netcdftime._netcdftime.DatetimeNoLeap(2001, 5, 16, 12, 0, 0, 0, 3, 136),
       netcdftime._netcdftime.DatetimeNoLeap(2001, 6, 16, 0, 0, 0, 0, 6, 167),
       netcdftime._netcdftime.DatetimeNoLeap(2001, 7, 16, 12, 0, 0, 0, 1, 197),
       netcdftime._netcdftime.DatetimeNoLeap(2001, 8, 16, 12, 0, 0, 0, 4, 228),
       netcdftime._netcdftime.DatetimeNoLeap(2001, 9, 16, 0, 0, 0, 0, 0, 259),
       netcdftime._netcdftime.DatetimeNoLeap(2001, 10, 16, 12, 0, 0, 0, 2, 289),
       netcdftime._netcdftime.DatetimeNoLeap(2001, 11, 16, 0, 0, 0, 0, 5, 320),
       netcdftime._netcdftime.DatetimeNoLeap(2001, 12, 16, 12, 0, 0, 0, 0, 350),
       netcdftime._netcdftime.DatetimeNoLeap(2002, 1, 16, 12, 0, 0, 0, 3, 16),
       netcdftime._netcdftime.DatetimeNoLeap(2002, 2, 15, 0, 0, 0, 0, 5, 46),
       netcdftime._netcdftime.DatetimeNoLeap(2002, 3, 16, 12, 0, 0, 0, 6, 75),
       netcdftime._netcdftime.DatetimeNoLeap(2002, 4, 16, 0, 0, 0, 0, 2, 106),
       netcdftime._netcdftime.DatetimeNoLeap(2002, 5, 16, 12, 0, 0, 0, 4, 136),
       netcdftime._netcdftime.DatetimeNoLeap(2002, 6, 16, 0, 0, 0, 0, 0, 167),
       netcdftime._netcdftime.DatetimeNoLeap(2002, 7, 16, 12, 0, 0, 0, 2, 197),
       netcdftime._netcdftime.DatetimeNoLeap(2002, 8, 16, 12, 0, 0, 0, 5, 228),
       netcdftime._netcdftime.DatetimeNoLeap(2002, 9, 16, 0, 0, 0, 0, 1, 259),
       netcdftime._netcdftime.DatetimeNoLeap(2002, 10, 16, 12, 0, 0, 0, 3, 289),
       netcdftime._netcdftime.DatetimeNoLeap(2002, 11, 16, 0, 0, 0, 0, 6, 320),
       netcdftime._netcdftime.DatetimeNoLeap(2002, 12, 16, 12, 0, 0, 0, 1, 350),
       netcdftime._netcdftime.DatetimeNoLeap(2003, 1, 16, 12, 0, 0, 0, 4, 16),
       netcdftime._netcdftime.DatetimeNoLeap(2003, 2, 15, 0, 0, 0, 0, 6, 46),
       netcdftime._netcdftime.DatetimeNoLeap(2003, 3, 16, 12, 0, 0, 0, 0, 75),
       netcdftime._netcdftime.DatetimeNoLeap(2003, 4, 16, 0, 0, 0, 0, 3, 106),
       netcdftime._netcdftime.DatetimeNoLeap(2003, 5, 16, 12, 0, 0, 0, 5, 136),
       netcdftime._netcdftime.DatetimeNoLeap(2003, 6, 16, 0, 0, 0, 0, 1, 167),
       netcdftime._netcdftime.DatetimeNoLeap(2003, 7, 16, 12, 0, 0, 0, 3, 197),
       netcdftime._netcdftime.DatetimeNoLeap(2003, 8, 16, 12, 0, 0, 0, 6, 228),
       netcdftime._netcdftime.DatetimeNoLeap(2003, 9, 16, 0, 0, 0, 0, 2, 259),
       netcdftime._netcdftime.DatetimeNoLeap(2003, 10, 16, 12, 0, 0, 0, 4, 289),
       netcdftime._netcdftime.DatetimeNoLeap(2003, 11, 16, 0, 0, 0, 0, 0, 320),
       netcdftime._netcdftime.DatetimeNoLeap(2003, 12, 16, 12, 0, 0, 0, 2, 350),
       netcdftime._netcdftime.DatetimeNoLeap(2004, 1, 16, 12, 0, 0, 0, 5, 16),
       netcdftime._netcdftime.DatetimeNoLeap(2004, 2, 15, 0, 0, 0, 0, 0, 46),
       netcdftime._netcdftime.DatetimeNoLeap(2004, 3, 16, 12, 0, 0, 0, 1, 75),
       netcdftime._netcdftime.DatetimeNoLeap(2004, 4, 16, 0, 0, 0, 0, 4, 106),
       netcdftime._netcdftime.DatetimeNoLeap(2004, 5, 16, 12, 0, 0, 0, 6, 136),
       netcdftime._netcdftime.DatetimeNoLeap(2004, 6, 16, 0, 0, 0, 0, 2, 167),
       netcdftime._netcdftime.DatetimeNoLeap(2004, 7, 16, 12, 0, 0, 0, 4, 197),
       netcdftime._netcdftime.DatetimeNoLeap(2004, 8, 16, 12, 0, 0, 0, 0, 228),
       netcdftime._netcdftime.DatetimeNoLeap(2004, 9, 16, 0, 0, 0, 0, 3, 259),
       netcdftime._netcdftime.DatetimeNoLeap(2004, 10, 16, 12, 0, 0, 0, 5, 289),
       netcdftime._netcdftime.DatetimeNoLeap(2004, 11, 16, 0, 0, 0, 0, 1, 320),
       netcdftime._netcdftime.DatetimeNoLeap(2004, 12, 16, 12, 0, 0, 0, 3, 350),
       netcdftime._netcdftime.DatetimeNoLeap(2005, 1, 16, 12, 0, 0, 0, 6, 16),
       netcdftime._netcdftime.DatetimeNoLeap(2005, 2, 15, 0, 0, 0, 0, 1, 46),
       netcdftime._netcdftime.DatetimeNoLeap(2005, 3, 16, 12, 0, 0, 0, 2, 75),
       netcdftime._netcdftime.DatetimeNoLeap(2005, 4, 16, 0, 0, 0, 0, 5, 106),
       netcdftime._netcdftime.DatetimeNoLeap(2005, 5, 16, 12, 0, 0, 0, 0, 136),
       netcdftime._netcdftime.DatetimeNoLeap(2005, 6, 16, 0, 0, 0, 0, 3, 167),
       netcdftime._netcdftime.DatetimeNoLeap(2005, 7, 16, 12, 0, 0, 0, 5, 197),
       netcdftime._netcdftime.DatetimeNoLeap(2005, 8, 16, 12, 0, 0, 0, 1, 228),
       netcdftime._netcdftime.DatetimeNoLeap(2005, 9, 16, 0, 0, 0, 0, 4, 259),
       netcdftime._netcdftime.DatetimeNoLeap(2005, 10, 16, 12, 0, 0, 0, 6, 289),
       netcdftime._netcdftime.DatetimeNoLeap(2005, 11, 16, 0, 0, 0, 0, 2, 320),
       netcdftime._netcdftime.DatetimeNoLeap(2005, 12, 16, 12, 0, 0, 0, 4, 350),
       netcdftime._netcdftime.DatetimeNoLeap(2006, 1, 16, 12, 0, 0, 0, 0, 16),
       netcdftime._netcdftime.DatetimeNoLeap(2006, 2, 15, 0, 0, 0, 0, 2, 46),
       netcdftime._netcdftime.DatetimeNoLeap(2006, 3, 16, 12, 0, 0, 0, 3, 75),
       netcdftime._netcdftime.DatetimeNoLeap(2006, 4, 16, 0, 0, 0, 0, 6, 106),
       netcdftime._netcdftime.DatetimeNoLeap(2006, 5, 16, 12, 0, 0, 0, 1, 136),
       netcdftime._netcdftime.DatetimeNoLeap(2006, 6, 16, 0, 0, 0, 0, 4, 167),
       netcdftime._netcdftime.DatetimeNoLeap(2006, 7, 16, 12, 0, 0, 0, 6, 197),
       netcdftime._netcdftime.DatetimeNoLeap(2006, 8, 16, 12, 0, 0, 0, 2, 228),
       netcdftime._netcdftime.DatetimeNoLeap(2006, 9, 16, 0, 0, 0, 0, 5, 259),
       netcdftime._netcdftime.DatetimeNoLeap(2006, 10, 16, 12, 0, 0, 0, 0, 289),
       netcdftime._netcdftime.DatetimeNoLeap(2006, 11, 16, 0, 0, 0, 0, 3, 320),
       netcdftime._netcdftime.DatetimeNoLeap(2006, 12, 16, 12, 0, 0, 0, 5, 350),
       netcdftime._netcdftime.DatetimeNoLeap(2007, 1, 16, 12, 0, 0, 0, 1, 16),
       netcdftime._netcdftime.DatetimeNoLeap(2007, 2, 15, 0, 0, 0, 0, 3, 46),
       netcdftime._netcdftime.DatetimeNoLeap(2007, 3, 16, 12, 0, 0, 0, 4, 75),
       netcdftime._netcdftime.DatetimeNoLeap(2007, 4, 16, 0, 0, 0, 0, 0, 106),
       netcdftime._netcdftime.DatetimeNoLeap(2007, 5, 16, 12, 0, 0, 0, 2, 136),
       netcdftime._netcdftime.DatetimeNoLeap(2007, 6, 16, 0, 0, 0, 0, 5, 167),
       netcdftime._netcdftime.DatetimeNoLeap(2007, 7, 16, 12, 0, 0, 0, 0, 197),
       netcdftime._netcdftime.DatetimeNoLeap(2007, 8, 16, 12, 0, 0, 0, 3, 228),
       netcdftime._netcdftime.DatetimeNoLeap(2007, 9, 16, 0, 0, 0, 0, 6, 259),
       netcdftime._netcdftime.DatetimeNoLeap(2007, 10, 16, 12, 0, 0, 0, 1, 289),
       netcdftime._netcdftime.DatetimeNoLeap(2007, 11, 16, 0, 0, 0, 0, 4, 320),
       netcdftime._netcdftime.DatetimeNoLeap(2007, 12, 16, 12, 0, 0, 0, 6, 350),
       netcdftime._netcdftime.DatetimeNoLeap(2008, 1, 16, 12, 0, 0, 0, 2, 16),
       netcdftime._netcdftime.DatetimeNoLeap(2008, 2, 15, 0, 0, 0, 0, 4, 46),
       netcdftime._netcdftime.DatetimeNoLeap(2008, 3, 16, 12, 0, 0, 0, 5, 75),
       netcdftime._netcdftime.DatetimeNoLeap(2008, 4, 16, 0, 0, 0, 0, 1, 106),
       netcdftime._netcdftime.DatetimeNoLeap(2008, 5, 16, 12, 0, 0, 0, 3, 136),
       netcdftime._netcdftime.DatetimeNoLeap(2008, 6, 16, 0, 0, 0, 0, 6, 167),
       netcdftime._netcdftime.DatetimeNoLeap(2008, 7, 16, 12, 0, 0, 0, 1, 197),
       netcdftime._netcdftime.DatetimeNoLeap(2008, 8, 16, 12, 0, 0, 0, 4, 228),
       netcdftime._netcdftime.DatetimeNoLeap(2008, 9, 16, 0, 0, 0, 0, 0, 259),
       netcdftime._netcdftime.DatetimeNoLeap(2008, 10, 16, 12, 0, 0, 0, 2, 289),
       netcdftime._netcdftime.DatetimeNoLeap(2008, 11, 16, 0, 0, 0, 0, 5, 320),
       netcdftime._netcdftime.DatetimeNoLeap(2008, 12, 16, 12, 0, 0, 0, 0, 350),
       netcdftime._netcdftime.DatetimeNoLeap(2009, 1, 16, 12, 0, 0, 0, 3, 16),
       netcdftime._netcdftime.DatetimeNoLeap(2009, 2, 15, 0, 0, 0, 0, 5, 46),
       netcdftime._netcdftime.DatetimeNoLeap(2009, 3, 16, 12, 0, 0, 0, 6, 75),
       netcdftime._netcdftime.DatetimeNoLeap(2009, 4, 16, 0, 0, 0, 0, 2, 106),
       netcdftime._netcdftime.DatetimeNoLeap(2009, 5, 16, 12, 0, 0, 0, 4, 136),
       netcdftime._netcdftime.DatetimeNoLeap(2009, 6, 16, 0, 0, 0, 0, 0, 167),
       netcdftime._netcdftime.DatetimeNoLeap(2009, 7, 16, 12, 0, 0, 0, 2, 197),
       netcdftime._netcdftime.DatetimeNoLeap(2009, 8, 16, 12, 0, 0, 0, 5, 228),
       netcdftime._netcdftime.DatetimeNoLeap(2009, 9, 16, 0, 0, 0, 0, 1, 259),
       netcdftime._netcdftime.DatetimeNoLeap(2009, 10, 16, 12, 0, 0, 0, 3, 289),
       netcdftime._netcdftime.DatetimeNoLeap(2009, 11, 16, 0, 0, 0, 0, 6, 320),
       netcdftime._netcdftime.DatetimeNoLeap(2009, 12, 16, 12, 0, 0, 0, 1, 350)], standard_name=u'time', calendar=u'365_day', long_name=u'time', var_name='time')

And I get this for the Observed data:

DimCoord([datetime.datetime(1901, 1, 16, 0, 0),
       datetime.datetime(1901, 2, 15, 0, 0),
       datetime.datetime(1901, 3, 16, 0, 0), ...,
       datetime.datetime(2015, 10, 16, 0, 0),
       datetime.datetime(2015, 11, 16, 0, 0),
       datetime.datetime(2015, 12, 16, 0, 0)], standard_name='time', calendar=u'gregorian', long_name=u'time', var_name='time')

So I’m a bit confused as to why it worked yesterday but isn’t working today. Do you think you might be able to help?

Here is a simplified version of the code I am running

import matplotlib.pyplot as plt
import iris
import iris.coord_categorisation as iriscc
import iris.plot as iplt
import iris.quickplot as qplt
import iris.analysis.cartography
import matplotlib.dates as mdates

#the first part of the code is all about the CORDEX models, the second half brings in the observed data, and the third plots the annual temperature in a line graph.

def main():
    #PART 1: CORDEX MODELS
    #bring in all the models we need and give them a name
    CCCma = '/exports/csce/datastore/geos/users/s0xxxx/Climate_Modelling/AFR_44_tas/ERAINT/1979-2012/tas_AFR-44_ECMWF-ERAINT_evaluation_r1i1p1_CCCma-CanRCM4_r2_mon_198901-200912.nc'  

    #Load exactly one cube from given file
    CCCma = iris.load_cube(CCCma)

    #remove flat latitude and longitude and only use grid latitude and grid longitude to make consistent with the observed data, also make sure all of the longitudes are monotonic 
    lats = iris.coords.DimCoord(CCCma.coord('latitude').points[:,0], \
                                standard_name='latitude', units='degrees')
    lons = CCCma.coord('longitude').points[0]
    for i in range(len(lons)):
        if lons[i]>100.:
            lons[i] = lons[i]-360.
    lons = iris.coords.DimCoord(lons, \
                                standard_name='longitude', units='degrees')

    CCCma.remove_coord('latitude')
    CCCma.remove_coord('longitude')
    CCCma.remove_coord('grid_latitude')
    CCCma.remove_coord('grid_longitude')
    CCCma.add_dim_coord(lats, 1)
    CCCma.add_dim_coord(lons, 2)

    #we are only interested in the latitude and longitude relevant to Malawi

    Malawi = iris.Constraint(longitude=lambda v: 32.5 <= v <= 36., \
                         latitude=lambda v: -17. <= v <= -9.) 

    CCCma = CCCma.extract(Malawi)

    #time constraignt to make all series the same
    iris.FUTURE.cell_datetime_objects = True
    t_constraint = iris.Constraint(time=lambda cell: 1989 <= cell.point.year <= 2008)

    CCCma = CCCma.extract(t_constraint)

    #data is in Kelvin, but we would like to show it in Celcius
    CCCma.convert_units('Celsius')

    #We are interested in plotting the graph with time along the x ais, so we need a mean of all the coordinates, i.e. mean temperature across whole country    
    iriscc.add_year(CCCma, 'time') 

    CCCma = CCCma.aggregated_by('year', iris.analysis.MEAN)

    CCCma.coord('latitude').guess_bounds()
    CCCma.coord('longitude').guess_bounds()
    CCCma_grid_areas = iris.analysis.cartography.area_weights(CCCma)
    CCCma_mean = CCCma.collapsed(['latitude', 'longitude'],
                                                   iris.analysis.MEAN,
                                                   weights=CCCma_grid_areas)


    #PART 2: OBSERVED DATA
    #bring in all the files we need and give them a name
    CRU= '/exports/csce/datastore/geos/users/s0xxxx/Climate_Modelling/Actual_Data/cru_ts4.00.1901.2015.tmp.dat.nc'

    #Load exactly one cube from given file
    CRU = iris.load_cube(CRU, 'near-surface temperature')

    #define the latitude and longitude
    lats = iris.coords.DimCoord(CRU.coord('latitude').points, \
                                standard_name='latitude', units='degrees')
    lons = CRU.coord('longitude').points

    #we are only interested in the latitude and longitude relevant to Malawi 
    Malawi = iris.Constraint(longitude=lambda v: 32.5 <= v <= 36., \
                         latitude=lambda v: -17. <= v <= -9.) 
    CRU = CRU.extract(Malawi)

    #time constraignt to make all series the same
    iris.FUTURE.cell_datetime_objects = True
    t_constraint = iris.Constraint(time=lambda cell: 1989 <= cell.point.year <= 2008)
    CRU = CRU.extract(t_constraint)

    #We are interested in plotting the graph with time along the x ais, so we need a mean of all the coordinates, i.e. mean temperature across whole country    
    iriscc.add_year(CRU, 'time') 

    CRU = CRU.aggregated_by('year', iris.analysis.MEAN)

    CRU.coord('latitude').guess_bounds()
    CRU.coord('longitude').guess_bounds()
    CRU_grid_areas = iris.analysis.cartography.area_weights(CRU)
    CRU_mean = CRU.collapsed(['latitude', 'longitude'],
                                                   iris.analysis.MEAN,
                                                   weights=CRU_grid_areas)


    #PART 3: PLOT LINE GRAPH - ANNUAL
    #set major plot indicators for x-axis                                              

    plt.gca().xaxis.set_major_locator(mdates.YearLocator(5))

    #assign the line colours
    qplt.plot(CCCma_mean, label='CanRCM4_ERAINT', lw=1.5, color='blue')
    qplt.plot(CRU_mean, label='Observed', lw=2, color='black')

    #create a legend and set its location to under the graph
    plt.legend(loc="upper center", bbox_to_anchor=(0.5,-0.05), fancybox=True, shadow=True, ncol=2)

    #create a title
    plt.title('Mean Near Surface Temperature for Malawi 1989-2008', fontsize=11)   

    #add grid lines
    plt.grid()

    #save the image of the graph and include full legend
    plt.savefig('ERAINT_Temperature_LineGraph_Annual', bbox_inches='tight')

    #show the graph in the console
    iplt.show()




if __name__ == '__main__':
    main()

Thanks! Erika

2

There are 2 answers

0
RuthC On BEST ANSWER

I don't know what's going on with your time coordinate, but a workaround might be to specifically plot against your year coordinates:

qplt.plot(CCCma_mean.coord('year'), CCCma_mean, label='CanRCM4_ERAINT', lw=1.5, color='blue')
qplt.plot(CRU_mean.coord('year'), CRU_mean, label='Observed', lw=2, color='black')
1
ErikaAWT On

Thank you @RuthC. That did the trick. It seemed to be plotting time as the default and since some data is days since 1949 and the other is days since 1900 this plotted them 49 years apart on the x axis. Although it is odd that it had worked the day before! Something must have changed with my software.

Note that I also had to remove this code:

 plt.gca().xaxis.set_major_locator(mdates.YearLocator(5))

otherwise the x-axis wouldn't show the year data along the bottom.

Appreciate it! Erika