예제 #1
0
        public static void InitializeClimData(IInputParameters _parameters)
        {
            parameters = _parameters;

            ReadContent();


            SetFileProps();

            Data = new DateVar <CClimDay>("ClimateData", FirstYearOnFile, LastYearOnFile);

            for (int Year = FirstYearOnFile; Year < LastYearOnFile; Year++)
            {
                for (int Month = 1; Month <= 12; Month++)
                {
                    string   line  = GetLine(Year, Month);
                    string[] terms = line.Split(delim);
                    if (terms.Count() != ColumnCount)
                    {
                        throw new System.Exception("Unexpected number of columns in " + parameters.climateFileName + " (year,month) " + Year + " " + Month);
                    }
                    DateTime CurrentDate = new DateTime(Year, Month, 15);

                    float TMax = float.Parse(terms[TMaxCol]);
                    float TMin = float.Parse(terms[TMinCol]);
                    float CO2  = float.Parse(terms[CO2Col]);
                    float PAR0 = float.Parse(terms[PAR0col]);
                    float Prec = float.Parse(terms[Preccol]);

                    if (TMax < TMin)
                    {
                        throw new System.Exception("Recheck climate data in " + parameters.climateFileName + " Tmax < Tmin on " + CurrentDate);
                    }
                    else if (Prec < 0)
                    {
                        throw new System.Exception("Recheck climate data in " + parameters.climateFileName + " Prec = " + Prec + "\t" + CurrentDate);
                    }

                    Data[CurrentDate] = new CClimDay(parameters.Latitude, CurrentDate, PAR0, TMin, TMax, Prec, CO2);
                }
            }
        }
예제 #2
0
        public static void Initialize(IInputParameters Parameters)
        {
            PlugIn.ModelCore.UI.WriteLine("   Reading climate date from " + Parameters.climateFileName);

            climateFileName = Parameters.climateFileName;
            SetDelimitor();
            string[] Content = ReadContent();
            SetFirstAndLastYearOnFile(Content);

            firstpossibleestmonth = new DateVar <int>("firstpossibleestmonth", FirstYearOnFile, LastYearOnFile);
            lastpossibleestmonth  = new DateVar <int>("lastpossibleestmonth", FirstYearOnFile, LastYearOnFile);
            possibleestmonth      = new DateVar <bool>("PossibleEstmonth", FirstYearOnFile, LastYearOnFile);
            tmax           = new DateVar <float>("tmax", FirstYearOnFile, LastYearOnFile);
            tmin           = new DateVar <float>("tmin", FirstYearOnFile, LastYearOnFile);
            co2            = new DateVar <float>("co2", FirstYearOnFile, LastYearOnFile);
            tday           = new DateVar <float>("tday", FirstYearOnFile, LastYearOnFile);
            par0           = new DateVar <float>("par0", FirstYearOnFile, LastYearOnFile);
            tave           = new DateVar <float>("tave", FirstYearOnFile, LastYearOnFile);
            prec           = new DateVar <float>("prec", FirstYearOnFile, LastYearOnFile);
            vpd            = new DateVar <float>("vpd", FirstYearOnFile, LastYearOnFile);
            dayspan        = new DateVar <int>("dayspan", FirstYearOnFile, LastYearOnFile);
            treesareactive = new DateVar <bool>("treesareactive", FirstYearOnFile, LastYearOnFile);


            SetClimateFileHeaders(Content[0]);

            FolNCon         = Parameters.FolNCon;
            BaseFolRespFrac = Parameters.BaseFolRespFrac;
            DVPD1           = Parameters.DVPD1;
            DVPD2           = Parameters.DVPD2;
            AmaxA           = Parameters.AmaxA;
            AmaxB           = Parameters.AmaxB;
            WUEConst        = Parameters.WUEConst;

            RespQ10 = Parameters.RespQ10;
            PsnTOpt = Parameters.PsnTOpt;
            PsnTMin = Parameters.PsnTMin;


            firstactivemonthspc = new DateVar <Landis.Library.Biomass.Species.AuxParm <int> >("wettestmonth", FirstYearOnFile, LastYearOnFile);
            wettestmonth        = new DateVar <int>("wettestmonth", FirstYearOnFile, LastYearOnFile);
            dtemppsn            = new DateVar <Library.Biomass.Species.AuxParm <float> >("dtemppsn", FirstYearOnFile, LastYearOnFile);
            wue            = new DateVar <Library.Biomass.Species.AuxParm <float> >("wue", FirstYearOnFile, LastYearOnFile);
            delamax        = new DateVar <Library.Biomass.Species.AuxParm <float> >("delamax", FirstYearOnFile, LastYearOnFile);
            refnetpsn      = new DateVar <Library.Biomass.Species.AuxParm <float> >("refnetpsn", FirstYearOnFile, LastYearOnFile);
            refresp        = new DateVar <Library.Biomass.Species.AuxParm <float> >("refresp", FirstYearOnFile, LastYearOnFile);
            dTempResp      = new DateVar <Library.Biomass.Species.AuxParm <float> >("dTempResp", FirstYearOnFile, LastYearOnFile);
            dTempRespDay   = new DateVar <Library.Biomass.Species.AuxParm <float> >("dTempRespDay", FirstYearOnFile, LastYearOnFile);
            dTempRespNight = new DateVar <Library.Biomass.Species.AuxParm <float> >("dTempRespNight", FirstYearOnFile, LastYearOnFile);
            wue_co2_corr   = new DateVar <Library.Biomass.Species.AuxParm <float> >("wue_co2_corr", FirstYearOnFile, LastYearOnFile);
            dvpd           = new DateVar <Library.Biomass.Species.AuxParm <float> >("dvpd", FirstYearOnFile, LastYearOnFile);
            resp_folbase   = new DateVar <Library.Biomass.Species.AuxParm <float> >("resp_folbase", FirstYearOnFile, LastYearOnFile);
            isactive       = new DateVar <Library.Biomass.Species.AuxParm <bool> >("IsActive", FirstYearOnFile, LastYearOnFile);
            gdd            = new DateVar <Library.Biomass.Species.AuxParm <float> >("gdd", FirstYearOnFile, LastYearOnFile);

            DateTime date = new DateTime(FirstYearOnFile, 1, 15);

            while (date.CompareTo(new DateTime(LastYearOnFile, 12, 15)) <= 0)
            {
                // GetLine checks if year/month according to the loop is equal to the date read in
                string[] terms = GetLine(date.Year, date.Month, Content).Split(delim);
                if (terms.Count() != ColumnCount)
                {
                    throw new System.Exception("Unexpected number of columns in " + Parameters.climateFileName + " date = " + date);
                }

                if (int.Parse(terms[0]) != date.Year || int.Parse(terms[1]) != date.Month)
                {
                    throw new System.Exception("Missing month " + date + " in climate file");
                }
                try
                {
                    tmax[date] = CheckInputValue(float.Parse(terms[TMaxCol]), -80, 80, "date = " + date);
                    tmin[date] = CheckInputValue(float.Parse(terms[TMinCol]), -80, tmax[date], "date = " + date);
                    co2[date]  = CheckInputValue(float.Parse(terms[CO2Col]), 0, float.MaxValue, "date = " + date);
                    par0[date] = CheckInputValue(float.Parse(terms[PAR0col]), 0, float.MaxValue, "date = " + date);
                    prec[date] = CheckInputValue(float.Parse(terms[Preccol]), 0, float.MaxValue, "date = " + date);
                    if (prec[date] < 0)
                    {
                        throw new System.Exception("Precipitation = " + prec + "\t" + date);
                    }

                    float hr          = Calculate_hr(date.DayOfYear, Parameters.Latitude);
                    float daylength   = Calculate_DayLength(hr);
                    float nightlength = Calculate_NightLength(hr);
                    dayspan[date] = Calculate_DaySpan(date.Month);
                    tave[date]    = (float)0.5 * (tmin[date] + tmax[date]);
                    tday[date]    = (float)0.5 * (tmax[date] + tave[date]);
                    vpd[date]     = Calculate_VPD(Tday[date], TMin[date]);

                    gdd[date]            = new Library.Biomass.Species.AuxParm <float>(PlugIn.ModelCore.Species);
                    isactive[date]       = new Library.Biomass.Species.AuxParm <bool>(PlugIn.ModelCore.Species);
                    dtemppsn [date]      = new Library.Biomass.Species.AuxParm <float>(PlugIn.ModelCore.Species);
                    wue[date]            = new Library.Biomass.Species.AuxParm <float>(PlugIn.ModelCore.Species);
                    delamax[date]        = new Library.Biomass.Species.AuxParm <float>(PlugIn.ModelCore.Species);
                    refnetpsn[date]      = new Library.Biomass.Species.AuxParm <float>(PlugIn.ModelCore.Species);
                    refresp[date]        = new Library.Biomass.Species.AuxParm <float>(PlugIn.ModelCore.Species);
                    dTempResp [date]     = new Library.Biomass.Species.AuxParm <float>(PlugIn.ModelCore.Species);
                    dTempRespDay[date]   = new Library.Biomass.Species.AuxParm <float>(PlugIn.ModelCore.Species);
                    dTempRespNight[date] = new Library.Biomass.Species.AuxParm <float>(PlugIn.ModelCore.Species);
                    wue_co2_corr[date]   = new Library.Biomass.Species.AuxParm <float>(PlugIn.ModelCore.Species);
                    resp_folbase[date]   = new Library.Biomass.Species.AuxParm <float>(PlugIn.ModelCore.Species);
                    gdd[date]            = new Library.Biomass.Species.AuxParm <float>(PlugIn.ModelCore.Species);
                    dvpd[date]           = new Library.Biomass.Species.AuxParm <float>(PlugIn.ModelCore.Species);

                    foreach (ISpecies spc in PlugIn.ModelCore.Species)
                    {
                        float dGDD = Math.Max(0, (Tave[date] - PsnTMin[spc]) * DaySpan[date]);
                        if (date.Month == 1)
                        {
                            gdd[date][spc] = dGDD;
                        }
                        else
                        {
                            DateTime last_month = new DateTime(date.Year, date.Month - 1, 15);
                            gdd[date][spc] = gdd[last_month][spc] + dGDD;
                        }

                        if (tday[date] < PsnTMin[spc])
                        {
                            IsActive[date][spc] = false;
                        }
                        else
                        {
                            IsActive[date][spc]  = true;
                            treesareactive[date] = true;
                        }


                        //dtemppsn[date][spc] = ParabolicPsnTempResponse(tday[date], PsnTOpt[spc], PsnTMin[spc]);
                        dtemppsn[date][spc] = LinearPsnTempResponse(tday[date], PsnTOpt[spc], PsnTMin[spc]);


                        dvpd[date][spc] = Math.Max(0, 1 - DVPD1[spc] * (float)Math.Pow(vpd[date], DVPD2[spc]));

                        float cicaRatio = (-0.075f * FolNCon[spc]) + 0.875f;
                        float ci350     = 350 * cicaRatio;
                        float Arel350   = 1.22f * ((ci350 - 68) / (ci350 + 136));

                        float ciElev   = co2[date] * cicaRatio;
                        float ArelElev = 1.22f * ((ciElev - 68) / (ciElev + 136));
                        DelAmax[date][spc] = 1 + ((ArelElev - Arel350) / Arel350);


                        // CO2 effect on photosynthesis
                        // Calculate CO2 effect on conductance and set slope and intercept for A-gs relationship
                        float Delgs = DelAmax[date][spc] / ((co2[date] - co2[date] * cicaRatio) / (350.0f - ci350));

                        wue[date][spc] = (WUEConst[spc] / vpd[date]) * (1 + 1 - Delgs);    //DWUE determined from CO2 effects on conductance

                        wue_co2_corr[date][spc] = wue[date][spc] / DelAmax[date][spc];

                        /*
                         * wue_co2_corr[spc] = WUEConst[spc];
                         * Delgs = DelAmax / ((site.CaMo[mo] - CiElev) / (350.0 - Ci350));
                         * DWUE = 1.0 + (1 - Delgs);
                         * gsSlope = (-1.1309 * DelAmax) + 1.9762;   // used to determine ozone uptake
                         * gsInt = (0.4656 * DelAmax) - 0.9701;
                         */

                        // NETPSN
                        float amax = DelAmax[date][spc] * (AmaxA[spc] + AmaxB[spc] * FolNCon[spc]);

                        //Reference net Psn (lab conditions)
                        RefNetPsn[date][spc] = Static.DaySpan[date] * (amax * dvpd[date][spc] * daylength * Constants.MC) / Constants.billion;

                        dTempRespDay[date][spc]   = ((float)Math.Pow(RespQ10[spc], (Tday[date] - PsnTOpt[spc]) / 10));
                        dTempRespNight[date][spc] = ((float)Math.Pow(RespQ10[spc], (TMin[date] - PsnTOpt[spc]) / 10));

                        dTempResp[date][spc] = (float)Math.Min(1.0, (dTempRespDay[date][spc] * daylength + dTempRespNight[date][spc] * nightlength) / ((float)daylength + (float)nightlength));

                        //  gC/day
                        RefResp[date][spc] = BaseFolRespFrac[spc] * Static.DaySpan[date] * (amax * daylength * Constants.MC) / Constants.billion;
                    }
                    date = date.AddMonths(1);
                }
                catch
                {
                    throw new System.Exception("Cannot find climate date for (year,month) " + date.Year.ToString() + " " + date.Month.ToString());
                }
            }


            while (date.CompareTo(new DateTime(LastYearOnFile, 12, 15)) < 0)
            {
                if (Parameters.EstMoistureSensitivity != null)
                {
                    wettestmonth[date] = GetWettestMonth(date, 10);
                }
                if (Parameters.EstRadSensitivity != null)
                {
                    firstactivemonthspc[date] = GetFirstActiveMonth(date, 10);
                }

                foreach (ISpecies spc in PlugIn.ModelCore.Species)
                {
                    int Firstpossibleestmonth = Math.Min(wettestmonth[date] - 1, firstactivemonthspc[date][spc]);
                    int Lastpossibleestmonth  = Math.Max(wettestmonth[date] + 1, firstactivemonthspc[date][spc] + 3);

                    if (date.Month >= Firstpossibleestmonth && date.Month <= Lastpossibleestmonth)
                    {
                        possibleestmonth[date] = true;
                    }
                }



                date = date.AddMonths(1);
            }
        }