-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathEcoregionData.cs
More file actions
218 lines (183 loc) · 6.58 KB
/
Copy pathEcoregionData.cs
File metadata and controls
218 lines (183 loc) · 6.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
using Landis.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using Landis.Library.Climate;
using System.Net.NetworkInformation;
//using Landis.Extension.Succession.BiomassPnET;
namespace Landis.Library.DensityCohorts
{
/// <summary>
/// The information for a tree species (its index and parameters).
/// </summary>
public class EcoregionData : IEcoregionData
{
#region private variables
private Landis.Core.IEcoregion ecoregion;
private float _latitude;
#endregion
#region private static variables
private static bool wythers;
private static bool dtemp;
private static Dictionary<IEcoregion, IEcoregionData> AllEcoregions;
private static Landis.Library.Parameters.Ecoregions.AuxParm<float> latitude;
public static Landis.Library.Parameters.Ecoregions.AuxParm<double> GSO1;
public static Landis.Library.Parameters.Ecoregions.AuxParm<double> GSO2;
public static Landis.Library.Parameters.Ecoregions.AuxParm<double> GSO3;
public static Landis.Library.Parameters.Ecoregions.AuxParm<double> GSO4;
#endregion
#region accessors for private static variables
public static List<IEcoregionData> Ecoregions
{
get
{
return AllEcoregions.Values.ToList();
}
}
/// <summary>Returns the PnET Ecoregion for a given Landis Core Ecoregion</summary>
/// <param name="landisCoreEcoregion"></param>
public static IEcoregionData GetPnETEcoregion(IEcoregion landisCoreEcoregion)
{
return AllEcoregions[landisCoreEcoregion];
}
#endregion
#region accessors for private variables
public string Description
{
get
{
return ecoregion.Description;
}
}
public bool Active
{
get
{
return ecoregion.Active;
}
}
public ushort MapCode
{
get
{
return ecoregion.MapCode;
}
}
public int Index
{
get
{
return ecoregion.Index;
}
}
public string Name
{
get
{
return ecoregion.Name;
}
}
public float Latitude
{
get
{
return _latitude;
}
}
#endregion
public static ICore ModelCore;
public static List<string> ParameterNames
{
get
{
System.Type type = typeof(EcoregionData); // Get type pointer
List<string> names = type.GetProperties().Select(x => x.Name).ToList(); // Obtain all fields
names.Add("ClimateFileName");
return names;
}
}
public static void InitializeCore(ICore mCore)
{
ModelCore = mCore;
}
public static void Initialize()
{
latitude = (Landis.Library.Parameters.Ecoregions.AuxParm<float>)(Parameter<float>)GetParameter("Latitude", -90, 90);
AllEcoregions = new Dictionary<IEcoregion, IEcoregionData>();
foreach (IEcoregion ecoregion in ModelCore.Ecoregions)
{
AllEcoregions.Add(ecoregion, new EcoregionData(ecoregion));
}
}
public EcoregionData(Landis.Core.IEcoregion ecoregion)
{
this.ecoregion = ecoregion;
this._latitude = latitude[ecoregion];
}
public static void EcoregionDynamicChange(IDynamicEcoregionRecord[] TimestepData)
{
//if (DynamicEcoregions.EcoRegData.ContainsKey(year))
//{
GSO1 = new Landis.Library.Parameters.Ecoregions.AuxParm<double>(ModelCore.Ecoregions);
GSO2 = new Landis.Library.Parameters.Ecoregions.AuxParm<double>(ModelCore.Ecoregions);
GSO3 = new Landis.Library.Parameters.Ecoregions.AuxParm<double>(ModelCore.Ecoregions);
GSO4 = new Landis.Library.Parameters.Ecoregions.AuxParm<double>(ModelCore.Ecoregions);
//DynamicEcoregions.TimestepData = DynamicEcoregions.EcoRegData[year];
foreach (IEcoregion ecoregion in ModelCore.Ecoregions)
{
if (!ecoregion.Active)
continue;
if (TimestepData[ecoregion.Index] == null)
continue;
GSO1[ecoregion] = TimestepData[ecoregion.Index].GSO1;
GSO2[ecoregion] = TimestepData[ecoregion.Index].GSO2;
GSO3[ecoregion] = TimestepData[ecoregion.Index].GSO3;
GSO4[ecoregion] = TimestepData[ecoregion.Index].GSO4;
}
//}
}
public static bool TryGetParameter(string label, out Parameter<string> parameter)
{
parameter = null;
if (label == null)
{
return false;
}
if (Names.parameters.ContainsKey(label) == false) return false;
else
{
parameter = Names.parameters[label];
return true;
}
}
public static Parameter<string> GetParameter(string label)
{
if (Names.parameters.ContainsKey(label) == false)
{
throw new System.Exception("No value provided for parameter " + label);
}
return Names.parameters[label];
}
public static Parameter<string> GetParameter(string label, float min, float max)
{
if (Names.parameters.ContainsKey(label) == false)
{
throw new System.Exception("No value provided for parameter " + label);
}
Parameter<string> p = Names.parameters[label];
foreach (KeyValuePair<string, string> value in p)
{
float f;
if (float.TryParse(value.Value, out f) == false)
{
throw new System.Exception("Unable to parse value " + value.Value + " for parameter " + label + " unexpected format.");
}
if (f > max || f < min)
{
throw new System.Exception("Parameter value " + value.Value + " for parameter " + label + " is out of range. [" + min + "," + max + "]");
}
}
return p;
}
}
}