Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/299.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python:生成包含反馈机制的模块图_Python_Numpy_Matplotlib_Feedback Loop - Fatal编程技术网

Python:生成包含反馈机制的模块图

Python:生成包含反馈机制的模块图,python,numpy,matplotlib,feedback-loop,Python,Numpy,Matplotlib,Feedback Loop,我对编程相当陌生,我正在尝试用Python 2.7 IDLE生成一个简单的零维能量平衡模型,以计算地球表面温度,并添加了冰反照率反馈,即,如果模型的温度输出高于280K,反照率保持在0.3(30%的能量反射),如果低于250k,反照率为0.7(70%的能量被反射,因为其温度较低,因此地球上有较大的冰(白色)覆盖),如果温度介于这两者之间;反照率用公式计算。这个反照率的新值然后从模型中返回,以提供更准确的温度 在我的模块中,我定义了 最终气候模型 反照率计算 一个新的最终气候模型,考虑了新的反照率

我对编程相当陌生,我正在尝试用Python 2.7 IDLE生成一个简单的零维能量平衡模型,以计算地球表面温度,并添加了冰反照率反馈,即,如果模型的温度输出高于280K,反照率保持在0.3(30%的能量反射),如果低于250k,反照率为0.7(70%的能量被反射,因为其温度较低,因此地球上有较大的冰(白色)覆盖),如果温度介于这两者之间;反照率用公式计算。这个反照率的新值然后从模型中返回,以提供更准确的温度

在我的模块中,我定义了

最终气候模型 反照率计算 一个新的最终气候模型,考虑了新的反照率

我试图制作一张图表,将第一个气候模型的输出与第二个气候模型的输出进行比较,第一个气候模型具有不同的太阳输入,但反照率一致,第二个气候模型具有不同的反照率和太阳输出。但是不断地出错

这是我的图表脚本:

  import matplotlib.pyplot as plt
  import numpy as np
  from EBM_IceAlbFeedback import *
  # q is for the Solar Constant
  q=np.linspace(2.5e26,4.0e26,150)
  # t= temperature derived from the final climate model
  t= finalCM(Q=q)
  plt.plot(q,t,'b-')
  q=np.linspace(3.0e26,4.5e26,150)
  # tb= is the second set of temperatures derived from the NEWfinalCM which contains an Ice Albedo Feedback
  tb= NEWfinalCM(Q=q)
  plt.plot(q,tb,'r-')
  plt.show ()
我的错误消息是:

Traceback (most recent call last):
 File "K:/python/CompareCMsPlt2.py", line 13, in <module>
tb= NEWfinalCM(Q=q)
 File "K:/python\EBM_IceAlbFeedback.py", line 228, in NEWfinalCM
 NewAlb=NAlb(dist=dist, Q=Q, co2Emissions=co2Emissions, alpha=alpha, cCycleInt=cCycleInt, cCycleSlope=cCycleSlope)
 File "K:/python\EBM_IceAlbFeedback.py", line 190, in NAlb
  if ta>280.0:
 ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
回溯(最近一次呼叫最后一次):
文件“K:/python/CompareCMsPlt2.py”,第13行,在
tb=新财务成本(Q=Q)
文件“K:/python\EBM_IceAlbFeedback.py”,第228行,在NEWfinalCM中
NewAlb=NAlb(dist=dist,Q=Q,CO2排放量=CO2排放量,alpha=alpha,cCycleInt=cCycleInt,cCycleSlope=cCycleSlope)
文件“K:/python\EBM_IceAlbFeedback.py”,第190行,在NAlb中
如果ta>280.0:
ValueError:包含多个元素的数组的真值不明确。使用a.any()或a.all()
我相信这是指我的模块的这一部分:

def NAlb (dist=150e9, Alb=0.3, Q=3.87e26, co2Emissions=0.0, alpha=3.0, cCycleInt=0.4,    cCycleSlope=0.0001):
'''
Readjusting Albedo to the output temperature

Arguments:

Q = solar ouput (W)
dist = distance from the sun (m)
co2Emissions = Cumulative CO2 emissions since 2010 (GtC)
alpha = climate sensitivity (K/2xCO2)
cCycleInt = Initial value of the airborne fraction (unitless)
cCycleSlope = Increment the airborne fraction per GtC (GtC^-1)

Return Value:
NewAlb= New Albedo (Unitless)
'''
# CALCULATE ABORTIVITY:
#Our model is baselined at an atmospheric CO2 concentration of 390 ppmv in 2010
baselineCO2=390.0
#The official IPCC figure for conversion of mass of emissions (GtC) top atmospheric   concentration (ppmv)
IPCCmassToConc=2.12
#approximate correction for the carbon cycle:
cCycleAdjust=cCycleInt+cCycleSlope*co2Emissions
#convert GtC to CO2 conc in ppmv:
co2=co2Emissions*cCycleAdjust/IPCCmassToConc+baselineCO2
#calculate absorptivity
absrp=absrpFromCO2( CO2=co2, alpha=alpha )

#CALCULATE TEMPERATURE: using the same method as in the finalCM
ta=transATmCM (absrpt=absrp, dist=dist, Alb=0.3, Q=Q)
# define the thresholds for an ice free state.
if ta>280.0:
    NewAlb=0.3
# define the threshold for a snow ball Earth state.
elif ta<250.0:
    NewAlb=0.7# Calculate albedo for temperatures between 280k to 230k
elif 250.0<ta<280.0:
    NewAlb=(0.3+(((0.7-0.3)/(280.0-250.0))*(280.0-ta)))
return NewAlb




  def NEWfinalCM( co2Emissions=0.0, alpha=3., dist=150e9, Q=3.87e26, cCycleInt=0.4, cCycleSlope=0.0001 ):
'''
A New final Climate model which contains and Ice Albedo Feedback

Arguments:

Q = solar ouput (W)
dist = distance from the sun (m)
co2Emissions = Cumulative CO2 emissions since 2010 (GtC)
alpha = climate sensitivity (K/2xCO2)
cCycleInt = Initial value of the airborne fraction (unitless)
cCycleSlope = Increment the airborne fraction per GtC (GtC^-1)

Return Value:
tn = surface temperature (K)
'''
#Our model is baselined at an atmospheric CO2 concentration of 390 ppmv in 2010
baselineCO2=390.0
#The official IPCC figure for conversion of mass of emissions (GtC) top atmospheric concentration (ppmv)
IPCCmassToConc=2.12
#approximate correction for the carbon cycle:
cCycleAdjust=cCycleInt+cCycleSlope*co2Emissions
#convert GtC to CO2 conc in ppmv:
co2=co2Emissions*cCycleAdjust/IPCCmassToConc+baselineCO2


#calculate temperature
absrp=absrpFromCO2(CO2=co2, alpha=alpha)
NewAlb=NAlb(dist=dist, Q=Q, co2Emissions=co2Emissions, alpha=alpha, cCycleInt=cCycleInt, cCycleSlope=cCycleSlope)

tn=transATmCM( absrpt=absrp, dist=dist, Alb=NewAlb, Q=Q)


return tn
def NAlb(dist=150e9,Alb=0.3,Q=3.87e26,CO2排放量=0.0,alpha=3.0,cCycleInt=0.4,cCycleSlope=0.0001):
'''
将反照率重新调整到输出温度
论据:
Q=太阳能输出(W)
dist=距太阳的距离(m)
CO2排放量=自2010年以来的累计CO2排放量(GtC)
α=气候敏感性(K/2xCO2)
CcCycleint=空气传播分数的初始值(无单位)
cCycleSlope=每GtC增加的空气传播分数(GtC^-1)
返回值:
NewAlb=新反照率(无单位)
'''
#计算流产率:
#我们的模型以2010年390 ppmv的大气CO2浓度为基准
基线CO2=390.0
#IPCC官方排放物质量(GtC)转换数据最高大气浓度(ppmv)
IPCCmassToConc=2.12
#碳循环的近似校正:
cCycleAdjust=cCycleInt+cCycleSlope*CO2排放量
#将GtC转换为ppmv中的CO2浓度:
二氧化碳=二氧化碳排放量*C循环排放量/IPCCmassToConc+基线二氧化碳
#计算吸收率
absrp=absrpFromCO2(CO2=CO2,α=alpha)
#计算温度:使用与finalCM中相同的方法
ta=变速器控制模块(absrpt=absrp,dist=dist,Alb=0.3,Q=Q)
#定义无冰状态的阈值。
如果ta>280.0:
NewAlb=0.3
#定义雪球地球状态的阈值。

elif ta上面的评论是正确的,不清楚您想做什么,但是如果您想检查数组中的所有元素是否都验证了条件,那么您可以执行以下操作:

if tb.all() > 280.0:
if tb.max() > 280.0:
    ...
elif tb.min() < 250.0:
如果您对数组中是否存在填充它的值感兴趣,可以执行以下操作:

if tb.all() > 280.0:
if tb.max() > 280.0:
    ...
elif tb.min() < 250.0:
如果tb.max()>280.0:
...
elif tb.min()<250.0:
对于第三个条件,上述两个示例不需要超过一个简单的else语句

如果你想单独评估职位,你也可以,但我会选择以下内容:

tb_test = np.ones(tb.shape) * 3
tb_test[np.where(tb > 280)] = 1
tb_test[np.where(tb < 250)] = 2
tb\u测试=np.one(tb.shape)*3
tb_试验[np.式中(tb>280)]=1
tb_试验[np.式中(tb<250)]=2
这将使tb_测试阵列在第一个条件适用的情况下为1,第二个条件为2,第三个条件为3


当然,您可以直接插入您的计算,而不是上述不同条件适用的标识…

@cillosis-为什么?科学家不是程序员。。。至于实际错误,numpy数组上的条件(例如
x>5
)返回布尔数组(例如
数组([True,True,False])
),而不是单个值。