How to use the xlrd.xldate.xldate_from_date_tuple function in xlrd

To help you get started, we’ve selected a few xlrd examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jnsebgosselin / gwhat / WHAT / hydrograph2.py View on Github external
#----------------------------------------------- time min and max ----
        
        if self.datemode == 'year':
            
            year = xldate_as_tuple(self.TIMEmin, 0)[0]
            self.TIMEmin = xldate_from_date_tuple((year, 1, 1), 0)
            
            last_month = xldate_as_tuple(self.TIMEmax, 0)[1] == 1
            last_day = xldate_as_tuple(self.TIMEmax, 0)[2] == 1
            
            if last_month and last_day:
                pass
            else:                                
                year = xldate_as_tuple(self.TIMEmax, 0)[0] + 1
                self.TIMEmax = xldate_from_date_tuple((year, 1, 1), 0)
                
        #---------------------------------------------- xticks and labels ----
        
        #---- compute parameters ----
        
        xticks_info = self.make_xticks_info()
        
        #---- major ----
        
        self.ax1.set_xticks(xticks_info[0])

        #---- minor ----

        # labels are set using the minor ticks.
        
#        self.ax1.set_xticks(xticks_info[1], minor=True)
github jnsebgosselin / gwhat / WHAT / gapfill_weather_gui2.py View on Github external
"""
       
        if self.CORRFLAG == 'on' and self.target_station.currentIndex() != -1:

            self.FILLPARAM.limitDist = self.distlimit.value()
            self.FILLPARAM.limitAlt = self.altlimit.value()
           
            y = self.date_start_widget.date().year()
            m = self.date_start_widget.date().month()
            d = self.date_start_widget.date().month()
            self.FILLPARAM.time_start = xldate_from_date_tuple((y, m, d), 0)
     
            y = self.date_end_widget.date().year()
            m = self.date_end_widget.date().month()
            d = self.date_end_widget.date().day()
            self.FILLPARAM.time_end = xldate_from_date_tuple((y, m, d), 0)
            
            self.gafill_display_table.populate_table(self.TARGET,
                                                     self.WEATHER,
                                                     self.FILLPARAM)
           
            table, target_info = correlation_table_generation(self.TARGET,
                                                              self.WEATHER,
                                                              self.FILLPARAM)
   
            self.FillTextBox.setText(table)
            self.target_station_info.setText(target_info)
github jnsebgosselin / gwhat / gwhat / HydroPrint2.py View on Github external
# WL Datum :

        self.hydrograph.WLdatum = self.datum_widget.currentIndex()

        # Dates :

        self.hydrograph.datemode = self.time_scale_label.currentText()

        year = self.date_start_widget.date().year()
        month = self.date_start_widget.date().month()
        self.hydrograph.TIMEmin = xldate_from_date_tuple((year, month, 1), 0)

        year = self.date_end_widget.date().year()
        month = self.date_end_widget.date().month()
        self.hydrograph.TIMEmax = xldate_from_date_tuple((year, month, 1), 0)

        self.hydrograph.date_labels_pattern = self.dateDispFreq_spinBox.value()

        # Page Setup :

        self.hydrograph.fwidth = self.page_setup_win.pageSize[0]
        self.hydrograph.fheight = self.page_setup_win.pageSize[1]
        self.hydrograph.va_ratio = self.page_setup_win.va_ratio

        self.hydrograph.trend_line = self.page_setup_win.isTrendLine
        self.hydrograph.isLegend = self.page_setup_win.isLegend
        self.hydrograph.isGraphTitle = self.page_setup_win.isGraphTitle
        self.hydrograph.set_meteo_on(self.page_setup_win.is_meteo_on)
        self.hydrograph.set_glue_wl_on(self.page_setup_win.is_glue_wl_on)
        self.hydrograph.set_mrc_wl_on(self.page_setup_win.is_mrc_wl_on)
        self.hydrograph.set_figframe_lw(self.page_setup_win.figframe_lw)
github jnsebgosselin / gwhat / gwhat / meteo / gapfill_weather_algorithm2.py View on Github external
# DATA = [YEAR, MONTH, DAY, VAR1, VAR2 ... VARn]
        #
        # 2D matrix containing the dates and the corresponding daily
        # meteorological data of a given weather station arranged in
        # chronological order.

        nVAR = len(DATA[0, :]) - 3  # number of meteorological variables
        nan2insert = np.zeros(nVAR) * np.nan

        i = 0
        date1 = xldate_from_date_tuple((DATA[i, 0].astype('int'),
                                        DATA[i, 1].astype('int'),
                                        DATA[i, 2].astype('int')), 0)

        while i < len(DATA[:, 0]) - 1:
            date2 = xldate_from_date_tuple((DATA[i+1, 0].astype('int'),
                                            DATA[i+1, 1].astype('int'),
                                            DATA[i+1, 2].astype('int')), 0)

            # If dates 1 and 2 are not consecutive, add a nan row to DATA
            # after date 1.
            if date2 - date1 > 1:
                date2insert = np.array(xldate_as_tuple(date1 + 1, 0))[:3]
                row2insert = np.append(date2insert, nan2insert)
                DATA = np.insert(DATA, i + 1, row2insert, 0)

            date1 += 1
            i += 1

        return DATA
github jnsebgosselin / gwhat / WHAT / hydrograph2.py View on Github external
def set_time_scale(self): #===============================================
        
        #----------------------------------------------- time min and max ----
        
        if self.datemode == 'year':
            
            year = xldate_as_tuple(self.TIMEmin, 0)[0]
            self.TIMEmin = xldate_from_date_tuple((year, 1, 1), 0)
            
            last_month = xldate_as_tuple(self.TIMEmax, 0)[1] == 1
            last_day = xldate_as_tuple(self.TIMEmax, 0)[2] == 1
            
            if last_month and last_day:
                pass
            else:                                
                year = xldate_as_tuple(self.TIMEmax, 0)[0] + 1
                self.TIMEmax = xldate_from_date_tuple((year, 1, 1), 0)
                
        #---------------------------------------------- xticks and labels ----
        
        #---- compute parameters ----
        
        xticks_info = self.make_xticks_info()
github jnsebgosselin / gwhat / gwhat / hydrograph4.py View on Github external
def set_time_scale(self):
        """Setup the time scale of the x-axis."""
        if self.datemode.lower() == 'year':
            year = xldate_as_tuple(self.TIMEmin, 0)[0]
            self.TIMEmin = xldate_from_date_tuple((year, 1, 1), 0)

            last_month = xldate_as_tuple(self.TIMEmax, 0)[1] == 1
            last_day = xldate_as_tuple(self.TIMEmax, 0)[2] == 1

            if last_month and last_day:
                pass
            else:
                year = xldate_as_tuple(self.TIMEmax, 0)[0] + 1
                self.TIMEmax = xldate_from_date_tuple((year, 1, 1), 0)

        self.setup_xticklabels()
        self.ax1.axis([self.TIMEmin, self.TIMEmax, 0, self.NZGrid])
github jnsebgosselin / gwhat / WHAT / hydrograph2.py View on Github external
0.5 * month_range +
                                                  xticks_labels_offset)
                    
                    xticks_labels.append("%s '%s" % (month_names[month - 1], 
                                                     str(year)[-2:]))
                                                     
                i += 1
                
        elif self.datemode == 'year':
            
            i = 0
            year = xldate_as_tuple(xticks_position[i], 0)[0]
            while xticks_position[i] < self.TIMEmax:
                
                xticks_position.append(
                                     xldate_from_date_tuple((year+1, 1, 1), 0))
                year_range = xticks_position[i+1] - xticks_position[i]
                
                if i % n == 0:         
    
                    xticks_labels_position.append(xticks_position[i] +
                                                  0.5 * year_range +
                                                  xticks_labels_offset)
                    
                    xticks_labels.append("%d" % year)
                
                year += 1
                i += 1
                
                
        return xticks_position, xticks_labels_position, xticks_labels
github jnsebgosselin / gwhat / gwhat / HydroCalc2.py View on Github external
def setup_axis_range(self, event=None):
        """Setup the range of the x- and y-axis."""
        if self.wldset is not None:
            y = self.water_lvl
            t = self.time + self.dt4xls2mpl * self.dformat
        elif self.wxdset is not None:
            y = [-1, 1]
            t = self.wxdset.get_xldates() + self.dt4xls2mpl * self.dformat
        else:
            y = [-1, 1]
            t = np.array(
                [xldate_from_date_tuple((1980, 1, 1), 0),
                 xldate_from_date_tuple((2018, 1, 1), 0)]
                ) + self.dt4xls2mpl * self.dformat

        Xmin0 = np.min(t) - (np.max(t) - np.min(t)) * 0.05
        Xmax0 = np.max(t) + (np.max(t) - np.min(t)) * 0.05
        Ymin0 = np.nanmin(y) - (np.nanmax(y) - np.nanmin(y)) * 0.25
        Ymax0 = np.nanmax(y) + (np.nanmax(y) - np.nanmin(y)) * 0.25
        self.fig.axes[0].axis([Xmin0, Xmax0, Ymax0, Ymin0])

        # Setup the yaxis range for the weather.
        self.fig.axes[1].axis(ymin=500, ymax=0)
        self.draw()
github jnsebgosselin / gwhat / WHAT / hydrograph.py View on Github external
self.TIMEmin = xldate_from_date_tuple(date0, 0)
        
        # ----- Date End -----
        
        date1 = xldate_as_tuple(TIME[-1], 0)
        
        year =  date1[0]
        month = date1[1] + 1
        if month > 12:
            month = 1
            year += 1
        
        date1 = (year, month, 1)
        
        self.TIMEmax = xldate_from_date_tuple(date1, 0)
        
        return date0, date1