diff --git a/geomagio/imfv283/IMFV283Parser.py b/geomagio/imfv283/IMFV283Parser.py index ae23d5e72734b13cbee5010021872520d01f4f88..b9ae702709bd703a8ce0d56aa39ab964161b7f8e 100644 --- a/geomagio/imfv283/IMFV283Parser.py +++ b/geomagio/imfv283/IMFV283Parser.py @@ -232,9 +232,10 @@ class IMFV283Parser(object): """ header = {} - # day of year and minute of day are combined into 3 bytes - header["day"] = data[0] + 0x100 * (data[1] & 0xF) - header["minute"] = (data[2] & 0xFF) * 0x10 + data[1] / 0x10 + # day of year and minute of day are each 12 bits: + # input bytes AB CD EF => day = DAB, minute = EFC + header["day"] = ((data[1] & 0xF) << 8) + data[0] + header["minute"] = ((data[2] & 0xFF) << 4) + ((data[1] & 0xF0) >> 4) # offset values for each channel are in bytes 3,4,5,6 respectively. header["offset"] = data[3:7] diff --git a/test/imfv283_test/IMFV283Parser_test.py b/test/imfv283_test/IMFV283Parser_test.py index 02ca2d3bda7abc23344363c1054c65135b8fe6f7..61d5f92b137242198997a6fec73b8053488fe2d5 100644 --- a/test/imfv283_test/IMFV283Parser_test.py +++ b/test/imfv283_test/IMFV283Parser_test.py @@ -21,24 +21,62 @@ IMFV283_EXAMPLE_FRD = ( + b"@cVAjT@[CAVW@cWAjT@[CAVT@cWAjU@[AAVO@cYAjV@Z}AVK@c[AjV" ) +IMFV283_EXAMPLE_STJ = ( + b"75C1E7AC20259002641G44-3NN027EXE00191`@OA@BWGbx{" + + b"x@@Bh\x7fD`@@@@@@@@@@@@@@@@@@@@@@@@@@@FDODdV}X_yxAGHODlV~L_z|AG" + + b"tODPV\x7f@_{pAxLOC`V\x7fp_|pAxPOBdV@D`}dAxdOAxVAX`~lAx`O@|VAp`\x7fXAyDO@tVCd`@\\Bx`O\x7fXUC|`APByDO\x7fdUEd`AtBx`O~\\UEp`BXBGtO}PUFP`CHB \n75C1E7AC20259001441G44-3NN027EXE00191`@LA@BWGbx{x@@Bh\x7fD`@@@@@@@@@@@@@@@@@@@@@@@@@@@\x7fhN{XU\x7fh_zPA\x7fPN|pU~P_xxA\x7fDN}xU|p_GpA@dO@pV||_FtA@hOA\\Vz|_FDAADOAxV{\\_FpABXOCXV{T_F`ABxODTV{L_F|ACpODxV{x_GPADLODpV|X_GxADpODhV|x_xlAEHODdV|x_yHA \n75C1E7AC20259000241G44-3NN027EXE00191`@IAEfWGby{x@@Bh\x7fD`@@@@@@@@@@@@@@@@@@@@@@@@@@@BxO{pT|h@y|BC@O|XT|t@yhBCDO}DT{p@xpBBpO}dT{H@ydBB`O\x7fLTyh@FHBAPO@PUGL@CxBAHOB\\UFL@BLBADOD\\UCh@\x7fdA@LOEHUB|@~|A@pOGdUB`@}dA\x7fxNx\\UAd@|hA\x7flNytU@H@{PA \n75C1E7AC20258235041G45-3NN027EXE00191`@JAEbWGby{x@@Bh\x7fD`@@@@@@@@@@@@@@@@@@@@@@@@@@@C|O{hT~D@{PBC`O{HT}h@{PBCtO{\\T}|@{TBCXOztT}X@{TBDPO{xT~`@{TBCdO{`T}p@z|BC@OzxT|x@z|BCPO{HT}\\@{DBC\\O{@T}t@{XBC\\O{XT}|@{HBCTO{lT}h@zhBB|O{\\T}H@z\\B \n" +) + def test_parse_msg_header(): """imfv283_test.IMFV283Parser_test.test_parse_msg_header() Call the _parse_header method with a header. - Verify the header name and value are split at the correct column. + Verify the header names and values are split at the correct columns. """ header = IMFV283Parser()._parse_msg_header(IMFV283_EXAMPLE_VIC) + assert_equal(header["daps_platform"], b"75C2A3A8") assert_equal(header["obs"], "VIC") + assert_equal(header["transmission_time"], b"14023012741") + assert_equal(header["data_len"], 191) -def test_parse_goes_header(): - """imfv283_test.IMFV283Parser_test.test_parse_goes_header()""" +def test_parse_goes_header_VIC(): + """imfv283_test.IMFV283Parser_test.test_parse_goes_header_VIC()""" goes_data = IMFV283Parser()._process_ness_block( IMFV283_EXAMPLE_VIC, imfv283_codes.OBSERVATORIES["VIC"], 191 ) - goes_header = IMFV283Parser()._parse_goes_header(goes_data) - assert_equal(goes_header["day"], 23) + actual_goes_header = IMFV283Parser()._parse_goes_header(goes_data) + + expected_header = { + "day": 23, + "minute": 73, + "offset": bytearray(b"\x96\x86\xbd\xc1"), + "orient": 0.0, + "scale": [1, 1, 1, 1], + } + + assert_equal(actual_goes_header, expected_header) + assert_equal(type(actual_goes_header["minute"]), int) + + +def test_parse_goes_header_STJ(): + """imfv283_test.IMFV283Parser_test.test_parse_goes_header_STJ()""" + goes_data = IMFV283Parser()._process_ness_block( + IMFV283_EXAMPLE_STJ, imfv283_codes.OBSERVATORIES["STJ"], 191 + ) + actual_goes_header = IMFV283Parser()._parse_goes_header(goes_data) + + expected_header = { + "day": 259, + "minute": 12, + "offset": bytearray(b"\x97x\xb8\xbe"), + "orient": 0.0, + "scale": [1, 1, 1, 1], + } + + assert_equal(actual_goes_header, expected_header) + assert_equal(type(actual_goes_header["minute"]), int) def test_estimate_data_time__correct_doy():