In [1]:
%run basics
%matplotlib


Using matplotlib backend: Qt4Agg

In [4]:
ncname = "C:/OzFlux/Sites/CUP/Processed/CumberlandPlain_2012_to_2015_L6.nc"

In [5]:
print ncname
type(ncname)


C:/OzFlux/Sites/CUP/Processed/CumberlandPlain_2012_to_2015_L6.nc
Out[5]:
str

In [6]:
ds=qcio.nc_read_series(ncname)

In [7]:
type(ds)


Out[7]:
qcio.DataStructure

In [8]:
ds.series.keys()


Out[8]:
[u'GPP_LT',
 u'Ts',
 u'DateTime',
 u'Precip',
 u'Fn',
 u'NEP_SOLO',
 u'NEE_SOLO',
 u'NEE_LT',
 u'Sws',
 u'Ddd',
 u'Second',
 u'Wd',
 u'VPD',
 u'Fsu',
 u'ER_LT',
 u'Fa',
 u'Fc',
 u'Ws',
 u'Fe',
 u'Fg',
 u'Fh',
 u'Hdh',
 u'RH',
 u'Day',
 u'Minute',
 u'xlDateTime',
 u'Fsd',
 u'Hour',
 u'ps',
 u'time',
 u'Flu',
 u'solar_altitude',
 u'Fsd_syn',
 u'SHD',
 u'ER_LT_all',
 u'ET',
 u'ER_SOLO',
 u'Fld',
 u'ER',
 u'Ta',
 u'Cc',
 u'Ah',
 u'NEP_LT',
 u'Month',
 u'q',
 u'ustar',
 u'ER_SOLO_all',
 u'GPP_SOLO',
 u'Fm',
 u'Year',
 u'Fc_storage']

In [37]:
dt=ds.series["DateTime"]["Data"]
Fsd,flag,attr=qcutils.GetSeriesasMA(ds,"Fsd")
Fc,flag,attr=qcutils.GetSeriesasMA(ds,"Fc")
VPD,flag,attr=qcutils.GetSeriesasMA(ds,"VPD")
Ta,flag,attr=qcutils.GetSeriesasMA(ds,"Ta")
Sws,flag,attr=qcutils.GetSeriesasMA(ds,"Sws")
Ts,flag,attr=qcutils.GetSeriesasMA(ds,"Ts")
ustar,flag,attr=qcutils.GetSeriesasMA(ds,"ustar")

In [10]:
fig = plt.figure()
ax1=plt.subplot(511)
plt.plot(dt,Fsd)
ax2=plt.subplot(512,sharex=ax1)
plt.plot(dt,VPD)
ax3=plt.subplot(513,sharex=ax1)
plt.plot(dt,Ta)
ax4=plt.subplot(514,sharex=ax1)
plt.plot(dt,Fc)
ax5=plt.subplot(515,sharex=ax1)
plt.plot(dt,Sws)
plt.show()

In [27]:
#here we have Fc day vs Fsd by VPD to see if intercept of Fsd=0 varies by VPD and season
#could do a bit more work setting the colorbar to a particular scale and labelling it
Fc_day=numpy.ma.masked_where(Fsd<10,Fc)
VPD_day=numpy.ma.masked_where(Fsd<10,VPD)
Fsd_day=numpy.ma.masked_where(Fsd<10,Fsd)
start_date = dt[0]
end_date = dt[-1]
this_date = start_date+dateutil.relativedelta.relativedelta(months=2)
while start_date<end_date:
    si = qcutils.GetDateIndex(dt,str(start_date))
    ei = qcutils.GetDateIndex(dt,str(this_date))
    Fsd_sub=Fsd_day[si:ei+1]
    Fc_sub=Fc_day[si:ei+1]
    VPD_sub=VPD_day[si:ei+1]
    fig=plt.figure()
    plt.title(str(start_date)+" to "+str(this_date)+" by VPD")
    cm=plt.cm.get_cmap('rainbow')
    sc=plt.scatter(Fsd_sub,Fc_sub,c=VPD_sub,cmap=cm)
    plt.xlabel("Fsd (W/m2)")
    plt.xlim([0,1200])
    plt.ylabel("Fc (umol/m2/s)")
    plt.ylim([-20,20])
    plt.colorbar(sc)
    plt.show()
    start_date = this_date
    this_date = start_date+dateutil.relativedelta.relativedelta(months=2)


---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-27-4e32d0786041> in <module>()
     21     plt.ylabel("Fc (umol/m2/s)")
     22     plt.ylim([-20,20])
---> 23     plt.colorbar(sc)
     24     plt.show()
     25     start_date = this_date

C:\Anaconda\lib\site-packages\matplotlib\pyplot.pyc in colorbar(mappable, cax, ax, **kw)
   2157         ax = gca()
   2158 
-> 2159     ret = gcf().colorbar(mappable, cax = cax, ax=ax, **kw)
   2160     draw_if_interactive()
   2161     return ret

C:\Anaconda\lib\site-packages\matplotlib\figure.pyc in colorbar(self, mappable, cax, ax, use_gridspec, **kw)
   1504                 cax, kw = cbar.make_axes(ax, **kw)
   1505         cax.hold(True)
-> 1506         cb = cbar.colorbar_factory(cax, mappable, **kw)
   1507 
   1508         self.sca(current_ax)

C:\Anaconda\lib\site-packages\matplotlib\colorbar.pyc in colorbar_factory(cax, mappable, **kwargs)
   1316         cb = ColorbarPatch(cax, mappable, **kwargs)
   1317     else:
-> 1318         cb = Colorbar(cax, mappable, **kwargs)
   1319 
   1320     cid = mappable.callbacksSM.connect('changed', cb.on_mappable_changed)

C:\Anaconda\lib\site-packages\matplotlib\colorbar.pyc in __init__(self, ax, mappable, **kw)
    867         # Ensure the given mappable's norm has appropriate vmin and vmax set
    868         # even if mappable.draw has not yet been called.
--> 869         mappable.autoscale_None()
    870 
    871         self.mappable = mappable

C:\Anaconda\lib\site-packages\matplotlib\cm.pyc in autoscale_None(self)
    332         """
    333         if self._A is None:
--> 334             raise TypeError('You must first set_array for mappable')
    335         self.norm.autoscale_None(self._A)
    336         self.changed()

TypeError: You must first set_array for mappable

In [22]:
#here we have Fc during daytime vs VPD by Fsd to evaluate if a VPD threshold exists, and by season
Fc_day=numpy.ma.masked_where(Fsd<10,Fc)
VPD_day=numpy.ma.masked_where(Fsd<10,VPD)
Fsd_day=numpy.ma.masked_where(Fsd<10,Fsd)
start_date = dt[0]
end_date = dt[-1]
this_date = start_date+dateutil.relativedelta.relativedelta(months=2)
while start_date<end_date:
    si = qcutils.GetDateIndex(dt,str(start_date))
    ei = qcutils.GetDateIndex(dt,str(this_date))
    Fsd_sub=Fsd_day[si:ei+1]
    Fc_sub=Fc_day[si:ei+1]
    VPD_sub=VPD_day[si:ei+1]
    fig=plt.figure()
    plt.title(str(start_date)+" to "+str(this_date)+" by Fsd")
    cm=plt.cm.get_cmap('rainbow')
    sc=plt.scatter(VPD_sub,Fc_sub,c=Fsd_sub,cmap=cm)
    plt.xlabel("VPD (kPa)")
    plt.xlim([-0.2,6])
    plt.ylabel("Fc (umol m-2 s-1)")
    plt.ylim([-20,20])
    plt.colorbar(sc)
    plt.show()
    start_date = this_date
    this_date = start_date+dateutil.relativedelta.relativedelta(months=2)


---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-22-11aea628b187> in <module>()
     20     plt.ylabel("Fc (umol m-2 s-1)")
     21     plt.ylim([-20,20])
---> 22     plt.colorbar(sc)
     23     plt.show()
     24     start_date = this_date

C:\Anaconda\lib\site-packages\matplotlib\pyplot.pyc in colorbar(mappable, cax, ax, **kw)
   2157         ax = gca()
   2158 
-> 2159     ret = gcf().colorbar(mappable, cax = cax, ax=ax, **kw)
   2160     draw_if_interactive()
   2161     return ret

C:\Anaconda\lib\site-packages\matplotlib\figure.pyc in colorbar(self, mappable, cax, ax, use_gridspec, **kw)
   1504                 cax, kw = cbar.make_axes(ax, **kw)
   1505         cax.hold(True)
-> 1506         cb = cbar.colorbar_factory(cax, mappable, **kw)
   1507 
   1508         self.sca(current_ax)

C:\Anaconda\lib\site-packages\matplotlib\colorbar.pyc in colorbar_factory(cax, mappable, **kwargs)
   1316         cb = ColorbarPatch(cax, mappable, **kwargs)
   1317     else:
-> 1318         cb = Colorbar(cax, mappable, **kwargs)
   1319 
   1320     cid = mappable.callbacksSM.connect('changed', cb.on_mappable_changed)

C:\Anaconda\lib\site-packages\matplotlib\colorbar.pyc in __init__(self, ax, mappable, **kw)
    867         # Ensure the given mappable's norm has appropriate vmin and vmax set
    868         # even if mappable.draw has not yet been called.
--> 869         mappable.autoscale_None()
    870 
    871         self.mappable = mappable

C:\Anaconda\lib\site-packages\matplotlib\cm.pyc in autoscale_None(self)
    332         """
    333         if self._A is None:
--> 334             raise TypeError('You must first set_array for mappable')
    335         self.norm.autoscale_None(self._A)
    336         self.changed()

TypeError: You must first set_array for mappable

In [35]:
#here we have Fc during nighttime vs Ts by soil moisture, and by season
Fc_night=numpy.ma.masked_where((Fsd>1)|(ustar<0.26),Fc)
Ts_night=numpy.ma.masked_where(Fsd>1,Ts)
Sws_night=numpy.ma.masked_where(Fsd>1,Sws)
start_date = dt[0]
end_date = dt[-1]
this_date = start_date+dateutil.relativedelta.relativedelta(months=2)
while start_date<end_date:
    si = qcutils.GetDateIndex(dt,str(start_date))
    ei = qcutils.GetDateIndex(dt,str(this_date))
    Ts_sub=Ts_night[si:ei+1]
    Fc_sub=Fc_night[si:ei+1]
    Sws_sub=Sws_night[si:ei+1]
    fig=plt.figure()
    plt.title(str(start_date)+" to "+str(this_date)+" by Sws")
    cm=plt.cm.get_cmap('rainbow')
    sc=plt.scatter(Ts_sub,Fc_sub,c=Sws_sub,cmap=cm)
    plt.xlabel("Ts (C)")
    plt.xlim([10,30])
    plt.ylabel("Fc (umol m-2 s-1)")
    plt.ylim([-20,20])
    plt.colorbar(sc)
    plt.show()
    start_date = this_date
    this_date = start_date+dateutil.relativedelta.relativedelta(months=2)


---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-35-3edee6f94e9c> in <module>()
     20     plt.ylabel("Fc (umol m-2 s-1)")
     21     plt.ylim([-20,20])
---> 22     plt.colorbar(sc)
     23     plt.show()
     24     start_date = this_date

C:\Anaconda\lib\site-packages\matplotlib\pyplot.pyc in colorbar(mappable, cax, ax, **kw)
   2157         ax = gca()
   2158 
-> 2159     ret = gcf().colorbar(mappable, cax = cax, ax=ax, **kw)
   2160     draw_if_interactive()
   2161     return ret

C:\Anaconda\lib\site-packages\matplotlib\figure.pyc in colorbar(self, mappable, cax, ax, use_gridspec, **kw)
   1504                 cax, kw = cbar.make_axes(ax, **kw)
   1505         cax.hold(True)
-> 1506         cb = cbar.colorbar_factory(cax, mappable, **kw)
   1507 
   1508         self.sca(current_ax)

C:\Anaconda\lib\site-packages\matplotlib\colorbar.pyc in colorbar_factory(cax, mappable, **kwargs)
   1316         cb = ColorbarPatch(cax, mappable, **kwargs)
   1317     else:
-> 1318         cb = Colorbar(cax, mappable, **kwargs)
   1319 
   1320     cid = mappable.callbacksSM.connect('changed', cb.on_mappable_changed)

C:\Anaconda\lib\site-packages\matplotlib\colorbar.pyc in __init__(self, ax, mappable, **kw)
    867         # Ensure the given mappable's norm has appropriate vmin and vmax set
    868         # even if mappable.draw has not yet been called.
--> 869         mappable.autoscale_None()
    870 
    871         self.mappable = mappable

C:\Anaconda\lib\site-packages\matplotlib\cm.pyc in autoscale_None(self)
    332         """
    333         if self._A is None:
--> 334             raise TypeError('You must first set_array for mappable')
    335         self.norm.autoscale_None(self._A)
    336         self.changed()

TypeError: You must first set_array for mappable

In [39]:
#here we have Fc during nighttime vs Ts by soil moisture, full record
#element-wise comparisons in  "or" use | "and" use &
#consider defining the thresholds above in order to do sensitvity testing

#Fc_night=numpy.ma.masked_where(Fsd>1,Fc)
Fc_night=numpy.ma.masked_where((Fsd>1)|(ustar<0.26),Fc)
Ts_night=numpy.ma.masked_where(Fsd>1,Ts)
Sws_night=numpy.ma.masked_where(Fsd>1,Sws)
fig=plt.figure()
plt.title(str(start_date)+" to "+str(this_date)+" by Sws")
cm=plt.cm.get_cmap('rainbow')
sc=plt.scatter(Ts_night,Fc_night,c=Sws_night,cmap=cm)
plt.xlabel("Ts (C)")
plt.xlim([10,30])
plt.ylabel("Fc (umol m-2 s-1)")
plt.ylim([-20,20])
plt.colorbar(sc)
plt.show()

In [ ]:
def ER_LloydTaylor(T,rb,E0):
#    return rb*numpy.exp(E0*(1/(c.Tref-c.T0)-1/(T-c.T0)))
    return rb*numpy.exp(E0*(1/(288.13-227.13)-1/((T+273.15)-227.13)))

In [28]:
#consider using Awesome_lasslop instead of this stuff
GPP,flag,attr=qcutils.GetSeriesasMA(ds,"GPP_LT",si=si,ei=ei)
fig=plt.figure()
plt.plot(Fsd,GPP,"b.")
plt.xlabel("Fsd")
plt.ylabel("GPP(units)")
plt.show()

In [33]:
GPP,flag,attr=qcutils.GetSeriesasMA(ds,"GPP_LT",si=si,ei=ei)
VPD,flag,attr=qcutils.GetSeriesasMA(ds,"VPD",si=si,ei=ei)
fig=plt.figure()
plt.scatter(Fsd,GPP,c=VPD)
plt.xlabel("Fsd")
plt.ylabel("GPP(units)")
plt.show()

In [30]:
def GPP_Lasslop(Fsd,D,alpha,beta0,k,D0):
    beta = beta0*SHD_func_Lasslop(D,k,D0)
    GPP = alpha*beta*Fsd/(alpha*Fsd+beta)
    return GPP
def SHD_func_Lasslop(D,k,D0):
    SHD_func = numpy.ones(len(D))
    idx = numpy.where(D>D0)[0]
    SHD_func[idx] = numpy.exp(-k*(D[idx]-D0))
    return SHD_func


C:\Anaconda\lib\site-packages\matplotlib\collections.py:590: FutureWarning: elementwise comparison failed; returning scalar instead, but in the future will perform elementwise comparison
  if self._edgecolors == str('face'):

In [ ]: