def test_Image_etf_values(lst, ndvi, dt, elev, tcorr, tmax, expected,
                          tol=0.0001):
    output_img = model.Image(
        default_image(lst=lst, ndvi=ndvi), dt_source=dt, elev_source=elev,
        tcorr_source=tcorr, tmax_source=tmax).etf
    output = utils.constant_image_value(ee.Image(output_img))
    assert abs(output['etf'] - expected) <= tol
def test_Image_ndvi_properties():
    """Test if properties are set on the NDVI image"""
    output = utils.getinfo(model.Image(default_image()).ndvi)
    assert output['bands'][0]['id'] == 'ndvi'
    assert output['properties']['system:index'] == SCENE_ID
    assert output['properties']['system:time_start'] == SCENE_TIME
    assert output['properties']['image_id'] == COLL_ID + SCENE_ID
def test_Image_time_values():
    # The time image is currently being built from the etf image, so all the
    #   ancillary values must be set for the constant_image_value to work.
    output = utils.constant_image_value(model.Image(
        default_image(ndvi=0.5, lst=308), dt_source=10, elev_source=50,
        tcorr_source=0.98, tmax_source=310).time)
    assert output['time'] == SCENE_TIME
Exemple #4
0
def test_Image_tcorr_ftr_source(tcorr_source,
                                tmax_source,
                                scene_id,
                                month,
                                expected,
                                tol=0.0001):
    """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()
    })
    m = ssebop.Image(input_image,
                     tcorr_source=tcorr_source,
                     tmax_source=tmax_source)
    # Overwrite the month property with the test value
    m._month = ee.Number(month)

    # _tcorr returns a tuple of the tcorr and tcorr_index
    tcorr, tcorr_index = m.tcorr
    tcorr = utils.getinfo(tcorr)
    tcorr_index = utils.getinfo(tcorr_index)

    assert abs(tcorr - expected[0]) <= tol
    assert tcorr_index == expected[1]
Exemple #5
0
def default_image_obj(
    lst=305,
    ndvi=0.8,
    # et_reference_source='IDAHO_EPSCOR/GRIDMET',
    et_reference_source=9.5730,
    et_reference_band='etr',
    et_reference_factor=1,
    et_reference_resample='nearest',
    dt_source=18,
    elev_source=67,
    elr_flag=False,
    tcorr_source=0.9744,
    tmax_source=310.15,
    dt_resample='nearest',
    tmax_resample='nearest',
):
    return ssebop.Image(**default_image_args(
        lst=lst,
        ndvi=ndvi,
        et_reference_source=et_reference_source,
        et_reference_band=et_reference_band,
        et_reference_factor=et_reference_factor,
        et_reference_resample=et_reference_resample,
        dt_source=dt_source,
        elev_source=elev_source,
        elr_flag=elr_flag,
        tcorr_source=tcorr_source,
        tmax_source=tmax_source,
        dt_resample=dt_resample,
        tmax_resample=tmax_resample,
    ))
def test_Image_etf_clamp_nodata(lst, ndvi, dt, elev, tcorr, tmax, expected):
    """Test that ETf is set to nodata for ETf > 1.3"""
    output_img = model.Image(
        default_image(lst=lst, ndvi=ndvi), dt_source=dt, elev_source=elev,
        tcorr_source=tcorr, tmax_source=tmax).etf
    output = utils.constant_image_value(ee.Image(output_img))
    assert output['etf'] is None and expected is None
Exemple #7
0
def test_Image_lst_properties():
    """Test if properties are set on the LST image"""
    output = utils.getinfo(ssebop.Image(default_image()).lst)
    assert output['bands'][0]['id'] == 'lst'
    assert output['properties']['system:index'] == SCENE_ID
    assert output['properties']['system:time_start'] == SCENE_TIME
    assert output['properties']['image_id'] == COLL_ID + SCENE_ID
Exemple #8
0
def test_Image_mask_values():
    output_img = ssebop.Image(default_image(ndvi=0.5, lst=308),
                              dt_source=10,
                              elev_source=50,
                              tcorr_source=0.98,
                              tmax_source=310).mask
    output = utils.constant_image_value(output_img)
    assert output['mask'] == 1
def test_Image_etf_elr_param(lst, ndvi, dt, elev, tcorr, tmax, elr, expected,
                             tol=0.0001):
    """Test that elr_flag works and changes ETf values"""
    output_img = model.Image(
        default_image(lst=lst, ndvi=ndvi), dt_source=dt, elev_source=elev,
        tcorr_source=tcorr, tmax_source=tmax, elr_flag=elr).etf
    output = utils.constant_image_value(ee.Image(output_img))
    assert abs(output['etf'] - expected) <= tol
def test_Image_etf_tdiff_param(lst, ndvi, dt, elev, tcorr, tmax, tdiff,
                               expected):
    """Test that ETf is set to nodata for tdiff values outside threshold"""
    output_img = model.Image(
        default_image(lst=lst, ndvi=ndvi), dt_source=dt, elev_source=elev,
        tcorr_source=tcorr, tmax_source=tmax, tdiff_threshold=tdiff).etf
    output = utils.constant_image_value(ee.Image(output_img))
    assert output['etf'] is None and expected is None
Exemple #11
0
def test_Image_et_values(tol=0.0001):
    output_img = ssebop.Image(default_image(ndvi=0.5, lst=308),
                              dt_source=10,
                              elev_source=50,
                              tcorr_source=0.98,
                              tmax_source=310,
                              etr_source=10).et
    output = utils.constant_image_value(output_img)
    assert abs(output['et'] - 5.8) <= tol
Exemple #12
0
def test_Image_tcorr_image_values(lst=300,
                                  ndvi=0.8,
                                  tmax=306,
                                  expected=0.9804,
                                  tol=0.0001):
    output = utils.constant_image_value(
        ssebop.Image(default_image(lst=lst, ndvi=ndvi),
                     tmax_source=tmax).tcorr_image)
    assert abs(output['tcorr'] - expected) <= tol
def test_Image_tcorr_stats_constant(expected=0.993548387, tol=0.00000001):
    # The input image needs to be clipped otherwise it is unbounded
    input_image = ee.Image(default_image(ndvi=0.8, lst=308)) \
        .clip(ee.Geometry.Rectangle(-120, 39, -119, 40))
    output = utils.getinfo(
        model.Image(input_image, dt_source=10, elev_source=50,
                     tcorr_source=0.98, tmax_source=310).tcorr_stats)
    assert abs(output['tcorr_p5'] - expected) <= tol
    assert output['tcorr_count'] == 1
Exemple #14
0
def test_Image_calculate_values(tol=0.0001):
    """Test if the calculate method returns ET, ETr, and ETf values"""
    output_img = ssebop.Image(
            default_image(ndvi=0.5, lst=308), dt_source=10, elev_source=50,
            tcorr_source=0.98, tmax_source=310, etr_source=10)\
        .calculate(['et', 'etr', 'etf'])
    output = utils.constant_image_value(output_img)
    assert abs(output['et'] - 5.8) <= tol
    assert abs(output['etr'] - 10) <= tol
    assert abs(output['etf'] - 0.58) <= tol
def test_Image_dt_clamping(doy, dt_min, dt_max):
    m = model.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
def test_Image_tcorr_image_daily():
    """Tcorr should be masked for date outside range with IMAGE_DAILY"""
    input_image = ee.Image.constant(1).set({
        'system:time_start': ee.Date('1980-07-04').millis()})
    m = model.Image(input_image, tcorr_source='IMAGE_DAILY',
                     tmax_source='TOPOWX_MEDIAN_V0')
    tcorr_img, index_img = m._tcorr
    tcorr = utils.point_image_value(tcorr_img, SCENE_POINT)
    index = utils.point_image_value(index_img, SCENE_POINT)
    assert tcorr['tcorr'] is None
    assert index['index'] is None
Exemple #17
0
def test_Image_tmax_fallback(tmax_source, xy, expected, tol=0.001):
    """Test getting Tmax median value when daily doesn't exist

    To test this, move the test date into the future
    """
    input_img = ee.Image.constant([300, 0.8]).rename(['lst', 'ndvi']) \
        .set({'system:index': SCENE_ID,
              'system:time_start': ee.Date(SCENE_DATE).update(2099).millis()})
    output_img = ssebop.Image(input_img, tmax_source=tmax_source).tmax
    output = utils.point_image_value(ee.Image(output_img), xy)
    assert abs(output['tmax'] - expected) <= tol
Exemple #18
0
def test_Image_dt_source_calculated(dt_source, date, xy, expected, tol=0.001):
    """Test getting calculated dT values for a single date at a real point"""
    m = ssebop.Image(default_image(), dt_source=dt_source)
    # Start/end date are needed to filter the source collection
    m._start_date = ee.Date.parse('yyyy-MM-dd', date)
    m._end_date = ee.Date.parse('yyyy-MM-dd', date).advance(1, 'day')
    # DOY is needed in dT calculation
    m._doy = ee.Date.parse('yyyy-MM-dd', date).getRelative('day', 'year')\
        .int().add(1)
    output = utils.point_image_value(ee.Image(m.dt), xy)
    assert abs(output['dt'] - expected) <= tol
def test_Image_tcorr_image_annual(expected=[0.9786, 2], tol=0.0001):
    """Test getting annual Tcorr from composite when monthly/daily are missing"""
    input_image = ee.Image.constant(1).set({
        'system:time_start': ee.Date('1980-07-04').millis()})
    m = model.Image(input_image, tcorr_source='IMAGE',
                     tmax_source='TOPOWX_MEDIAN_V0')
    m._month = ee.Number(9999)
    tcorr_img, index_img = m._tcorr
    tcorr = utils.point_image_value(tcorr_img, SCENE_POINT)
    index = utils.point_image_value(index_img, SCENE_POINT)
    assert abs(tcorr['tcorr'] - expected[0]) <= tol
    assert index['index'] == expected[1]
Exemple #20
0
def default_image_obj(lst=305,
                      ndvi=0.8,
                      etr_source='IDAHO_EPSCOR/GRIDMET',
                      etr_band='etr',
                      etr_factor=0.85,
                      etr_resample='nearest'):
    return ssebop.Image(**default_image_args(lst=lst,
                                             ndvi=ndvi,
                                             etr_source=etr_source,
                                             etr_band=etr_band,
                                             etr_factor=etr_factor,
                                             etr_resample=etr_resample))
def test_Image_default_parameters():
    m = model.Image(default_image())
    assert m.etr_source == None
    assert m.etr_band == None
    assert m.etr_factor == 1.0
    assert m._dt_source == 'DAYMET_MEDIAN_V1'
    assert m._elev_source == 'SRTM'
    assert m._tcorr_source == 'IMAGE'
    assert m._tmax_source == 'TOPOWX_MEDIAN_V0'
    assert m._elr_flag == False
    assert m._tdiff_threshold == 15
    assert m._dt_min == 6
    assert m._dt_max == 25
def test_Image_tcorr_image_month(expected=[0.9723, 1], tol=0.0001):
    """Test getting monthly Tcorr from composite when daily is missing"""
    # Setting start date to well before beginning of daily Tcorr images
    # 1980-07-04 should have the same cycle_day value as previous tests
    input_image = ee.Image.constant(1).set({
        'system:time_start': ee.Date('1980-07-04').millis()})
    m = model.Image(input_image, tcorr_source='IMAGE',
                     tmax_source='TOPOWX_MEDIAN_V0')
    tcorr_img, index_img = m._tcorr
    tcorr = utils.point_image_value(tcorr_img, SCENE_POINT)
    index = utils.point_image_value(index_img, SCENE_POINT)
    assert abs(tcorr['tcorr'] - expected[0]) <= tol
    assert index['index'] == expected[1]
Exemple #23
0
def test_Image_init_default_parameters():
    m = ssebop.Image(default_image())
    assert m.et_reference_source == None
    assert m.et_reference_band == None
    assert m.et_reference_factor == None
    assert m.et_reference_resample == None
    assert m._dt_source == 'DAYMET_MEDIAN_V0'
    assert m._elev_source == 'SRTM'
    assert m._tcorr_source == 'IMAGE'
    assert m._tmax_source == 'DAYMET_MEDIAN_V2'
    assert m._elr_flag == False
    assert m._dt_min == 6
    assert m._dt_max == 25
Exemple #24
0
def test_Image_tcorr_image_default(expected=[0.978, 3], tol=0.0001):
    """Test getting default Tcorr from composite"""
    input_image = ee.Image.constant(1).set(
        {'system:time_start': ee.Date('1980-07-04').millis()})
    m = ssebop.Image(input_image,
                     tcorr_source='IMAGE',
                     tmax_source='TOPOWX_MEDIAN_V0')
    m._month = ee.Number(9999)
    m._cycle_day = ee.Number(9999)
    tcorr_img, index_img = m.tcorr
    tcorr = utils.point_image_value(tcorr_img, SCENE_POINT)
    index = utils.point_image_value(index_img, SCENE_POINT)
    assert abs(tcorr['tcorr'] - expected[0]) <= tol
    assert index['index'] == expected[1]
def test_Image_tcorr_image_source(tcorr_source, tmax_source, scene_id,
                                  expected, tol=0.0001):
    """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:time_start': ee.Date(scene_date).millis()})
    tcorr_img, index_img = model.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.point_image_value(index_img, SCENE_POINT)
    assert abs(tcorr['tcorr'] - expected[0]) <= tol
    assert index['index'] == expected[1]
Exemple #26
0
def test_Image_tcorr_image_daily_last_date_ingested():
    """Test if last exported daily Tcorr image is used

    Two extra daily images with system:time_starts of "1979-01-01" but different
    "date_ingested" properties were added to the collection for this test.
    The "first" and "second" images have values of 1 and 2 respectively.
    """
    input_image = ee.Image.constant(1).set(
        {'system:time_start': ee.Date('1979-01-01').millis()})
    m = ssebop.Image(input_image,
                     tcorr_source='IMAGE_DAILY',
                     tmax_source='TOPOWX_MEDIAN_V0')
    tcorr_img, index_img = m.tcorr
    tcorr = utils.point_image_value(tcorr_img, SCENE_POINT)
    assert tcorr['tcorr'] == 2
Exemple #27
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
Exemple #28
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]
Exemple #29
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]
Exemple #30
0
def test_Image_tcorr_image_nodata(lst, ndvi, tmax, expected):
    output = utils.constant_image_value(
        ssebop.Image(default_image(lst=lst, ndvi=ndvi),
                     tmax_source=tmax).tcorr_image)
    assert output['tcorr'] is None and expected is None