How to use the sentinelsat.format_query_date function in sentinelsat

To help you get started, we’ve selected a few sentinelsat 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 sentinelsat / sentinelsat / tests / test_opensearch.py View on Github external
def test_format_date(api):
    assert format_query_date(datetime(2015, 1, 1)) == "2015-01-01T00:00:00Z"
    assert format_query_date(date(2015, 1, 1)) == "2015-01-01T00:00:00Z"
    assert format_query_date("2015-01-01T00:00:00Z") == "2015-01-01T00:00:00Z"
    assert format_query_date("20150101") == "2015-01-01T00:00:00Z"
    assert format_query_date(" NOW ") == "NOW"
    assert format_query_date(None) == "*"

    for date_str in (
        "NOW",
        "NOW-1DAY",
        "NOW-1DAYS",
        "NOW-500DAY",
        "NOW-500DAYS",
        "NOW-2MONTH",
        "NOW-2MONTHS",
        "NOW-20MINUTE",
        "NOW-20MINUTES",
        "NOW+10HOUR",
        "2015-01-01T00:00:00Z+1DAY",
        "NOW+3MONTHS-7DAYS/DAYS",
github sentinelsat / sentinelsat / tests / test_mod.py View on Github external
def test_format_date(api):
    assert format_query_date(datetime(2015, 1, 1)) == '2015-01-01T00:00:00Z'
    assert format_query_date(date(2015, 1, 1)) == '2015-01-01T00:00:00Z'
    assert format_query_date('2015-01-01T00:00:00Z') == '2015-01-01T00:00:00Z'
    assert format_query_date('20150101') == '2015-01-01T00:00:00Z'
    assert format_query_date(' NOW ') == 'NOW'
    assert format_query_date(None) == '*'

    for date_str in ("NOW", "NOW-1DAY", "NOW-1DAYS", "NOW-500DAY", "NOW-500DAYS",
                     "NOW-2MONTH", "NOW-2MONTHS", "NOW-20MINUTE", "NOW-20MINUTES",
                     "NOW+10HOUR", "2015-01-01T00:00:00Z+1DAY", "NOW+3MONTHS-7DAYS/DAYS",
                     "*"):
        assert format_query_date(date_str) == date_str
        api.query(raw='ingestiondate:[{} TO *]'.format(date_str), limit=0)

    for date_str in ("NOW - 1HOUR", "NOW -   1HOURS", "NOW-1 HOURS", "NOW-1", "NOW-", "**", "+", "-"):
        with pytest.raises(ValueError):
            format_query_date(date_str)
        with pytest.raises(SentinelAPIError):
            api.query(raw='ingestiondate:[{} TO *]'.format(date_str), limit=0)
github sentinelsat / sentinelsat / tests / test_mod.py View on Github external
def test_format_date(api):
    assert format_query_date(datetime(2015, 1, 1)) == '2015-01-01T00:00:00Z'
    assert format_query_date(date(2015, 1, 1)) == '2015-01-01T00:00:00Z'
    assert format_query_date('2015-01-01T00:00:00Z') == '2015-01-01T00:00:00Z'
    assert format_query_date('20150101') == '2015-01-01T00:00:00Z'
    assert format_query_date(' NOW ') == 'NOW'
    assert format_query_date(None) == '*'

    for date_str in ("NOW", "NOW-1DAY", "NOW-1DAYS", "NOW-500DAY", "NOW-500DAYS",
                     "NOW-2MONTH", "NOW-2MONTHS", "NOW-20MINUTE", "NOW-20MINUTES",
                     "NOW+10HOUR", "2015-01-01T00:00:00Z+1DAY", "NOW+3MONTHS-7DAYS/DAYS",
                     "*"):
        assert format_query_date(date_str) == date_str
        api.query(raw='ingestiondate:[{} TO *]'.format(date_str), limit=0)

    for date_str in ("NOW - 1HOUR", "NOW -   1HOURS", "NOW-1 HOURS", "NOW-1", "NOW-", "**", "+", "-"):
        with pytest.raises(ValueError):
            format_query_date(date_str)
        with pytest.raises(SentinelAPIError):
            api.query(raw='ingestiondate:[{} TO *]'.format(date_str), limit=0)
github sentinelsat / sentinelsat / tests / test_opensearch.py View on Github external
def test_api_query_format():
    wkt = "POLYGON((0 0,1 1,0 1,0 0))"

    now = datetime.now()
    last_24h = format_query_date(now - timedelta(hours=24))
    query = SentinelAPI.format_query(wkt, (last_24h, now))
    assert (
        query
        == "beginPosition:[%s TO %s] " % (last_24h, format_query_date(now))
        + 'footprint:"Intersects(POLYGON((0 0,1 1,0 1,0 0)))"'
    )

    query = SentinelAPI.format_query(wkt, date=(last_24h, "NOW"), producttype="SLC", raw="IW")
    assert (
        query
        == "beginPosition:[%s TO NOW] " % (format_query_date(last_24h))
        + 'producttype:SLC IW footprint:"Intersects(POLYGON((0 0,1 1,0 1,0 0)))"'
    )

    query = SentinelAPI.format_query(wkt, producttype="SLC", raw="IW")
    assert query == 'producttype:SLC IW footprint:"Intersects(POLYGON((0 0,1 1,0 1,0 0)))"'

    query = SentinelAPI.format_query(area=None, date=None)
    assert query == ""
github sentinelsat / sentinelsat / tests / test_mod.py View on Github external
def test_api_query_format():
    wkt = 'POLYGON((0 0,1 1,0 1,0 0))'

    now = datetime.now()
    last_24h = format_query_date(now - timedelta(hours=24))
    query = SentinelAPI.format_query(wkt, (last_24h, now))
    assert query == 'beginPosition:[%s TO %s] ' % (last_24h, format_query_date(now)) + \
           'footprint:"Intersects(POLYGON((0 0,1 1,0 1,0 0)))"'

    query = SentinelAPI.format_query(wkt, date=(last_24h, "NOW"), producttype='SLC', raw='IW')
    assert query == 'beginPosition:[%s TO NOW] ' % (format_query_date(last_24h)) + \
           'producttype:SLC IW footprint:"Intersects(POLYGON((0 0,1 1,0 1,0 0)))"'

    query = SentinelAPI.format_query(wkt, producttype='SLC', raw='IW')
    assert query == 'producttype:SLC IW footprint:"Intersects(POLYGON((0 0,1 1,0 1,0 0)))"'

    query = SentinelAPI.format_query(area=None, date=None)
    assert query == ''

    query = SentinelAPI.format_query()
    assert query == ''
github sentinelsat / sentinelsat / tests / test_mod.py View on Github external
assert format_query_date(date(2015, 1, 1)) == '2015-01-01T00:00:00Z'
    assert format_query_date('2015-01-01T00:00:00Z') == '2015-01-01T00:00:00Z'
    assert format_query_date('20150101') == '2015-01-01T00:00:00Z'
    assert format_query_date(' NOW ') == 'NOW'
    assert format_query_date(None) == '*'

    for date_str in ("NOW", "NOW-1DAY", "NOW-1DAYS", "NOW-500DAY", "NOW-500DAYS",
                     "NOW-2MONTH", "NOW-2MONTHS", "NOW-20MINUTE", "NOW-20MINUTES",
                     "NOW+10HOUR", "2015-01-01T00:00:00Z+1DAY", "NOW+3MONTHS-7DAYS/DAYS",
                     "*"):
        assert format_query_date(date_str) == date_str
        api.query(raw='ingestiondate:[{} TO *]'.format(date_str), limit=0)

    for date_str in ("NOW - 1HOUR", "NOW -   1HOURS", "NOW-1 HOURS", "NOW-1", "NOW-", "**", "+", "-"):
        with pytest.raises(ValueError):
            format_query_date(date_str)
        with pytest.raises(SentinelAPIError):
            api.query(raw='ingestiondate:[{} TO *]'.format(date_str), limit=0)
github sentinelsat / sentinelsat / tests / test_opensearch.py View on Github external
def test_format_date(api):
    assert format_query_date(datetime(2015, 1, 1)) == "2015-01-01T00:00:00Z"
    assert format_query_date(date(2015, 1, 1)) == "2015-01-01T00:00:00Z"
    assert format_query_date("2015-01-01T00:00:00Z") == "2015-01-01T00:00:00Z"
    assert format_query_date("20150101") == "2015-01-01T00:00:00Z"
    assert format_query_date(" NOW ") == "NOW"
    assert format_query_date(None) == "*"

    for date_str in (
        "NOW",
        "NOW-1DAY",
        "NOW-1DAYS",
        "NOW-500DAY",
        "NOW-500DAYS",
        "NOW-2MONTH",
        "NOW-2MONTHS",
        "NOW-20MINUTE",
        "NOW-20MINUTES",
        "NOW+10HOUR",
github sentinelsat / sentinelsat / tests / test_mod.py View on Github external
def test_format_date(api):
    assert format_query_date(datetime(2015, 1, 1)) == '2015-01-01T00:00:00Z'
    assert format_query_date(date(2015, 1, 1)) == '2015-01-01T00:00:00Z'
    assert format_query_date('2015-01-01T00:00:00Z') == '2015-01-01T00:00:00Z'
    assert format_query_date('20150101') == '2015-01-01T00:00:00Z'
    assert format_query_date(' NOW ') == 'NOW'
    assert format_query_date(None) == '*'

    for date_str in ("NOW", "NOW-1DAY", "NOW-1DAYS", "NOW-500DAY", "NOW-500DAYS",
                     "NOW-2MONTH", "NOW-2MONTHS", "NOW-20MINUTE", "NOW-20MINUTES",
                     "NOW+10HOUR", "2015-01-01T00:00:00Z+1DAY", "NOW+3MONTHS-7DAYS/DAYS",
                     "*"):
        assert format_query_date(date_str) == date_str
        api.query(raw='ingestiondate:[{} TO *]'.format(date_str), limit=0)

    for date_str in ("NOW - 1HOUR", "NOW -   1HOURS", "NOW-1 HOURS", "NOW-1", "NOW-", "**", "+", "-"):
        with pytest.raises(ValueError):
            format_query_date(date_str)
        with pytest.raises(SentinelAPIError):
            api.query(raw='ingestiondate:[{} TO *]'.format(date_str), limit=0)
github sentinelsat / sentinelsat / tests / test_opensearch.py View on Github external
def test_api_query_format():
    wkt = "POLYGON((0 0,1 1,0 1,0 0))"

    now = datetime.now()
    last_24h = format_query_date(now - timedelta(hours=24))
    query = SentinelAPI.format_query(wkt, (last_24h, now))
    assert (
        query
        == "beginPosition:[%s TO %s] " % (last_24h, format_query_date(now))
        + 'footprint:"Intersects(POLYGON((0 0,1 1,0 1,0 0)))"'
    )

    query = SentinelAPI.format_query(wkt, date=(last_24h, "NOW"), producttype="SLC", raw="IW")
    assert (
        query
        == "beginPosition:[%s TO NOW] " % (format_query_date(last_24h))
        + 'producttype:SLC IW footprint:"Intersects(POLYGON((0 0,1 1,0 1,0 0)))"'
    )

    query = SentinelAPI.format_query(wkt, producttype="SLC", raw="IW")
    assert query == 'producttype:SLC IW footprint:"Intersects(POLYGON((0 0,1 1,0 1,0 0)))"'
github sentinelsat / sentinelsat / tests / test_opensearch.py View on Github external
def test_format_date(api):
    assert format_query_date(datetime(2015, 1, 1)) == "2015-01-01T00:00:00Z"
    assert format_query_date(date(2015, 1, 1)) == "2015-01-01T00:00:00Z"
    assert format_query_date("2015-01-01T00:00:00Z") == "2015-01-01T00:00:00Z"
    assert format_query_date("20150101") == "2015-01-01T00:00:00Z"
    assert format_query_date(" NOW ") == "NOW"
    assert format_query_date(None) == "*"

    for date_str in (
        "NOW",
        "NOW-1DAY",
        "NOW-1DAYS",
        "NOW-500DAY",
        "NOW-500DAYS",
        "NOW-2MONTH",
        "NOW-2MONTHS",
        "NOW-20MINUTE",
        "NOW-20MINUTES",
        "NOW+10HOUR",
        "2015-01-01T00:00:00Z+1DAY",