@@ -607,35 +607,48 @@ def mosaic(name, data_dir, stac_url, collection, output_dir, start_year, start_m
607607    if  collection  not  in 'S2_L2A-1' ]: #'S2-16D-2' 
608608        return  print (f"{ collection ['collection' ]}  )
609609
610+     #geometry 
611+     if  (geom ):
612+         bbox  =  geom .bounds 
613+     
610614    #bbox 
611-     if  ( bbox   !=   None ) :
615+     else :
612616        tuple_bbox  =  tuple (map (float , bbox .split (',' )))
613617        geom  =  shapely .geometry .box (* tuple_bbox )
614618        bbox  =  geom .bounds 
615619
616620    start_date  =  datetime .datetime .strptime (str (start_year )+ '-' + str (start_month )+ '-' + str (start_day ), "%Y-%m-%d" )
617621
618-     if  (end_year  !=  None  and  end_month  !=  None  and  end_day  !=  None  ):
622+     end_date  =  None 
623+     if  all (v  is  not None  for  v  in  [end_year , end_month , end_day ]):
619624        end_date  =  datetime .datetime .strptime (str (end_year )+ '-' + str (end_month )+ '-' + str (end_day ), "%Y-%m-%d" )
620-     elif  (duration_months ):
621-         end_date  =  str (add_months_to_date (start_date , duration_months - 1 ))
622-     else :
623-         return  print (f"Not provided with a valid time interval." )
625+     elif  duration_months  is  not None :
626+         end_date  =  add_months_to_date (start_date ,duration_months - 1 )
627+     elif  duration_days  is  not None  and  not  any ([end_year , end_month , end_day , duration_months ]):
628+         end_date  =  add_days_to_date (start_date ,duration_days )
629+     
630+     if  end_date  is  None :
631+         return  print ("Not provided with a valid time interval." )
624632
625633    periods  =  []
626-     current_period_start  =  start_date 
634+     current_start_date  =  start_date 
627635
628-     while   current_period_start   <=   end_date :
629-         current_period_end   =   add_days_to_date ( current_period_start ,  duration_days   -   1 ) 
630-         if   current_period_end   >   end_date : 
631-             current_period_end   =   end_date 
632-         if   current_period_start . strftime ( "%Y-%m-%d" )  !=   current_period_end . strftime ( "%Y-%m-%d" ): 
636+     if   duration_days :
637+         while   current_start_date   <=   end_date : 
638+              current_end_date   =   add_days_to_date ( current_start_date , duration_days - 1 ) 
639+             if   current_end_date   >   end_date : 
640+                  current_end_date   =   end_date 
633641            periods .append ({
634-                 'start' : current_period_start .strftime ("%Y-%m-%d" ),
635-                 'end' : current_period_end .strftime ("%Y-%m-%d" )
642+                 'start' : current_start_date .strftime ("%Y-%m-%d" ),
643+                 'end' : current_end_date .strftime ("%Y-%m-%d" )
636644            })
637-         current_period_start  =  add_days_to_date (current_period_start , duration_days )
638- 
645+             current_start_date  +=  datetime .timedelta (days = duration_days )
646+     else :
647+         periods .append ({
648+             'start' : start_date .strftime ("%Y-%m-%d" ),
649+             'end' : end_date .strftime ("%Y-%m-%d" )
650+         })
651+         
639652    dict_collection = collection_query (
640653        collection = collection ,
641654        start_date = start_date .strftime ("%Y-%m-%d" ),
0 commit comments