spedas / bleeding_edge

IDL-based Space Physics Environment Data Analysis Software (bleeding edge)
http://www.spedas.org
Other
7 stars 0 forks source link

Question on calculating MLT from magnetic longitude #80

Closed ericthewizard closed 11 months ago

ericthewizard commented 1 year ago

I received a question from a user attempting to convert from magnetic longitude to MLT:

I was looking for a SPEDAS routine that would convert from some coordinates (probably magnetic longitude) and time to get MLT. I found mlt_v2.pro, but when I tried a test run it crashed when it hit common AACGM_v2_Com saying: “% Common block AACGM_V2_COM must contain variables.”

Do you know if there is a better routine for getting MLT, and if this mlt_v2 is just broken and shouldn’t be used?

I tried using calc_mlt from aacgmidl.pro, but got a crash there as well:

% Variable is undefined: SOL_DEC_OLD (MLT_COM). % Execution halted at: MLT1 512 /Users/eric/trunk/general/cotrans/aacgm/aacgmidl.pro % CALC_MLT 549 /Users/eric/trunk/general/cotrans/aacgm/aacgmidl.pro % $MAIN$

ericthewizard commented 1 year ago

The user found a working method that uses the SuperDARN AACGM library:

year=2016
t0=3600.*24*31.+3600.*6.
glat=56.4
glon=265.4
hgt=110.

aacgmconvcoord, glat,glon,hgt, mlat,mlon,err,/TO_AACGM

mlt = aacgmmlt(year, t0, mlon )

But it appears to be using old coefficients (see #81)

jameswilburlewis commented 1 year ago

I've seen this before! There is a non-obvious bit of initialization that needs to happen before certain aacgm_v2 calls are made. I dug this out of my email archives:

I was able to reproduce the error you reported -- it only happens if I run your example commands in a fresh IDL session. If I've already run the AACGM crib sheet, the error doesn't occur. It turns out that some of the common block variables are initialized in the routines that set the date and time, and if you just call aacgmidl_v2 and then aacgm_v2_convertgeocoord, the common block isn't completely initialized. So I would suggest adding a call like

ret = AACGM_v2_SetDateTime(year,month,day)

with suitable values for year, month, and day, and I believe that you'll then be able to call aacgm_v2_convertgeocoord without getting the error.

ericthewizard commented 1 year ago

Thanks! I let her know

jameswilburlewis commented 1 year ago

We should see if it's possible to update the coefficient files for the older version of AACGM.

Update: this does not appear to be possible -- the latest IGRF13 coefficient file does not appear to be compatible with the AACGM version 1 model. See final comment on related issue https://github.com/spedas/bleeding_edge/issues/81