OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
read_pos_vel_quat.py
Go to the documentation of this file.
1 '''
2 Created on Nov 20, 2015
3 updated 11/23/2015
4 
5 @author: rhealy
6 '''
7 import numpy as np
8 import pandas as pd
9 from hico.exceptions import PVQException
10 
11 
12 class QuatHeader:
13 
14  def __init__(self, **kwargs):
15  self.properties = kwargs
16 
17  def get_properties(self):
18  return self.properties
19 
20  def get_property(self, key):
21  return self.properties.get(key, None)
22 
23 
25  pass
26 
27 
28 class PVQInputVelocityError(PVQException):
29  pass
30 
31 
33  pass
34 
35 
37  pass
38 
39 
40 def checkData(indata, X, Y, Z, scl, lower, upper):
41  rsltx = (indata[X]*scl)**2
42  rslty = (indata[Y]*scl)**2
43  rsltz = (indata[Z]*scl)**2
44  sumsqrs = np.sqrt(rsltx+rslty+rsltz)
45  idx = (sumsqrs > upper) | (sumsqrs < lower)
46  return idx.any()
47 
48 
49 def checkQData(indata):
50  rsltx = (indata['ISSQX'])**2
51  rslty = (indata['ISSQY'])**2
52  rsltz = (indata['ISSQZ'])**2
53  rslts = (indata['ISSQS'])**2
54  sumsqrs = np.sqrt(rsltx+rslty+rsltz+rslts) - 1.0
55  idx = (np.abs(sumsqrs) > 0.01)
56  return idx.any()
57 
58 
59 """
60 
61 def print_warning_msg(header, filename, exit_flag):
62  print('PLEASE CHECK FILE: {}'.format(filename))
63  print('And its source files: \n{}\n{}\n'.format(header['Source CSV file'],
64  header['Subset CSV file']))
65  sys.exit(exit_flag)
66 
67 """
68 
69 
70 def read_pos_vel_quat(filename):
71  re = 6378137e0 # WGS-84
72  lower = re + 2.5e5
73  upper = re + 5.e5 # upper and lower bounds for ISS in m wrt WGS-84
74  header = {}
75  quat = QuatHeader()
76  lcnt = 0
77  cnt = 0
78 
79  for theLine in open(filename, 'r'):
80  cnt += 1
81  fields = theLine.split(',')
82  if len(fields) > 1 and len(fields) < 10 and 'This field is currently'\
83  not in fields and 'SecondsSinceEpoch' not in fields:
84  header[fields[0]] = ''.join(fields[1]).strip()
85  setattr(quat, fields[0], header[fields[0]])
86 # print(header[fields[0]])
87  if 'SecondsSinceEpoch' in fields:
88  lcnt = cnt - 1
89 
90  error_str_1 = 'PLEASE CHECK FILE: {}\n'.format(filename)
91  error_str_2 = 'And source files: \n{}\n{}'.format(header
92  ['Source CSV file'],
93  header['Subset CSV file']
94  )
95  error_str = error_str_1 + error_str_2
96  pvq_data = pd.read_csv(filename, skiprows=lcnt, skipinitialspace=True)
97  if np.isnan(pvq_data['ISSPOSX']).any()\
98  or np.isnan(pvq_data['ISSPOSY']).any()\
99  or np.isnan(pvq_data['ISSPOSZ']).any():
100  flag_str = 'NaN detected in input position.\n' + error_str
101  raise PVQInputPositionError(flag_str)
102  if np.isnan(pvq_data['ISSQX']).any()\
103  or np.isnan(pvq_data['ISSQY']).any()\
104  or np.isnan(pvq_data['ISSQZ']).any():
105  flag_str = 'NaN in input quaternion.' + error_str
106  raise PVQInputPositionError(flag_str)
107  if checkData(pvq_data, 'ISSPOSX', 'ISSPOSY', 'ISSPOSZ', .3048,
108  lower, upper):
109  flag_str = '< 200km or > 500km, above WGS-84.\n' + error_str
110  raise PVQInputPositionError(flag_str)
111 
112  if checkData(pvq_data, 'ISSVELX', 'ISSVELY', 'ISSVELZ',
113  .3048, 6500.0, 9000.0):
114  flag_str = 'ISS velocity out of range.\n' + error_str
115  raise PVQInputVelocityError(flag_str)
116  if checkQData(pvq_data):
117  flag_str = 'Interpolated ISS USGNC quaternions not normalized.\n' + error_str
119 
120  # Now, the times in the HICO files are in seconds since 2009-Jan01-00:00:00 UTC.
121  # N.B. The original files have GPS times in them, and the file interpolate_fields_to_hico_times.pro
122  # calculates the GPS second for the above UTC date, and subtracts it form the GPS times in the files.
123  # Now, I've verified that the times in the original CSV files are GPS. The YYYYMMDD hhmmss in the files
124  # are not UTC, but are instead just GPS time converted. So they differ from UTC by the number of leap
125  # seconds there are. So, while my EPOCH date is UTC, NO LEAP SECONDS are included since the epoch. Which means
126  # that after 2012/06/30 23:59:59, I have an added second (leap second) that I will need to account for.
127  # So, I need to properly count seconds and properly account for leap seconds in order to really get/stay in UTC.
128  if header['Epoch'] != '2009 Jan 01 00:00:00 UTC':
129  flag_str = 'Unexpected epoch:\n%s.' % header['Epoch'] + error_str_1
130  raise PVQEpochError(flag_str)
131  return header, quat, pvq_data
def checkData(indata, X, Y, Z, scl, lower, upper)
def read_pos_vel_quat(filename)