2727"""
2828
2929# mithagi required Base,Utils imports
30- from skdaccess .framework .data_class import DataFetcherBase
30+ from skdaccess .framework .data_class import DataFetcherBase , DataPanelWrapper
3131from skdaccess .utilities import pbo_util
3232from skdaccess .utilities import data_util
3333
3737# 3rd party package imports
3838import pandas as pd
3939import numpy as np
40- import pickle
4140
4241
4342
@@ -48,7 +47,7 @@ class DataFetcher(DataFetcherBase):
4847 2) stabilization area (for running stabilization)
4948 '''
5049
51- def __init__ (self , start_time , end_time , lat_range , lon_range , ap_paramList , mdyratio = .5 , epFlag = 1 , stabFlag = 1 ):
50+ def __init__ (self , start_time , end_time , lat_range , lon_range , ap_paramList , mdyratio = .5 , ep_flag = 1 , stab_flag = 1 , wrapper_type = 'series' ):
5251 '''
5352 Initialize a DataFetcher
5453
@@ -58,21 +57,25 @@ def __init__(self, start_time, end_time, lat_range, lon_range, ap_paramList, mdy
5857 @param lon_range: Longitude range used to select stabilization sites
5958 @range ap_paramList[radius]: Site radius to search around (km)
6059 @param ap_paramList[geo_point] Tuple containing lat and lon coordinates
60+ @param ep_flag: Propagate errors through stabilization
61+ @param stab_flag: Perform regional stabilization
62+ @param wrapper_type: Select the type of iterator wrapper to generate, as series or table
6163 '''
6264
6365
64- self .start_time = start_time
65- self .end_time = end_time
66+ self ._start_time = start_time
67+ self ._end_time = end_time
6668 self .ap_paramList = ap_paramList
67- self .geospace = (lat_range , lon_range )
69+ self ._geospace = (lat_range , lon_range )
6870 self .station_list = None
69- self .mdyratio = mdyratio
70- self .epFlag = epFlag
71- self .stabFlag = stabFlag
71+ self ._mdyratio = mdyratio
72+ self ._ep_flag = ep_flag
73+ self ._stab_flag = stab_flag
74+ self .wrapper_type = wrapper_type
7275
7376 self .meta_data = DataFetcher .getStationMetadata ()
7477
75- if stabFlag == 1 :
78+ if stab_flag == 1 :
7679 self .stabilize ()
7780 else :
7881 self .rawData ()
@@ -119,17 +122,17 @@ def stabilize(self):
119122
120123 storeData = pd .HDFStore (storeData_fn )
121124
122- mdyratio = self .mdyratio
123- epFlag = self .epFlag
125+ mdyratio = self ._mdyratio
126+ epFlag = self ._ep_flag
124127
125128 keyList = []
126129 for ii in storeName .keys ():
127130 coord = storeName [ii ]['refNEU' ]
128- if coord [0 ]> self .geospace [0 ][0 ] and coord [0 ]< self .geospace [0 ][1 ] and coord [1 ]> self .geospace [1 ][0 ] and coord [1 ]< self .geospace [1 ][1 ]:
131+ if coord [0 ]> self ._geospace [0 ][0 ] and coord [0 ]< self ._geospace [0 ][1 ] and coord [1 ]> self ._geospace [1 ][0 ] and coord [1 ]< self ._geospace [1 ][1 ]:
129132 keyList .append (storeName [ii ]['4ID' ])
130- elif coord [0 ]> self .geospace [0 ][0 ] and coord [0 ]< self .geospace [0 ][1 ] and coord [1 ]> (360 + self .geospace [1 ][0 ]) and coord [1 ]< (360 + self .geospace [1 ][1 ]):
133+ elif coord [0 ]> self ._geospace [0 ][0 ] and coord [0 ]< self ._geospace [0 ][1 ] and coord [1 ]> (360 + self ._geospace [1 ][0 ]) and coord [1 ]< (360 + self ._geospace [1 ][1 ]):
131134 keyList .append (storeName [ii ]['4ID' ])
132- smSet_all , smHdr_all = pbo_util .stab_sys (storeName ,storeData ,[self .start_time ,self .end_time ],indx = keyList ,mdyratio = mdyratio ,errProp = epFlag )
135+ smSet_all , smHdr_all = pbo_util .stab_sys (storeName ,storeData ,[self ._start_time ,self ._end_time ],indx = keyList ,mdyratio = mdyratio ,errProp = epFlag )
133136
134137 self .smSet_all = smSet_all
135138 self .smHdr_all = smHdr_all
@@ -150,16 +153,16 @@ def rawData(self):
150153
151154 storeData = pd .HDFStore (storeData_fn )
152155
153- mdyratio = self .mdyratio
156+ mdyratio = self ._mdyratio
154157
155158 keyList = []
156159 for ii in storeName .keys ():
157160 coord = storeName [ii ]['refNEU' ]
158- if coord [0 ]> self .geospace [0 ][0 ] and coord [0 ]< self .geospace [0 ][1 ] and coord [1 ]> self .geospace [1 ][0 ] and coord [1 ]< self .geospace [1 ][1 ]:
161+ if coord [0 ]> self ._geospace [0 ][0 ] and coord [0 ]< self ._geospace [0 ][1 ] and coord [1 ]> self ._geospace [1 ][0 ] and coord [1 ]< self ._geospace [1 ][1 ]:
159162 keyList .append (storeName [ii ]['4ID' ])
160- elif coord [0 ]> self .geospace [0 ][0 ] and coord [0 ]< self .geospace [0 ][1 ] and coord [1 ]> (360 + self .geospace [1 ][0 ]) and coord [1 ]< (360 + self .geospace [1 ][1 ]):
163+ elif coord [0 ]> self ._geospace [0 ][0 ] and coord [0 ]< self ._geospace [0 ][1 ] and coord [1 ]> (360 + self ._geospace [1 ][0 ]) and coord [1 ]< (360 + self ._geospace [1 ][1 ]):
161164 keyList .append (storeName [ii ]['4ID' ])
162- smSet_all , smHdr_all = pbo_util .nostab_sys (storeName ,storeData ,[self .start_time ,self .end_time ],indx = keyList ,mdyratio = mdyratio )
165+ smSet_all , smHdr_all = pbo_util .nostab_sys (storeName ,storeData ,[self ._start_time ,self ._end_time ],indx = keyList ,mdyratio = mdyratio )
163166
164167 self .smSet_all = smSet_all
165168 self .smHdr_all = smHdr_all
@@ -215,7 +218,14 @@ def output(self):
215218 data [ii ] = self .smSet_all [ii ]
216219 info [ii ] = self .smHdr_all [ii ]
217220
218- return DataWrapper (pd .Panel .from_dict (data , orient = 'minor' ), geo_point , info )
221+ if self .wrapper_type == 'series' :
222+ return DataWrapper (pd .Panel .from_dict (data , orient = 'minor' ), geo_point , info )
223+ elif self .wrapper_type == 'table' :
224+ return (DataPanelWrapper (pd .Panel .from_dict (data ,orient = 'minor' ), meta_data = info ))
225+ else :
226+ print ('... Invald wrapper type, defaulting to series ...' )
227+ return DataWrapper (pd .Panel .from_dict (data , orient = 'minor' ), geo_point , info )
228+
219229
220230 def __str__ (self ):
221231 '''
0 commit comments