예제 #1
0
    def _print_soil_from_ui(self):
        """Print the 'custom soil data' (if entered) to a csv."""
        Cy0 = self.ui.Cy0Input.value()
        clay = self.ui.clayInput.value()
        data = np.array([Cy0, clay])

        filepath = os.path.join(cfg.INP_DIR, 'soil.csv')
        io_.print_csv(filepath, data, col_names=['Cy0', 'clay'])

        return filepath    
예제 #2
0
    def save_(self, file='climate.csv'):
        """Save climate data to a csv file.
        Default path is in cfg.OUT_DIR with filename 'climate.csv'.
        
        Args:
            file: name or path to csv file. If only name is given, file
                  is put in cfg.INP_DIR.

        """
        io_.print_csv(file,
                      np.transpose(self.clim),
                      col_names=['temp', 'rain', 'evap'])
예제 #3
0
    def save_(self, file='soil_params.csv'):
        """Save soil params to a csv file. Default path is in OUT_DIR
        with filename soil_params.csv

        Args:
            file: name or path to csv file. If path is not given
                  (only name), put in OUT_DIR for this program run.

        """
        data = np.array([self.Cy0, self.clay, self.Ceq, self.iom, self.depth])
        cols = ['Cy0', 'clay', 'Ceq', 'iom', 'depth']
        io_.print_csv(file, data, col_names=cols)
예제 #4
0
    def _print_climate_from_ui(self):
        """
        Print the climate data in the ui table to csv
        (called if 'custom climate data' was selected)
        """
        cols = self.ui.climateTable.columnCount()
        rows = self.ui.climateTable.rowCount()

        clim = []
        for c in range(cols):
            clim.append([])
            for r in range(rows):
                item = self.ui.climateTable.item(r, c)
                try:
                    item = float(item.text())
                except AttributeError:  # field is empty
                    log.warning(
                            "Empty field in climate table - was set to 0")
                    item = 0
                except ValueError:  # non-numeric field
                    log.exception(
                            "Non-numeric value in climate table - set to nan")
                    item = np.nan

                clim[c].append(item)

        clim = np.array(clim)

        if self.ui.openPanEvapCheck.isChecked():
            evap = True
        elif self.ui.evapotransCheck.isChecked():
            clim[2] /= 0.75     # convert to evap
        else:
            log.error("ONE OF EVAP/PET not selected")
            sys.exit(2)

        # Save climate to csv in INP_DIR then init climate object from that
        filepath = os.path.join(cfg.INP_DIR, 'climate.csv')
        io_.print_csv(
                filepath,
                 np.transpose(clim),
                col_names=['temp', 'rain', 'evap'],

        )
        return filepath
예제 #5
0
    def save_(emit_base, emit_proj=None, file='emissions.csv'):
        """Save emission data to csv file. Default path is OUT_DIR.

        Args:
            emit_base: Emission object to print.
                       If two emissions are being compared (base and proj),
                       this should be the baseline object.
            emit_proj: Second emission object to be compared - difference
                        is emit_proj - emit_base, so ensure correct order
            file: filename or path to csv file
            printTotal: print total of each column
                        **currently only works if emit_proj not given**

        """
        if emit_proj is None:
            data = emit_base.emissions  # just one emission vector to save
            cols = ['emissions']
        else:
            data = np.column_stack((emit_base.emissions, emit_proj.emissions,
                                    emit_proj.emissions - emit_base.emissions))
            cols = ['difference', 'baseline', 'project']

        io_.print_csv(file, data, col_names=cols, print_column=True)
예제 #6
0
    def save_(self, file='tree_params.csv'):
        """Save tree params to a csv. 
        Default path is in OUT_DIR with filename 'tree_params.csv'

        Args:
            file: name or path to csv file

        """
        # index is 0 if not in the SPP_LIST
        if self.species in SPP_LIST:
            index = SPP_LIST.index(self.species) + 1
        else:
            index = 0

        data = [
            index, self.species, self.nitrogen[0], self.nitrogen[1],
            self.nitrogen[2], self.nitrogen[3], self.nitrogen[4], self.carbon,
            self.rootToShoot, self.dens
        ]
        cols = [
            'Sc', 'Name', 'N_leaf', 'N_branch', 'N_stem', 'N_croot', 'N_froot',
            'C', 'rw', 'dens'
        ]
        io_.print_csv(file, data, col_names=cols)
예제 #7
0
    def save_(self, file='crop_params.csv'):
        """Save crop params in a csv. 
        Default path is in OUT_DIR with filename 'crop_params.csv'

        Args:
            file: name or path to csv file

        """
        # Index is 0 if not in the SPP_LIST
        if self.species in SPP_LIST:
            index = SPP_LIST.index(self.species) + 1
        else:
            index = 0

        data = [
            index, self.species, self.slope, self.intercept,
            self.nitrogenBelow, self.nitrogenAbove, self.carbonBelow,
            self.carbonAbove, self.rootToShoot
        ]
        cols = [
            'Sc', 'Name', 'a', 'b', 'crop_bgn', 'crop_agn', 'crop_bgc',
            'crop_agc', 'crop_rs'
        ]
        io_.print_csv(file, data, col_names=cols)