Skip to content

Commit

Permalink
Add function SC_timestamp to convert PRM date to timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexeyPechnikov committed Nov 19, 2024
1 parent c53936a commit f7a79bb
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions pygmtsar/pygmtsar/PRM.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit f7a79bb

Please sign in to comment.