Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable decoding of tbm dataset name #131

Merged
merged 2 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions pygac/pod_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,20 @@

import datetime
import logging

try:
from enum import IntFlag
except ImportError:
# python version < 3.6, use a simple object without nice representation
IntFlag = object

import numpy as np

from pyorbital.geoloc_instrument_definitions import avhrr_gac
from pyorbital.geoloc import compute_pixels, get_lonlatalt
from pyorbital.geoloc_instrument_definitions import avhrr_gac

from pygac.clock_offsets_converter import get_offsets
from pygac.correct_tsm_issue import TSM_AFFECTED_INTERVALS_POD, get_tsm_idx
from pygac.reader import Reader, ReaderError, NoTLEData
from pygac.reader import NoTLEData, Reader, ReaderError
from pygac.slerp import slerp
from pygac.utils import file_opener

Expand Down Expand Up @@ -321,9 +321,14 @@ def read_header(cls, filename, fileobj=None, header_date="auto"):
_tbm_head, = np.frombuffer(
fd_.read(tbm_header.itemsize),
dtype=tbm_header, count=1)
try:
data_set_name = _tbm_head['data_set_name'].decode()
except UnicodeDecodeError:
for encoding in ("utf-8", "cp500"):
try:
data_set_name = _tbm_head['data_set_name'].decode(encoding)
except ValueError:
continue
else:
break
else:
data_set_name = '---'
sfinkens marked this conversation as resolved.
Show resolved Hide resolved
allowed_empty = (42*b'\x00' + b' ')
if (cls.data_set_pattern.match(data_set_name)
Expand Down
18 changes: 9 additions & 9 deletions pygac/tests/test_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,20 @@
import os
import sys
import unittest
import pytest

from unittest import mock

import numpy as np
import numpy.testing
from pygac.gac_reader import GACReader, ReaderError
from pygac.lac_reader import LACReader
from pygac.pod_reader import POD_QualityIndicator
import pytest

from pygac.gac_pod import scanline
from pygac.reader import NoTLEData
from pygac.gac_reader import GACReader, ReaderError
from pygac.lac_pod import LACPODReader

from pygac.pod_reader import tbm_header as tbm_header_dtype, header3
from pygac.lac_pod import scanline as lacpod_scanline
from pygac.lac_reader import LACReader
from pygac.pod_reader import POD_QualityIndicator, header3
from pygac.pod_reader import tbm_header as tbm_header_dtype
from pygac.reader import NoTLEData


class TestPath(os.PathLike):
Expand Down Expand Up @@ -688,7 +688,7 @@ def pod_file_with_tbm_header(tmp_path):
number_of_scans = 3

tbm_header = np.zeros(1, dtype=tbm_header_dtype)
tbm_header["data_set_name"] = b"BRN.HRPT.NJ.D00322.S0334.E0319.B3031919.BL "
tbm_header["data_set_name"] = "BRN.HRPT.NJ.D00322.S0334.E0319.B3031919.BL\x80\x80".encode("cp500")
tbm_header["select_flag"] = b"S"
tbm_header["beginning_latitude"] = b"+77"
tbm_header["ending_latitude"] = b"+22"
Expand Down
Loading