When using IMF files with a declination in the format, It will not be correctly interpreted and cause missing interpretation of values being xyz ibstead of hdz. The cause of this is that in the code format_imf there is no interpretation of the file values with the corresponding headers everithing is always considered as being nanoTesla values also the DataComponents headers is always XYZF which causes problems later on you can see this conversion in the code for readIMF
The same is true for the write imf.
The way I solved is to extract the method that adds the headers into a method that is inspired by the code you find in the iaga2002 format
I also added two methods proprietary at the imfv format that encodes and decodes the values according to IMFV standards
based on the units
def decode(type, value)-> float:
"""
type : variable is deg or nT
value the value to decode
"""
if type == 'deg':
return value/6000
else:
return value/10
def encode(type, value)-> float:
"""
type : variable is deg or nT
value the value to encorde
"""
if type == 'deg':
return value*6000
else:
return value*10
These methods make it now simple to adapt the readIMF and writeIMF methods
# in READIMF
....
headers['DataComponents'] = block[4]
headers['DataSensorAzimuth'] = float(block[8])/10/60
headers['DataSamplingRate'] = '60 sec'
headers['DataType'] = block[5]
format = block[4].lower()
add_col_info_headers(headers, format)
....
if not int(data[0+index]) > 999990:
array[1].append(decode(headers["unit-col-x"], float(data[0 + index])))
else:
array[1].append(np.nan)
if not int(data[1+index]) > 999990:
array[2].append(decode(headers["unit-col-y"], float(data[1 + index])))
else:
array[2].append(np.nan)
if not int(data[2+index]) > 999990:
array[3].append(decode(headers["unit-col-z"], float(data[2 + index])))
else:
array[3].append(np.nan)
if not int(data[3+index]) > 999990:
array[4].append(decode(headers["unit-col-f"],float(data[3+index])))
........
# in writeIMF
elemtype = datastream.header['DataComponents']
if not isnan(elemx):
x = encode(header['unit-col-x'],elemx)
else:
x = 999999
if not isnan(elemy):
y =encode(header['unit-col-y'],elemy)
else:
y = 999999
if not isnan(elemz):
z = encode(header['unit-col-z'],elemz)
else:
z = 999999
if not isnan(elemf):
f = encode(header['unit-col-f'],elemf)
The method add_col_info_headers could be externalised and used in all conversions making sure that all headers are always set with the correct names and formats needed for the GUI
When using IMF files with a declination in the format, It will not be correctly interpreted and cause missing interpretation of values being xyz ibstead of hdz. The cause of this is that in the code format_imf there is no interpretation of the file values with the corresponding headers everithing is always considered as being nanoTesla values also the DataComponents headers is always XYZF which causes problems later on you can see this conversion in the code for readIMF
https://github.com/geomagpy/magpy/blob/e7761aff7f2c33e46298ef7cbbce987b96e009c7/magpy/lib/format_imf.py#L1750-L1775
The same is true for the write imf. The way I solved is to extract the method that adds the headers into a method that is inspired by the code you find in the iaga2002 format
I also added two methods proprietary at the imfv format that encodes and decodes the values according to IMFV standards based on the units
These methods make it now simple to adapt the readIMF and writeIMF methods
The method add_col_info_headers could be externalised and used in all conversions making sure that all headers are always set with the correct names and formats needed for the GUI