我正在使用Iris和Matplotlib直观地比较两组数据(地图,折线图等)。两个数据集都包含时间,纬度,经度和温度数据。然而,这两个数据集具有不同的时间序列(一个来自1901-2007,一个来自1950-2005)。如何限制数据集以便我可以在时间方面进行比较?时间数据采用以下格式:
DimCoord([1950-01-16 12:00:00, 1950-02-15 00:00:00, 1950-03-16 12:00:00,
1950-04-16 00:00:00, 1950-05-16 12:00:00, 1950-06-16 00:00:00,
1950-07-16 12:00:00, 1950-08-16 12:00:00, 1950-09-16 00:00:00,
1950-10-16 12:00:00, 1950-11-16 00:00:00, 1950-12-16 12:00:00,
1951-01-16 12:00:00, 1951-02-15 00:00:00, 1951-03-16 12:00:00,
1951-04-16 00:00:00, 1951-05-16 12:00:00, 1951-06-16 00:00:00,
1951-07-16 12:00:00, 1951-08-16 12:00:00, 1951-09-16 00:00:00,
1951-10-16 12:00:00, 1951-11-16 00:00:00, 1951-12-16 12:00:00,
1952-01-16 12:00:00, 1952-02-15 00:00:00, 1952-03-16 12:00:00,
1952-04-16 00:00:00, 1952-05-16 12:00:00, 1952-06-16 00:00:00,
1952-07-16 12:00:00, 1952-08-16 12:00:00, 1952-09-16 00:00:00,
1952-10-16 12:00:00, 1952-11-16 00:00:00, 1952-12-16 12:00:00,
1953-01-16 12:00:00, 1953-02-15 00:00:00, 1953-03-16 12:00:00,
1953-04-16 00:00:00, 1953-05-16 12:00:00, 1953-06-16 00:00:00,
1953-07-16 12:00:00, 1953-08-16 12:00:00, 1953-09-16 00:00:00,
1953-10-16 12:00:00, 1953-11-16 00:00:00, 1953-12-16 12:00:00,
1954-01-16 12:00:00, 1954-02-15 00:00:00, 1954-03-16 12:00:00,
1954-04-16 00:00:00, 1954-05-16 12:00:00, 1954-06-16 00:00:00,
1954-07-16 12:00:00, 1954-08-16 12:00:00, 1954-09-16 00:00:00,
1954-10-16 12:00:00, 1954-11-16 00:00:00, 1954-12-16 12:00:00,
1955-01-16 12:00:00, 1955-02-15 00:00:00, 1955-03-16 12:00:00,
1955-04-16 00:00:00, 1955-05-16 12:00:00, 1955-06-16 00:00:00,
1955-07-16 12:00:00, 1955-08-16 12:00:00, 1955-09-16 00:00:00,
1955-10-16 12:00:00, 1955-11-16 00:00:00, 1955-12-16 12:00:00,
1956-01-16 12:00:00, 1956-02-15 00:00:00, 1956-03-16 12:00:00,
1956-04-16 00:00:00, 1956-05-16 12:00:00, 1956-06-16 00:00:00,
1956-07-16 12:00:00, 1956-08-16 12:00:00, 1956-09-16 00:00:00,
1956-10-16 12:00:00, 1956-11-16 00:00:00, 1956-12-16 12:00:00,
1957-01-16 12:00:00, 1957-02-15 00:00:00, 1957-03-16 12:00:00,
1957-04-16 00:00:00, 1957-05-16 12:00:00, 1957-06-16 00:00:00,
1957-07-16 12:00:00, 1957-08-16 12:00:00, 1957-09-16 00:00:00,
1957-10-16 12:00:00, 1957-11-16 00:00:00, 1957-12-16 12:00:00,
1958-01-16 12:00:00, 1958-02-15 00:00:00, 1958-03-16 12:00:00,
1958-04-16 00:00:00, 1958-05-16 12:00:00, 1958-06-16 00:00:00,
1958-07-16 12:00:00, 1958-08-16 12:00:00, 1958-09-16 00:00:00,
1958-10-16 12:00:00, 1958-11-16 00:00:00, 1958-12-16 12:00:00,
1959-01-16 12:00:00, 1959-02-15 00:00:00, 1959-03-16 12:00:00,
1959-04-16 00:00:00, 1959-05-16 12:00:00, 1959-06-16 00:00:00,
1959-07-16 12:00:00, 1959-08-16 12:00:00, 1959-09-16 00:00:00,
1959-10-16 12:00:00, 1959-11-16 00:00:00, 1959-12-16 12:00:00,
1960-01-16 12:00:00, 1960-02-15 00:00:00, 1960-03-16 12:00:00,
1960-04-16 00:00:00, 1960-05-16 12:00:00, 1960-06-16 00:00:00,
1960-07-16 12:00:00, 1960-08-16 12:00:00, 1960-09-16 00:00:00,
1960-10-16 12:00:00, 1960-11-16 00:00:00, 1960-12-16 12:00:00,
1961-01-16 12:00:00, 1961-02-15 00:00:00, 1961-03-16 12:00:00,
1961-04-16 00:00:00, 1961-05-16 12:00:00, 1961-06-16 00:00:00,
1961-07-16 12:00:00, 1961-08-16 12:00:00, 1961-09-16 00:00:00,
1961-10-16 12:00:00, 1961-11-16 00:00:00, 1961-12-16 12:00:00,
1962-01-16 12:00:00, 1962-02-15 00:00:00, 1962-03-16 12:00:00,
1962-04-16 00:00:00, 1962-05-16 12:00:00, 1962-06-16 00:00:00,
1962-07-16 12:00:00, 1962-08-16 12:00:00, 1962-09-16 00:00:00,
1962-10-16 12:00:00, 1962-11-16 00:00:00, 1962-12-16 12:00:00,
1963-01-16 12:00:00, 1963-02-15 00:00:00, 1963-03-16 12:00:00,
1963-04-16 00:00:00, 1963-05-16 12:00:00, 1963-06-16 00:00:00,
1963-07-16 12:00:00, 1963-08-16 12:00:00, 1963-09-16 00:00:00,
1963-10-16 12:00:00, 1963-11-16 00:00:00, 1963-12-16 12:00:00,
1964-01-16 12:00:00, 1964-02-15 00:00:00, 1964-03-16 12:00:00,
1964-04-16 00:00:00, 1964-05-16 12:00:00, 1964-06-16 00:00:00,
1964-07-16 12:00:00, 1964-08-16 12:00:00, 1964-09-16 00:00:00,
1964-10-16 12:00:00, 1964-11-16 00:00:00, 1964-12-16 12:00:00,
1965-01-16 12:00:00, 1965-02-15 00:00:00, 1965-03-16 12:00:00,
1965-04-16 00:00:00, 1965-05-16 12:00:00, 1965-06-16 00:00:00,
1965-07-16 12:00:00, 1965-08-16 12:00:00, 1965-09-16 00:00:00,
1965-10-16 12:00:00, 1965-11-16 00:00:00, 1965-12-16 12:00:00,
1966-01-16 12:00:00, 1966-02-15 00:00:00, 1966-03-16 12:00:00,
1966-04-16 00:00:00, 1966-05-16 12:00:00, 1966-06-16 00:00:00,
1966-07-16 12:00:00, 1966-08-16 12:00:00, 1966-09-16 00:00:00,
1966-10-16 12:00:00, 1966-11-16 00:00:00, 1966-12-16 12:00:00,
1967-01-16 12:00:00, 1967-02-15 00:00:00, 1967-03-16 12:00:00,
1967-04-16 00:00:00, 1967-05-16 12:00:00, 1967-06-16 00:00:00,
1967-07-16 12:00:00, 1967-08-16 12:00:00, 1967-09-16 00:00:00,
1967-10-16 12:00:00, 1967-11-16 00:00:00, 1967-12-16 12:00:00,
1968-01-16 12:00:00, 1968-02-15 00:00:00, 1968-03-16 12:00:00,
1968-04-16 00:00:00, 1968-05-16 12:00:00, 1968-06-16 00:00:00,
1968-07-16 12:00:00, 1968-08-16 12:00:00, 1968-09-16 00:00:00,
1968-10-16 12:00:00, 1968-11-16 00:00:00, 1968-12-16 12:00:00,
1969-01-16 12:00:00, 1969-02-15 00:00:00, 1969-03-16 12:00:00,
1969-04-16 00:00:00, 1969-05-16 12:00:00, 1969-06-16 00:00:00,
1969-07-16 12:00:00, 1969-08-16 12:00:00, 1969-09-16 00:00:00,
1969-10-16 12:00:00, 1969-11-16 00:00:00, 1969-12-16 12:00:00,
1970-01-16 12:00:00, 1970-02-15 00:00:00, 1970-03-16 12:00:00,
1970-04-16 00:00:00, 1970-05-16 12:00:00, 1970-06-16 00:00:00,
1970-07-16 12:00:00, 1970-08-16 12:00:00, 1970-09-16 00:00:00,
1970-10-16 12:00:00, 1970-11-16 00:00:00, 1970-12-16 12:00:00,
1971-01-16 12:00:00, 1971-02-15 00:00:00, 1971-03-16 12:00:00,
1971-04-16 00:00:00, 1971-05-16 12:00:00, 1971-06-16 00:00:00,
1971-07-16 12:00:00, 1971-08-16 12:00:00, 1971-09-16 00:00:00,
1971-10-16 12:00:00, 1971-11-16 00:00:00, 1971-12-16 12:00:00,
1972-01-16 12:00:00, 1972-02-15 00:00:00, 1972-03-16 12:00:00,
1972-04-16 00:00:00, 1972-05-16 12:00:00, 1972-06-16 00:00:00,
1972-07-16 12:00:00, 1972-08-16 12:00:00, 1972-09-16 00:00:00,
1972-10-16 12:00:00, 1972-11-16 00:00:00, 1972-12-16 12:00:00,
1973-01-16 12:00:00, 1973-02-15 00:00:00, 1973-03-16 12:00:00,
1973-04-16 00:00:00, 1973-05-16 12:00:00, 1973-06-16 00:00:00,
1973-07-16 12:00:00, 1973-08-16 12:00:00, 1973-09-16 00:00:00,
1973-10-16 12:00:00, 1973-11-16 00:00:00, 1973-12-16 12:00:00,
1974-01-16 12:00:00, 1974-02-15 00:00:00, 1974-03-16 12:00:00,
1974-04-16 00:00:00, 1974-05-16 12:00:00, 1974-06-16 00:00:00,
1974-07-16 12:00:00, 1974-08-16 12:00:00, 1974-09-16 00:00:00,
1974-10-16 12:00:00, 1974-11-16 00:00:00, 1974-12-16 12:00:00,
1975-01-16 12:00:00, 1975-02-15 00:00:00, 1975-03-16 12:00:00,
1975-04-16 00:00:00, 1975-05-16 12:00:00, 1975-06-16 00:00:00,
1975-07-16 12:00:00, 1975-08-16 12:00:00, 1975-09-16 00:00:00,
1975-10-16 12:00:00, 1975-11-16 00:00:00, 1975-12-16 12:00:00,
1976-01-16 12:00:00, 1976-02-15 00:00:00, 1976-03-16 12:00:00,
1976-04-16 00:00:00, 1976-05-16 12:00:00, 1976-06-16 00:00:00,
1976-07-16 12:00:00, 1976-08-16 12:00:00, 1976-09-16 00:00:00,
1976-10-16 12:00:00, 1976-11-16 00:00:00, 1976-12-16 12:00:00,
1977-01-16 12:00:00, 1977-02-15 00:00:00, 1977-03-16 12:00:00,
1977-04-16 00:00:00, 1977-05-16 12:00:00, 1977-06-16 00:00:00,
1977-07-16 12:00:00, 1977-08-16 12:00:00, 1977-09-16 00:00:00,
1977-10-16 12:00:00, 1977-11-16 00:00:00, 1977-12-16 12:00:00,
1978-01-16 12:00:00, 1978-02-15 00:00:00, 1978-03-16 12:00:00,
1978-04-16 00:00:00, 1978-05-16 12:00:00, 1978-06-16 00:00:00,
1978-07-16 12:00:00, 1978-08-16 12:00:00, 1978-09-16 00:00:00,
1978-10-16 12:00:00, 1978-11-16 00:00:00, 1978-12-16 12:00:00,
1979-01-16 12:00:00, 1979-02-15 00:00:00, 1979-03-16 12:00:00,
1979-04-16 00:00:00, 1979-05-16 12:00:00, 1979-06-16 00:00:00,
1979-07-16 12:00:00, 1979-08-16 12:00:00, 1979-09-16 00:00:00,
1979-10-16 12:00:00, 1979-11-16 00:00:00, 1979-12-16 12:00:00,
1980-01-16 12:00:00, 1980-02-15 00:00:00, 1980-03-16 12:00:00,
1980-04-16 00:00:00, 1980-05-16 12:00:00, 1980-06-16 00:00:00,
1980-07-16 12:00:00, 1980-08-16 12:00:00, 1980-09-16 00:00:00,
1980-10-16 12:00:00, 1980-11-16 00:00:00, 1980-12-16 12:00:00,
1981-01-16 12:00:00, 1981-02-15 00:00:00, 1981-03-16 12:00:00,
1981-04-16 00:00:00, 1981-05-16 12:00:00, 1981-06-16 00:00:00,
1981-07-16 12:00:00, 1981-08-16 12:00:00, 1981-09-16 00:00:00,
1981-10-16 12:00:00, 1981-11-16 00:00:00, 1981-12-16 12:00:00,
1982-01-16 12:00:00, 1982-02-15 00:00:00, 1982-03-16 12:00:00,
1982-04-16 00:00:00, 1982-05-16 12:00:00, 1982-06-16 00:00:00,
1982-07-16 12:00:00, 1982-08-16 12:00:00, 1982-09-16 00:00:00,
1982-10-16 12:00:00, 1982-11-16 00:00:00, 1982-12-16 12:00:00,
1983-01-16 12:00:00, 1983-02-15 00:00:00, 1983-03-16 12:00:00,
1983-04-16 00:00:00, 1983-05-16 12:00:00, 1983-06-16 00:00:00,
1983-07-16 12:00:00, 1983-08-16 12:00:00, 1983-09-16 00:00:00,
1983-10-16 12:00:00, 1983-11-16 00:00:00, 1983-12-16 12:00:00,
1984-01-16 12:00:00, 1984-02-15 00:00:00, 1984-03-16 12:00:00,
1984-04-16 00:00:00, 1984-05-16 12:00:00, 1984-06-16 00:00:00,
1984-07-16 12:00:00, 1984-08-16 12:00:00, 1984-09-16 00:00:00,
1984-10-16 12:00:00, 1984-11-16 00:00:00, 1984-12-16 12:00:00,
1985-01-16 12:00:00, 1985-02-15 00:00:00, 1985-03-16 12:00:00,
1985-04-16 00:00:00, 1985-05-16 12:00:00, 1985-06-16 00:00:00,
1985-07-16 12:00:00, 1985-08-16 12:00:00, 1985-09-16 00:00:00,
1985-10-16 12:00:00, 1985-11-16 00:00:00, 1985-12-16 12:00:00,
1986-01-16 12:00:00, 1986-02-15 00:00:00, 1986-03-16 12:00:00,
1986-04-16 00:00:00, 1986-05-16 12:00:00, 1986-06-16 00:00:00,
1986-07-16 12:00:00, 1986-08-16 12:00:00, 1986-09-16 00:00:00,
1986-10-16 12:00:00, 1986-11-16 00:00:00, 1986-12-16 12:00:00,
1987-01-16 12:00:00, 1987-02-15 00:00:00, 1987-03-16 12:00:00,
1987-04-16 00:00:00, 1987-05-16 12:00:00, 1987-06-16 00:00:00,
1987-07-16 12:00:00, 1987-08-16 12:00:00, 1987-09-16 00:00:00,
1987-10-16 12:00:00, 1987-11-16 00:00:00, 1987-12-16 12:00:00,
1988-01-16 12:00:00, 1988-02-15 00:00:00, 1988-03-16 12:00:00,
1988-04-16 00:00:00, 1988-05-16 12:00:00, 1988-06-16 00:00:00,
1988-07-16 12:00:00, 1988-08-16 12:00:00, 1988-09-16 00:00:00,
1988-10-16 12:00:00, 1988-11-16 00:00:00, 1988-12-16 12:00:00,
1989-01-16 12:00:00, 1989-02-15 00:00:00, 1989-03-16 12:00:00,
1989-04-16 00:00:00, 1989-05-16 12:00:00, 1989-06-16 00:00:00,
1989-07-16 12:00:00, 1989-08-16 12:00:00, 1989-09-16 00:00:00,
1989-10-16 12:00:00, 1989-11-16 00:00:00, 1989-12-16 12:00:00,
1990-01-16 12:00:00, 1990-02-15 00:00:00, 1990-03-16 12:00:00,
1990-04-16 00:00:00, 1990-05-16 12:00:00, 1990-06-16 00:00:00,
1990-07-16 12:00:00, 1990-08-16 12:00:00, 1990-09-16 00:00:00,
1990-10-16 12:00:00, 1990-11-16 00:00:00, 1990-12-16 12:00:00,
1991-01-16 12:00:00, 1991-02-15 00:00:00, 1991-03-16 12:00:00,
1991-04-16 00:00:00, 1991-05-16 12:00:00, 1991-06-16 00:00:00,
1991-07-16 12:00:00, 1991-08-16 12:00:00, 1991-09-16 00:00:00,
1991-10-16 12:00:00, 1991-11-16 00:00:00, 1991-12-16 12:00:00,
1992-01-16 12:00:00, 1992-02-15 00:00:00, 1992-03-16 12:00:00,
1992-04-16 00:00:00, 1992-05-16 12:00:00, 1992-06-16 00:00:00,
1992-07-16 12:00:00, 1992-08-16 12:00:00, 1992-09-16 00:00:00,
1992-10-16 12:00:00, 1992-11-16 00:00:00, 1992-12-16 12:00:00,
1993-01-16 12:00:00, 1993-02-15 00:00:00, 1993-03-16 12:00:00,
1993-04-16 00:00:00, 1993-05-16 12:00:00, 1993-06-16 00:00:00,
1993-07-16 12:00:00, 1993-08-16 12:00:00, 1993-09-16 00:00:00,
1993-10-16 12:00:00, 1993-11-16 00:00:00, 1993-12-16 12:00:00,
1994-01-16 12:00:00, 1994-02-15 00:00:00, 1994-03-16 12:00:00,
1994-04-16 00:00:00, 1994-05-16 12:00:00, 1994-06-16 00:00:00,
1994-07-16 12:00:00, 1994-08-16 12:00:00, 1994-09-16 00:00:00,
1994-10-16 12:00:00, 1994-11-16 00:00:00, 1994-12-16 12:00:00,
1995-01-16 12:00:00, 1995-02-15 00:00:00, 1995-03-16 12:00:00,
1995-04-16 00:00:00, 1995-05-16 12:00:00, 1995-06-16 00:00:00,
1995-07-16 12:00:00, 1995-08-16 12:00:00, 1995-09-16 00:00:00,
1995-10-16 12:00:00, 1995-11-16 00:00:00, 1995-12-16 12:00:00,
1996-01-16 12:00:00, 1996-02-15 00:00:00, 1996-03-16 12:00:00,
1996-04-16 00:00:00, 1996-05-16 12:00:00, 1996-06-16 00:00:00,
1996-07-16 12:00:00, 1996-08-16 12:00:00, 1996-09-16 00:00:00,
1996-10-16 12:00:00, 1996-11-16 00:00:00, 1996-12-16 12:00:00,
1997-01-16 12:00:00, 1997-02-15 00:00:00, 1997-03-16 12:00:00,
1997-04-16 00:00:00, 1997-05-16 12:00:00, 1997-06-16 00:00:00,
1997-07-16 12:00:00, 1997-08-16 12:00:00, 1997-09-16 00:00:00,
1997-10-16 12:00:00, 1997-11-16 00:00:00, 1997-12-16 12:00:00,
1998-01-16 12:00:00, 1998-02-15 00:00:00, 1998-03-16 12:00:00,
1998-04-16 00:00:00, 1998-05-16 12:00:00, 1998-06-16 00:00:00,
1998-07-16 12:00:00, 1998-08-16 12:00:00, 1998-09-16 00:00:00,
1998-10-16 12:00:00, 1998-11-16 00:00:00, 1998-12-16 12:00:00,
1999-01-16 12:00:00, 1999-02-15 00:00:00, 1999-03-16 12:00:00,
1999-04-16 00:00:00, 1999-05-16 12:00:00, 1999-06-16 00:00:00,
1999-07-16 12:00:00, 1999-08-16 12:00:00, 1999-09-16 00:00:00,
1999-10-16 12:00:00, 1999-11-16 00:00:00, 1999-12-16 12:00:00,
2000-01-16 12:00:00, 2000-02-15 00:00:00, 2000-03-16 12:00:00,
2000-04-16 00:00:00, 2000-05-16 12:00:00, 2000-06-16 00:00:00,
2000-07-16 12:00:00, 2000-08-16 12:00:00, 2000-09-16 00:00:00,
2000-10-16 12:00:00, 2000-11-16 00:00:00, 2000-12-16 12:00:00,
2001-01-16 12:00:00, 2001-02-15 00:00:00, 2001-03-16 12:00:00,
2001-04-16 00:00:00, 2001-05-16 12:00:00, 2001-06-16 00:00:00,
2001-07-16 12:00:00, 2001-08-16 12:00:00, 2001-09-16 00:00:00,
2001-10-16 12:00:00, 2001-11-16 00:00:00, 2001-12-16 12:00:00,
2002-01-16 12:00:00, 2002-02-15 00:00:00, 2002-03-16 12:00:00,
2002-04-16 00:00:00, 2002-05-16 12:00:00, 2002-06-16 00:00:00,
2002-07-16 12:00:00, 2002-08-16 12:00:00, 2002-09-16 00:00:00,
2002-10-16 12:00:00, 2002-11-16 00:00:00, 2002-12-16 12:00:00,
2003-01-16 12:00:00, 2003-02-15 00:00:00, 2003-03-16 12:00:00,
2003-04-16 00:00:00, 2003-05-16 12:00:00, 2003-06-16 00:00:00,
2003-07-16 12:00:00, 2003-08-16 12:00:00, 2003-09-16 00:00:00,
2003-10-16 12:00:00, 2003-11-16 00:00:00, 2003-12-16 12:00:00,
2004-01-16 12:00:00, 2004-02-15 00:00:00, 2004-03-16 12:00:00,
2004-04-16 00:00:00, 2004-05-16 12:00:00, 2004-06-16 00:00:00,
2004-07-16 12:00:00, 2004-08-16 12:00:00, 2004-09-16 00:00:00,
2004-10-16 12:00:00, 2004-11-16 00:00:00, 2004-12-16 12:00:00,
2005-01-16 12:00:00, 2005-02-15 00:00:00, 2005-03-16 12:00:00,
2005-04-16 00:00:00, 2005-05-16 12:00:00, 2005-06-16 00:00:00,
2005-07-16 12:00:00, 2005-08-16 12:00:00, 2005-09-16 00:00:00,
2005-10-16 12:00:00, 2005-11-16 00:00:00, 2005-12-16 12:00:00], standard_name=u'time', calendar=u'365_day', long_name=u'time', var_name='time')
谢谢!
答案 0 :(得分:2)
您可以定义时间约束并使用约束从多维数据集中提取。 Iris用户指南有关于约束的部分;见http://scitools.org.uk/iris/docs/latest/userguide/loading_iris_cubes.html#constrained-loading。我们特别感兴趣的是关于限制时间的小节,因为我们需要在这里制定时间限制。
在这种情况下,我们需要构建一个时间约束,可以用来从两个数据集中提取1950 - 2005年内包含的所有值。您可以按如下方式执行此操作:
iris.FUTURE.cell_datetime_objects = True
t_constraint = iris.Constraint(time=lambda cell: 1950 <= cell.point.year <= 2005)
shorter_series_1 = longer_series_cube.extract(t_constraint)
shorter_series_2 = shorter_series_cube.extract(t_constraint)
请注意,严格意义上的第二个摘录(使shorter_series_2
)在这种情况下不执行任何操作,但我已将其包含在内以保证完整性。 iris.FUTURE
调用意味着我们可以使用单元格(实际上是单个点及其来自坐标的边界),就像它们是Python日期时间对象一样,在这种情况下允许我们在{{cell.point.year
中调用lambda
1}}在约束内。
答案 1 :(得分:1)
subset方法是否符合您的要求?
E.g。
longer_series_cube.subset(shorter_series_cube.coord('time'))
从与较短系列匹配的较长系列中提取月份。
答案 2 :(得分:0)
我最近了解到 CubeList.extract_overlapping 方法的存在。所以另一个选择可能是
newcube1, newcube2 = iris.cube.CubeList([cube1, cube2]).extract_overlapping('time')