Opened 11 years ago

Closed 9 years ago

Last modified 9 years ago

#590 closed defect (invalid)

WCPS1.5_WCPS count operation and RasQL count_cells( )

Reported by: Piero Campalani Owned by: Alex Dumitru
Priority: major Milestone: 10.0
Component: petascope Version: development
Keywords: count count_cells Cc: Peter Baumann, Vlad Merticariu, Alex Dumitru
Complexity: Medium

Description

There is not a biunivocal relation between the WCPS count condenser and the RasQL count_cells operation.

Whereas the former applies (as any other reduceExpr like add, avg, etc.) to any coverage expression, the latter by definition counts the cells containing true, hence applies only to boolean expressions.

Indeed, when sending the following WCPS query:

for c in (eobstest) return encode(
  count(c[Lat(0), Long(51)])
, "csv")

..RasQL returns error:

Operand of count_cells must be of type r_Marray<d_Boolean>.

When a user wants to count the total number of cells in a nD coverage, a workaround is to force a boolean expression in the WCPS count that will always apply, e.g.:

for c in (eobstest) return encode(
  count(c[Lat(0), Long(51)] != -9999999999)
, "csv")

However, this makes WCPS more verbose (and less elegant). Counting cells is a fundamental operator, which is especially usefull when co-locating different coverages via scaling and coverage constructors.

Change History (12)

comment:1 by Dimitar Misev, 11 years ago

In the WCPS standard count is defined as

count(b) = 
condense + 
over p1 D1(imageCrsDomain(a,D1)), 
     ..., 
     pd Dd(imageCrsDomain(a,D1)) 
     where b[x] 
     using 1 

So it is indeed expecting a boolean coverage for evaluation (note the where clause) and the implementation is correct.

comment:2 by Piero Campalani, 11 years ago

The standard says that count(b) returns the Number of points in b.
Indeed that general condense operation is not expecting a boolean expression, as I see it.

b[x] is at worse cast to boolean, so that count(b) then would only count the cells which are not 0.

comment:3 by Dimitar Misev, 11 years ago

No there is no cast there as you can see, it is expecting an already boolean value. The where clause only accepts boolean and does not do an implicit cast if it isn't boolean.

comment:4 by Piero Campalani, 11 years ago

Cc: Peter Baumann added

Ok, it seems we need a little longer discussion, moving to the mailing-list (rasdaman-users, "WCPS count()").

comment:5 by Piero Campalani, 11 years ago

Cc: Vlad Merticariu Alex Dumitru added

comment:6 by Bang Pham Huu, 9 years ago

Cc: mantovani@… removed
Component: undecidedpetascope
Milestone: Future10.0
Owner: changed from Dimitar Misev to Alex Dumitru
Summary: WCPS count operation and RasQL count_cells( )WCPS1.5_WCPS count operation and RasQL count_cells( )

comment:7 by Bang Pham Huu, 9 years ago

from Piero's last comment in https://groups.google.com/forum/#!searchin/rasdaman-users/WCPS$20count/rasdaman-users/ZF-AVlj4MH8/1IIXQgNbvkIJ

this ticket can be fixed by casting (bool) the coverageExpression, e.g WCPS query:

for c in (eobstest) return encode(count(c[Lat(0), Long(51)]), "csv")

is translated to Rasql in WCPS1.5:

SELECT encode( count_cells(c[*:*,52,151]) , "csv" ) FROM eobstest AS c

and returns error

Execution error 415 in line 1, column 16, near token count_cells:
Operand of count_cells must be of type r_Marray<d_Boolean>.

then needs to cast the coverage too bool to make it work:

SELECT encode( count_cells((bool)c[*:*,52,151]) , "csv" ) FROM eobstest AS c

It will be fixed in WCPS 1.5.

comment:8 by Dimitar Misev, 9 years ago

I don't think that's correct Bang, to force cast in this case. You will get a different result from what Piero's idea in this ticket is (to simply return the number of cells, i.e.

(sdom(c)[0].hi - sdom(c)[0].lo + 1) * (sdom(c)[1].hi - sdom(c)[1].lo + 1) * ...

As I said, the current implementation seems in line with the standard to me, but I wouldn't want to close the ticket without getting more opinions first.

comment:9 by Peter Baumann, 9 years ago

let us not waste time on this - a change is not necessary as you always can write "count_cells(a!=0)". All the above proposal wants to introduce is a tweak, unless I am missing something.

comment:10 by Dimitar Misev, 9 years ago

Resolution: invalid
Status: newclosed

Ok I'm closing the ticket.

comment:11 by Piero Campalani, 9 years ago

Hey there :)
I'm not really comfortable about this resolution, I still believe that being able to count the elements of a (sub)coverage without needing to find a boolean condition which *in your case* is always true (if ever exists btw) is not viable at all !
Just saying, I see this as a valid ticket, with workaround available.
Imho

comment:12 by Dimitar Misev, 9 years ago

Piero, I agree with you, but I hope you'll also agree that introducing new functions outside of the WCPS standard is not a great idea. The correct way to compute this is

(sdom(c)[0].hi - sdom(c)[0].lo + 1) * (sdom(c)[1].hi - sdom(c)[1].lo + 1) * ...

But a shortcut function for this does not exist in WCPS at the moment.

Note: See TracTickets for help on using tickets.