Skip to content

Commit

Permalink
add smoothValues() method and SpatialKernel class
Browse files Browse the repository at this point in the history
  • Loading branch information
bhaller committed Sep 10, 2023
1 parent 24a0f9e commit ca76d76
Show file tree
Hide file tree
Showing 15 changed files with 987 additions and 199 deletions.
20 changes: 10 additions & 10 deletions QtSLiM/QtSLiMTablesDrawer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -906,11 +906,11 @@ QVariant QtSLiMInteractionTypeTableModel::data(const QModelIndex &p_index, int r
{
switch (interactionType->if_type_)
{
case IFType::kFixed: return QVariant(QString("fixed"));
case IFType::kLinear: return QVariant(QString("linear"));
case IFType::kExponential: return QVariant(QString("exp"));
case IFType::kNormal: return QVariant(QString("normal"));
case IFType::kCauchy: return QVariant(QString("Cauchy"));
case SpatialKernelType::kFixed: return QVariant(QString("fixed"));
case SpatialKernelType::kLinear: return QVariant(QString("linear"));
case SpatialKernelType::kExponential: return QVariant(QString("exp"));
case SpatialKernelType::kNormal: return QVariant(QString("normal"));
case SpatialKernelType::kCauchy: return QVariant(QString("Cauchy"));
}
}
else if (p_index.column() == 3)
Expand All @@ -923,16 +923,16 @@ QVariant QtSLiMInteractionTypeTableModel::data(const QModelIndex &p_index, int r
// append second parameters where applicable
switch (interactionType->if_type_)
{
case IFType::kFixed:
case IFType::kLinear:
case SpatialKernelType::kFixed:
case SpatialKernelType::kLinear:
break;
case IFType::kExponential:
case SpatialKernelType::kExponential:
paramString += QString(", β=%1").arg(interactionType->if_param2_, 0, 'f', 3);
break;
case IFType::kNormal:
case SpatialKernelType::kNormal:
paramString += QString(", σ=%1").arg(interactionType->if_param2_, 0, 'f', 3);
break;
case IFType::kCauchy:
case SpatialKernelType::kCauchy:
paramString += QString(", γ=%1").arg(interactionType->if_param2_, 0, 'f', 3);
break;
}
Expand Down
12 changes: 8 additions & 4 deletions QtSLiM/help/SLiMHelpClasses.html
Original file line number Diff line number Diff line change
Expand Up @@ -701,10 +701,10 @@
<p class="p11"><i>5.14.2<span class="Apple-converted-space">  </span></i><span class="s1"><i>SpatialMap</i></span><i> methods</i></p>
<p class="p5">– (void)changeValues(numeric values)</p>
<p class="p6">Changes the grid values used for the target spatial map.<span class="Apple-converted-space">  </span>The <span class="s1">values</span> parameter should be a vector, matrix, or array of numeric values as described in the documentation for <span class="s1">defineSpatialMap()</span>.<span class="Apple-converted-space">  </span>Other characteristics of the spatial map, such as its color mapping (if defined), its spatial bounds, and its spatiality, will remain unchanged.<span class="Apple-converted-space">  </span>The grid resolution of the spatial map is allowed to change with this method.<span class="Apple-converted-space">  </span>This method is useful for changing the values of a spatial map over time, such as to implement changes to the landscape’s characteristics due to seasonality, climate change, processes such as fire or urbanization, and so forth.<span class="Apple-converted-space">  </span>As with the original map values provided to <span class="s1">defineSpatialMap()</span>, it is often useful to read map values from a PNG image file using the Eidos class <span class="s1">Image</span>.</p>
<p class="p5">– (void)interpolateValues(integer$ factor)</p>
<p class="p6">Increases the resolution of the spatial map by <span class="s1">factor</span>, changing the dimensions of the spatial map’s grid of values (while leaving its spatial bounds unchanged), by interpolating new values between the existing values.<span class="Apple-converted-space">  </span>The parameter <span class="s1">factor</span> must be an integer in [<span class="s1">2</span>, <span class="s1">100</span>].</p>
<p class="p6">For a 1D spatial map, <span class="s1">factor-1</span> new values will be inserted between every pair of values in the original value grid.<span class="Apple-converted-space">  </span>A <span class="s1">factor</span> of <span class="s1">2</span> would therefore insert one new value between each pair of existing values, thereby increasing the map’s resolution by a factor of two.<span class="Apple-converted-space">  </span>Note that if the spatial map’s original grid dimension was <i>N</i>, the new grid dimension with a <span class="s1">factor</span> of <i>k</i> would be <i>kN</i>1, not <i>kN</i>, because new values are inserted only <i>between</i> existing values.<span class="Apple-converted-space">  </span>For 2D and 3D spatial maps, essentially the same process is conducted along each axis of the map’s spatiality, increasing the resolution of the map by <span class="s1">factor</span> in every dimension.</p>
<p class="p6">Linear (or bilinear or trilinear) interpolation will be used to interpolate the values for the new grid points; this is done even if interpolation is not normally enabled for the spatial map (i.e., if the map’s <span class="s1">interpolate</span> property is <span class="s1">F</span>).</p>
<p class="p5">– (void)interpolateValues(integer$ factor, [string$ method = "linear"])</p>
<p class="p6">Increases the resolution of the spatial map by <span class="s1">factor</span>, changing the dimensions of the spatial map’s grid of values (while leaving its spatial bounds unchanged), by interpolating new values between the existing values.<span class="Apple-converted-space">  </span>The parameter <span class="s1">factor</span> must be an integer in [<span class="s1">2</span>, <span class="s1">201</span>], somewhat arbitrarily</p>
<p class="p6">For a 1D spatial map, <span class="s1">factor-1</span> new values will be inserted between every pair of values in the original value grid.<span class="Apple-converted-space">  </span>A <span class="s1">factor</span> of <span class="s1">2</span> would therefore insert one new value between each pair of existing values, thereby increasing the map’s resolution by a factor of two.<span class="Apple-converted-space">  </span>Note that if the spatial map’s original grid dimension was <i>N</i>, the new grid dimension with a <span class="s1">factor</span> of <i>k</i> would be <i>k</i>(<i>N</i>−1)+1, not <i>kN</i>, because new values are inserted only <i>between</i> existing values.<span class="Apple-converted-space">  </span>For 2D and 3D spatial maps, essentially the same process is conducted along each axis of the map’s spatiality, increasing the resolution of the map by <span class="s1">factor</span> in every dimension.</p>
<p class="p6">If <span class="s1">method</span> is <span class="s1">"linear"</span> (the default), linear (or bilinear or trilinear) interpolation will be used to interpolate the values for the new grid points.<span class="Apple-converted-space">  </span>Alternatively, if <span class="s1">method</span> is <span class="s1">"nearest"</span>, the nearest value in the old grid will be used for new grid points; with this method, it is recommended that <span class="s1">factor</span> be odd, not even, to avoid artifacts due to rounding of coordinates midway between the original grid positions.<span class="Apple-converted-space">  </span>Other interpolation methods may be added in future.<span class="Apple-converted-space">  </span>The choice of interpolation method used here is independent of the map’s <span class="s1">interpolate</span> property.</p>
<p class="p5">– (string)mapColor(numeric value)</p>
<p class="p6">Uses the spatial map’s color-translation machinery (as defined by the <span class="s1">valueRange</span> and <span class="s1">colors</span> parameters to <span class="s1">defineSpatialMap()</span>) to translate each element of <span class="s1">value</span> into a corresponding color string.<span class="Apple-converted-space">  </span>If the spatial map does not have color-translation capabilities, an error will result.<span class="Apple-converted-space">  </span>See the documentation for <span class="s1">defineSpatialMap()</span> for information regarding the details of color translation.<span class="Apple-converted-space">  </span>See the Eidos manual for further information on color strings.</p>
<p class="p5">– (object&lt;Image&gt;$)mapImage([Ni$ width = NULL], [Ni$ height = NULL], [logical$ centers = F], [logical$ color = T])</p>
Expand All @@ -715,6 +715,10 @@
<p class="p6">Uses the spatial map’s mapping machinery (as defined by the <span class="s1">gridSize</span>, <span class="s1">values</span>, and <span class="s1">interpolate</span> parameters to <span class="s1">defineSpatialMap()</span>) to translate the coordinates of <span class="s1">point</span> into a corresponding map value.<span class="Apple-converted-space">  </span>The parameter <span class="s1">map</span> may specify the map either as a <span class="s1">SpatialMap</span> object, or by its <span class="s1">string</span> name; in either case, the map must have been added to the subpopulation.<span class="Apple-converted-space">  </span>The length of <span class="s1">point</span> must be equal to the spatiality of the spatial map; in other words, for a spatial map with spatiality <span class="s1">"xz"</span>, <span class="s1">point</span> must be of length <span class="s1">2</span>, specifying the <i>x</i> and <i>z</i> coordinates of the point to be evaluated.<span class="Apple-converted-space">  </span>Interpolation will automatically be used if it was enabled for the spatial map.<span class="Apple-converted-space">  </span>Point coordinates are clamped into the range defined by the spatial boundaries, even if the spatial boundaries are periodic; use <span class="s1">pointPeriodic()</span> to wrap the point coordinates first if desired.<span class="Apple-converted-space">  </span>See the documentation for <span class="s1">defineSpatialMap()</span> for information regarding the details of value mapping.</p>
<p class="p6">Beginning in SLiM 3.3, <span class="s1">point</span> may contain more than one point to be looked up.<span class="Apple-converted-space">  </span>In this case, the length of <span class="s1">point</span> must be an exact multiple of the spatiality of the spatial map; for a spatial map with spatiality <span class="s1">"xz"</span>, for example, the length of <span class="s1">point</span> must be an exact multiple of <span class="s1">2</span>, and successive pairs of elements from point (elements <span class="s1">0</span> and <span class="s1">1</span>, then elements <span class="s1">2</span> and <span class="s1">3</span>, etc.) will be taken as the <i>x</i> and <i>z</i> coordinates of the points to be evaluated.<span class="Apple-converted-space">  </span>This allows <span class="s1">spatialMapValue()</span> to be used in a vectorized fashion.</p>
<p class="p6">The <span class="s1">spatialMapValue()</span> method of <span class="s1">Subpopulation</span> provides the same functionality as this method; it may be more convenient to use, for some usage cases, and it checks that the spatial map is actually added to the subpopulation in question, providing an additional consistency check.<span class="Apple-converted-space">  </span>However, either method may be used.</p>
<p class="p5">– (void)smoothValues(float$ maxDistance, string$ functionType, ...)</p>
<p class="p6">Smooths (or blurs, one could say) the values of the spatial map by convolution with a kernel.<span class="Apple-converted-space">  </span>The kernel is specified with a maximum distance <span class="s1">maxDistance</span> (beyond which the kernel cuts off to a value of zero), a kernel type <span class="s1">functionType</span> that should be <span class="s1">"f"</span>, <span class="s1">"l"</span>, <span class="s1">"e"</span>, <span class="s1">"n"</span>, or <span class="s1">"c"</span>, and additional parameters in the ellipsis that depend upon the kernel type and further specify its shape.<span class="Apple-converted-space">  </span>The kernel types and their additional parameters are exactly the same as for the <span class="s1">setInteractionType()</span> method of <span class="s1">InteractionType</span>; see the documentation of that method for details.</p>
<p class="p6">Distance metrics specified to this method, such as <span class="s1">maxDistance</span> and the additional kernel shape parameters, are measured in the distance scale of the spatial map – the same distance scale in which the spatial bounds of the map are specified.<span class="Apple-converted-space">  </span>The operation is performed upon the grid values of the spatial map; distances are internally translated into the scale of the value grid.</p>
<p class="p6">The density scale of the kernel is unimportant and will be normalized; for example, a kernel specified to have a maximum value of <span class="s1">1</span>, versus a kernel specified to have a maximum value of <span class="s1">10</span>, will produce the same effect.<span class="Apple-converted-space">  </span>This normalization prevents the kernel from increasing or decreasing the average spatial map value (apart from possible edge effects).</p>
<p class="p1"><b>5.15<span class="Apple-converted-space">  </span>Class Species</b></p>
<p class="p2"><i>5.15.1<span class="Apple-converted-space">  </span></i><span class="s1"><i>Species</i></span><i> properties</i></p>
<p class="p5">avatar =&gt; (string$)</p>
Expand Down
12 changes: 12 additions & 0 deletions SLiM.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,10 @@
985F3F0E24BA31D900E712E0 /* eidos_test_functions_statistics.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 985F3F0A24BA31D900E712E0 /* eidos_test_functions_statistics.cpp */; };
98606AEE1DED0DCD00821CFF /* mutation_run.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 98606AEC1DED0DCD00821CFF /* mutation_run.cpp */; };
98606AEF1DED0DCD00821CFF /* mutation_run.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 98606AEC1DED0DCD00821CFF /* mutation_run.cpp */; };
986070EA2AACECD600FD6143 /* spatial_kernel.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 986070E82AACECD600FD6143 /* spatial_kernel.cpp */; };
986070EB2AACECD600FD6143 /* spatial_kernel.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 986070E82AACECD600FD6143 /* spatial_kernel.cpp */; };
986070EC2AACECD600FD6143 /* spatial_kernel.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 986070E82AACECD600FD6143 /* spatial_kernel.cpp */; };
986070ED2AACECD600FD6143 /* spatial_kernel.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 986070E82AACECD600FD6143 /* spatial_kernel.cpp */; };
986926D41AA1337A0000E138 /* graph_submenu_H.pdf in Resources */ = {isa = PBXBuildFile; fileRef = 986926D21AA1337A0000E138 /* graph_submenu_H.pdf */; };
986926D51AA1337A0000E138 /* graph_submenu.pdf in Resources */ = {isa = PBXBuildFile; fileRef = 986926D31AA1337A0000E138 /* graph_submenu.pdf */; };
986926D91AA140550000E138 /* GraphView.mm in Sources */ = {isa = PBXBuildFile; fileRef = 986926D81AA140550000E138 /* GraphView.mm */; };
Expand Down Expand Up @@ -1612,6 +1616,8 @@
986021081A3BB504001BDCFE /* LICENSE */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = LICENSE; sourceTree = "<group>"; };
98606AEC1DED0DCD00821CFF /* mutation_run.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = mutation_run.cpp; sourceTree = "<group>"; };
98606AED1DED0DCD00821CFF /* mutation_run.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = mutation_run.h; sourceTree = "<group>"; };
986070E82AACECD600FD6143 /* spatial_kernel.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = spatial_kernel.cpp; sourceTree = "<group>"; };
986070E92AACECD600FD6143 /* spatial_kernel.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = spatial_kernel.h; sourceTree = "<group>"; };
986764A92089066A00E81B2E /* tables.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = tables.h; path = treerec/tskit/tables.h; sourceTree = "<group>"; };
986926D21AA1337A0000E138 /* graph_submenu_H.pdf */ = {isa = PBXFileReference; lastKnownFileType = image.pdf; path = graph_submenu_H.pdf; sourceTree = "<group>"; };
986926D31AA1337A0000E138 /* graph_submenu.pdf */ = {isa = PBXFileReference; lastKnownFileType = image.pdf; path = graph_submenu.pdf; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2186,6 +2192,8 @@
98E9A69A1A3CD542000AD4FC /* polymorphism.cpp */,
985D1D8A2808B84F00461CFA /* sparse_vector.h */,
985D1D892808B84F00461CFA /* sparse_vector.cpp */,
986070E92AACECD600FD6143 /* spatial_kernel.h */,
986070E82AACECD600FD6143 /* spatial_kernel.cpp */,
98DB3D6E1E6122AE00E2C200 /* interaction_type.h */,
98DB3D6D1E6122AE00E2C200 /* interaction_type.cpp */,
98DEB47D2AA632AA00ABE60F /* spatial_map.h */,
Expand Down Expand Up @@ -3466,6 +3474,7 @@
981DC36C28E26F8B000ABE91 /* eidos_functions_other.cpp in Sources */,
98332AC21FDBA53F00274FF0 /* xerbla.c in Sources */,
985724D51AD481070047C223 /* eidos_test.cpp in Sources */,
986070EA2AACECD600FD6143 /* spatial_kernel.cpp in Sources */,
98332AB41FDBA1E100274FF0 /* blas.c in Sources */,
9809DFA02550F32500C4E82D /* log_file.cpp in Sources */,
989A5BE92525304100E7192D /* eidos_class_Dictionary.cpp in Sources */,
Expand Down Expand Up @@ -3779,6 +3788,7 @@
98CF5251294A3FC900557BBA /* eidos_class_Dictionary.cpp in Sources */,
98CF5252294A3FC900557BBA /* elementary.c in Sources */,
98CF5253294A3FC900557BBA /* SLiMHaplotypeManager.mm in Sources */,
986070EC2AACECD600FD6143 /* spatial_kernel.cpp in Sources */,
98CF5254294A3FC900557BBA /* GraphView_FitnessOverTime.mm in Sources */,
98CF5255294A3FC900557BBA /* SLiMWindowController.mm in Sources */,
98CF5256294A3FC900557BBA /* PopulationView.mm in Sources */,
Expand Down Expand Up @@ -4087,6 +4097,7 @@
989A5BEA2525304100E7192D /* eidos_class_Dictionary.cpp in Sources */,
98C821561C7A983700548839 /* elementary.c in Sources */,
98B40DFA1FB2DA8C0046F695 /* SLiMHaplotypeManager.mm in Sources */,
986070EB2AACECD600FD6143 /* spatial_kernel.cpp in Sources */,
986926E81AA40AFF0000E138 /* GraphView_FitnessOverTime.mm in Sources */,
98D4C2041A701D5A00FFB083 /* SLiMWindowController.mm in Sources */,
98D4C2071A704EA700FFB083 /* PopulationView.mm in Sources */,
Expand Down Expand Up @@ -4367,6 +4378,7 @@
98D7ECE228CE58FC00DEAAC4 /* eidos_token.cpp in Sources */,
98D7ECE328CE58FC00DEAAC4 /* core.c in Sources */,
98D7ECE428CE58FC00DEAAC4 /* minmax.c in Sources */,
986070ED2AACECD600FD6143 /* spatial_kernel.cpp in Sources */,
98D7ECE528CE58FC00DEAAC4 /* trees.c in Sources */,
98D7ECE628CE58FC00DEAAC4 /* xerbla.c in Sources */,
98D7ECE728CE58FC00DEAAC4 /* eidos_test.cpp in Sources */,
Expand Down
Loading

0 comments on commit ca76d76

Please sign in to comment.