geomagpy / magpy

MagPy (or GeomagPy) is a Python package for analysing and displaying geomagnetic data.
BSD 3-Clause "New" or "Revised" License
49 stars 27 forks source link

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

Closed stephanbracke closed 3 years ago

stephanbracke commented 3 years ago

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

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 https://github.com/geomagpy/magpy/blob/146a350ecfb2b623ebc1d8a381ac6afe78d99417/magpy/lib/format_imf.py#L2411-L2413

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 : https://github.com/geomagpy/magpy/blob/146a350ecfb2b623ebc1d8a381ac6afe78d99417/magpy/lib/format_imf.py#L2480-L2485

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])
leonro commented 3 years ago

Has been incorporated as suggested in commit:

42dcf12ee6c934733ceafa26a5396b9ebef3721f