Exemple #1
0
    def get_dates(self, wdmpath, dsn):
        """Gets the start and end date.  Returns the start and end dates as d
        atetime.datetime instances.

        wdmpath    -- path to the WDM file
        dsn        -- the dataset number
        """

        if self.verbose: 
            print('getting start and end dates for dataset %d' % dsn)

        wdm_number = self.openfiles[wdmpath]
        tdsfrc, llsdat, lledat, retcode = hspf.wtfndtpy(wdm_number, dsn, 1)

        if retcode == -6: 
            print('no data present')
            return None, None

        # Determine the number of values in the dataset
            
        dataset = DSN(wdm_number, dsn, self.message)

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

        if tcode == 2: unit = datetime.timedelta(minutes = tsstep)
        if tcode == 3: unit = datetime.timedelta(hours   = tsstep)
        if tcode == 4: unit = datetime.timedelta(days    = tsstep)

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

        start = datetime.datetime(*llsdat)
        end   = start + unit * n

        return start, end
Exemple #2
0
    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
Exemple #3
0
    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
Exemple #4
0
    def get_dates(
        self,
        wdmpath,
        dsn,
    ):
        """
        Gets the start and end date.  Returns the start and end dates as d
        atetime.datetime instances.

        wdmpath    -- path to the WDM file
        dsn        -- the dataset number
        """

        if self.verbose:
            print('getting start and end dates for dataset {}'.format(dsn))

        wdm_number = self.openfiles[wdmpath]
        tdsfrc, llsdat, lledat, retcode = hspf.wtfndtpy(wdm_number, dsn, 1)

        if retcode == -6:
            print('error: no data present')
            return None, None

        # Determine the number of values in the dataset

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

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

        if tcode == 2: unit = datetime.timedelta(minutes=tsstep)
        if tcode == 3: unit = datetime.timedelta(hours=tsstep)
        if tcode == 4: unit = datetime.timedelta(days=tsstep)

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

        # work around for "24th" hour start date

        yr, mo, da, hr, mi, se = llsdat

        start = (datetime.datetime(yr, mo, da) + datetime.timedelta(
            hours=float(hr), minutes=float(mi), seconds=float(se)))
        end = start + unit * n

        return start, end
Exemple #5
0
    def get_dates(self, 
                  wdmpath, 
                  dsn,
                  ):
        """
        Gets the start and end date.  Returns the start and end dates as d
        atetime.datetime instances.

        wdmpath    -- path to the WDM file
        dsn        -- the dataset number
        """

        if self.verbose: 
            print('getting start and end dates for dataset {}'.format(dsn))

        wdm_number = self.openfiles[wdmpath]
        tdsfrc, llsdat, lledat, retcode = hspf.wtfndtpy(wdm_number, dsn, 1)

        if retcode == -6: 
            print('error: no data present')
            return None, None

        # Determine the number of values in the dataset
            
        dataset = DSN(wdm_number, dsn, self.message)

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

        if tcode == 2: unit = datetime.timedelta(minutes = tsstep)
        if tcode == 3: unit = datetime.timedelta(hours   = tsstep)
        if tcode == 4: unit = datetime.timedelta(days    = tsstep)

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

        # work around for "24th" hour start date

        yr, mo, da, hr, mi, se = llsdat

        start = (datetime.datetime(yr, mo, da) + 
                 datetime.timedelta(hours = float(hr), minutes = float(mi), 
                                    seconds = float(se)))
        end   = start + unit * n

        return start, end
Exemple #6
0
    def get_dates(self, wdmpath, dsn):
        """Gets the start and end date.  Returns the start and end dates as d
        atetime.datetime instances.

        wdmpath    -- path to the WDM file
        dsn        -- the dataset number
        """

        if self.verbose:
            print('getting start and end dates for dataset %d' % dsn)

        wdm_number = self.openfiles[wdmpath]
        tdsfrc, llsdat, lledat, retcode = hspf.wtfndtpy(wdm_number, dsn, 1)

        if retcode == -6:
            print('no data present')
            return None, None

        # Determine the number of values in the dataset

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

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

        if tcode == 2: unit = datetime.timedelta(minutes=tsstep)
        if tcode == 3: unit = datetime.timedelta(hours=tsstep)
        if tcode == 4: unit = datetime.timedelta(days=tsstep)

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

        start = datetime.datetime(*llsdat)
        end = start + unit * n

        return start, end