how to calculate the area of Geohash? - geography

I known the area of geohash(precision is 5)is 10 square kilometres. But I want to know the area of geohash(precision is 4) and I dont't know how to calculate. I read the wiki about Geohash, but I still get confused.
https://en.wikipedia.org/wiki/Geohash

The following the approx area for the specified precision.
Geohash length Cell width Cell height
1 ≤ 5,000km × 5,000km
2 ≤ 1,250km × 625km
3 ≤ 156km × 156km
4 ≤ 39.1km × 19.5km
5 ≤ 4.89km × 4.89km
6 ≤ 1.22km × 0.61km
7 ≤ 153m × 153m
8 ≤ 38.2m × 19.1m
9 ≤ 4.77m × 4.77m
10 ≤ 1.19m × 0.596m
11 ≤ 149mm × 149mm
12 ≤ 37.2mm × 18.6mm
More info: https://www.movable-type.co.uk/scripts/geohash.html

Related

DimensionMismatch: mismatch in dimension

working on a longblock of code, the sum total of which is here. My issue comes in with this particular block:
# path_skaters is a string that gives the path to the csv file with the skaters information (see example file for suggested format)
path_skaters = "https://raw.githubusercontent.com/dscotthunter/Fantasy-Hockey-IP-Code/master/example_skaters.csv"
# path_goalies is a string that gives the path to the csv file with the goalies information (see example file for suggested format)
path_goalies = "https://raw.githubusercontent.com/dscotthunter/Fantasy-Hockey-IP-Code/673b0a5119ed746a8dc2347206d138c84407def1/example_goalies.csv"
goalies = DataFrame(CSV.File(HTTP.get(path_goalies).body, normalizenames=true, delim=","))
skaters = DataFrame(CSV.File(HTTP.get(path_skaters).body, normalizenames=true, delim=","))
the_lineup= formulation(skaters, goalies, hcat(zeros(Int, num_skaters + num_goalies), zeros(Int, num_skaters + num_goalies)), num_overlap, num_skaters, num_goalies, centers, wingers, defenders, num_teams, skaters_teams, goalie_opponents, team_lines, num_lines, P1_info)
the_lineup2 = formulation(skaters, goalies, hcat(the_lineup, zeros(Int, num_skaters + num_goalies)), num_overlap, num_skaters, num_goalies, centers, wingers, defenders, num_teams, skaters_teams, goalie_opponents, team_lines, num_lines, P1_info)
tracer = hcat(the_lineup, the_lineup2)
for i=1:(num_lineups-2)
try
thelineup=formulation(skaters, goalies, tracer, num_overlap, num_skaters, num_goalies, centers, wingers, defenders, num_teams, skaters_teams, goalie_opponents, team_lines, num_lines, P1_info)
tracer = hcat(tracer,thelineup)
catch
break
end
end
is producing this error:
DimensionMismatch: mismatch in dimension 1 (expected 1 got 190)
Stacktrace:
[1] _cs
# ./abstractarray.jl:1717 [inlined]
[2] _cshp
# ./abstractarray.jl:1713 [inlined]
[3] _cat_size_shape
# ./abstractarray.jl:1693 [inlined]
[4] cat_size_shape(dims::Tuple{Bool, Bool}, X::Nothing, tail::Vector{Int64})
# Base ./abstractarray.jl:1691
[5] _cat_t(::Val{2}, ::Type{Union{Nothing, Int64}}, ::Nothing, ::Vararg{Any})
# Base ./abstractarray.jl:1732
[6] _cat(::Val{2}, ::Nothing, ::Vararg{Any})
# Base ./abstractarray.jl:1728
[7] #cat#155
# ./abstractarray.jl:1916 [inlined]
[8] hcat
# ./abstractarray.jl:1878 [inlined]
[9] create_lineups(num_lineups::Int64, num_overlap::Int64, path_skaters::String, path_goalies::String, formulation::typeof(one_lineup_Type_4), path_to_output::String)
# Main ./In[20]:805
[10] top-level scope
# In[20]:874
[11] eval
# ./boot.jl:368 [inlined]
[12] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)
# Base ./loading.jl:1428
I'm reasonably sure this is because the players data frame and goalies = 190, but I can't figure out why that's a problem.
The error is saying that you cannot call tracer = hcat(tracer,thelineup):
julia> x = zeros(190);
julia> hcat(0, x)
ERROR: DimensionMismatch("mismatch in dimension 1 (expected 1 got 190)")
Stacktrace:
[...]
What are you trying to achieve? If you want to concatenate two vectors, you might want vcat instead. Or perhaps `pushfirst!.
help?> vcat
search: vcat hvcat VecOrMat DenseVecOrMat StridedVecOrMat AbstractVecOrMat VectorConstraint
vcat(A...)
Concatenate along dimension 1.
Examples
≡≡≡≡≡≡≡≡≡≡
julia> a = [1 2 3 4 5]
1×5 Matrix{Int64}:
1 2 3 4 5
julia> b = [6 7 8 9 10; 11 12 13 14 15]
2×5 Matrix{Int64}:
6 7 8 9 10
11 12 13 14 15
julia> vcat(a,b)
3×5 Matrix{Int64}:
1 2 3 4 5
6 7 8 9 10
11 12 13 14 15
julia> c = ([1 2 3], [4 5 6])
([1 2 3], [4 5 6])
julia> vcat(c...)
2×3 Matrix{Int64}:
1 2 3
4 5 6
help?> pushfirst!
search: pushfirst!
pushfirst!(collection, items...) -> collection
Insert one or more items at the beginning of collection.
Examples
≡≡≡≡≡≡≡≡≡≡
julia> pushfirst!([1, 2, 3, 4], 5, 6)
6-element Vector{Int64}:
5
6
1
2
3
4

Finding matching rows

Given two matrices A and B with the same number of columns I would like to know if there are any rows which are the same in A and B. In Dyalog APL I can use the function split like this:
(↓A) ∊ ↓B
Is there a way to calculate the same result without the split function?
What you've found is a design flaw in Membership ∊ in that it implies that the right argument is a set of scalars rather than looking at it as a collection of major cells. This precluded extension according to Leading axis theory. However, Index of ⍳ was extended thus, and so we can use the fact that it returns the index beyond the end of of the lookup array when a major cell isn't found:
⎕← A ← 4 2⍴2 7 1 8 2 8 1 8
2 7
1 8
2 8
1 8
⎕← B ← 5 2⍴1 6 1 8 0 3 3 9 8 9
1 6
1 8
0 3
3 9
8 9
(↓A) ∊ ↓B
0 1 0 1
Membership ← {(≢⍵) ≥ ⍵⍳⍺}
A Membership B
0 1 0 1
Try it online!
This can also be written tacitly as Membership ← ⊢∘≢ ≥ ⍳⍨.
Either way, note that avoiding the detour of nested arrays leads to significant speed gains:
A←?1000 4⍴10
B←?1000 4⍴10
]runtime -compare "(↓A) ∊ ↓B" "A Membership B"
(↓A) ∊ ↓B → 1.6E¯4 | 0% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
A Membership B → 8.9E¯6 | -95% ⎕⎕
Something like A⍳B would show not only membership but location of equal rows.

How to delete a selected element in a range construct in Julia?

From here I found that in a range construct one cannot find and replace its elements via array functions... How can be do it anyway?
Suppose I want to delete the elements 2,6,7,8,13,19 in range(1, step=1, stop=21). Or more generally, suppose a is a random array that contains numbers in the range [1,21] and one wants to delete these elementes in the given range.
You cannot delete from a range object, since that is immutable, but you can filter it:
julia> filter(x -> x ∉ [2,6,7,8,13,19], a)
15-element Array{Int64,1}:
1
3
4
5
9
10
11
12
14
15
16
17
18
20
21
However, if a is a "real" array, you can use filter! to operate in-place.
Another solution that if often convenient is to use InvertedIndices.jl package which exports Not and you can just use indexing:
julia> r = 1:21
1:21
julia> x = [2,6,7,8,13,19]
6-element Array{Int64,1}:
2
6
7
8
13
19
julia> r[Not(x)]
15-element Array{Int64,1}:
1
3
4
5
9
10
11
12
14
15
16
17
18
20
21

Summing depth data (consecutive rows) in R

How is it possible with to sum up consecutive depth data with R?
For instance:
a <- data.frame(label = as.factor(c("Air","Air","Air","Air","Air","Air","Wood","Wood","Wood","Wood","Wood","Air","Air","Air","Air","Stone","Stone","Stone","Stone","Air","Air","Air","Air","Air","Wood","Wood")),
depth = as.numeric(c(1,2,3,-1,4,5,4,5,4,6,8,9,8,9,10,9,10,11,10,11,12,10,12,13,14,14)))
The given output should be something like:
Label Depth
Air 7
Wood 3
Stone 1
First the removal of negative values is done with cummax(), because depth can only increase in this special case. Hence:
label depth
1 Air 1
2 Air 2
3 Air 3
4 Air 3
5 Air 4
6 Air 5
7 Wood 5
8 Wood 5
9 Wood 5
10 Wood 6
11 Wood 8
12 Air 9
13 Air 9
14 Air 9
15 Air 10
16 Stone 10
17 Stone 10
18 Stone 11
19 Stone 11
20 Air 11
21 Air 12
22 Air 12
23 Air 12
24 Air 13
25 Wood 14
26 Wood 14
Now by max-min the increase in depth for every consecutive row you would get: (the question is how to do this step)
label depth
1 Air 4
2 Wood 3
3 Air 1
4 Stone 1
5 Air 2
5 Wood 0
And finally summing up those max-min values the output is the one presented above.
Steps tried to achieve the output:
The first obvious solution would be for instance for Air:
diff(cummax(a[a$label=="Air",]$depth))
This solution gets rid of the negative data, which is necessary due to an expected constant increase in depth.
The problem is the output also takes into account the big steps in between each consecutive subset. Hence, the sum for Air would be 12 instead of 7.
[1] 1 1 0 1 1 4 0 0 1 1 1 0 0 1
Even worse would be a solution with aggreagte, e.g.:
aggregate(depth~label, a, FUN=function(x){sum(x>0)})
Note: solutions with filtering big jumps is not what i'm looking for. Sure you could hard code a limit for instance <2 for the example of Air once again:
sum(diff(cummax(a[a$label=="Air",]$depth))[diff(cummax(a[a$label=="Air",]$depth))<2])
Gives you almost the right result but does not work as it is expected here. I'm pretty sure there is already a function for what I'm looking for because it is not a uncommon problem for many different tasks.
I guess taking the minimum and maximum value of each set of consecutive rows per material and summing those up would be one possible solution, but I'm not sure how to apply a function to only the consecutive subsets.
You can use data.table::rleid to quickly group by run, or reconstruct it with rle if you really like. After that, aggregating is fairly easy in any grammar. In dplyr,
library(dplyr)
a <- data.frame(label = c("Air","Air","Air","Air","Air","Air","Wood","Wood","Wood","Wood","Wood","Air","Air","Air","Air","Stone","Stone","Stone","Stone","Air","Air","Air","Air","Air","Wood","Wood"),
depth = c(1,2,3,-1,4,5,4,5,4,6,8,9,8,9,10,9,10,11,10,11,12,10,12,13,14,14))
a2 <- a %>%
# filter to rows where previous value is lower, equal, or NA
filter(depth >= lag(depth) | is.na(lag(depth))) %>%
# group by label and its run
group_by(label, run = data.table::rleid(label)) %>%
summarise(depth = max(depth) - min(depth)) # aggregate
a2 %>% arrange(run) # sort to make it pretty
#> # A tibble: 6 x 3
#> # Groups: label [3]
#> label run depth
#> <fctr> <int> <dbl>
#> 1 Air 1 4
#> 2 Wood 2 3
#> 3 Air 3 1
#> 4 Stone 4 1
#> 5 Air 5 2
#> 6 Wood 6 0
a3 <- a2 %>% summarise(depth = sum(depth)) # a2 is still grouped, so aggregate more
a3
#> # A tibble: 3 x 2
#> label depth
#> <fctr> <dbl>
#> 1 Air 7
#> 2 Stone 1
#> 3 Wood 3
A base R method using aggregate is
aggregate(cbind(val=cummax(a$depth)),
list(label=a$label, ID=c(0, cumsum(diff(as.integer(a$label)) != 0))),
function(x) diff(range(x)))
The first argument to aggregate calculates the cumulative maximum as the OP does above for the input vector, the use of cbind provide for the final output of the calculated vector. The second argument is the grouping argument. This uses a different method than rle, which calculates the cumulative sum of the differences. Finally, the third argument provides the function which calculates the desired output by taking a difference of the range for each group.
This returns
label ID val
1 Air 0 4
2 Wood 1 3
3 Air 2 1
4 Stone 3 1
5 Air 4 2
6 Wood 5 0
The data.table way (borrowing in part from #alistaire):
setDT(a)
a[, depth := cummax(depth)]
depth_gain <- a[,
list(
depth = max(depth) - depth[1], # Only need the starting and max values
label = label[1]
),
by = rleidv(label)
]
result <- depth_gain[, list(depth = sum(depth)), by = label]

Woocommerce USPS

Just want to ask on how to add this in Woocommerce Shipping
see attached.
This is the dimension the box:
Small-FRB
ID: 5 3/8 x 8 5/8 x 1 5/8
OD: 8 11/16 x 5 7/16 x 1 3/4
ODCUFT: 0.044
What is the meaning of ID, OD, ODCUFT in USPS?
Thanks for the help

Resources