11from __future__ import print_function
22from __future__ import absolute_import
3- import sys
43import copy
5-
64import numpy as np
5+ import string
6+ import sys
7+
8+ import pandas
9+ import pysat
710
811from . import fortran_cdf
912
@@ -29,7 +32,7 @@ class CDF(object):
2932 Note when opening a CDF file with this module all data is
3033 automatically loaded from disk unless specific variables
3134 are excluded upon instantiation.
32-
35+
3336 """
3437
3538 def __init__ (self , fname ):
@@ -185,10 +188,10 @@ def _read_all_z_variable_info(self):
185188
186189 def load_all_variables (self ):
187190 """Loads all variables from CDF.
188-
191+
189192 Note this routine is called automatically
190193 upon instantiation.
191-
194+
192195 """
193196
194197 self .data = {}
@@ -286,7 +289,7 @@ def _call_multi_fortran_z(self, names, data_types, rec_nums,
286289 epoch16 : bool
287290 Flag indicating type is epoch16. Translates things to datetime standard.
288291
289-
292+
290293 """
291294
292295 # isolate input type code variables from total supplied types
@@ -308,7 +311,7 @@ def _call_multi_fortran_z(self, names, data_types, rec_nums,
308311 if epoch :
309312 # account for difference in seconds between
310313 # CDF epoch and python's epoch, leap year in there
311- # (datetime(1971,1,2) -
314+ # (datetime(1971,1,2) -
312315 # datetime(1,1,1)).total_seconds()*1000
313316 data -= 62167219200000
314317 data = data .astype ('<M8[ms]' )
@@ -380,7 +383,7 @@ def _read_all_attribute_info(self):
380383 def _read_all_z_attribute_data (self ):
381384 """Read all CDF z-attribute data"""
382385 self .meta = {}
383- # collect attribute info needed to get more info from
386+ # collect attribute info needed to get more info from
384387 # fortran routines
385388 max_entries = []
386389 attr_nums = []
@@ -396,7 +399,7 @@ def _read_all_z_attribute_data(self):
396399 max_entries = np .array (max_entries )
397400
398401 info = fortran_cdf .z_attr_all_inquire (self .fname , attr_nums ,
399- num_z_attrs , max_entries ,
402+ num_z_attrs , max_entries ,
400403 self ._num_z_vars , len (self .fname ))
401404
402405 status = info [0 ]
@@ -488,7 +491,7 @@ def _call_multi_fortran_z_attr(self, names, data_types, num_elems,
488491 entry_nums , attr_nums , var_names ,
489492 input_type_code , func , data_offset = None ):
490493 """Calls Fortran function that reads attribute data.
491-
494+
492495 data_offset translates unsigned into signed.
493496 If number read in is negative, offset added.
494497 """
@@ -536,32 +539,32 @@ def _process_return_multi_z_attr(self, data, attr_names, var_names, sub_num_elem
536539 self .meta [var_name ][attr_name ] = data [i , 0 :num_e ]
537540
538541 def to_pysat (self , flatten_twod = True , units_label = 'UNITS' , name_label = 'long_name' ,
539- fill_label = 'FILLVAL' , plot_label = 'FieldNam' ,
540- min_label = 'ValidMin' , max_label = 'ValidMax' ,
542+ fill_label = 'FILLVAL' , plot_label = 'FieldNam' ,
543+ min_label = 'ValidMin' , max_label = 'ValidMax' ,
541544 notes_label = 'Var_Notes' , desc_label = 'CatDesc' ,
542545 axis_label = 'LablAxis' ):
543546 """
544547 Exports loaded CDF data into data, meta for pysat module
545-
548+
546549 Notes
547550 -----
548551 The *_labels should be set to the values in the file, if present.
549552 Note that once the meta object returned from this function is attached
550553 to a pysat.Instrument object then the *_labels on the Instrument
551554 are assigned to the newly attached Meta object.
552-
555+
553556 The pysat Meta object will use data with labels that match the patterns
554557 in *_labels even if the case does not match.
555558
556559 Parameters
557560 ----------
558561 flatten_twod : bool (True)
559- If True, then two dimensional data is flattened across
562+ If True, then two dimensional data is flattened across
560563 columns. Name mangling is used to group data, first column
561- is 'name', last column is 'name_end'. In between numbers are
564+ is 'name', last column is 'name_end'. In between numbers are
562565 appended 'name_1', 'name_2', etc. All data for a given 2D array
563566 may be accessed via, data.ix[:,'item':'item_end']
564- If False, then 2D data is stored as a series of DataFrames,
567+ If False, then 2D data is stored as a series of DataFrames,
565568 indexed by Epoch. data.ix[0, 'item']
566569 units_label : str
567570 Identifier within metadata for units. Defults to CDAWab standard.
@@ -575,7 +578,7 @@ def to_pysat(self, flatten_twod=True, units_label='UNITS', name_label='long_name
575578 Identifier within metadata for variable name used when plotting.
576579 Defults to CDAWab standard.
577580 min_label : str
578- Identifier within metadata for minimim variable value.
581+ Identifier within metadata for minimim variable value.
579582 Defults to CDAWab standard.
580583 max_label : str
581584 Identifier within metadata for maximum variable value.
@@ -586,36 +589,32 @@ def to_pysat(self, flatten_twod=True, units_label='UNITS', name_label='long_name
586589 Identifier within metadata for a variable description.
587590 Defults to CDAWab standard.
588591 axis_label : str
589- Identifier within metadata for axis name used when plotting.
592+ Identifier within metadata for axis name used when plotting.
590593 Defults to CDAWab standard.
591-
592-
594+
595+
593596 Returns
594597 -------
595598 pandas.DataFrame, pysat.Meta
596599 Data and Metadata suitable for attachment to a pysat.Instrument
597600 object.
598-
599- """
600601
601- import string
602- import pysat
603- import pandas
602+ """
604603
605604 # copy data
606605 cdata = self .data .copy ()
607606 #
608607 # create pysat.Meta object using data above
609608 # and utilizing the attribute labels provided by the user
610- meta = pysat .Meta (pysat .DataFrame .from_dict (self .meta , orient = 'index' ),
609+ meta = pysat .Meta (pandas .DataFrame .from_dict (self .meta , orient = 'index' ),
611610 units_label = units_label , name_label = name_label ,
612611 fill_label = fill_label , plot_label = plot_label ,
613612 min_label = min_label , max_label = max_label ,
614613 notes_label = notes_label , desc_label = desc_label ,
615614 axis_label = axis_label )
616-
615+
617616 # account for different possible cases for Epoch, epoch, EPOCH, epOch
618- lower_names = [name .lower () for name in meta .keys ()]
617+ lower_names = [name .lower () for name in meta .keys ()]
619618 for name , true_name in zip (lower_names , meta .keys ()):
620619 if name == 'epoch' :
621620 meta .data .rename (index = {true_name : 'Epoch' }, inplace = True )
@@ -633,7 +632,7 @@ def to_pysat(self, flatten_twod=True, units_label='UNITS', name_label='long_name
633632 if not flatten_twod :
634633 # put 2D data into a Frame at each time
635634 # remove data from dict when adding to the DataFrame
636- frame = pysat .DataFrame (cdata [name ].flatten (), columns = [name ])
635+ frame = pandas .DataFrame (cdata [name ].flatten (), columns = [name ])
637636 drop_list .append (name )
638637
639638 step = temp [0 ]
@@ -653,14 +652,14 @@ def to_pysat(self, flatten_twod=True, units_label='UNITS', name_label='long_name
653652 new_names .insert (0 , name )
654653 # remove data from dict when adding to the DataFrame
655654 drop_list .append (name )
656- frame = pysat .DataFrame (cdata [name ].T ,
655+ frame = pandas .DataFrame (cdata [name ].T ,
657656 index = epoch ,
658657 columns = new_names )
659658 two_d_data .append (frame )
660659 for name in drop_list :
661660 _ = cdata .pop (name )
662661 # all of the data left over is 1D, add as Series
663- data = pysat .DataFrame (cdata , index = epoch )
662+ data = pandas .DataFrame (cdata , index = epoch )
664663 two_d_data .append (data )
665664 data = pandas .concat (two_d_data , axis = 1 )
666665 data .drop ('Epoch' , axis = 1 , inplace = True )
@@ -669,12 +668,12 @@ def to_pysat(self, flatten_twod=True, units_label='UNITS', name_label='long_name
669668
670669class chameleon (object ):
671670 """Provides multiple access mechanisms for larger CDF object.
672-
671+
673672 Supports spacepy access pattern along with pysatCDF native
674673 data access pattern.
675-
674+
676675 """
677-
676+
678677 def __init__ (self , fname , name , data , attr , info ):
679678 self .fname = fname
680679 self .data = data
0 commit comments