예제 #1
0
파일: wdmutil.py 프로젝트: timcera/PyHSPF
    def get_data(
        self,
        wdmpath,
        dsn,
        start=None,
        end=None,
    ):
        """
        Gets attributes and data from a DSN in a WDM file.

        wdmpath    -- path to the WDM file
        dsn        -- the dataset number
        attributes -- a list of the six character code from LIB3.0
        start      -- the start date and time as Python datetime.datetime class
        end        -- the end date and time as Python datetime.datetime class
        """

        wdm_number = self.openfiles[wdmpath]
        if self.verbose: print('getting data from dataset number %d' % dsn)

        if hspf.wdckdtpy(wdm_number, dsn) == 0:
            if self.verbose:
                print('DSN {} in file {} does not exist'.format(dsn, wdmpath))
            return None

        dataset = DSN(wdm_number, dsn, self.message)

        tdsfrc, llsdat, lledat, retcode = hspf.wtfndtpy(wdm_number, dsn, 1)
        if retcode == -6:
            print('no data present')
            return None

        if self.verbose: print('reading data from DSN {}'.format(dsn))

        if start != None:
            llsdat = [
                start.year, start.month, start.day, start.hour, start.minute,
                start.second
            ]
        if end != None:
            lledat = [
                end.year, end.month, end.day, end.hour, end.minute, end.second
            ]

        # Determine the number of values in the dataset

        tcode = dataset.get_attribute(17, self.attributes['TCODE '])[0]
        tsstep = dataset.get_attribute(33, self.attributes['TSSTEP'])[0]

        n = hspf.timdifpy(llsdat, lledat, tcode, tsstep)

        # Get the data and put it into dictionary

        data, retcode = hspf.wdtgetpy(wdm_number, dsn, tsstep, llsdat, n, 0,
                                      30, tcode)
        self.retcode_check(retcode, function='wdtget')

        return data
예제 #2
0
파일: wdmutil.py 프로젝트: djibi2/PyHSPF
    def get_data(self, 
                 wdmpath, 
                 dsn, 
                 start = None, 
                 end = None,
                 ):
        """
        Gets attributes and data from a DSN in a WDM file.

        wdmpath    -- path to the WDM file
        dsn        -- the dataset number
        attributes -- a list of the six character code from LIB3.0
        start      -- the start date and time as Python datetime.datetime class
        end        -- the end date and time as Python datetime.datetime class
        """

        wdm_number = self.openfiles[wdmpath]
        if self.verbose: print('getting data from dataset number %d' % dsn)

        if hspf.wdckdtpy(wdm_number, dsn) == 0:
            if self.verbose: 
                print('DSN {} in file {} does not exist'.format(dsn, wdmpath))
            return None

        dataset = DSN(wdm_number, dsn, self.message)

        tdsfrc, llsdat, lledat, retcode = hspf.wtfndtpy(wdm_number, dsn, 1)
        if retcode == -6: 
            print('no data present')
            return None

        if self.verbose: print('reading data from DSN {}'.format(dsn))

        if start != None:
            llsdat = [start.year, start.month, start.day, start.hour, 
                      start.minute, start.second]
        if end != None:
            lledat = [end.year, end.month, end.day, end.hour, end.minute, 
                      end.second]

        # Determine the number of values in the dataset
            
        tcode  = dataset.get_attribute(17, self.attributes['TCODE '])[0]
        tsstep = dataset.get_attribute(33, self.attributes['TSSTEP'])[0]

        n = hspf.timdifpy(llsdat, lledat, tcode, tsstep)

        # Get the data and put it into dictionary

        data, retcode = hspf.wdtgetpy(wdm_number, dsn, tsstep, llsdat, n,
                                      0, 30, tcode)
        self.retcode_check(retcode, function = 'wdtget')

        return data
예제 #3
0
파일: wdmutil.py 프로젝트: timcera/PyHSPF
    def create_dataset(
        self,
        wdmpath,
        dsn,
        attributes,
        pointers=None,
    ):
        """
        Creates new dataset in self.wdmfp/dsn. Parameters:

        wdmpath:     path to the WDM file to add the dataset
        dsn:         the dataset number
        pointers:    a class containing the pointer attributes
        attributes:  a dictionary of the attributes for the DSN, using the six
                     character designation from the message file. These are:

                     tstype:      the type of time series
                     step:        the time step size (some restrictions)
                     station:     station ID
                     scenario:    scenario (e.g., OBSERVED)
                     location:    location
                     description: description
                     constituent: constituent
                     fill:        value to fill missing data
        """

        wdm_number = self.openfiles[wdmpath]

        if self.verbose: print('creating DSN {} in {}'.format(dsn, wdmpath))

        if hspf.wdckdtpy(wdm_number, dsn) == 1 and self.verbose:
            print('DSN {} already exists'.format(dsn))

        dataset = DSN(wdm_number, dsn, self.message)

        if pointers is None: pointers = Pointers()
        dataset.create(pointers)

        if self.verbose:
            print('created new DSN {}'.format(dsn))
            print('writing attributes to DSN {}'.format(dsn))

        for k, v in attributes.items():
            retcode, var = dataset.add_attribute(v, self.attributes[k])

            if retcode == 0 and self.verbose:
                print('set {} to {}'.format(k, v))
            elif self.verbose:
                print('failed to set value of {}'.format(k))
                raise

        self.dsns[wdm_number] = dsn
예제 #4
0
파일: wdmutil.py 프로젝트: djibi2/PyHSPF
    def create_dataset(self, 
                       wdmpath, 
                       dsn, 
                       attributes, 
                       pointers = None,
                       ):
        """Creates new dataset in self.wdmfp/dsn. Parameters:

        wdmpath:     path to the WDM file to add the dataset
        dsn:         the dataset number
        pointers:    a class containing the pointer attributes
        attributes:  a dictionary of the attributes for the DSN, using the six
                     character designation from the message file. These are:
        
                     tstype:      the type of time series                      
                     step:        the time step size (some restrictions)
                     station:     station ID
                     scenario:    scenario (e.g., OBSERVED)
                     location:    location
                     description: description
                     constituent: constituent
                     fill:        value to fill missing data
        """

        wdm_number = self.openfiles[wdmpath]

        if self.verbose: print('creating DSN {} in {}'.format(dsn, wdmpath))

        if hspf.wdckdtpy(wdm_number, dsn) == 1 and self.verbose: 
            print('DSN {} already exists'.format(dsn))

        dataset = DSN(wdm_number, dsn, self.message)

        if pointers is None: pointers = Pointers()
        dataset.create(pointers)

        if self.verbose: 
            print('created new DSN {}'.format(dsn))
            print('writing attributes to DSN {}'.format(dsn))

        for k, v in attributes.items():
            retcode, var = dataset.add_attribute(v, self.attributes[k])

            if retcode == 0 and self.verbose:
                print('set {} to {}'.format(k, v))
            elif self.verbose:
                print('failed to set value of {}'.format(k))

        self.dsns[wdm_number] = dsn