def modis_chla_monavg(input_file, output_file): output_file = functions.list_to_element(output_file) out_filename=os.path.basename(output_file) str_date=out_filename[0:6] expected_ndays=functions.get_number_days_month(str_date) functions.check_output_dir(os.path.dirname(output_file)) current_ndays=len(input_file) if expected_ndays != current_ndays: logger.info('Missing days for period: %s. Skip' % str_date) else: args = {"input_file": input_file, "output_file": output_file, "output_format": 'GTIFF', \ "options": "compress=lzw", "input_nodata": in_nodata} raster_image_math.do_avg_image(**args)
def modis_chla_monavg(input_file, output_file): output_file = functions.list_to_element(output_file) out_filename = os.path.basename(output_file) str_date = out_filename[0:6] expected_ndays = functions.get_number_days_month(str_date) functions.check_output_dir(os.path.dirname(output_file)) current_ndays = len(input_file) if expected_ndays != current_ndays: logger.info('Missing days for period: %s. Skip' % str_date) else: args = {"input_file": input_file, "output_file": output_file, "output_format": 'GTIFF', \ "options": "compress=lzw", "input_nodata": in_nodata} raster_image_math.do_avg_image(**args)
def add_cgl_dekads(date, dekads=1): # Copernicus global data products are obtained from the vito website and the dekad naming format is different from the actual dekad patern. # The dekadal dates are 1stDekad - 10th day, 2ndDekad - 20th day and 3rdDekad - last day of the month. new_date = date # ES2-502 isdatetime = isinstance(date, datetime.datetime) # ES2-281 Robust way to handle the dates if date.day >= 1 and date.day < 10: # ES2-502 if isdatetime: new_date = datetime.datetime(new_date.year, new_date.month, 10) else: new_date = datetime.date(new_date.year, new_date.month, 10) elif date.day >= 10 and date.day < 20: if isdatetime: new_date = datetime.datetime(new_date.year, new_date.month, 20) else: new_date = datetime.date(new_date.year, new_date.month, 20) # elif date.day >= 20 and date.day < 27: # tot_days = functions.get_number_days_month(str(date.year)+date.strftime('%m')+date.strftime('%d')) # new_date = datetime.datetime(new_date.year, new_date.month, tot_days) else: tot_days = functions.get_number_days_month( str(date.year) + date.strftime('%m') + date.strftime('%d')) # Last day of the month # check if the current day is last date of the month if date.day != tot_days: if isdatetime: # ES2-502 new_date = datetime.datetime(new_date.year, new_date.month, tot_days) else: new_date = datetime.date(new_date.year, new_date.month, tot_days) else: new_date = add_months(date, 1) if new_date.month != date.month: if isdatetime: # ES2-502 new_date = datetime.datetime(new_date.year, new_date.month, 10) else: new_date = datetime.date(new_date.year, new_date.month, 10) date = new_date return date
def add_cgl_dekads(date, dekads=1): # Copernicus global data products are obtained from the vito website and the dekad naming format is different from the actual dekad patern. # The dekadal dates are 1stDekad - 10th day, 2ndDekad - 20th day and 3rdDekad - last day of the month. new_date = date if date.day == 1: new_date += datetime.timedelta(9) elif date.day == 10: new_date += datetime.timedelta(10) elif date.day == 20: tot_days = functions.get_number_days_month( str(date.year) + date.strftime('%m') + date.strftime('%d')) new_date = datetime.datetime(new_date.year, new_date.month, tot_days) elif date.day == 28 or date.day == 29 or date.day == 30 or date.day == 31: new_date = add_months(date, 1) if new_date.month != date.month: new_date = datetime.datetime(new_date.year, new_date.month, 10) date = new_date return date
def test_convert_date_get_number_days_month(self): import lib.python.functions as f self.assertEqual(f.get_number_days_month('20180201'), 28)
def test_get_number_days_month(self): self.assertEqual(functions.get_number_days_month('20180201'), 28)