def test_Collection_build_filter_args_keyword():
    # Need to test with two collections to catch bug when deepcopy isn't used
    collections = ['LANDSAT/LC08/C02/T1_L2', 'LANDSAT/LE07/C02/T1_L2']
    wrs2_filter = [
        {'type': 'equals', 'leftField': 'WRS_PATH', 'rightValue': 44},
        {'type': 'equals', 'leftField': 'WRS_ROW', 'rightValue': 33}]
    coll_obj = default_coll_obj(
        collections=collections,
        geometry=ee.Geometry.Rectangle(-125, 35, -120, 40),
        filter_args={c: wrs2_filter for c in collections})
    output = utils.getinfo(coll_obj._build(variables=['et']))
    assert {x[5:11] for x in parse_scene_id(output)} == {'044033'}
def test_Collection_interpolate_et_reference_params_interpolate_args():
    """Test setting et_reference parameters in the interpolate call"""
    et_reference_args = {'et_reference_source': 'IDAHO_EPSCOR/GRIDMET',
                         'et_reference_band': 'etr', 'et_reference_factor': 0.5,
                         'et_reference_resample': 'bilinear'}
    output = utils.getinfo(default_coll_obj(
        et_reference_source=None, et_reference_band=None,
        et_reference_factor=None, et_reference_resample=None,
        model_args={}).interpolate(**et_reference_args))
    assert {y['id'] for x in output['features'] for y in x['bands']} == VARIABLES
    assert output['features'][0]['properties']['et_reference_factor'] == 0.5
    assert output['features'][0]['properties']['et_reference_resample'] == 'bilinear'
예제 #3
0
def test_Image_tcorr_stats_constant(tcorr=0.993548387,
                                    count=41479998,
                                    tol=0.00000001):
    output = utils.getinfo(
        default_image_obj(ndvi=0.8,
                          lst=308,
                          dt_source=10,
                          elev_source=50,
                          tcorr_source=0.98,
                          tmax_source=310).tcorr_stats)
    assert abs(output['tcorr_p5'] - tcorr) <= tol
    assert output['tcorr_count'] == count
예제 #4
0
def test_Image_dt_clamping(doy, dt_min, dt_max):
    m = ssebop.Image(default_image(),
                     dt_source='DAYMET_MEDIAN_V1',
                     dt_min=dt_min,
                     dt_max=dt_max)
    m._doy = doy
    reducer = ee.Reducer.min().combine(ee.Reducer.max(), sharedInputs=True)
    output = utils.getinfo(ee.Image(m.dt)\
        .reduceRegion(reducer=reducer, scale=1000, tileScale=4, maxPixels=2E8,
                      geometry=ee.Geometry.Rectangle(-125, 25, -65, 50)))
    assert output['dt_min'] >= dt_min
    assert output['dt_max'] <= dt_max
예제 #5
0
def test_Collection_interpolate_only_interpolate_images():
    """Test if count band is returned if no images in the date range"""
    variables = {'et', 'count'}
    output = utils.getinfo(
        default_coll_obj(collections=['LANDSAT/LC08/C01/T1_RT_TOA'],
                         geometry=ee.Geometry.Point(-123.623, 44.745),
                         start_date='2017-04-01',
                         end_date='2017-04-30',
                         variables=list(variables),
                         cloud_cover_max=70).interpolate())
    assert {y['id']
            for x in output['features'] for y in x['bands']} == variables
예제 #6
0
def test_Collection_interpolate_t_interval_daily():
    """Test if the daily time interval parameter works

    Since end_date is exclusive last image date will be one day earlier
    """
    coll_obj = default_coll_obj(start_date='2017-07-01', end_date='2017-07-05')
    output = utils.getinfo(coll_obj.interpolate(t_interval='daily'))
    assert output['type'] == 'ImageCollection'
    assert parse_scene_id(output)[0] == '20170701'
    assert parse_scene_id(output)[-1] == '20170704'
    assert {y['id']
            for x in output['features'] for y in x['bands']} == VARIABLES
예제 #7
0
def test_Image_init_date_properties():
    m = default_image_obj()
    assert utils.getinfo(m._date)['value'] == SCENE_TIME
    assert utils.getinfo(m._year) == int(SCENE_DATE.split('-')[0])
    assert utils.getinfo(m._month) == int(SCENE_DATE.split('-')[1])
    assert utils.getinfo(m._start_date)['value'] == SCENE_TIME
    assert utils.getinfo(m._end_date)['value'] == utils.millis(
        SCENE_DT + datetime.timedelta(days=1))
    assert utils.getinfo(m._doy) == SCENE_DOY
    assert utils.getinfo(m._cycle_day) == int(
        (SCENE_DT - datetime.datetime(1970, 1, 3)).days % 8 + 1)
예제 #8
0
def test_Collection_interpolate_etr_source_method():
    """Test setting etr_source in the interpolate call"""
    args = default_coll_args()
    del args['etr_source']
    del args['etr_band']
    etr_kwargs = {
        'etr_source': 'IDAHO_EPSCOR/GRIDMET',
        'etr_band': 'etr',
        'etr_factor': 0.85
    }
    output = utils.getinfo(model.Collection(**args).interpolate(**etr_kwargs))
    assert VARIABLES == sorted(
        list(set([y['id'] for x in output['features'] for y in x['bands']])))
예제 #9
0
def test_Collection_interpolate_et_reference_params_kwargs():
    """Test setting et_reference parameters in the Collection init args"""
    output = utils.getinfo(
        default_coll_obj(et_reference_source='IDAHO_EPSCOR/GRIDMET',
                         et_reference_band='etr',
                         et_reference_factor=0.5,
                         et_reference_resample='bilinear',
                         model_args={}).interpolate())
    assert {y['id']
            for x in output['features'] for y in x['bands']} == VARIABLES
    assert output['features'][0]['properties']['et_reference_factor'] == 0.5
    assert output['features'][0]['properties'][
        'et_reference_resample'] == 'bilinear'
예제 #10
0
def test_Collection_build_filter_dates_lc08():
    """Test that pre-op Landsat 8 images before 2013-03-24 are filtered.

    We may want to move this date back to 2013-04-01.
    """
    output = utils.getinfo(
        default_coll_obj(collections=['LANDSAT/LC08/C01/T1_TOA'],
                         start_date='2013-01-01',
                         end_date='2013-05-01',
                         geometry=ee.Geometry.Rectangle(
                             -125, 25, -65, 50))._build(variables=['et']))
    assert not [
        x for x in parse_scene_id(output) if x.split('_')[-1] < '20130324'
    ]
예제 #11
0
def test_Collection_interpolate_output_type_parameter(output_type, precision,
                                                      max_value):
    """Test if changing the output_type parameter works"""
    output = utils.getinfo(
        default_coll_obj().interpolate(output_type=output_type))
    output = output['features'][0]['bands']
    bands = {info['id']: i for i, info in enumerate(output)}

    assert (output[bands['et']]['data_type']['precision'] == precision)
    assert (output[bands['etr']]['data_type']['precision'] == precision)

    if max_value is not None:
        assert (output[bands['et']]['data_type']['max'] == max_value)
        assert (output[bands['etr']]['data_type']['max'] == max_value)
예제 #12
0
def test_Image_tcorr_scene_daily():
    """Tcorr should be masked for date outside range with SCENE_DAILY"""
    input_image = ee.Image.constant(1).set({
        'system:index':
        'LC08_042035_20150713',
        'system:time_start':
        ee.Date('1980-07-04').millis()
    })
    m = ssebop.Image(input_image,
                     tcorr_source='SCENE_DAILY',
                     tmax_source='DAYMET_MEDIAN_V2')
    tcorr_img = m.tcorr
    tcorr = utils.point_image_value(tcorr_img, SCENE_POINT)
    index = utils.getinfo(tcorr_img.get('tcorr_index'))
    assert tcorr['tcorr'] is None
    assert index == 9
예제 #13
0
def test_Model_dt_calc_rso_no_ea(tmax,
                                 tmin,
                                 elev,
                                 doy,
                                 lat,
                                 expected,
                                 tol=0.0001):
    """Test dt calculation using Rso and Ea from Tmin"""
    dt = utils.getinfo(
        model.dt(tmax=ee.Number(tmax),
                 tmin=ee.Number(tmin),
                 elev=ee.Number(elev),
                 rs=None,
                 doy=ee.Number(doy),
                 lat=ee.Number(lat)))
    assert abs(float(dt) - expected) <= tol
예제 #14
0
def test_Model_dt_calc_rso_ea(tmax,
                              tmin,
                              elev,
                              doy,
                              lat,
                              ea,
                              expected,
                              tol=0.0001):
    """Test dt calculation using 'measured' Ea (from Tdew, sph, vp) and Rso"""
    dt = utils.getinfo(
        model.dt(tmax=ee.Number(tmax),
                 tmin=ee.Number(tmin),
                 elev=ee.Number(elev),
                 ea=ee.Number(ea),
                 doy=ee.Number(doy),
                 lat=ee.Number(lat)))
    assert abs(float(dt) - expected) <= tol
예제 #15
0
def test_Image_tcorr_scene_annual(expected=[0.9762536456651, 2], tol=0.000001):
    """Test getting annual Tcorr from composite when monthly/daily are missing"""
    input_image = ee.Image.constant(1).set({
        'system:index':
        'LC08_042035_20150713',
        'system:time_start':
        ee.Date('1980-07-13').millis()
    })
    m = ssebop.Image(input_image,
                     tcorr_source='SCENE',
                     tmax_source='DAYMET_MEDIAN_V2')
    m._month = ee.Number(9999)
    tcorr_img = m.tcorr
    tcorr = utils.point_image_value(tcorr_img, SCENE_POINT)
    index = utils.getinfo(tcorr_img.get('tcorr_index'))
    assert abs(tcorr['tcorr'] - expected[0]) <= tol
    assert index == expected[1]
예제 #16
0
def test_Image_tcorr_scene_month(expected=[0.97006134520787, 1], tol=0.000001):
    """Test getting monthly Tcorr from composite when daily is missing"""
    # Setting start date to well before beginning of daily Tcorr images
    input_image = ee.Image.constant(1).set({
        'system:index':
        'LC08_042035_20150713',
        'system:time_start':
        ee.Date('1980-07-13').millis()
    })
    m = ssebop.Image(input_image,
                     tcorr_source='SCENE',
                     tmax_source='DAYMET_MEDIAN_V2')
    tcorr_img = m.tcorr
    tcorr = utils.point_image_value(tcorr_img, SCENE_POINT)
    index = utils.getinfo(tcorr_img.get('tcorr_index'))
    assert abs(tcorr['tcorr'] - expected[0]) <= tol
    assert index == expected[1]
예제 #17
0
def test_Collection_build_filter_args():
    coll_obj = default_coll_obj(collections=['LANDSAT/LC08/C01/T1_SR'],
                                geometry=ee.Geometry.Rectangle(
                                    -125, 35, -120, 40),
                                filter_args={
                                    'LANDSAT/LC08/C01/T1_SR': [{
                                        'type': 'equals',
                                        'leftField': 'WRS_PATH',
                                        'rightValue': 44
                                    }, {
                                        'type': 'equals',
                                        'leftField': 'WRS_ROW',
                                        'rightValue': 33
                                    }]
                                })
    output = utils.getinfo(coll_obj._build(variables=['et']))
    assert {x[5:11] for x in parse_scene_id(output)} == {'044033'}
예제 #18
0
def test_Collection_build_filter_args():
    args = default_coll_args()
    coll_id = 'LANDSAT/LC08/C01/T1_SR'
    args['collections'] = [coll_id]
    args['geometry'] = ee.Geometry.Rectangle(-125, 35, -120, 40)
    args['filter_args'] = {
        coll_id: [{
            'type': 'equals',
            'leftField': 'WRS_PATH',
            'rightValue': 44
        }, {
            'type': 'equals',
            'leftField': 'WRS_ROW',
            'rightValue': 33
        }]
    }
    output = utils.getinfo(model.Collection(**args)._build(variables=['et']))
    assert set([x[5:11] for x in parse_scene_id(output)]) == set(['044033'])
예제 #19
0
def test_Image_tcorr_scene_source(tcorr_source,
                                  tmax_source,
                                  scene_id,
                                  expected,
                                  tol=0.000001):
    """Test getting Tcorr value and index for a single date at a real point"""
    scene_date = datetime.datetime.strptime(scene_id.split('_')[-1], '%Y%m%d') \
        .strftime('%Y-%m-%d')
    input_image = ee.Image.constant(1).set({
        'system:index':
        scene_id,
        'system:time_start':
        ee.Date(scene_date).millis()
    })
    tcorr_img = ssebop.Image(input_image,
                             tcorr_source=tcorr_source,
                             tmax_source=tmax_source).tcorr

    # Tcorr images are constant images and need to be queried at a point
    tcorr = utils.point_image_value(tcorr_img, SCENE_POINT)
    index = utils.getinfo(tcorr_img.get('tcorr_index'))
    assert abs(tcorr['tcorr'] - expected[0]) <= tol
    assert index == expected[1]
예제 #20
0
def test_Collection_interpolate_t_interval_exception():
    """Test if Exception is raised for an invalid t_interval parameter"""
    with pytest.raises(ValueError):
        utils.getinfo(default_coll_obj().interpolate(t_interval='DEADBEEF'))
예제 #21
0
def test_Collection_interpolate_etr_resample_exception():
    """Test if Exception is raised if etr_resample is not set"""
    with pytest.raises(ValueError):
        utils.getinfo(
            default_coll_obj(etr_resample='deadbeef',
                             model_args={}).interpolate())
예제 #22
0
def test_Collection_interpolate_etr_factor_exception():
    """Test if Exception is raised if etr_factor is not a number or negative"""
    with pytest.raises(ValueError):
        utils.getinfo(
            default_coll_obj(etr_factor=-1, model_args={}).interpolate())
예제 #23
0
def test_Collection_interpolate_etr_factor_not_set():
    """Test if Exception is raised if etr_factor is not set"""
    with pytest.raises(ValueError):
        utils.getinfo(
            default_coll_obj(etr_factor=None, model_args={}).interpolate())
예제 #24
0
def test_Collection_interpolate_variables_custom():
    output = utils.getinfo(default_coll_obj().interpolate(variables=['et']))
    assert [y['id'] for x in output['features'] for y in x['bands']] == ['et']
예제 #25
0
def test_Collection_overpass_method_variables():
    """Test that custom method variables are passed through to build function"""
    output = utils.getinfo(default_coll_obj().overpass(variables=['et']))
    assert {y['id'] for x in output['features'] for y in x['bands']} == {'et'}
예제 #26
0
def test_Collection_interpolate_interp_days_exception():
    """Test if Exception is raised for an invalid interp_days parameter"""
    with pytest.raises(ValueError):
        utils.getinfo(default_coll_obj().interpolate(interp_days=0))
예제 #27
0
def test_Collection_interpolate_no_variables_exception():
    """Test if Exception is raised if variables is not set in init or method"""
    with pytest.raises(ValueError):
        utils.getinfo(default_coll_obj(variables=[]).interpolate())
예제 #28
0
def test_Collection_build_invalid_variable_exception():
    """Test if Exception is raised for an invalid variable"""
    with pytest.raises(ValueError):
        utils.getinfo(default_coll_obj()._build(variables=['FOO']))
예제 #29
0
def test_Collection_interpolate_output_type_exception():
    """Test if Exception is raised for an invalid interp_method parameter"""
    with pytest.raises(ValueError):
        utils.getinfo(default_coll_obj().interpolate(output_type='DEADBEEF'))
예제 #30
0
def test_Collection_overpass_default():
    """Test overpass method with default values (variables from Class init)"""
    output = utils.getinfo(default_coll_obj().overpass())
    assert {y['id']
            for x in output['features'] for y in x['bands']} == VARIABLES
    assert parse_scene_id(output) == SCENE_ID_LIST