def calibrate(**kwargs):
    # calibrator instance
    calibrator_kwargs = {
        'aggregatefile': kwargs['aggregatefile'],
        'calibratefile': kwargs['calibratefile'],
        'rainstationsfile': kwargs['rainstationsfile'],
        'areamaskfile': kwargs['areamaskfile'],
    }
    cal = Calibrator(**calibrator_kwargs)

    # perform calibration by interpolation
    interpolation_methods = {
        'ked': ked,
        'ked_r': ked_r,
        'idw': idw,
    }
    interpolate_kwargs = {
        'method': interpolation_methods[kwargs['method']],
        'to_cellsize': kwargs['cellsize'],
        'factor_bounds': kwargs['factor_bounds'],
    }

    cal.interpolate(**interpolate_kwargs)
    if cal.result is None:
        log.warning('no result, exiting')
        return

    # save result to HDF5 file
    resultfile = kwargs['resultfile']
    cal.save(resultfile)
    def test_interpolate_ked_r_cellsize_1000_from_100(self):
        aggregatefile = r'24uur_20170223080000.h5'
        calibratefile = r'RAD_TF2400_U_20170223080000.h5'
        aggregatefile = os.path.join(testconfig.DATADIR, aggregatefile)
        calibratefile = os.path.join(testconfig.DATADIR, calibratefile)
        cal = Calibrator(
            aggregatefile=aggregatefile,
            calibratefile=calibratefile,
            areamaskfile=testconfig.AREAMASKFILE,
            )

        # resample to 100 x 100 cellsize
        cal.resample(to_cellsize=[100., 100.])

        # interpolate
        cal.interpolate(method=ked_r,
            to_cellsize=[1000., 1000.],
            )

        # resample back to 1000 x 1000 cellsize
        cal.resample(to_cellsize=[1000., 1000.])

        # save
        resultfile = os.path.join(testconfig.RESULTDIR,
            'ked_r_cellsize_1000_from_100_20170223080000.h5')
        cal.save(resultfile=resultfile)
        assert (cal.result is not None) and ('calibrate' in cal.result)
 def test_interpolate_ked_r_cellsize_2000(self):
     aggregatefile = r'24uur_20170223080000.h5'
     calibratefile = r'RAD_TF2400_U_20170223080000.h5'
     aggregatefile = os.path.join(testconfig.DATADIR, aggregatefile)
     calibratefile = os.path.join(testconfig.DATADIR, calibratefile)
     cal = Calibrator(
         aggregatefile=aggregatefile,
         calibratefile=calibratefile,
         )
     cal.interpolate(method=ked_r, to_cellsize=[2000., 2000.])
     resultfile = os.path.join(testconfig.RESULTDIR,
         'ked_r_cellsize_2000_20170223080000.h5')
     cal.save(resultfile=resultfile)
     assert (cal.result is not None) and ('calibrate' in cal.result)