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

Add support for EO-SIP AVHRR LAC data #2762

Merged
merged 7 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions continuous_integration/environment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ dependencies:
- pytest-cov
- pytest-lazy-fixture
- fsspec
- botocore>=1.33
- s3fs
- python-geotiepoints
- pooch
Expand Down
1 change: 1 addition & 0 deletions satpy/etc/readers/avhrr_l1b_gaclac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -185,3 +185,4 @@ file_types:
file_patterns:
- '{creation_site:3s}.{transfer_mode:4s}.{platform_id:2s}.D{start_time:%y%j.S%H%M}.E{end_time:%H%M}.B{orbit_number:05d}{end_orbit_last_digits:02d}.{station:2s}'
- '{subscription_prefix:10d}.{creation_site:3s}.{transfer_mode:4s}.{platform_id:2s}.D{start_time:%y%j.S%H%M}.E{end_time:%H%M}.B{orbit_number:05d}{end_orbit_last_digits:02d}.{station:2s}'
- '{platform_id:3s}_RPRO_AVH_L1B_1P_{start_time:%Y%m%dT%H%M%S}_{end_time:%Y%m%dT%H%M%S}_{orbit_number:06d}/image.l1b'
21 changes: 17 additions & 4 deletions satpy/readers/avhrr_l1b_gaclac.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python

Check notice on line 1 in satpy/readers/avhrr_l1b_gaclac.py

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

✅ No longer an issue: Overall Code Complexity

The mean cyclomatic complexity in this module is no longer above the threshold
# -*- coding: utf-8 -*-
# Copyright (c) 2009-2019 Satpy developers
#
Expand Down Expand Up @@ -30,7 +30,7 @@
"""

import logging
from datetime import datetime, timedelta
from datetime import date, datetime, timedelta

import dask.array as da
import numpy as np
Expand Down Expand Up @@ -98,15 +98,18 @@
if self._end_time < self._start_time:
self._end_time += timedelta(days=1)
self.platform_id = filename_info["platform_id"]
if self.platform_id in ["NK", "NL", "NM", "NN", "NP", "M1", "M2",
"M3"]:

if len(self.platform_id) == 3:
self.reader_kwargs["header_date"] = date(2000, 1, 1)

if self._is_avhrr3():
if filename_info.get("transfer_mode") == "GHRR":
self.reader_class = GACKLMReader
else:
self.reader_class = LACKLMReader
self.chn_dict = AVHRR3_CHANNEL_NAMES
self.sensor = "avhrr-3"
elif self.platform_id in ["NC", "ND", "NF", "NH", "NJ"]:
elif self._is_avhrr2():

Check warning on line 112 in satpy/readers/avhrr_l1b_gaclac.py

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ Getting worse: Complex Method

GACLACFile.__init__ increases in cyclomatic complexity from 11 to 12, threshold = 9. This function has many conditional statements (e.g. if, for, while), leading to lower code health. Avoid adding more conditionals and code to it without refactoring.
if filename_info.get("transfer_mode") == "GHRR":
self.reader_class = GACPODReader
else:
Expand All @@ -122,6 +125,16 @@
self.sensor = "avhrr"
self.filename_info = filename_info

def _is_avhrr2(self):
return self.platform_id in ["NC", "NE", "NF", "NG", "NH", "ND", "NJ",
"N07", "N08", "N09", "N10", "N11", "N12", "N14"]

def _is_avhrr3(self):
return self.platform_id in ["NK", "NL", "NM", "NN", "NP",
"N15", "N16", "N17", "N18", "N19",
"M1", "M2", "M3",
"MOB", "MOA", "MOC"]

def read_raw_data(self):
"""Create a pygac reader and read raw data from the file."""
if self.reader is None:
Expand Down
33 changes: 32 additions & 1 deletion satpy/tests/reader_tests/test_avhrr_l1b_gaclac.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# satpy. If not, see <http://www.gnu.org/licenses/>.
"""Pygac interface."""

from datetime import datetime
from datetime import date, datetime
from unittest import TestCase, mock

import dask.array as da
Expand All @@ -26,6 +26,7 @@
import xarray as xr

GAC_PATTERN = '{creation_site:3s}.{transfer_mode:4s}.{platform_id:2s}.D{start_time:%y%j.S%H%M}.E{end_time:%H%M}.B{orbit_number:05d}{end_orbit_last_digits:02d}.{station:2s}' # noqa
EOSIP_PATTERN = '{platform_id:3s}_RPRO_AVH_L1B_1P_{start_time:%Y%m%dT%H%M%S}_{end_time:%Y%m%dT%H%M%S}_{orbit_number:06d}/image.l1b' # noqa

GAC_POD_FILENAMES = ["NSS.GHRR.NA.D79184.S1150.E1337.B0008384.WI",
"NSS.GHRR.NA.D79184.S2350.E0137.B0008384.WI",
Expand Down Expand Up @@ -68,6 +69,8 @@
"NSS.FRAC.M2.D12153.S1729.E1910.B2915354.SV",
"NSS.LHRR.NP.D16306.S1803.E1814.B3985555.WI"]

LAC_EOSIP_FILENAMES = ["N06_RPRO_AVH_L1B_1P_20061206T010808_20061206T012223_007961/image.l1b"]


@mock.patch("satpy.readers.avhrr_l1b_gaclac.GACLACFile.__init__", return_value=None)
def _get_fh_mocked(init_mock, **attrs):
Expand Down Expand Up @@ -138,6 +141,12 @@ def _get_fh(self, filename="NSS.GHRR.NG.D88002.S0614.E0807.B0670506.WI",
filename_info = parse(GAC_PATTERN, filename)
return self.GACLACFile(filename, filename_info, {}, **kwargs)

def _get_eosip_fh(self, filename, **kwargs):
"""Create a file handler."""
from trollsift import parse
filename_info = parse(EOSIP_PATTERN, filename)
return self.GACLACFile(filename, filename_info, {}, **kwargs)

def test_init(self):
"""Test GACLACFile initialization."""
from pygac.gac_klm import GACKLMReader
Expand All @@ -161,6 +170,28 @@ def test_init(self):
assert fh.start_time < fh.end_time
assert fh.reader_class is reader_cls


def test_init_eosip(self):
"""Test GACLACFile initialization."""
from pygac.lac_pod import LACPODReader

kwargs = {"start_line": 1,
"end_line": 2,
"strip_invalid_coords": True,
"interpolate_coords": True,
"adjust_clock_drift": True,
"tle_dir": "tle_dir",
"tle_name": "tle_name",
"tle_thresh": 123,
"calibration": "calibration"}
for filenames, reader_cls in zip([LAC_EOSIP_FILENAMES],
[LACPODReader]):
for filename in filenames:
fh = self._get_eosip_fh(filename, **kwargs)
assert fh.start_time < fh.end_time
assert fh.reader_class is reader_cls
assert fh.reader_kwargs["header_date"] > date(1994, 11, 15)

def test_read_raw_data(self):
"""Test raw data reading."""
fh = _get_fh_mocked(reader=None,
Expand Down
Loading