-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathATL06_pair.py
More file actions
43 lines (40 loc) · 1.8 KB
/
ATL06_pair.py
File metadata and controls
43 lines (40 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# -*- coding: utf-8 -*-
"""
Created on Mon Nov 13 10:27:00 2017
@author: ben
"""
import numpy as np
class ATL06_pair:
def __init__(self, D6=None, pair_data=None):
if D6 is not None:
#initializes based on input D6, assumed to contain one pair
# 2a. Set pair_data x and y
self.x=np.mean(D6.x_atc) # mean of the pair, nan if not both defined
self.y=np.mean(D6.y_atc)
self.dh_dx=D6.dh_fit_dx
self.dh_dx.shape=[1,2]
self.dh_dy=np.mean(D6.dh_fit_dy)
self.dh_dy_sigma=np.sqrt(np.sum(D6.h_li_sigma**2))/np.abs(np.diff(D6.y_atc))
self.delta_time=np.mean(D6.delta_time)
self.segment_id=np.mean(D6.segment_id)
self.cycle=np.mean(D6.cycle_number)
self.h=D6.h_li
self.h.shape=[1,2]
self.valid=np.zeros(1, dtype='bool')
elif pair_data is not None:
# initializes based on a list of pairs, to produce a structure with numpy arrays for fields
for field in ('x','y','dh_dx','dh_dy','delta_time','segment_id','cycle','h','valid'):
setattr(self, field, np.c_[[getattr(this_pair,field).ravel() for this_pair in pair_data]])
else:
#initializes an empty structure
for field in ('x','y','dh_dx','dh_dy','delta_time','segment_id','cycle','h','valid'):
setattr(self, field, np.NaN)
def __getitem__(self, key):
temp06=ATL06_pair()
for field in ('x','y','dh_dx','dh_dy','delta_time','segment_id','cycle','h','valid'):
temp_field=getattr(self, field)
if len(temp_field.shape)>1 and temp_field.shape[1] > 1:
setattr(temp06, temp_field[key,:])
else:
setattr(temp06, temp_field[key])
return temp06