tsssss / geopack

Python version of geopack and Tsyganenko models
MIT License
30 stars 12 forks source link

Antiparallel tracing for geopack.trace source code error #3

Closed Rhyst223 closed 5 years ago

Rhyst223 commented 5 years ago

Hi, I am trying to use the geopack.trace function to calculate the limiting field line position antiparallel to my point (dir=1). However whenever I use dir=1 I get the following error:

UnboundLocalError                         Traceback (most recent call last)
<ipython-input-121-b09879ee0d08> in <module>
      1 parmod = [data['Pdyn'][k],data['SYMH'][k],data['BYGSM'][k],data['BZGSM'][k],data['W1'][k],data['W2'][k],data['W3'][k], \
      2           data['W4'][k],data['W5'][k],data['W6'][k]]
----> 3 a,b,c,_,_,_ = geopack.trace(xgsm,ygsm,zgsm,dir=1)
      4 a1,b1,c1 = geopack.geogsm(a,b,c,-1)
      5 print(a1,b1,c1)

~/.conda/envs/rtenv36/lib/python3.6/site-packages/geopack/geopack.py in trace(xi, yi, zi, dir, rlim, r0, parmod, exname, inname, maxloop)
   1165             # find the footpoint position by interpolating between the current and previous field line points:
   1166             r1=(r0-r)/(rr-r)
-> 1167             x=x-(x-xr)*r1
   1168             y=y-(y-yr)*r1
   1169             z=z-(z-zr)*r1

UnboundLocalError: local variable 'xr' referenced before assignment

When I look at the source code, I see that xr, yr, zr are all never defined but are referenced before their assignment. Has part of the source code been omitted?

tsssss commented 5 years ago

Hi, Thank you so much for letting me know the problem. I'll look into it this weekend. Just a quick check: does parallel tracing work for you? -Sheng

On Fri, 26 Apr 2019 at 07:46, Rhyst223 notifications@github.com wrote:

Hi, I am trying to use the geopack.trace function to calculate the limiting field line position antiparallel to my point (dir=1). However whenever I use dir=1 I get the following error:

UnboundLocalError Traceback (most recent call last)

in 1 parmod = [data['Pdyn'][k],data['SYMH'][k],data['BYGSM'][k],data['BZGSM'][k],data['W1'][k],data['W2'][k],data['W3'][k], \ 2 data['W4'][k],data['W5'][k],data['W6'][k]] ----> 3 a,b,c,_,_,_ = geopack.trace(xgsm,ygsm,zgsm,dir=1) 4 a1,b1,c1 = geopack.geogsm(a,b,c,-1) 5 print(a1,b1,c1) ~/.conda/envs/rtenv36/lib/python3.6/site-packages/geopack/geopack.py in trace(xi, yi, zi, dir, rlim, r0, parmod, exname, inname, maxloop) 1165 # find the footpoint position by interpolating between the current and previous field line points: 1166 r1=(r0-r)/(rr-r) -> 1167 x=x-(x-xr)*r1 1168 y=y-(y-yr)*r1 1169 z=z-(z-zr)*r1 UnboundLocalError: local variable 'xr' referenced before assignment When I look at the source code, I see that xr, yr, zr are all never defined but are referenced before their assignment. Has part of the source code been omitted? — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub , or mute the thread .
tsssss commented 5 years ago

Hi Rhyst223,

Can you send me the input for the example you reported? More specifically, the position, time, and parameters?

It is true that L1167 has [xyz]r referenced before they are defined (L1190). However, the program is expected to reach L1190 first but not L1167. So I'm curious to track the program using your input.

Thanks, Sheng

On Fri, 26 Apr 2019 at 08:52, Sheng Tian tsheng886@gmail.com wrote:

Hi, Thank you so much for letting me know the problem. I'll look into it this weekend. Just a quick check: does parallel tracing work for you? -Sheng

On Fri, 26 Apr 2019 at 07:46, Rhyst223 notifications@github.com wrote:

Hi, I am trying to use the geopack.trace function to calculate the limiting field line position antiparallel to my point (dir=1). However whenever I use dir=1 I get the following error:

UnboundLocalError Traceback (most recent call last)

in 1 parmod = [data['Pdyn'][k],data['SYMH'][k],data['BYGSM'][k],data['BZGSM'][k],data['W1'][k],data['W2'][k],data['W3'][k], \ 2 data['W4'][k],data['W5'][k],data['W6'][k]] ----> 3 a,b,c,_,_,_ = geopack.trace(xgsm,ygsm,zgsm,dir=1) 4 a1,b1,c1 = geopack.geogsm(a,b,c,-1) 5 print(a1,b1,c1) ~/.conda/envs/rtenv36/lib/python3.6/site-packages/geopack/geopack.py in trace(xi, yi, zi, dir, rlim, r0, parmod, exname, inname, maxloop) 1165 # find the footpoint position by interpolating between the current and previous field line points: 1166 r1=(r0-r)/(rr-r) -> 1167 x=x-(x-xr)*r1 1168 y=y-(y-yr)*r1 1169 z=z-(z-zr)*r1 UnboundLocalError: local variable 'xr' referenced before assignment When I look at the source code, I see that xr, yr, zr are all never defined but are referenced before their assignment. Has part of the source code been omitted? — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub , or mute the thread .
Rhyst223 commented 5 years ago

Hi Sheng,

I am running my code as follows:

from geopack import geopack
import numpy as np
import pandas as pd

glats = [45.871,48.027,50.199,52.035,53.856,54.929,56.376,57.707,58.763,62.824]
glons = [264.917,263.635,263.960,264.537,265.340,264.713,265.300,265.794,265.920,267.890]

data = pd.Series([2.008e+03,  1.000e+00,  2.100e+01,  3.500e+01, -2.140e+00,
        1.560e+00,  2.200e-01, -3.514e+02, -2.200e+00, -7.900e+00,
        7.750e+00,  3.131e+04, -4.000e+00,  1.000e+00,  1.000e+00,
       -3.380e-01,  1.850e+00,  0.000e+00,  0.000e+00,  0.000e+00,
        0.000e+00,  0.000e+00,  0.000e+00])

data.columns = ['IYEAR', 'IDAY', 'IHOUR', 'MIN', 'BXGSM', 'BYGSM', 'BZGSM', 'VXGSE',
       'VYGSE', 'VZGSE', 'DEN', 'TEMP', 'SYMH', 'IMFFLAG', 'ISWFLAG', 'TILT',
       'Pdyn', 'W1', 'W2', 'W3', 'W4', 'W5', 'W6']

ut = data['IHOUR']*3600 + data['MIN']*60  
ps = geopack.recalc(ut)

Re = 6371.2
x, y,= geopack.geodgeo(100,np.deg2rad(glats[0]),1)
xgsm, ygsm, zgsm = geopack.geogsm(x,y,100,1)
xgsm /= Re
ygsm /= Re
zgsm /= Re

parmod = [data['Pdyn'][0],data['SYMH'][0],data['BYGSM'][0],data['BZGSM'][0]]
geopack.trace(xgsm,ygsm,zgsm,1,parmod=parmod,rlim=100,exname='t96')

Thanks,

Rhys

tsssss commented 5 years ago

Thanks, I'll check it out. -Sheng

On Wed, 1 May 2019 at 07:05, Rhyst223 notifications@github.com wrote:

Hi Sheng,

I am running my code as follows:

from geopack import geopack import numpy as np import pandas as pd

glats = [45.871,48.027,50.199,52.035,53.856,54.929,56.376,57.707,58.763,62.824] glons = [264.917,263.635,263.960,264.537,265.340,264.713,265.300,265.794,265.920,267.890]

data = pd.Series(2.008e+03, 1.000e+00, 2.100e+01, 3.500e+01, -2.140e+00, 1.560e+00, 2.200e-01, -3.514e+02, -2.200e+00, -7.900e+00, 7.750e+00, 3.131e+04, -4.000e+00, 1.000e+00, 1.000e+00, -3.380e-01, 1.850e+00, 0.000e+00, 0.000e+00, 0.000e+00, 0.000e+00, 0.000e+00, 0.000e+00])

data.columns = ['IYEAR', 'IDAY', 'IHOUR', 'MIN', 'BXGSM', 'BYGSM', 'BZGSM', 'VXGSE', 'VYGSE', 'VZGSE', 'DEN', 'TEMP', 'SYMH', 'IMFFLAG', 'ISWFLAG', 'TILT', 'Pdyn', 'W1', 'W2', 'W3', 'W4', 'W5', 'W6']

ut = data['IHOUR']3600 + data['MIN']60 ps = geopack.recalc(ut)

Re = 6371.2 x, y,= geopack.geodgeo(100,np.deg2rad(glats[0]),1) xgsm, ygsm, zgsm = geopack.geogsm(x,y,100,1) xgsm /= Re ygsm /= Re zgsm /= Re

parmod = [data['Pdyn'][0],data['SYMH'][0],data['BYGSM'][0],data['BZGSM'][0]] geopack.trace(xgsm,ygsm,zgsm,-1,parmod=parmod,rlim=100,exname='t96')

Thanks,

Rhys

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/tsssss/geopack/issues/3#issuecomment-488257624, or mute the thread https://github.com/notifications/unsubscribe-auth/ADBMLBRYI4JUHTLJ3JLBRCTPTF2OVANCNFSM4HIVJ6YQ .

tsssss commented 5 years ago

Hi, I updated the code at Github (not pip yet) and it runs for your inputs. Please let me know if the problem persists.

On Wed, 1 May 2019 at 20:36, Sheng Tian tsheng886@gmail.com wrote:

Thanks, I'll check it out. -Sheng

On Wed, 1 May 2019 at 07:05, Rhyst223 notifications@github.com wrote:

Hi Sheng,

I am running my code as follows:

from geopack import geopack import numpy as np import pandas as pd

glats = [45.871,48.027,50.199,52.035,53.856,54.929,56.376,57.707,58.763,62.824] glons = [264.917,263.635,263.960,264.537,265.340,264.713,265.300,265.794,265.920,267.890]

data = pd.Series(2.008e+03, 1.000e+00, 2.100e+01, 3.500e+01, -2.140e+00, 1.560e+00, 2.200e-01, -3.514e+02, -2.200e+00, -7.900e+00, 7.750e+00, 3.131e+04, -4.000e+00, 1.000e+00, 1.000e+00, -3.380e-01, 1.850e+00, 0.000e+00, 0.000e+00, 0.000e+00, 0.000e+00, 0.000e+00, 0.000e+00])

data.columns = ['IYEAR', 'IDAY', 'IHOUR', 'MIN', 'BXGSM', 'BYGSM', 'BZGSM', 'VXGSE', 'VYGSE', 'VZGSE', 'DEN', 'TEMP', 'SYMH', 'IMFFLAG', 'ISWFLAG', 'TILT', 'Pdyn', 'W1', 'W2', 'W3', 'W4', 'W5', 'W6']

ut = data['IHOUR']3600 + data['MIN']60 ps = geopack.recalc(ut)

Re = 6371.2 x, y,= geopack.geodgeo(100,np.deg2rad(glats[0]),1) xgsm, ygsm, zgsm = geopack.geogsm(x,y,100,1) xgsm /= Re ygsm /= Re zgsm /= Re

parmod = [data['Pdyn'][0],data['SYMH'][0],data['BYGSM'][0],data['BZGSM'][0]] geopack.trace(xgsm,ygsm,zgsm,-1,parmod=parmod,rlim=100,exname='t96')

Thanks,

Rhys

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/tsssss/geopack/issues/3#issuecomment-488257624, or mute the thread https://github.com/notifications/unsubscribe-auth/ADBMLBRYI4JUHTLJ3JLBRCTPTF2OVANCNFSM4HIVJ6YQ .