geomagpy / magpy

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

saving the blv doesn't take into account the fit that was included in the pycdf for baselines #119

Closed stephanbracke closed 1 year ago

stephanbracke commented 2 years ago

After adding possability to save the baselines with the fit functions into a pycdf file, we use the pycdf in a script to generate the .BLV file. However the fit that is included is not used and you always get

Reading PYCDF with CDFLIB
Found special header content !!!!!!!!!!!!!!!! --  version 1.2
 -> functions loaded
writeBLV: no baseline function(s) specified - using default values

the script written is straighforward

    baseline_stream: mp.DataStream = mp.read(bl_file)
    baseline_stream.write(filepath=target_dir,year=year,coverage='all',format_type='BLV',diff=delta_f_daily,meanh=mean_h,meanf=mean_f)

I went through the code and found out that the fit objects are in the header under DataFunctionObject. So I quickly changed the method
https://github.com/geomagpy/magpy/blob/6a560b1cf7b9a0a76604250cbdb3ccf3aa2595a9/magpy/lib/format_imf.py#L2188

I just added in the beginning

basefunctionlist = datastream.header.get('DataFunctionObject')

and on line 2304 # get functionlist I changed

    if basefunctionlist is None:
        basefunctionlist =[]

This is probably not the best way to do it but I managed to generate a correct BLV and it can help to better understand the problem

leonro commented 1 year ago

Is included as suggested in 188336a6644df476c3e00dc03caf7c5d117b9b3e