22import logging
33
44import ee
5- from dateutil .relativedelta import *
5+ from dateutil .relativedelta import relativedelta
66
77from . import utils
88# import openet.core.utils as utils
99
1010
11- def daily (target_coll , source_coll , interp_days = 32 , interp_method = 'linear' ,
12- use_joins = False , compute_product = False ):
11+ def daily (
12+ target_coll ,
13+ source_coll ,
14+ interp_days = 32 ,
15+ interp_method = 'linear' ,
16+ use_joins = False ,
17+ compute_product = False
18+ ):
1319 """Interpolate non-daily source images to a daily target image collection
1420
1521 Parameters
@@ -252,8 +258,12 @@ def aggregate_daily(image_coll, start_date=None, end_date=None,
252258 return aggregate_to_daily (image_coll , start_date , end_date , agg_type )
253259
254260
255- def aggregate_to_daily (image_coll , start_date = None , end_date = None ,
256- agg_type = 'mean' ):
261+ def aggregate_to_daily (
262+ image_coll ,
263+ start_date = None ,
264+ end_date = None ,
265+ agg_type = 'mean'
266+ ):
257267 """Aggregate images by day without using joins
258268
259269 The primary purpose of this function is to join separate Landsat images
@@ -288,10 +298,12 @@ def aggregate_to_daily(image_coll, start_date=None, end_date=None,
288298 test_coll = image_coll .filterDate (ee .Date (start_date ), ee .Date (end_date ))
289299 elif start_date :
290300 test_coll = image_coll .filter (ee .Filter .greaterThanOrEquals (
291- 'system:time_start' , ee .Date (start_date ).millis ()))
301+ 'system:time_start' , ee .Date (start_date ).millis ()
302+ ))
292303 elif end_date :
293304 test_coll = image_coll .filter (ee .Filter .lessThan (
294- 'system:time_start' , ee .Date (end_date ).millis ()))
305+ 'system:time_start' , ee .Date (end_date ).millis ()
306+ ))
295307 else :
296308 test_coll = image_coll
297309
@@ -321,10 +333,15 @@ def aggregate_func(date_str):
321333 return ee .ImageCollection (date_list .map (aggregate_func ))
322334
323335
324- def from_scene_et_fraction (scene_coll , start_date , end_date , variables ,
325- interp_args , model_args , t_interval ,
326- use_joins = False ,
327- ):
336+ def from_scene_et_fraction (
337+ scene_coll ,
338+ start_date , end_date ,
339+ variables ,
340+ interp_args ,
341+ model_args ,
342+ t_interval ,
343+ use_joins = False ,
344+ ):
328345 """Interpolate from a precomputed collection of Landsat ET fraction scenes
329346
330347 Parameters
@@ -521,8 +538,10 @@ def et_reference_adjust(input_img):
521538 # For count, compute the composite/mosaic image for the mask band only
522539 if 'count' in variables :
523540 aggregate_coll = aggregate_to_daily (
524- image_coll = scene_coll .select (['mask' ]),
525- start_date = start_date , end_date = end_date )
541+ image_coll = scene_coll .select (['mask' ]),
542+ start_date = start_date ,
543+ end_date = end_date ,
544+ )
526545
527546 # The following is needed because the aggregate collection can be
528547 # empty if there are no scenes in the target date range but there
@@ -531,13 +550,15 @@ def et_reference_adjust(input_img):
531550 # bands will be which causes a non-homogeneous image collection.
532551 aggregate_coll = aggregate_coll .merge (
533552 ee .Image .constant (0 ).rename (['mask' ])
534- .set ({'system:time_start' : ee .Date (start_date ).millis ()}))
553+ .set ({'system:time_start' : ee .Date (start_date ).millis ()})
554+ )
535555
536556 # Interpolate to a daily time step
537557 daily_coll = daily (
538558 target_coll = daily_et_ref_coll ,
539559 source_coll = scene_coll .select (interp_vars ),
540- interp_method = interp_method , interp_days = interp_days ,
560+ interp_method = interp_method ,
561+ interp_days = interp_days ,
541562 use_joins = use_joins ,
542563 compute_product = False ,
543564 )
@@ -554,8 +575,7 @@ def et_reference_adjust(input_img):
554575 # if 'et' in variables or 'et_fraction' in variables:
555576 def compute_et (img ):
556577 """This function assumes ETr and ETf are present"""
557- et_img = img .select (['et_fraction' ]) \
558- .multiply (img .select (['et_reference' ]))
578+ et_img = img .select (['et_fraction' ]).multiply (img .select (['et_reference' ]))
559579 return img .addBands (et_img .double ().rename ('et' ))
560580 daily_coll = daily_coll .map (compute_et )
561581
@@ -598,8 +618,8 @@ def aggregate_image(agg_start_date, agg_end_date, date_format):
598618 if 'et_fraction' in variables :
599619 # Compute average et fraction over the aggregation period
600620 image_list .append (
601- et_img .divide (et_reference_img ).rename (
602- [ 'et_fraction' ]). float () )
621+ et_img .divide (et_reference_img ).rename ([ 'et_fraction' ]). float ()
622+ )
603623 if 'ndvi' in variables :
604624 # Compute average ndvi over the aggregation period
605625 ndvi_img = daily_coll \
@@ -629,7 +649,8 @@ def agg_daily(daily_img):
629649 return aggregate_image (
630650 agg_start_date = agg_start_date ,
631651 agg_end_date = ee .Date (agg_start_date ).advance (1 , 'day' ),
632- date_format = 'YYYYMMdd' )
652+ date_format = 'YYYYMMdd' ,
653+ )
633654
634655 return ee .ImageCollection (daily_coll .map (agg_daily ))
635656
@@ -647,7 +668,8 @@ def agg_monthly(agg_start_date):
647668 return aggregate_image (
648669 agg_start_date = agg_start_date ,
649670 agg_end_date = ee .Date (agg_start_date ).advance (1 , 'month' ),
650- date_format = 'YYYYMM' )
671+ date_format = 'YYYYMM' ,
672+ )
651673
652674 return ee .ImageCollection (month_list .map (agg_monthly ))
653675
@@ -664,21 +686,30 @@ def agg_annual(agg_start_date):
664686 return aggregate_image (
665687 agg_start_date = agg_start_date ,
666688 agg_end_date = ee .Date (agg_start_date ).advance (1 , 'year' ),
667- date_format = 'YYYY' )
689+ date_format = 'YYYY' ,
690+ )
668691
669692 return ee .ImageCollection (year_list .map (agg_annual ))
670693
671694 elif t_interval .lower () == 'custom' :
672695 # Returning an ImageCollection to be consistent
673696 return ee .ImageCollection (aggregate_image (
674- agg_start_date = start_date , agg_end_date = end_date ,
675- date_format = 'YYYYMMdd' ))
697+ agg_start_date = start_date ,
698+ agg_end_date = end_date ,
699+ date_format = 'YYYYMMdd' ,
700+ ))
676701
677702
678- def from_scene_et_actual (scene_coll , start_date , end_date , variables ,
679- interp_args , model_args , t_interval ,
680- use_joins = False ,
681- ):
703+ def from_scene_et_actual (
704+ scene_coll ,
705+ start_date ,
706+ end_date ,
707+ variables ,
708+ interp_args ,
709+ model_args ,
710+ t_interval ,
711+ use_joins = False ,
712+ ):
682713 """Interpolate from a precomputed collection of Landsat actual ET scenes
683714
684715 Parameters
0 commit comments