How do I create a 10x10 grid for polygons<1 kilometer in turf.js? - turfjs

How do I create a 10x10 grid for polygons<1 kilometer in turf.js?
let gridOptions = {units: 'kilometers'};
let grid = turf.squareGrid([ 176.4218616, -37.8028137, 176.4288378, -37.7992033 ], 100, gridOptions);
This produces an empty result. I presume because the polygon is too small.

That's right: your area is less than 1sqkm:
const area_in_sqkm = turf.convertArea(
turf.area(
turf.bboxPolygon([176.4218616, -37.8028137, 176.4288378, -37.7992033])
),
'meters', 'kilometers'
)
// area_in_sqkm = 0.2466

The units are applied to the cellSide argument when calling squareGrid. In your example your cellSide value is 100 meaning a grid with cells of size 100kmĀ². Change this value to resize the cells:
let grid = turf.squareGrid(bbox, 0.1, { units: 'kilometers'})

Related

OpenCV Error using function matchTemplate

While using the matchTemplate function in OpenCV, I get the error that the template image is larger than the original image. How to overcome that?
The code is as follows:
def imagecheck(name1):
os.chdir('/content/drive/My Drive/Mad Street Den/Images')
main_image = cv2.imread('image_name_100.jpg')
gray_image = cv2.cvtColor(main_image, cv2.COLOR_BGR2GRAY)
#open the template as gray scale image
os.chdir('/content/drive/My Drive/Mad Street Den/Crops')
template = cv2.imread(name1, 0)
width, height = template.shape[::-1] #get the width and height
#match the template using cv2.matchTemplate
match = cv2.matchTemplate(gray_image, template, cv2.TM_CCOEFF_NORMED)
threshold = 0.9
position = np.where(match >= threshold) #get the location of template in the image
for point in zip(*position[::-1]): #draw the rectangle around the matched template
cv2.rectangle(main_image, point, (point[0] + width, point[1] + height), (0, 204, 153), 2)
#result=[position[1][0],position[0][0],position[0][1],position[0][2]]
result=[]
if (all (position)):
result.append(int(position[1]))
result.append(int(position[0]))
result.append(int(position[1]+width))
result.append(int(position[0]+height))
return (result)
#cv2_imshow(main_image)
for i in range(0,273):
name1='image_name_'+str(i)+'.jpg'
result=imagecheck(name1)
print(name1, ' : ',result)
The Error is
error: OpenCV(3.4.3) /io/opencv/modules/imgproc/src/templmatch.cpp:1107: error: (-215:Assertion failed) _img.size().height <= _templ.size().height && _img.size().width <= _templ.size().width in function 'matchTemplate' site:stackoverflow.com
You can avoid the issue by not attempting to match a template against an image if the template is larger. Compare the template dimensions to the image dimensions and, in this case, return [] if they template is larger in any dimension.

How to resize font in plot_net feature of phyloseq?

I want to resize my text in plot_net but none of the options are working for me. I am trying
p <- plot_net(physeqP, maxdist = 0.4, point_label = "ID", color = "Cond", shape = "Timeperiod") p + geom_text(size=15)
This gives me error
"Error: geom_text requires the following missing aesthetics: x, y,
label".
Can anyone please tell me how can I fix the issue?
I dont want to resize legends or the axis, but the nodes text.
this image is drawn using phyloseq but since the font size is very small, i want to make it prominent.
Without an example it's hard to reproduce.
p <- plot_net(physeqP, maxdist = 0.4, point_label = "ID"
, color = "Cond", shape = "Timeperiod", cex_val = 2)
I believe this is with the NeuralNetTools package.
Try using: cex_val numeric value indicating size of text labels, default 1
https://www.rdocumentation.org/packages/NeuralNetTools/versions/1.5.0/topics/plotnet

Cytoscape.js layout edge length

Hi I'm trying to build a web-crawler visualization tool for a school project. I decided to use Cytoscape.js and it's been really nice to use. The problem i'm having is the edge lengths for some of the layouts (circle, breadth first, concentric) seem too large and the graph looks odd.
When I first start the application, I manually make and load a graph(it's a tree) with 100 nodes and that looks good in Circle layout:
However after I perform a web-crawl the new graph( this one has 44 nodes) doesn't fit in the view for circle:
Is there a way to get this to work so that the edges are not so long and the nodes look larger?
Edit:
Here's the code I use to change the layout:
changeLayout = function(layoutName, title, root){
var numOfNodes = cy.filter('node').length;
//extent changes when I repeatedly change the layout to circle, (don't understand this behavior)
var extent = cy.extent();
var rect = document.getElementById("cy-container").getBoundingClientRect();
var x1 = rect.left;
var x2 = rect.right;
var y1 = rect.top;
var y2 = rect.bottom;
var height = (y2 - y1);
var width = (x2 - x1);
var fact = (height < width) ? (height/numOfNodes) : (width/numOfNodes);
fact *= 5;
var myRadius = height < width ? (height-fact) : (width-fact);
switch(layoutName){
case 'circle':
myLayout = cy.makeLayout(
{ name: layoutName,
radius: myRadius,
boundingBox: {x1: x1, x2: x2, y1: y1, y2: y2},
fit: true,
avoidOverlap: false
});
break;
case 'concentric':
myLayout = cy.makeLayout(
{ name: layoutName,
height: height,
width: width,
fit: false,
avoidOverlap: true
});
break;
case 'breadthfirst':
myLayout = cy.makeLayout(
{ name: layoutName,
boundingBox: {x1: x1, x2: x2, y1: y1, y2: y2},
fit: true,
roots: root,
avoidOverlap: false
});
break;
default :
myLayout = cy.makeLayout(
{
name: layoutName
});
}
myLayout.run();
$('#graphTitle').text(title + " Layout");
};
The length of an edge is a function of the positions of the nodes. The layout sets the positions, so you have to set the layout options to make the nodes closer together.
For force-directed (physics simulation) layouts, you adjust the forces. In other layouts, you can adjust spacing values or enforce a bounding box to affect how spread out the nodes are.

Setting a max axis value or range step for a Morris Bar Chart?

I was wondering if it is possible to set a max axis value (say, I want the highest point of my data to be the top end of the y-axis) on a bar chart? I see there are options for ymin and ymax on line charts but I can't seem to find any information about the bar charts.
Also, it would be helpful if anyone knew how to force the range between axis lanes to be a certain amount (say step up by 250 each line instead of the generated amount which in my case is too high for my liking).
Set a maximum value for the y axis
You can, indeed, set the ymax for bar charts also (even though this is not documented).
Morris.Bar({
element: 'bar-example',
data: [
{ y: '2006', a: 100, b: 90 },
{ y: '2007', a: 75, b: 65 },
{ y: '2008', a: 50, b: 40 },
{ y: '2009', a: 75, b: 65 },
{ y: '2010', a: 50, b: 40 },
{ y: '2011', a: 75, b: 65 },
{ y: '2012', a: 100, b: 90 }
],
xkey: 'y',
ymax: 300, // set this value according to your liking
ykeys: ['a', 'b'],
labels: ['Series A', 'Series B']
});
And have your y axis set to this maximum value:
Set a range value for the y axis
It seems that it's not possible to set a range value for the y axis. This value appears to be computed according to the values of the data passed to Morris.Bar.
Not documented, but you can set maximum y by applying ymax. You can manipulate the range by setting numLines (also not documented).
E.g.
var chart = new Morris.Bar({
...
ymin: 0,
ymax: 7,
numLines: 8,
...
});
The above defined chart will display values from 0 to 7 and display a grid line for each integer between 0 and 7 (therefore 8 as a parameter)
To change to ymax call this
chart.options["ymax"] = 300;
Where chart is your chart variable
I want the highest point of my data to be the top end of the y-axis
The documentation is very sparse and confusing but this is possible using the ymin variable which is only documented in the Lines & Area Charts. The default value for that variable seems to be auto 0 and changing it to just auto seems to produce the desired result as you can see below.
how to force the range between axis lanes to be a certain amount
This does not seem to be possible, natively. However, you can kind of hack the axis label with the following function. It will round the value to multiples of 250 BUT the grid lines won't be at the number shown. E.g. say a grid line is at 570. The function below will change the label to 500 but the line will still show at 570 mark.
yLabelFormat: function(d) {
return Math.round(d) - (Math.round(d) % 250);
},
As others have mentioned, you can set ymax to a value that you want your upper bound to be but since you want the highest data point to be the upper bound, set ymax to auto. You can also try changing numLines to different values for a better aesthetic.

how to draw the second curve based Y2axis while the first curve is based on YAxis?

I'm using ZedGraph.
I have 2 curves to draw, the first curve is based on the scale of YAxis, while the second one is based on the Y2Axis, the value in first curve is far bigger than the second value.
In my project, both curves are based on YAxis, which makes the graph ugly.
Does anyone has experience to draw second curve based on the Y2Axis?
Here is my code: (What should I change?)
PointPairList p1 = new PointPairList(),
p2 = new PointPairList();
//code to add data into p1 and p2
GraphPane gp = new GraphPane();
gp.AddCurve(p1, "", Color.Black);
gp.AddCurve(p2, "", Color.Blue);
gp.XAxis.Scale.Min = v1;
gp.Y2Axis.Scale.Max = v2;
gp.AxisChange();
gp.XAxis.Scale.IsUseTenPower = false;
gp.Y2Axis.Scale.IsUseTenPower=false;
Thank you.
If I want to set the Y2Axis share the same grid of Y1Axis, after:
LineItem curveY2 = gp.AddCurve(p2, "", Color.Blue);
...
curveY2 .IsY2Axis = true;
i.e., the grid is based on Y1Axis, then Y2Axis has the same grid but with different lable.
For example, Y1Axis is from 1 to 300, and have 7 rows, however Y2Axis has 1 to 20, I want the Y2Axis also have 7 rows (same as the Y1Axis), which function should I use?
LineItem curveY2 = gp.AddCurve(p2, "", Color.Blue);
...
curveY2 .IsY2Axis = true;
//If you have more than one axis on the related side, you have to assign the index of the axis
curveY2 .YAxisIndex = 0;