Exemple #1
0
    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)))
Exemple #2
0
 def test_do_cumulate(self):
     # 1moncum
     output_filename = 'fewsnet-rfe/1moncum/20200301_fewsnet-rfe_1moncum_FEWSNET-Africa-8km_2.0.tif'
     output_file = os.path.join(self.root_out_dir, output_filename)
     ref_file = os.path.join(self.ref_dir, output_filename)
     functions.check_output_dir(os.path.dirname(output_file))
     input_files = [
         self.ref_dir +
         '/fewsnet-rfe/10d/20200321_fewsnet-rfe_10d_FEWSNET-Africa-8km_2.0.tif',
         self.ref_dir +
         '/fewsnet-rfe/10d/20200311_fewsnet-rfe_10d_FEWSNET-Africa-8km_2.0.tif',
         self.ref_dir +
         '/fewsnet-rfe/10d/20200301_fewsnet-rfe_10d_FEWSNET-Africa-8km_2.0.tif',
     ]
     args = {
         "input_file": input_files,
         "output_file": output_file,
         "output_format": 'GTIFF',
         "options": "compress=lzw",
         'output_type': 'Float32',
         'input_nodata': -32767
     }
     raster_image_math.do_cumulate(**args)
     equal = self.checkFile(ref_file, output_file)
     self.assertEqual(equal, 1)
Exemple #3
0
    def msg_mpe_1dcum(input_file, output_file):
        #
        output_file = functions.list_to_element(output_file)
        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)
        # Divide by 10 to pass from 0.01 to 0.1 as scale factor for 1d cum
        factor = 0.1
        args = {
            "input_file": input_file,
            "output_file": tmp_output_file,
            "output_format": 'GTIFF',
            "options": "compress=lzw",
            "scale_factor": factor,
            "input_nodata": -32768
        }

        raster_image_math.do_cumulate(**args)

        reproject_output(tmp_output_file, native_mapset, target_mapset)

        # Copy the non-reprojected file for validation, only in test_mode
        if test_mode:
            msg_proj_dir = es_constants.processing_dir + functions.set_path_sub_directory(
                prod, '1dcum', 'Derived', version, native_mapset)
            functions.check_output_dir(msg_proj_dir)
            shutil.copy(tmp_output_file, msg_proj_dir + os.path.sep)

        # Copy the non-reprojected file for validation, only in test_mode
        shutil.rmtree(tmpdir)
Exemple #4
0
    def cum(input_files, output_file):
        # Ensure out subdirectory exists
        functions.check_output_dir(os.path.dirname(output_file))

        # If output_file it is a list, force to a string
        output_file = functions.list_to_element(output_file)

        # Prepare temporary working directory for intermediate results
        tmpdirpath = tempfile.mkdtemp()
        # Cumulated but not masked output
        tmp_output_file = tmpdirpath + os.path.sep + os.path.basename(
            output_file)

        # Call the function for cumulating
        args = {
            "input_file": input_files,
            "output_file": tmp_output_file,
            "output_format": 'GTIFF',
            "options": "compress=lzw"
        }
        raster_image_math.do_cumulate(**args)

        # Create from the original mask a new one, by using raster_image_math.do_reprojection()
        # and save it as a temporary mask

        # raster_image_math.do_reproject(agriculture_mask, tmp_reproj_file, 'SPOTV-SADC-1km', mapset)
        raster_image_math.do_reproject(tmp_output_file, output_file,
                                       native_mapset, mapset)

        # Remove temp directory
        shutil.rmtree(tmpdirpath)
    def std_precip_1yearcum(input_file, output_file):

        output_file = functions.list_to_element(output_file)
        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":scale_factor_conv}
        raster_image_math.do_cumulate(**args)
    def std_precip_10dmeas(input_file, output_file):

        output_file = functions.list_to_element(output_file)
        functions.check_output_dir(os.path.dirname(output_file))

        # Prepare temporary working directory for intermediate results
        tmpdirpath = tempfile.mkdtemp()
        # Cumulated but not masked output
        tmp_output_file = tmpdirpath + os.path.sep + os.path.basename(
            output_file)

        # Call the function for cumulating
        args = {
            "input_file": input_file,
            "output_file": tmp_output_file,
            "output_format": 'GTIFF',
            "options": "compress=lzw"
        }
        raster_image_math.do_cumulate(**args)

        # Call the function for masking
        args = {
            "input_file": tmp_output_file,
            "mask_file": land_mask,
            "output_file": output_file,
            "output_format": 'GTIFF',
            "options": "compress=lzw",
            "mask_value": 0,
            "out_value": 0
        }
        raster_image_math.do_mask_image(**args)

        # Remove temp directory
        shutil.rmtree(tmpdirpath)
    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 lsasaf_etp_1moncum(input_file, output_file):
#
        output_file = functions.list_to_element(output_file)
        functions.check_output_dir(os.path.dirname(output_file))
        args = {"input_file": input_file, "output_file": output_file, "output_format": 'GTIFF',
                "options": "compress=lzw", "input_nodata":-32768}

        # See ES2-416: we need all 3 files for the monthly cumulate
        if len(input_file) >= 3:
            raster_image_math.do_cumulate(**args)
Exemple #9
0
    def std_precip_10dcount(input_file, output_file):

        output_file = functions.list_to_element(output_file)
        functions.check_output_dir(os.path.dirname(output_file))
        args = {
            "input_file": input_file,
            "output_file": output_file,
            "output_format": 'GTIFF',
            "options": "compress=lzw"
        }
        raster_image_math.do_cumulate(**args)
Exemple #10
0
 def lsasaf_etp_1moncum(input_file, output_file):
     #
     output_file = functions.list_to_element(output_file)
     functions.check_output_dir(os.path.dirname(output_file))
     args = {
         "input_file": input_file,
         "output_file": output_file,
         "output_format": 'GTIFF',
         "options": "compress=lzw",
         "input_nodata": -32768
     }
     raster_image_math.do_cumulate(**args)
Exemple #11
0
    def std_precip_1moncum(input_file, output_file):
        #ES2- 235 Do not show temporary products like composite not complete (ex monthly composite available mid month...)
        # ex: monthly RFE in the middle of the month should not be available because incomplete and lead to wrong analysis...
        # Check current month  ---> yes  ---> skip
        #                      ----> NO   ---> Check No of days (10% tolerance)
        #                                       acceptable ---->
        #                                                   Yes ---> proceed
        #                                                   No ----> Skip
        input_file_date = functions.get_date_from_path_full(input_file[0])

        if len(input_file) == 3:
            if not functions.is_date_current_month(input_file_date):
                output_file = functions.list_to_element(output_file)
                functions.check_output_dir(os.path.dirname(output_file))
                args = {
                    "input_file": input_file,
                    "output_file": output_file,
                    "output_format": 'GTIFF',
                    "options": "compress=lzw"
                }
                raster_image_math.do_cumulate(**args)
    def std_precip_1moncum(input_file, output_file):

        output_file = functions.list_to_element(output_file)
        functions.check_output_dir(os.path.dirname(output_file))
        args = {"input_file": input_file,"output_file": output_file, "output_format": 'GTIFF', "options": "compress=lzw"}
        raster_image_math.do_cumulate(**args)