def test_day_per_dekad(self): yyyymmdd = '20200121' # myvar = functions.day_per_dekad(yyyymmdd) self.assertEqual(functions.day_per_dekad(yyyymmdd), 11) yyyymmdd = '20200101' # myvar = functions.day_per_dekad(yyyymmdd) self.assertEqual(functions.day_per_dekad(yyyymmdd), 10)
def msg_mpe_10dcum(input_file, output_file): if len(input_file) > 8: output_file = functions.list_to_element(output_file) # Get the number of days of that dekad basename = os.path.basename(output_file) mydate = functions.get_date_from_path_filename(basename) nbr_days_dekad = functions.day_per_dekad(mydate) factor = 1.0 functions.check_output_dir(os.path.dirname(output_file)) args = { "input_file": input_file, "output_file": output_file, "output_format": 'GTIFF', "options": "compress=lzw", "scale_factor": factor, "input_nodata": -32768 } raster_image_math.do_cumulate(**args) else: logger.warning( 'More than 2 files missing for output {0}: Skip'.format( os.path.basename(output_file)))
def lsasaf_etp_10dcum(input_file, output_file): output_file = functions.list_to_element(output_file) # Get the number of days of that dekad basename=os.path.basename(output_file) mydate=functions.get_date_from_path_filename(basename) nbr_days_dekad = functions.day_per_dekad(mydate) # Compute the correcting factor: we sum-up all 48 30min cycles and: # Divide by 2 (mm/h -> mm) # Multiply by number of days # Divide by 100, so that the scale factor changes from 0.0001 (30min) to 0.01 factor = float(nbr_days_dekad)*0.005 functions.check_output_dir(os.path.dirname(output_file)) tmpdir = tempfile.mkdtemp(prefix=__name__, suffix='',dir=es_constants.base_tmp_dir) tmp_output_file = tmpdir+os.path.sep+os.path.basename(output_file) args = {"input_file": input_file, "output_file": tmp_output_file, "output_format": 'GTIFF', "options": "compress=lzw", "scale_factor": factor, "input_nodata":-32768} # See ES2-416: we accept at least 40 files out of the expect 48 if len(input_file) >= 40: raster_image_math.do_cumulate(**args) reproject_output(tmp_output_file, native_mapset, target_mapset) # Do also the house-keeping, by deleting the files older than 6 months number_months_keep = 6 remove_old_files(prod, "10d30min-et", version, native_mapset, 'Derived', number_months_keep) # Remove tmp dir (moved out of if-clause - 21.11.19) shutil.rmtree(tmpdir)
def generate_parameters_1d_to_10d(self): dekad_list = [] # Create unique list of all dekads (as 'Julian' number) for input_file in self.input_files: basename = os.path.basename(input_file) mydate = functions.get_date_from_path_filename(basename) mydate_yyyymmdd = str(mydate)[0:8] mydekad_nbr = functions.conv_date_2_dekad(mydate_yyyymmdd) if mydekad_nbr not in dekad_list: dekad_list.append(mydekad_nbr) dekad_list = sorted(dekad_list) # Compute the 'julian' dakad for the current day today = datetime.date.today() today_str = today.strftime('%Y%m%d') dekad_now = functions.conv_date_2_dekad(today_str) for dekad in dekad_list: # Exclude the current dekad if dekad != dekad_now: file_list = [] my_dekad_str = functions.conv_dekad_2_date(dekad) expected_days = functions.day_per_dekad(my_dekad_str) for input_file in self.input_files: basename = os.path.basename(input_file) mydate_yyyymmdd = functions.get_date_from_path_filename( basename) mydekad_nbr = functions.conv_date_2_dekad( mydate_yyyymmdd[0:8]) if mydekad_nbr == dekad: file_list.append(input_file) output_file = es_constants.processing_dir + self.output_subdir_10d + os.path.sep + my_dekad_str + self.out_prod_ident_10d if len(file_list) >= expected_days - 1: yield (file_list, output_file) else: print('Too many missing filed for dekad {0}'.format( my_dekad_str))
def generate_parameters_1moncum(): month_list = [] # Create unique list of all months (as 'Julian' number) for input_file in input_files: basename = os.path.basename(input_file) mydate = functions.get_date_from_path_filename(basename) mymonth_yyyymm = str(mydate)[0:6] if mymonth_yyyymm not in month_list: month_list.append(mymonth_yyyymm) month_list = sorted(month_list) # Compute the 'julian' dakad for the current day today = datetime.date.today() today_mon = today.strftime('%Y%m') for month in month_list: # Exclude the current dekad if month != today_mon: file_list = [] exp_days_last_dk = functions.day_per_dekad(month + '21') expected_days = int(exp_days_last_dk) + 20 for input_file in input_files: basename = os.path.basename(input_file) mydate_yyyymmdd = functions.get_date_from_path_filename( basename) mydate_yyyymm = mydate_yyyymmdd[0:6] if mydate_yyyymm == month: file_list.append(input_file) output_file = es_constants.processing_dir + output_subdir_1moncum + os.path.sep + month + '01' + out_prod_ident_1moncum if len(file_list) >= expected_days - 3: yield (file_list, output_file) else: print('Too many missing filed for month {0}'.format(month))