How to use the cftime.date2index function in cftime

To help you get started, we’ve selected a few cftime 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 Unidata / cftime / test / test_cftime.py View on Github external
def test_list(self):
        t = date2index(
            [datetime(1950, 2, 1), datetime(1950, 2, 3)], self.standardtime)
        assert_equal(t, [31, 33])
github Unidata / cftime / test / test_cftime.py View on Github external
def test_simple(self):
        t = date2index(datetime(1950, 2, 1), self.standardtime)
        assert_equal(t, 31)
github Unidata / cftime / test / test_cftime.py View on Github external
def test_simple(self):
        t = date2index(datetime(1950, 2, 1), self.standardtime)
        assert_equal(t, 31)
github Unidata / cftime / test / test_cftime.py View on Github external
def test_select_dummy(self):
        nutime = self.TestTime(datetime(1950, 1, 1), 366, 24,
                               'hours since 1400-01-01', 'standard')

        dates = [datetime(1950, 1, 2, 6), datetime(
            1950, 1, 3), datetime(1950, 1, 3, 18)]

        t = date2index(dates, nutime, select='before')
        assert_equal(t, [1, 2, 2])

        t = date2index(dates, nutime, select='after')
        assert_equal(t, [2, 2, 3])

        t = date2index(dates, nutime, select='nearest')
        assert_equal(t, [1, 2, 3])
github Unidata / cftime / test / test_cftime.py View on Github external
def test_nonuniform(self):
        """Check that the fallback mechanism works. """
        nutime = self.TestTime(datetime(1950, 1, 1), 366, 24,
                               'hours since 1900-01-01', 'standard')

        # Let's remove the second entry, so that the computed stride is not
        # representative and the bisection method is needed.
        nutime._data = nutime._data[np.r_[0, slice(2, 200)]]

        t = date2index(datetime(1950, 2, 1), nutime)
        assert_equal(t, 30)

        t = date2index([datetime(1950, 2, 1), datetime(1950, 2, 3)], nutime)
        assert_equal(t, [30, 32])
github Unidata / cftime / test / test_cftime.py View on Github external
def test_singletime(self):
        # issue 215 test (date2index with time variable length == 1)
        time2 = self.time_vars['time2']
        result_index = date2index(self.first_timestamp, time2, select="exact")
        assert_equal(result_index, 0)
github Unidata / cftime / test / test_cftime.py View on Github external
def test_singletime(self):
        # issue 215 test (date2index with time variable length == 1)
        time2 = self.time_vars['time2']
        result_index = date2index(self.first_timestamp, time2, select="exact")
        assert_equal(result_index, 0)
github openstreams / wflow / wflow / pcrglobwb / virtualOS.py View on Github external
# Get netCDF file and variable name:
    f = nc.Dataset(ncFile)
    varName = str(varName)

    # date
    date = dateInput
    if useDoy == "Yes":
        idx = dateInput - 1
    else:
        if isinstance(date, str) == True:
            date = datetime.datetime.strptime(str(date), "%Y-%m-%d")
        date = datetime.datetime(date.year, date.month, date.day, 0, 0)
        # time index (in the netCDF file)
        nctime = f.variables["time"]  # A netCDF time variable object.
        idx = cftime.date2index(date, nctime, select="exact")
    idx = int(idx)

    #    sameClone = True
    #    # check whether clone and input maps have the same attributes:
    #    if cloneMapFileName != None:
    #        # get the attributes of cloneMap
    #        #attributeClone = getMapAttributesALL(cloneMapFileName)
    #        #cellsizeClone = attributeClone['cellsize']
    #        #rowsClone = attributeClone['rows']
    #        #colsClone = attributeClone['cols']
    #        #xULClone = attributeClone['xUL']
    #        #yULClone = attributeClone['yUL']
    #        attributeClone = getgridparams()
    #        cellsizeClone = attributeClone[2]
    #        rowsClone = attributeClone[4]
    #        colsClone = attributeClone[5]