【问题标题】:How to calculate the number distribution of data in IDL如何计算IDL中数据的个数分布
【发布时间】:2018-06-12 12:27:43
【问题描述】:

我有一个由时间和通量组成的数据(4117 行 x 2 列)我想计算并绘制与图片相同的两个连续数据点对之间亮度变化的数量分布distribution of brightness variation

这是我在idl中使用的代码

nx=4117
t=fltarr(nx)
f=fltarr(nx)
df=fltarr(nx-1)
dt=fltarr(nx-1)
n=4116
dff=fltarr(n)
dc=fltarr(n-1)

data=read_table('data.dat')
;print,data(0,*) ;this is t (time)
;print,data(1,*) ;this is f (flux)

; Plot the light curve

window,0
plot,data(0,*)/data(0,0),data(1,*)/data(1,0),yrange=[0.93,1.1],ystyle=1 

; calculate the flux difference (dff)

for i=0,nx-2 do begin
df(i)=data(1,i+1)/data(1,0) - data(1,i)/data(1,0)
dt(i)=data(0,i+1)/data(0,0) - data(0,i)/data(0,0)
endfor

for i=0,n-1 do dff(i)=min(df)+i*(max(df)-min(df))/float(n-1.0)

print,dff

; calculate the number distribution (dc), I want the counter to reset to zero after every point and start to count again

for i=0,n-2 do begin
c=0.0
for j=0,nx-2 do begin
IF (df(j) < dff(i+1)) or (df(j) > dff(i)) THEN begin
c=c+1
dc(i)=c
endif
endfor

print, dc(i)
endfor

end

当我运行代码时, dc 的所有值都是 4116 。我认为我计算 dc 的方式是错误的。任何建议以正确的方式做到这一点?

【问题讨论】:

    标签: idl-programming-language


    【解决方案1】:

    我很确定问题出在这一行:

    IF (df(j) < dff(i+1)) or (df(j) > dff(i)) THEN begin
    

    在 IDL 中,a &lt; b 是“a 和 b 中的较小者”的简写,a &gt; b 同样是“a 和 b 中的较大者”的简写。所以现在,你的 IF 语句实际上被评估为:

    IF (df(j) or dff(i+1), whichever is less) OR (df(j) or dff(i), whichever is more) THEN begin
    

    并且由于非零浮点数在 IDL 中评估为 TRUE,因此最终是这样的:

    IF TRUE or TRUE THEN begin
    

    因为 IF 语句始终为真,c 始终递增,dc 的每个值最终都是 4116。

    要解决此问题,您需要使用返回 TRUE 或 FALSE 的关系运算符 LTGT。换句话说,你的代码应该是:

    IF (df(j) LT dff(i+1)) or (df(j) GT dff(i)) THEN begin
    

    【讨论】:

      猜你喜欢
      • 2021-12-19
      • 1970-01-01
      • 2021-03-01
      • 2016-05-31
      • 2015-08-08
      • 2019-07-19
      • 1970-01-01
      • 2013-09-24
      • 2018-03-05
      相关资源
      最近更新 更多