From f7a79bb577a793b823de2ab98c20364d2a3d0363 Mon Sep 17 00:00:00 2001 From: Alexey Pechnikov Date: Wed, 20 Nov 2024 02:28:11 +0700 Subject: [PATCH] Add function SC_timestamp to convert PRM date to timestamp --- pygmtsar/pygmtsar/PRM.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/pygmtsar/pygmtsar/PRM.py b/pygmtsar/pygmtsar/PRM.py index c188b686..cff98fbc 100644 --- a/pygmtsar/pygmtsar/PRM.py +++ b/pygmtsar/pygmtsar/PRM.py @@ -14,6 +14,23 @@ class PRM(datagrid, PRM_gmtsar): int_types = ['num_valid_az', 'num_rng_bins', 'num_patches', 'bytes_per_line', 'good_bytes_per_line', 'num_lines','SC_identity'] + @staticmethod + def SC_timestamp(SC_clock): + from datetime import datetime, timedelta + + # extract year and Julian day with fractional part + year = int(SC_clock // 1000) + julian_day = SC_clock % 1000 # Keep fractional part of the day + + # split integer Julian day and fractional day + integer_julian_day = int(julian_day) + fractional_day = julian_day - integer_julian_day + + # convert integer and fraction parts of Julian day to datetime + timestamp = datetime(year, 1, 1) + timedelta(days=integer_julian_day) + timedelta(days=fractional_day) + + return timestamp + @staticmethod def to_numeric_or_original(val): if isinstance(val, str):