geomagpy/magpy

Faulty generate .blv (IBF) file for XYZ baseline values

stephanbracke opened this issue · 1 comments

When having a year of baselinevalues XYZ and doing the export towards an IBF (.BLV) value the following is done :

  • the header shows HDZ instead of XYZ
  • the file lists X Y*60 and Z baseline values

The errors are located in the writeBLV(datastream, filename, **kwargs) method of the format_imf.py package.
The datastream gets converted to a DHZ format by following code

magpy/magpy/lib/format_imf.py

Lines 2411 to 2413 in 146a350

elif comps in ['XYZF','xyzf','xyz','XYZ']:
datastream = datastream.xyz2hdz()
comps = 'HDZF'

You can replace it with following snippet keepen the comps as XYZF

       if comps in ['IDFF','idff','idf','IDF']:
            datastream = datastream.idf2xyz()
            datastream = datastream.xyz2hdz()
            comps = 'HDZF'
        #elif comps in ['XYZF','xyzf','xyz','XYZ']:
        #    datastream = datastream.xyz2hdz()
        #comps = 'HDZF'

This will prevent any transformation of the current stream and comp will stay on XYZF.
You can if you want also do the datastream conversion xyz2hdz but I don't see extra value here.

Later on you will need to add an extra check to the code :

magpy/magpy/lib/format_imf.py

Lines 2480 to 2485 in 146a350

if t2 >= elem >= t1:
day = datetime.strftime(num2date(elem),'%j')
x = float(datastream.ndarray[indx][idx])
y = float(datastream.ndarray[indy][idx])*60.
z = float(datastream.ndarray[indz][idx])
df = float(datastream.ndarray[indf][idx])

Here a check is missing on the comps causing y to be multiplied by 60
It can be solved the same way as it is done later on with a small check on componens ( this only works if the comps are on XYZF

                x = float(datastream.ndarray[indx][idx])
                if comps.lower() == 'xyzf':
                    y = float(datastream.ndarray[indy][idx])
                else:
                    y = float(datastream.ndarray[indy][idx])*60.
                z = float(datastream.ndarray[indz][idx])

Has been incorporated as suggested in commit:

42dcf12