示例#1
0
    def add_data(self):
        """ """
        ekcl = ekc.EpicKeyCodes()
        for k in self.data.columns.values:
            try:
                kname = self.epicvars[k]
                if kname is None: #dave K designated variables which aren't in epic.key of form -4084 for key 84
                    kname = ekcl.epic_dic_call( self.sbe2epic[k][-2:] )
                    temp = ('_'.join((kname[0].strip().strip('\\'),  self.sbe2epic[k].split('-')[-1]))) 

                elif (kname[0].strip().lower()) is not '': #no variables without Epic Keys
                    temp = ('_'.join((kname[0].strip().strip('\\'), self.sbe2epic[k])))

                else:
                    continue
            except:
                continue

            di = self.rec_vars.index(temp)
            self.var_class[di][:] = self.data[k].values
示例#2
0
    def variable_init(self):
        """data.columns.values is a list of all parameters in seabird file.
        We need to match these to EPIC key codes.  These can be found in the EPICNetCDF folder
        
        Usage:
        ------
        
        from EPICnetCDF import SBE_Epiclibrary
        from EPICnetCDF import epic_key_codes as ekc 
        
        ekcl = ekc.EpicKeyCodes()
        
        ekcl.epic_dic_call(SBE_Epiclibrary.SBE_EPIC['sal00']) 
        
        #will return
        #['S  ', 'SALINITY (PSU)           ', 'sal', 'PSU', ' ', 'Practical Salinity Units']
        
        DataFrame.columns.values[0]
        """
        ekcl = ekc.EpicKeyCodes()
        self.epicvars = {}
        self.sbe2epic = {}
        
        # get list of only epic variables in sbe file
        for pname in self.data.columns.values:
            try:
                self.epicvars[pname] = ekcl.epic_dic_call(SBE_Epiclibrary.SBE_EPIC[pname])
                self.sbe2epic[pname] = SBE_Epiclibrary.SBE_EPIC[pname]
            except KeyError:
                print "%s is not in the SBE_Epiclibrary and will not be added to the .nc file" % pname
        
        #build record variable attributes
        rec_vars, rec_var_name, rec_var_longname = [], [], []
        rec_var_generic_name, rec_var_missing, rec_var_units, rec_epic_code = [], [], [], []
        
        # for each epic variable, build required metainformation from epic.key file
        for i, k in enumerate(self.epicvars.keys()):
            kname = self.epicvars[k]
            if kname is None: # variables not in epic.key but given epic like codes
                              # these are often secondary instruments
                kname = ekcl.epic_dic_call(self.sbe2epic[k][-2:])
                print "Variables in .cnv file %s listed as secondary" % ( k )
                rec_vars.append( k.replace('/','per') )
                rec_var_name.append( kname[0].strip() )
                rec_var_longname.append( kname[1].strip() )
                rec_var_generic_name.append( kname[2].strip() )
                rec_var_units.append( kname[3].strip() )
                rec_epic_code.append( self.sbe2epic[k] )


            else:
                print "Variables in .cnv file %s" % ( k )
                rec_vars.append( k.replace('/','per') )
                rec_var_name.append( kname[0].strip() )
                rec_var_longname.append( kname[1].strip() )
                rec_var_generic_name.append( kname[2].strip() )
                rec_var_units.append( kname[3].strip() )
                rec_epic_code.append( self.sbe2epic[k] )
                            
        #hard coded variables are expected coordinate variables
        rec_vars = ['time','dep','lat','lon'] + rec_vars
        rec_var_name = ['', '', '', ''] + rec_var_name
        rec_var_longname = ['', '', '', ''] + rec_var_longname
        rec_var_generic_name = ['', '', '', ''] + rec_var_generic_name
        rec_var_units = ['Days Since 01 01 0001 00:00:00','dbar','degrees_north','degrees_east'] + rec_var_units
        rec_var_type= ['f8'] + ['f4' for spot in rec_vars[1:]]
        rec_epic_code = ['','1','500','501'] + rec_epic_code
        rec_var_missing = [-9999. for spot in rec_vars]
        
        
        var_class = []
        var_class.append(self.rootgrpID.createVariable(rec_vars[0], rec_var_type[0], self.dim_vars[0]))#time1
        var_class.append(self.rootgrpID.createVariable(rec_vars[1], rec_var_type[1], self.dim_vars[1]))#depth
        var_class.append(self.rootgrpID.createVariable(rec_vars[2], rec_var_type[2], self.dim_vars[2]))#lat
        var_class.append(self.rootgrpID.createVariable(rec_vars[3], rec_var_type[3], self.dim_vars[3]))#lon
        
        for i, v in enumerate(rec_vars[4:]):  #1D coordinate variables
            var_class.append(self.rootgrpID.createVariable(rec_vars[i+4], rec_var_type[i+4], self.dim_vars))

        ### add variable attributes
        for i, v in enumerate(var_class): #4dimensional for all vars
            print ("Adding Variable {0}").format(v)#
            v.setncattr('name',rec_var_name[i])
            v.long_name = rec_var_longname[i]
            v.generic_name = rec_var_generic_name[i]
            v.units = rec_var_units[i]
            v.historic_epic_code = rec_epic_code[i]
            v.missing_value = rec_var_missing[i]
            
        self.var_class = var_class
        self.rec_vars = rec_vars
示例#3
0
    def variable_init(self):
        """data.columns.values is a list of all parameters in seabird file.
        We need to match these to EPIC key codes.  These can be found in the EPICNetCDF folder
        
        Usage:
        ------
        
        from EPICnetCDF import SBE_Epiclibrary
        from EPICnetCDF import epic_key_codes as ekc 
        
        ekcl = ekc.EpicKeyCodes()
        
        ekcl.epic_dic_call(SBE_Epiclibrary.SBE_EPIC['sal00']) 
        
        #will return
        #['S  ', 'SALINITY (PSU)           ', 'sal', 'PSU', ' ', 'Practical Salinity Units']
        
        DataFrame.columns.values[0]
        """
        ekcl = ekc.EpicKeyCodes()
        self.epicvars = {}
        self.sbe2epic = {}
        
        # get list of only epic variables in sbe file
        for pname in self.data.columns.values:
            try:
                self.epicvars[pname] = ekcl.epic_dic_call(SBE_Epiclibrary.SBE_EPIC[pname])
                self.sbe2epic[pname] = SBE_Epiclibrary.SBE_EPIC[pname]
                print pname
            except KeyError:
                print "%s is not in the SBE_Epiclibrary and will not be added to the .nc file" % pname
        
        #build record variable attributes
        rec_vars, rec_var_name, rec_var_longname = [], [], []
        rec_var_generic_name, rec_var_FORTRAN, rec_var_units, rec_var_epic = [], [], [], []
        
        # for each epic variable, build required metainformation from epic.key file
        # temperatures should always be first


        for i, k in enumerate(sorted(self.epicvars.keys())):
            kname = self.epicvars[k]
            if kname is None: #dave K designated variables which aren't in epic.key of form -4084 for key 84
                print "Variables in .cnv file %s using identifier %s" % (k, self.sbe2epic[k].split('_')[-1])
                kname = ekcl.epic_dic_call( self.sbe2epic[k][-2:] )
                rec_vars.append('_'.join((kname[0].strip().strip('\\'), self.sbe2epic[k].split('-')[-1])))
            elif (kname[0].strip().lower()) is not '': #no variables without Epic Keys
                print "Variables in .cnv file %s" % ('_'.join((kname[0].strip().strip('\\'), self.sbe2epic[k])))
                rec_vars.append('_'.join((kname[0].strip().strip('\\'), self.sbe2epic[k])))

            else:
                print "No EPICkey. Variables in .cnv file %s -  %s skipped" % (k, self.sbe2epic[k].split('_')[-1])
                continue

                
            rec_var_name.append( kname[0].strip() )
            rec_var_longname.append( kname[1].strip() )
            rec_var_generic_name.append( kname[2].strip() )
            rec_var_units.append( kname[3].strip() )
            rec_var_FORTRAN.append( kname[4].strip() )
            rec_var_epic.append( int(self.sbe2epic[k].split('_')[-1]) )                            

        rec_vars = ['time','time2','dep','lat','lon'] + rec_vars

        rec_var_name = ['', '', '', '', ''] + rec_var_name
        rec_var_longname = ['', '', '', '', ''] + rec_var_longname
        rec_var_generic_name = ['', '', '', '', ''] + rec_var_generic_name
        rec_var_FORTRAN = ['', '', '', '', ''] + rec_var_FORTRAN
        rec_var_units = ['True Julian Day', 'msec since 0:00 GMT','dbar','degree_north','degree_west'] + rec_var_units
        rec_var_type= ['i4', 'i4'] + ['f4' for spot in rec_vars[2:]]
        rec_var_strtype= ['EVEN', 'EVEN', 'EVEN', 'EVEN', 'EVEN']
        rec_epic_code = [624,624,1,500,501] + rec_var_epic
        
        var_class = []
        var_class.append(self.rootgrpID.createVariable(rec_vars[0], rec_var_type[0], self.dim_vars[0]))#time1
        var_class.append(self.rootgrpID.createVariable(rec_vars[1], rec_var_type[1], self.dim_vars[0]))#time2
        var_class.append(self.rootgrpID.createVariable(rec_vars[2], rec_var_type[2], self.dim_vars[1]))#depth
        var_class.append(self.rootgrpID.createVariable(rec_vars[3], rec_var_type[3], self.dim_vars[2]))#lat
        var_class.append(self.rootgrpID.createVariable(rec_vars[4], rec_var_type[4], self.dim_vars[3]))#lon
        
        for i, v in enumerate(rec_vars[5:]):  #1D coordinate variables
            var_class.append(self.rootgrpID.createVariable(rec_vars[i+5], rec_var_type[i+5], self.dim_vars))

        ### add variable attributes
        for i, v in enumerate(var_class): #4dimensional for all vars
            print ("Adding Variable {0}").format(v)#
            v.setncattr('name',rec_var_name[i])
            v.long_name = rec_var_longname[i]
            v.generic_name = rec_var_generic_name[i]
            v.FORTRAN_format = rec_var_FORTRAN[i]
            v.units = rec_var_units[i]
            if (i <= 4) :
            #no type indicator for non dimensional variables
                v.type = rec_var_strtype[i]
            v.epic_code = rec_epic_code[i]
            
        self.var_class = var_class
        self.rec_vars = rec_vars