예제 #1
0
    def runmodel(self, verbose=False):
        """
        Runs the model and saves the results
        """
        solver = cmf.CVodeIntegrator(self.project, 1e-9)
        c = self.project[0]

        # result timeseries
        res_q = cmf.timeseries(self.begin, cmf.day)

        tstart = datetime.datetime.now()
        # start solver and calculate in daily steps
        for t in solver.run(self.data.begin, self.end, cmf.day):
            if t > self.begin:
                # append results, when spin up time is over
                res_q.add(self.outlet.waterbalance(t))
            # Give the status the screen to let us know what is going on
            if verbose:
                print(t, 'P={:5.3f}'.format(c.get_rainfall(t)))
            if datetime.datetime.now() - tstart > datetime.timedelta(minutes=self.max_run_minutes):
                print('Cancelled, since it took more than {} minutes'.format(self.max_run_minutes))
                for t in cmf.timerange(solver.t, self.end, cmf.day):
                    res_q.add(np.nan)

        return res_q
예제 #2
0
    def make_result_table(self, for_time):
        """
        Creates a xarray.Dataset to store the results
        :param for_time: duration of model run

        :return:
        """
        time = [
            t.AsPython()
            for t in cmf.timerange(cmf.AsCMFtime(self.starttime),
                                   cmf.AsCMFtime(self.starttime +
                                                 for_time), self.dt)
        ]
        depth = self.depth
        layer_template = np.zeros((len(time), len(depth))) * np.NaN
        ds = xr.Dataset(
            {
                'N': (('time', 'depth'), layer_template.copy()),
                'Corg': (('time', 'depth'), layer_template.copy()),
                'DOC': (('time', 'depth'), layer_template.copy()),
                'Temp': (('time', 'depth'), layer_template.copy()),
                'wetness': (('time', 'depth'), layer_template.copy()),
            }, {
                'time': time,
                'depth': list(depth)
            })
        return ds