2012-03-17 7 views
3

저는 프로그래밍을 처음 접했고 Python 2.7 IDLE에서 지구의 표면 온도를 계산하기 위해 간단한 0 차원 에너지 균형 모델을 만들려고합니다. 얼음 알데히드 피드백을 추가했다. 즉, 모델의 온도 출력이 280K보다 높으면 알베도가 0.3 (30 % 에너지 반사)에 머무르며, 알베도가 250k 미만이면 0.7 (70 % 에너지는 냉각기로 반사되므로) 지구상에 더 큰 얼음 (흰색) 덮개가 있고 온도가 이들 사이의 범위에 있다면; 알베도는 공식으로 계산됩니다. 알베도에 대한이 새로운 값은보다 정확한 온도를주기 위해 모델로부터 다시 돌아 간다.Python : 피드백 메커니즘을 포함하는 모듈의 그래프 생성

내 모듈에서 정의했습니다.

알베도 concideration로 촬영 한 새로운 알베도 (들)과 새로운 마무리 기후 모델에 대한 최종 기후 모델 계산 내가 변화와 함께 최초의 기후 모델의 출력을 비교하는 그래프를 생산하기 위해 노력하고

태양 입력은 있지만 일관된 알베도는 다양한 알베도와 태양 출력을 가진 두 번째 실행 결과로 나타납니다. 그러나 계속 오류가 발생합니다.

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 
:

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() 

나는이 내 모듈의이 부분에 뭔가를 참조 믿습니다 :

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() 

내 오류 메시지는 다음과 같습니다

내 그래프 내 스크립트입니다

도움을 주신다면

,210

감사

+1

@cillosis을 - 왜? 과학자들은 프로그래머가 아닙니다 ... 실제 오류에 관해서는 numpy 배열 (예 :'x> 5') 조건은 단일 값보다는 부울 배열 (예 :'array ([True, True, False]) '을 반환합니다. –

답변

1

코멘트 위의 올바른이며, 그것은 당신이 원하는 무엇인지 분명하지 않다, 그러나 당신이 당신의 배열의 모든 요소 상태를 확인 있는지 확인하려는 경우 다음 당신이 할 수 있습니다 :

if tb.all() > 280.0: 

당신이 그것을 fullfills 배열에 값이 존재하는 경우에 관심이 있다면 당신은 할 수 :

if tb.max() > 280.0: 
    ... 
elif tb.min() < 250.0: 

모두 위의 예는 세 번째 조건에 대한 간단한 다른 문보다 더 할 필요가 없습니다.

개별적으로 위치를 평가하려는 경우뿐만 아니라,하지만 나는 다음에 갈 것입니다 수 :

tb_test = np.ones(tb.shape) * 3 
tb_test[np.where(tb > 280)] = 1 
tb_test[np.where(tb < 250)] = 2 

하면 초 동안 tb_test 배열의 첫 번째 조건이 적용되는 경우에 대한 것들, 조로을 만들 것입니다 세 번째로는 열 셋입니다. 당신이 당신의 계산을 삽입 할 수 있습니다 물론 직접 대신 다른 조건이 적용되는 곳의 위의 식별의

...