0

Simply I want to translate the IDL code to python code. This is an easy task for any IDL and Python Expert. But it is not possible for me, if anybody helps me to translate this code then I will thankful to him/her.

RelA = ABS((image1 ) - (image2))
index = where(RelA gt 180.D)
RelA[index] = 360.D- RelA[index]
index = where(RelA le 180.)
RelA[index] = 180.D- RelA[index]
CosRe = cos(RelA * !pi / 180.D)
mgalloy
  • 2,356
  • 1
  • 12
  • 10

2 Answers2

1

It's a straightforward conversion to NumPy:

#RelA = ABS((image1 ) - (image2))
RelA = np.abs(image1 - image2)

#index = where(RelA gt 180.D)
index = np.where(RelA > 180.0)

#RelA[index] = 360.D- RelA[index]
RelA[index] = 360.0 - RelA[index]

#index = where(RelA le 180.)
index = np.where(RelA <= 180.0)

#RelA[index] = 180.D- RelA[index]
RelA[index] = 180.0 - RelA[index]

#CosRe = cos(RelA * !pi / 180.D)
CosRe = np.cos(np.radians(RelA))

To translate your second piece of code, just remove the "D" specifiers (Python scalars are automatically higher precision), use "**" instead of "^", and use Numpy's cos function:

D1 = (0.00864 + (0.0000065)) * (0.86D)**(-(3.916 + (0.074 * 0.86)+ (0.05/0.86D)))
D2 = 0.008569 * ((0.8585)**(-4))*(1. + (0.0113 *(0.8585)**(-2)) + (0.00013 * (0.8585D)^(-4)))
D1 = (Pz/Po) * (0.00864 + (0.0000065 * z)) * (0.55)**(-(3.916 + (0.074 * 0.55)+ (0.05/0.55)))
Pr1 = (3./16.*np.pi)* (2/(2+delta))* ((1+delta)+((1+delta)*(np.cos(Agl) * np.cos(Agl))))
Pr2 =  (3./16.*np.pi) * (1 + (np.cos(Agl) * np.cos(Agl)))
mgalloy
  • 2,356
  • 1
  • 12
  • 10
  • Thanks for your kind response. I am little bit worried another five lines of IDL code, can you translate this code for me. I will be obliged if you kindly help me. – Bijoy Krishna Gayen Jun 11 '19 at 18:12
0
Pz=image1
Po=image2
Agl=image3
delta=0.0139
D1 = (0.00864D + (0.0000065D )) * (0.86D)^(-(3.916 + (0.074 * 0.86D)+ (0.05/0.86D)))
D2 = 0.008569D * ((0.8585D)^(-4))*(1.D + (0.0113D *(0.8585D)^(-2)) + (0.00013D * (0.8585D)^(-4)))
D1 = (Pz/Po) * (0.00864D + (0.0000065D * z)) * (0.55D)^(-(3.916 + (0.074 * 0.55)+ (0.05/0.55)))

Pr1 = (3.D/16.D*!dPi)* (2/(2+delta))* ((1+delta)+((1+delta)*(cos(Agl) * cos(Agl))))
Pr2 =  (3.D/16.D*!Pi) * (1 + (cos(Agl) * cos(Agl)))