version 1.33, 2015/01/23 01:18:13
|
version 1.38, 2020/06/30 22:38:17
|
|
|
|
|
/*=========================================== | /*=========================================== |
| |
The following 14 functions calculate the following spaceweather indices: | The following 14 functions calculate the following spaceweather indices: |
Line 246 int computeB_total(float *bx_err, float |
|
Line 247 int computeB_total(float *bx_err, float |
|
/*===========================================*/ | /*===========================================*/ |
/* Example function 5: Derivative of B_Total SQRT( (dBt/dx)^2 + (dBt/dy)^2 ) */ | /* Example function 5: Derivative of B_Total SQRT( (dBt/dx)^2 + (dBt/dy)^2 ) */ |
| |
int computeBtotalderivative(float *bt, int *dims, float *mean_derivative_btotal_ptr, int *mask, int *bitmask, float *derx_bt, float *dery_bt, float *bt_err, float *mean_derivative_btotal_err_ptr) |
int computeBtotalderivative(float *bt, int *dims, float *mean_derivative_btotal_ptr, int *mask, int *bitmask, float *derx_bt, float *dery_bt, float *bt_err, float *mean_derivative_btotal_err_ptr, float *err_termAt, float *err_termBt) |
{ | { |
| |
int nx = dims[0]; | int nx = dims[0]; |
Line 266 int computeBtotalderivative(float *bt, i |
|
Line 267 int computeBtotalderivative(float *bt, i |
|
for (j = 0; j <= ny-1; j++) | for (j = 0; j <= ny-1; j++) |
{ | { |
derx_bt[j * nx + i] = (bt[j * nx + i+1] - bt[j * nx + i-1])*0.5; | derx_bt[j * nx + i] = (bt[j * nx + i+1] - bt[j * nx + i-1])*0.5; |
|
err_termAt[j * nx + i] = (((bt[j * nx + (i+1)]-bt[j * nx + (i-1)])*(bt[j * nx + (i+1)]-bt[j * nx + (i-1)])) * (bt_err[j * nx + (i+1)]*bt_err[j * nx + (i+1)] + bt_err[j * nx + (i-1)]*bt_err[j * nx + (i-1)])) ; |
} | } |
} | } |
| |
Line 275 int computeBtotalderivative(float *bt, i |
|
Line 277 int computeBtotalderivative(float *bt, i |
|
for (j = 1; j <= ny-2; j++) | for (j = 1; j <= ny-2; j++) |
{ | { |
dery_bt[j * nx + i] = (bt[(j+1) * nx + i] - bt[(j-1) * nx + i])*0.5; | dery_bt[j * nx + i] = (bt[(j+1) * nx + i] - bt[(j-1) * nx + i])*0.5; |
|
err_termBt[j * nx + i] = (((bt[(j+1) * nx + i]-bt[(j-1) * nx + i])*(bt[(j+1) * nx + i]-bt[(j-1) * nx + i])) * (bt_err[(j+1) * nx + i]*bt_err[(j+1) * nx + i] + bt_err[(j-1) * nx + i]*bt_err[(j-1) * nx + i])) ; |
} | } |
} | } |
| |
|
/* consider the edges for the arrays that contribute to the variable "sum" in the computation below. |
/* consider the edges */ |
ignore the edges for the error terms as those arrays have been initialized to zero. |
|
this is okay because the error term will ultimately not include the edge pixels as they are selected out by the mask and bitmask arrays.*/ |
i=0; | i=0; |
for (j = 0; j <= ny-1; j++) | for (j = 0; j <= ny-1; j++) |
{ | { |
Line 304 int computeBtotalderivative(float *bt, i |
|
Line 308 int computeBtotalderivative(float *bt, i |
|
dery_bt[j * nx + i] = ( (3*bt[j * nx + i]) + (-4*bt[(j-1) * nx + i]) - (-bt[(j-2) * nx + i]) )*0.5; | dery_bt[j * nx + i] = ( (3*bt[j * nx + i]) + (-4*bt[(j-1) * nx + i]) - (-bt[(j-2) * nx + i]) )*0.5; |
} | } |
| |
|
// Calculate the sum only |
for (i = 1; i <= nx-2; i++) | for (i = 1; i <= nx-2; i++) |
{ | { |
for (j = 1; j <= ny-2; j++) | for (j = 1; j <= ny-2; j++) |
Line 320 int computeBtotalderivative(float *bt, i |
|
Line 324 int computeBtotalderivative(float *bt, i |
|
if isnan(derx_bt[j * nx + i]) continue; | if isnan(derx_bt[j * nx + i]) continue; |
if isnan(dery_bt[j * nx + i]) continue; | if isnan(dery_bt[j * nx + i]) continue; |
sum += sqrt( derx_bt[j * nx + i]*derx_bt[j * nx + i] + dery_bt[j * nx + i]*dery_bt[j * nx + i] ); /* Units of Gauss */ | sum += sqrt( derx_bt[j * nx + i]*derx_bt[j * nx + i] + dery_bt[j * nx + i]*dery_bt[j * nx + i] ); /* Units of Gauss */ |
err += (((bt[(j+1) * nx + i]-bt[(j-1) * nx + i])*(bt[(j+1) * nx + i]-bt[(j-1) * nx + i])) * (bt_err[(j+1) * nx + i]*bt_err[(j+1) * nx + i] + bt_err[(j-1) * nx + i]*bt_err[(j-1) * nx + i])) / (16.0*( derx_bt[j * nx + i]*derx_bt[j * nx + i] + dery_bt[j * nx + i]*dery_bt[j * nx + i] ))+ |
err += err_termBt[j * nx + i] / (16.0*( derx_bt[j * nx + i]*derx_bt[j * nx + i] + dery_bt[j * nx + i]*dery_bt[j * nx + i] ))+ |
(((bt[j * nx + (i+1)]-bt[j * nx + (i-1)])*(bt[j * nx + (i+1)]-bt[j * nx + (i-1)])) * (bt_err[j * nx + (i+1)]*bt_err[j * nx + (i+1)] + bt_err[j * nx + (i-1)]*bt_err[j * nx + (i-1)])) / (16.0*( derx_bt[j * nx + i]*derx_bt[j * nx + i] + dery_bt[j * nx + i]*dery_bt[j * nx + i] )) ; |
err_termAt[j * nx + i] / (16.0*( derx_bt[j * nx + i]*derx_bt[j * nx + i] + dery_bt[j * nx + i]*dery_bt[j * nx + i] )) ; |
count_mask++; | count_mask++; |
} | } |
} | } |
Line 338 int computeBtotalderivative(float *bt, i |
|
Line 342 int computeBtotalderivative(float *bt, i |
|
/*===========================================*/ | /*===========================================*/ |
/* Example function 6: Derivative of Bh SQRT( (dBh/dx)^2 + (dBh/dy)^2 ) */ | /* Example function 6: Derivative of Bh SQRT( (dBh/dx)^2 + (dBh/dy)^2 ) */ |
| |
int computeBhderivative(float *bh, float *bh_err, int *dims, float *mean_derivative_bh_ptr, float *mean_derivative_bh_err_ptr, int *mask, int *bitmask, float *derx_bh, float *dery_bh) |
int computeBhderivative(float *bh, float *bh_err, int *dims, float *mean_derivative_bh_ptr, float *mean_derivative_bh_err_ptr, int *mask, int *bitmask, float *derx_bh, float *dery_bh, float *err_termAh, float *err_termBh) |
{ | { |
| |
int nx = dims[0]; | int nx = dims[0]; |
Line 358 int computeBhderivative(float *bh, float |
|
Line 362 int computeBhderivative(float *bh, float |
|
for (j = 0; j <= ny-1; j++) | for (j = 0; j <= ny-1; j++) |
{ | { |
derx_bh[j * nx + i] = (bh[j * nx + i+1] - bh[j * nx + i-1])*0.5; | derx_bh[j * nx + i] = (bh[j * nx + i+1] - bh[j * nx + i-1])*0.5; |
|
err_termAh[j * nx + i] = (((bh[j * nx + (i+1)]-bh[j * nx + (i-1)])*(bh[j * nx + (i+1)]-bh[j * nx + (i-1)])) * (bh_err[j * nx + (i+1)]*bh_err[j * nx + (i+1)] + bh_err[j * nx + (i-1)]*bh_err[j * nx + (i-1)])); |
} | } |
} | } |
| |
Line 367 int computeBhderivative(float *bh, float |
|
Line 372 int computeBhderivative(float *bh, float |
|
for (j = 1; j <= ny-2; j++) | for (j = 1; j <= ny-2; j++) |
{ | { |
dery_bh[j * nx + i] = (bh[(j+1) * nx + i] - bh[(j-1) * nx + i])*0.5; | dery_bh[j * nx + i] = (bh[(j+1) * nx + i] - bh[(j-1) * nx + i])*0.5; |
|
err_termBh[j * nx + i] = (((bh[ (j+1) * nx + i]-bh[(j-1) * nx + i])*(bh[(j+1) * nx + i]-bh[(j-1) * nx + i])) * (bh_err[(j+1) * nx + i]*bh_err[(j+1) * nx + i] + bh_err[(j-1) * nx + i]*bh_err[(j-1) * nx + i])); |
} | } |
} | } |
| |
|
/* consider the edges for the arrays that contribute to the variable "sum" in the computation below. |
/* consider the edges */ |
ignore the edges for the error terms as those arrays have been initialized to zero. |
|
this is okay because the error term will ultimately not include the edge pixels as they are selected out by the mask and bitmask arrays.*/ |
i=0; | i=0; |
for (j = 0; j <= ny-1; j++) | for (j = 0; j <= ny-1; j++) |
{ | { |
Line 412 int computeBhderivative(float *bh, float |
|
Line 419 int computeBhderivative(float *bh, float |
|
if isnan(derx_bh[j * nx + i]) continue; | if isnan(derx_bh[j * nx + i]) continue; |
if isnan(dery_bh[j * nx + i]) continue; | if isnan(dery_bh[j * nx + i]) continue; |
sum += sqrt( derx_bh[j * nx + i]*derx_bh[j * nx + i] + dery_bh[j * nx + i]*dery_bh[j * nx + i] ); /* Units of Gauss */ | sum += sqrt( derx_bh[j * nx + i]*derx_bh[j * nx + i] + dery_bh[j * nx + i]*dery_bh[j * nx + i] ); /* Units of Gauss */ |
err += (((bh[(j+1) * nx + i]-bh[(j-1) * nx + i])*(bh[(j+1) * nx + i]-bh[(j-1) * nx + i])) * (bh_err[(j+1) * nx + i]*bh_err[(j+1) * nx + i] + bh_err[(j-1) * nx + i]*bh_err[(j-1) * nx + i])) / (16.0*( derx_bh[j * nx + i]*derx_bh[j * nx + i] + dery_bh[j * nx + i]*dery_bh[j * nx + i] ))+ |
err += err_termBh[j * nx + i] / (16.0*( derx_bh[j * nx + i]*derx_bh[j * nx + i] + dery_bh[j * nx + i]*dery_bh[j * nx + i] ))+ |
(((bh[j * nx + (i+1)]-bh[j * nx + (i-1)])*(bh[j * nx + (i+1)]-bh[j * nx + (i-1)])) * (bh_err[j * nx + (i+1)]*bh_err[j * nx + (i+1)] + bh_err[j * nx + (i-1)]*bh_err[j * nx + (i-1)])) / (16.0*( derx_bh[j * nx + i]*derx_bh[j * nx + i] + dery_bh[j * nx + i]*dery_bh[j * nx + i] )) ; |
err_termAh[j * nx + i] / (16.0*( derx_bh[j * nx + i]*derx_bh[j * nx + i] + dery_bh[j * nx + i]*dery_bh[j * nx + i] )) ; |
count_mask++; | count_mask++; |
} | } |
} | } |
Line 429 int computeBhderivative(float *bh, float |
|
Line 436 int computeBhderivative(float *bh, float |
|
/*===========================================*/ | /*===========================================*/ |
/* Example function 7: Derivative of B_vertical SQRT( (dBz/dx)^2 + (dBz/dy)^2 ) */ | /* Example function 7: Derivative of B_vertical SQRT( (dBz/dx)^2 + (dBz/dy)^2 ) */ |
| |
int computeBzderivative(float *bz, float *bz_err, int *dims, float *mean_derivative_bz_ptr, float *mean_derivative_bz_err_ptr, int *mask, int *bitmask, float *derx_bz, float *dery_bz) |
int computeBzderivative(float *bz, float *bz_err, int *dims, float *mean_derivative_bz_ptr, float *mean_derivative_bz_err_ptr, int *mask, int *bitmask, float *derx_bz, float *dery_bz, float *err_termA, float *err_termB) |
{ | { |
| |
int nx = dims[0]; | int nx = dims[0]; |
Line 448 int computeBzderivative(float *bz, float |
|
Line 455 int computeBzderivative(float *bz, float |
|
{ | { |
for (j = 0; j <= ny-1; j++) | for (j = 0; j <= ny-1; j++) |
{ | { |
if isnan(bz[j * nx + i]) continue; |
|
derx_bz[j * nx + i] = (bz[j * nx + i+1] - bz[j * nx + i-1])*0.5; | derx_bz[j * nx + i] = (bz[j * nx + i+1] - bz[j * nx + i-1])*0.5; |
|
err_termA[j * nx + i] = (((bz[j * nx + (i+1)]-bz[j * nx + (i-1)])*(bz[j * nx + (i+1)]-bz[j * nx + (i-1)])) * (bz_err[j * nx + (i+1)]*bz_err[j * nx + (i+1)] + bz_err[j * nx + (i-1)]*bz_err[j * nx + (i-1)])); |
} | } |
} | } |
| |
Line 458 int computeBzderivative(float *bz, float |
|
Line 465 int computeBzderivative(float *bz, float |
|
{ | { |
for (j = 1; j <= ny-2; j++) | for (j = 1; j <= ny-2; j++) |
{ | { |
if isnan(bz[j * nx + i]) continue; |
|
dery_bz[j * nx + i] = (bz[(j+1) * nx + i] - bz[(j-1) * nx + i])*0.5; | dery_bz[j * nx + i] = (bz[(j+1) * nx + i] - bz[(j-1) * nx + i])*0.5; |
|
err_termB[j * nx + i] = (((bz[(j+1) * nx + i]-bz[(j-1) * nx + i])*(bz[(j+1) * nx + i]-bz[(j-1) * nx + i])) * (bz_err[(j+1) * nx + i]*bz_err[(j+1) * nx + i] + bz_err[(j-1) * nx + i]*bz_err[(j-1) * nx + i])); |
} | } |
} | } |
| |
|
/* consider the edges for the arrays that contribute to the variable "sum" in the computation below. |
/* consider the edges */ |
ignore the edges for the error terms as those arrays have been initialized to zero. |
|
this is okay because the error term will ultimately not include the edge pixels as they are selected out by the mask and bitmask arrays.*/ |
i=0; | i=0; |
for (j = 0; j <= ny-1; j++) | for (j = 0; j <= ny-1; j++) |
{ | { |
if isnan(bz[j * nx + i]) continue; |
|
derx_bz[j * nx + i] = ( (-3*bz[j * nx + i]) + (4*bz[j * nx + (i+1)]) - (bz[j * nx + (i+2)]) )*0.5; | derx_bz[j * nx + i] = ( (-3*bz[j * nx + i]) + (4*bz[j * nx + (i+1)]) - (bz[j * nx + (i+2)]) )*0.5; |
} | } |
| |
i=nx-1; | i=nx-1; |
for (j = 0; j <= ny-1; j++) | for (j = 0; j <= ny-1; j++) |
{ | { |
if isnan(bz[j * nx + i]) continue; |
|
derx_bz[j * nx + i] = ( (3*bz[j * nx + i]) + (-4*bz[j * nx + (i-1)]) - (-bz[j * nx + (i-2)]) )*0.5; | derx_bz[j * nx + i] = ( (3*bz[j * nx + i]) + (-4*bz[j * nx + (i-1)]) - (-bz[j * nx + (i-2)]) )*0.5; |
} | } |
| |
j=0; | j=0; |
for (i = 0; i <= nx-1; i++) | for (i = 0; i <= nx-1; i++) |
{ | { |
if isnan(bz[j * nx + i]) continue; |
|
dery_bz[j * nx + i] = ( (-3*bz[j*nx + i]) + (4*bz[(j+1) * nx + i]) - (bz[(j+2) * nx + i]) )*0.5; | dery_bz[j * nx + i] = ( (-3*bz[j*nx + i]) + (4*bz[(j+1) * nx + i]) - (bz[(j+2) * nx + i]) )*0.5; |
} | } |
| |
j=ny-1; | j=ny-1; |
for (i = 0; i <= nx-1; i++) | for (i = 0; i <= nx-1; i++) |
{ | { |
if isnan(bz[j * nx + i]) continue; |
|
dery_bz[j * nx + i] = ( (3*bz[j * nx + i]) + (-4*bz[(j-1) * nx + i]) - (-bz[(j-2) * nx + i]) )*0.5; | dery_bz[j * nx + i] = ( (3*bz[j * nx + i]) + (-4*bz[(j-1) * nx + i]) - (-bz[(j-2) * nx + i]) )*0.5; |
} | } |
| |
Line 509 int computeBzderivative(float *bz, float |
|
Line 513 int computeBzderivative(float *bz, float |
|
if isnan(derx_bz[j * nx + i]) continue; | if isnan(derx_bz[j * nx + i]) continue; |
if isnan(dery_bz[j * nx + i]) continue; | if isnan(dery_bz[j * nx + i]) continue; |
sum += sqrt( derx_bz[j * nx + i]*derx_bz[j * nx + i] + dery_bz[j * nx + i]*dery_bz[j * nx + i] ); /* Units of Gauss */ | sum += sqrt( derx_bz[j * nx + i]*derx_bz[j * nx + i] + dery_bz[j * nx + i]*dery_bz[j * nx + i] ); /* Units of Gauss */ |
err += (((bz[(j+1) * nx + i]-bz[(j-1) * nx + i])*(bz[(j+1) * nx + i]-bz[(j-1) * nx + i])) * (bz_err[(j+1) * nx + i]*bz_err[(j+1) * nx + i] + bz_err[(j-1) * nx + i]*bz_err[(j-1) * nx + i])) / |
err += err_termB[j * nx + i] / (16.0*( derx_bz[j * nx + i]*derx_bz[j * nx + i] + dery_bz[j * nx + i]*dery_bz[j * nx + i] )) + |
(16.0*( derx_bz[j * nx + i]*derx_bz[j * nx + i] + dery_bz[j * nx + i]*dery_bz[j * nx + i] )) + |
err_termA[j * nx + i] / (16.0*( derx_bz[j * nx + i]*derx_bz[j * nx + i] + dery_bz[j * nx + i]*dery_bz[j * nx + i] )) ; |
(((bz[j * nx + (i+1)]-bz[j * nx + (i-1)])*(bz[j * nx + (i+1)]-bz[j * nx + (i-1)])) * (bz_err[j * nx + (i+1)]*bz_err[j * nx + (i+1)] + bz_err[j * nx + (i-1)]*bz_err[j * nx + (i-1)])) / |
|
(16.0*( derx_bz[j * nx + i]*derx_bz[j * nx + i] + dery_bz[j * nx + i]*dery_bz[j * nx + i] )) ; |
|
count_mask++; | count_mask++; |
} | } |
} | } |
Line 582 int computeJz(float *bx_err, float *by_e |
|
Line 584 int computeJz(float *bx_err, float *by_e |
|
{ | { |
for (j = 0; j <= ny-1; j++) | for (j = 0; j <= ny-1; j++) |
{ | { |
if isnan(by[j * nx + i]) continue; |
|
derx[j * nx + i] = (by[j * nx + i+1] - by[j * nx + i-1])*0.5; | derx[j * nx + i] = (by[j * nx + i+1] - by[j * nx + i-1])*0.5; |
err_term1[j * nx + i] = (by_err[j * nx + i+1])*(by_err[j * nx + i+1]) + (by_err[j * nx + i-1])*(by_err[j * nx + i-1]); | err_term1[j * nx + i] = (by_err[j * nx + i+1])*(by_err[j * nx + i+1]) + (by_err[j * nx + i-1])*(by_err[j * nx + i-1]); |
} | } |
Line 592 int computeJz(float *bx_err, float *by_e |
|
Line 593 int computeJz(float *bx_err, float *by_e |
|
{ | { |
for (j = 1; j <= ny-2; j++) | for (j = 1; j <= ny-2; j++) |
{ | { |
if isnan(bx[j * nx + i]) continue; |
|
dery[j * nx + i] = (bx[(j+1) * nx + i] - bx[(j-1) * nx + i])*0.5; | dery[j * nx + i] = (bx[(j+1) * nx + i] - bx[(j-1) * nx + i])*0.5; |
err_term2[j * nx + i] = (bx_err[(j+1) * nx + i])*(bx_err[(j+1) * nx + i]) + (bx_err[(j-1) * nx + i])*(bx_err[(j-1) * nx + i]); | err_term2[j * nx + i] = (bx_err[(j+1) * nx + i])*(bx_err[(j+1) * nx + i]) + (bx_err[(j-1) * nx + i])*(bx_err[(j-1) * nx + i]); |
} | } |
} | } |
| |
// consider the edges |
/* consider the edges for the arrays that contribute to the variable "sum" in the computation below. |
|
ignore the edges for the error terms as those arrays have been initialized to zero. |
|
this is okay because the error term will ultimately not include the edge pixels as they are selected out by the mask and bitmask arrays.*/ |
|
|
i=0; | i=0; |
for (j = 0; j <= ny-1; j++) | for (j = 0; j <= ny-1; j++) |
{ | { |
if isnan(by[j * nx + i]) continue; |
|
derx[j * nx + i] = ( (-3*by[j * nx + i]) + (4*by[j * nx + (i+1)]) - (by[j * nx + (i+2)]) )*0.5; | derx[j * nx + i] = ( (-3*by[j * nx + i]) + (4*by[j * nx + (i+1)]) - (by[j * nx + (i+2)]) )*0.5; |
err_term1[j * nx + i] = ( (3*by_err[j * nx + i])*(3*by_err[j * nx + i]) + (4*by_err[j * nx + (i+1)])*(4*by_err[j * nx + (i+1)]) + (by_err[j * nx + (i+2)])*(by_err[j * nx + (i+2)]) ); |
|
} | } |
| |
i=nx-1; | i=nx-1; |
for (j = 0; j <= ny-1; j++) | for (j = 0; j <= ny-1; j++) |
{ | { |
if isnan(by[j * nx + i]) continue; |
|
derx[j * nx + i] = ( (3*by[j * nx + i]) + (-4*by[j * nx + (i-1)]) - (-by[j * nx + (i-2)]) )*0.5; | derx[j * nx + i] = ( (3*by[j * nx + i]) + (-4*by[j * nx + (i-1)]) - (-by[j * nx + (i-2)]) )*0.5; |
err_term1[j * nx + i] = ( (3*by_err[j * nx + i])*(3*by_err[j * nx + i]) + (4*by_err[j * nx + (i+1)])*(4*by_err[j * nx + (i+1)]) + (by_err[j * nx + (i+2)])*(by_err[j * nx + (i+2)]) ); |
|
} | } |
| |
j=0; | j=0; |
for (i = 0; i <= nx-1; i++) | for (i = 0; i <= nx-1; i++) |
{ | { |
if isnan(bx[j * nx + i]) continue; |
|
dery[j * nx + i] = ( (-3*bx[j*nx + i]) + (4*bx[(j+1) * nx + i]) - (bx[(j+2) * nx + i]) )*0.5; | dery[j * nx + i] = ( (-3*bx[j*nx + i]) + (4*bx[(j+1) * nx + i]) - (bx[(j+2) * nx + i]) )*0.5; |
err_term2[j * nx + i] = ( (3*bx_err[j*nx + i])*(3*bx_err[j*nx + i]) + (4*bx_err[(j+1) * nx + i])*(4*bx_err[(j+1) * nx + i]) + (bx_err[(j+2) * nx + i])*(bx_err[(j+2) * nx + i]) ); |
|
} | } |
| |
j=ny-1; | j=ny-1; |
for (i = 0; i <= nx-1; i++) | for (i = 0; i <= nx-1; i++) |
{ | { |
if isnan(bx[j * nx + i]) continue; |
|
dery[j * nx + i] = ( (3*bx[j * nx + i]) + (-4*bx[(j-1) * nx + i]) - (-bx[(j-2) * nx + i]) )*0.5; | dery[j * nx + i] = ( (3*bx[j * nx + i]) + (-4*bx[(j-1) * nx + i]) - (-bx[(j-2) * nx + i]) )*0.5; |
err_term2[j * nx + i] = ( (3*bx_err[j*nx + i])*(3*bx_err[j*nx + i]) + (4*bx_err[(j+1) * nx + i])*(4*bx_err[(j+1) * nx + i]) + (bx_err[(j+2) * nx + i])*(bx_err[(j+2) * nx + i]) ); |
|
|
|
} | } |
| |
| |
Line 837 int computeHelicity(float *jz_err, float |
|
Line 831 int computeHelicity(float *jz_err, float |
|
/* Example function 12: Sum of Absolute Value per polarity */ | /* Example function 12: Sum of Absolute Value per polarity */ |
| |
// The Sum of the Absolute Value per polarity is defined as the following: | // The Sum of the Absolute Value per polarity is defined as the following: |
// fabs(sum(jz gt 0)) + fabs(sum(jz lt 0)) and the units are in Amperes per arcsecond. |
// fabs(sum(jz gt 0)) + fabs(sum(jz lt 0)) and the units are in Amperes per square arcsecond. |
// The units of jz are in G/pix. In this case, we would have the following: | // The units of jz are in G/pix. In this case, we would have the following: |
// Jz = (Gauss/pix)(1/CDELT1)(0.00010)(1/MUNAUGHT)(RSUN_REF/RSUN_OBS)(RSUN_REF/RSUN_OBS)(RSUN_OBS/RSUN_REF), | // Jz = (Gauss/pix)(1/CDELT1)(0.00010)(1/MUNAUGHT)(RSUN_REF/RSUN_OBS)(RSUN_REF/RSUN_OBS)(RSUN_OBS/RSUN_REF), |
// = (Gauss/pix)(1/CDELT1)(0.00010)(1/MUNAUGHT)(RSUN_REF/RSUN_OBS) | // = (Gauss/pix)(1/CDELT1)(0.00010)(1/MUNAUGHT)(RSUN_REF/RSUN_OBS) |
Line 1240 int computeLorentz(float *bx, float *by |
|
Line 1234 int computeLorentz(float *bx, float *by |
|
| |
} | } |
| |
|
/*===========================================*/ |
|
|
|
/* Example function 17: Compute total unsigned flux in units of G/cm^2 on the LOS field */ |
|
|
|
// To compute the unsigned flux, we simply calculate |
|
// flux = surface integral [(vector LOS) dot (normal vector)], |
|
// = surface integral [(magnitude LOS)*(magnitude normal)*(cos theta)]. |
|
// However, since the field is radial, we will assume cos theta = 1. |
|
// Therefore the pixels only need to be corrected for the projection. |
|
|
|
// To convert G to G*cm^2, simply multiply by the number of square centimeters per pixel. |
|
// As an order of magnitude estimate, we can assign 0.5 to CDELT1 and 722500m/arcsec to (RSUN_REF/RSUN_OBS). |
|
// (Gauss/pix^2)(CDELT1)^2(RSUN_REF/RSUN_OBS)^2(100.cm/m)^2 |
|
// =Gauss*cm^2 |
|
|
|
int computeAbsFlux_los(float *los, int *dims, float *absFlux, |
|
float *mean_vf_ptr, float *count_mask_ptr, |
|
int *bitmask, float cdelt1, double rsun_ref, double rsun_obs) |
|
|
|
{ |
|
|
|
int nx = dims[0]; |
|
int ny = dims[1]; |
|
int i = 0; |
|
int j = 0; |
|
int count_mask = 0; |
|
double sum = 0.0; |
|
*absFlux = 0.0; |
|
*mean_vf_ptr = 0.0; |
|
|
|
|
|
if (nx <= 0 || ny <= 0) return 1; |
|
|
|
for (i = 0; i < nx; i++) |
|
{ |
|
for (j = 0; j < ny; j++) |
|
{ |
|
if ( bitmask[j * nx + i] < 30 ) continue; |
|
if isnan(los[j * nx + i]) continue; |
|
sum += (fabs(los[j * nx + i])); |
|
count_mask++; |
|
} |
|
} |
|
|
|
*mean_vf_ptr = sum*cdelt1*cdelt1*(rsun_ref/rsun_obs)*(rsun_ref/rsun_obs)*100.0*100.0; |
|
*count_mask_ptr = count_mask; |
|
|
|
return 0; |
|
} |
|
|
|
/*===========================================*/ |
|
/* Example function 18: Derivative of B_LOS (approximately B_vertical) = SQRT( ( dLOS/dx )^2 + ( dLOS/dy )^2 ) */ |
|
|
|
int computeLOSderivative(float *los, int *dims, float *mean_derivative_los_ptr, int *bitmask, float *derx_los, float *dery_los) |
|
{ |
|
|
|
int nx = dims[0]; |
|
int ny = dims[1]; |
|
int i = 0; |
|
int j = 0; |
|
int count_mask = 0; |
|
double sum = 0.0; |
|
*mean_derivative_los_ptr = 0.0; |
|
|
|
if (nx <= 0 || ny <= 0) return 1; |
|
|
|
/* brute force method of calculating the derivative (no consideration for edges) */ |
|
for (i = 1; i <= nx-2; i++) |
|
{ |
|
for (j = 0; j <= ny-1; j++) |
|
{ |
|
derx_los[j * nx + i] = (los[j * nx + i+1] - los[j * nx + i-1])*0.5; |
|
} |
|
} |
|
|
|
/* brute force method of calculating the derivative (no consideration for edges) */ |
|
for (i = 0; i <= nx-1; i++) |
|
{ |
|
for (j = 1; j <= ny-2; j++) |
|
{ |
|
dery_los[j * nx + i] = (los[(j+1) * nx + i] - los[(j-1) * nx + i])*0.5; |
|
} |
|
} |
|
|
|
/* consider the edges for the arrays that contribute to the variable "sum" in the computation below. |
|
ignore the edges for the error terms as those arrays have been initialized to zero. |
|
this is okay because the error term will ultimately not include the edge pixels as they are selected out by the mask and bitmask arrays.*/ |
|
i=0; |
|
for (j = 0; j <= ny-1; j++) |
|
{ |
|
derx_los[j * nx + i] = ( (-3*los[j * nx + i]) + (4*los[j * nx + (i+1)]) - (los[j * nx + (i+2)]) )*0.5; |
|
} |
|
|
|
i=nx-1; |
|
for (j = 0; j <= ny-1; j++) |
|
{ |
|
derx_los[j * nx + i] = ( (3*los[j * nx + i]) + (-4*los[j * nx + (i-1)]) - (-los[j * nx + (i-2)]) )*0.5; |
|
} |
|
|
|
j=0; |
|
for (i = 0; i <= nx-1; i++) |
|
{ |
|
dery_los[j * nx + i] = ( (-3*los[j*nx + i]) + (4*los[(j+1) * nx + i]) - (los[(j+2) * nx + i]) )*0.5; |
|
} |
|
|
|
j=ny-1; |
|
for (i = 0; i <= nx-1; i++) |
|
{ |
|
dery_los[j * nx + i] = ( (3*los[j * nx + i]) + (-4*los[(j-1) * nx + i]) - (-los[(j-2) * nx + i]) )*0.5; |
|
} |
|
|
|
|
|
for (i = 0; i <= nx-1; i++) |
|
{ |
|
for (j = 0; j <= ny-1; j++) |
|
{ |
|
if ( bitmask[j * nx + i] < 30 ) continue; |
|
if ( (derx_los[j * nx + i] + dery_los[j * nx + i]) == 0) continue; |
|
if isnan(los[j * nx + i]) continue; |
|
if isnan(los[(j+1) * nx + i]) continue; |
|
if isnan(los[(j-1) * nx + i]) continue; |
|
if isnan(los[j * nx + i-1]) continue; |
|
if isnan(los[j * nx + i+1]) continue; |
|
if isnan(derx_los[j * nx + i]) continue; |
|
if isnan(dery_los[j * nx + i]) continue; |
|
sum += sqrt( derx_los[j * nx + i]*derx_los[j * nx + i] + dery_los[j * nx + i]*dery_los[j * nx + i] ); /* Units of Gauss */ |
|
count_mask++; |
|
} |
|
} |
|
|
|
*mean_derivative_los_ptr = (sum)/(count_mask); // would be divided by ((nx-2)*(ny-2)) if shape of count_mask = shape of magnetogram |
|
//printf("mean_derivative_los_ptr=%f\n",*mean_derivative_los_ptr); |
|
|
|
return 0; |
|
} |
|
|
/*==================KEIJI'S CODE =========================*/ | /*==================KEIJI'S CODE =========================*/ |
| |
// #include <omp.h> | // #include <omp.h> |