aodn / imos-toolbox

Graphical tool for QC'ing and NetCDF'ing oceanographic datasets
GNU General Public License v3.0
46 stars 31 forks source link

OceanContour parser handling of magnetic declination #800

Open sspagnol opened 1 year ago

sspagnol commented 1 year ago

I asked the OceanIllumination devs a question about some attributes in the exported netcdf files, namely

Regarding attributes 

:Instrument_user_decl = 0.0f; // float
:Instrument_user_decl_description = "Enable sync trigger";
:Instrument_trig_en = 0; // int
:Instrument_trig_en_description = "Magnetic Declination (degrees)";
:DataInfo_transformsAndCorrections_magneticDeclination = 0.0f; // float
:DataInfo_transformsAndCorrections_magneticDeclination_description = "Compass magnetic declination correction";

Just want to check

1. It's just the descriptions of user_decl and trig_en are swapped?

2. Does Instrument_user_decl records value of declination correction applied on instrument setup?

3. DataInfo_transformsAndCorrections_magneticDeclination  records value of declination correction applied during processing?

4. If questions 2 and 3 are correct, are these declination corrections additive? Wondering if a use had set user_decl to say 3, then when they came to process the data realized it should be 5, so they set transformsAndCorrections_magneticDeclination to 2, for a total declination correction of 5.

Their response was

1.) Yes.  Just the description had been swapped (a cut-paste error).  This was fixed internally a while ago.
2.) Yes.  User_decl is the instrument supplied magnetic declination.
3.) Yes.  The magnetic declination is the magnetic declination as supplied by the user to Ocean Contour.
4.) Contour assumes that the user_decl is factored into the raw data so it adjusts the Contour supplied magnetic declination accordingly to make the Contour declination the total declination.
Declination applied by Contour = contourMagneticDeclination - instrumentMagneticDeclination;

In your example, you would supply a declination of 5 to Contour to get  a total correction of 5.

So I think the handling of magnetic declination needs to be change so that in function get_attmap

attmap.('magDec_User') = 'Instrument_user_decl';
attmap.('magDec_DataInfo') = 'DataInfo_transformsAndCorrections_magneticDeclination';

And in function readOceanContourFile

magDec_User = get_att('magDec_User');
magDec_DataInfo = get_att('magDec_DataInfo');
has_magdec_user = logical(magDec_User);
has_magdec_oceancontour = logical(magDec_DataInfo);
meta.magDec = 0.0;
custom_magnetic_declination = has_magdec_user | has_magdec_oceancontour;
if has_magdec_oceancontour % testing order important
    meta.magDec = magDec_DataInfo;
elseif has_magdec_user
    meta.magDec = magDec_User;
end

And further in function build_magnetic_variables, I think the test should be against ~custom_magnetic_declination, that is

if ~custom_magnetic_declination
    %TODO: This is probably unecessary
    %I believe OceanContourDouble-check if OceanContour will change variable names if custom magnetic declination is used.
    dispmsg('%s: Assigning non ENU Velocities to ENU variables. Verify the magnetic declination angles.')
    ucur_name = 'UCUR_MAG';
    vcur_name = 'VCUR_MAG';
    heading_name = 'HEADING_MAG';
else
    ucur_name = 'UCUR';
    vcur_name = 'VCUR';
    heading_name = 'HEADING';
end