Skip to content

Conversation

@saket0187
Copy link
Contributor

This PR addresses #6968

I have tried to rewrite these files with Parson support. In the print_json.c file, I have added one extra function because I wanted the matrix to be printed like it was before:

              "matrix": [
                  [34931,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
                  [38146,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
                  [0,2137,0,0,0,0,0,0,0,0,0,0,0,0,0],
                  [0,0,25488,0,0,0,0,0,0,0,0,0,0,0,0],
                  [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
                  [0,0,30,0,0,0,0,0,0,0,0,0,0,0,0],
                  [0,0,0,16464,0,0,0,0,0,0,0,0,0,0,0],
                  [0,0,0,320,0,0,0,0,0,0,0,0,0,0,0],
                  [0,0,0,45,0,0,0,0,0,0,0,0,0,0,0],
                  [0,0,0,0,7893,0,0,0,0,0,0,0,0,0,0],
                  [0,0,0,0,19733,0,0,0,0,0,0,0,0,0,0],
                  [0,0,0,0,64774,0,0,0,0,0,0,0,0,0,0],
                  [0,0,0,0,33865,0,0,0,0,0,0,0,0,0,0],
                  [0,0,0,0,0,5303,0,0,0,0,0,0,0,0,0],
                  [0,0,0,0,0,0,194,0,0,0,0,0,0,0,0]
              ],

Because due to G_json_serialize_to_string_pretty, the matrix will look like this, which doesn’t feel right for a 2D matrix output to me, that’s why I have added it. If this is wrong, please do let me know.

                "matrix": [
                        [
                            34931,
                            0,
                            0,
                            0,
                            0,
                            0,
                            0,
                            0,
                            0,
                            0,
                            0,
                            0,
                            0,
                            0,
                            0
                        ],
                        [
                            38146,
                            0,
                            0,
                            0,
                            0,
                            0,
                            0,
                            0,
                            0,
                            0,
                            0,
                            0,
                            0,
                            0,
                            0
                        ],
                      

Other than that, it looks good to me. I have tested it. If there is a better way to implement this, then do let me know.

@nilason
Copy link
Contributor

nilason commented Jan 26, 2026

What would it look like without G_json_serialize_to_string_pretty?

@saket0187
Copy link
Contributor Author

What would it look like without G_json_serialize_to_string_pretty?

Sorry, I misread your comment last time. I haven’t tested without it yet. Will try tomorrow

@nilason
Copy link
Contributor

nilason commented Jan 26, 2026

I now see we have no wrapper function G_json_serialize_to_string for Parson's json_serialize_to_string in https://github.com/OSGeo/grass/blob/main/lib/external/parson/gjson.h and https://github.com/OSGeo/grass/blob/main/lib/external/parson/gjson.c.

Could you please try out what the output would be by calling G_json_serialize_to_string instead, by adding such a wrapper?
(A lot of relatively complex code for something no-one will read anyway.)

@saket0187
Copy link
Contributor Author

Sure, will do that.

@github-actions github-actions bot added raster Related to raster data processing C Related code is in C module CMake labels Jan 26, 2026
@petrasovaa petrasovaa linked an issue Jan 27, 2026 that may be closed by this pull request
@saket0187
Copy link
Contributor Author

@nilason This is what it looks like with G_json_serialize_to_string (I can make a separate PR for this)

{"reference":"landclass96","classification":"landuse96_28m","observations":249323,"correct":34931,"overall_accuracy":14.010340000721955,"kappa":0.094647985487459979,"kappa_variance":1.2427421149984878e-06,"cats":[1,2,3,4,5,6,7,8,9,10,11,15,18,20,21],"matrix":[[34931,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[38146,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,2137,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,25488,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,30,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,16464,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,320,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,45,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,7893,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,19733,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,64774,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,33865,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,5303,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,194,0,0,0,0,0,0,0,0]],"row_sum":[34931,38146,2137,25488,0,30,16464,320,45,7893,19733,64774,33865,5303,194],"col_sum":[73077,2137,25518,16829,126265,5303,194,0,0,0,0,0,0,0,0],"producers_accuracy":[47.800265473404771,0,0,0,0,0,0,null,null,null,null,null,null,null,null],"users_accuracy":[100,0,0,0,null,0,0,0,0,0,0,0,0,0,0],"conditional_kappa":[1,-0.0086453116276811789,-0.114018900382029,-0.072384663690245751,null,-0.021731825260224571,-0.00077871303621818416,0,0,0,0,0,0,0,0],"mcc":0.12180041392181627}

@nilason
Copy link
Contributor

nilason commented Jan 27, 2026

@nilason This is what it looks like with G_json_serialize_to_string

{"reference":"landclass96","classification":"landuse96_28m","observations":249323,"correct":34931,"overall_accuracy":14.010340000721955,"kappa":0.094647985487459979,"kappa_variance":1.2427421149984878e-06,"cats":[1,2,3,4,5,6,7,8,9,10,11,15,18,20,21],"matrix":[[34931,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[38146,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,2137,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,25488,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,30,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,16464,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,320,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,45,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,7893,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,19733,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,64774,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,33865,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,5303,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,194,0,0,0,0,0,0,0,0]],"row_sum":[34931,38146,2137,25488,0,30,16464,320,45,7893,19733,64774,33865,5303,194],"col_sum":[73077,2137,25518,16829,126265,5303,194,0,0,0,0,0,0,0,0],"producers_accuracy":[47.800265473404771,0,0,0,0,0,0,null,null,null,null,null,null,null,null],"users_accuracy":[100,0,0,0,null,0,0,0,0,0,0,0,0,0,0],"conditional_kappa":[1,-0.0086453116276811789,-0.114018900382029,-0.072384663690245751,null,-0.021731825260224571,-0.00077871303621818416,0,0,0,0,0,0,0,0],"mcc":0.12180041392181627}

I would prefer this to adding complicated formatting code. What do you say @petrasovaa ?

(I can make a separate PR for this)

Please, do. Sooner or later we will likely need it anyway, regardless of the outcome here.

@nilason nilason requested a review from petrasovaa January 28, 2026 08:57
@saket0187
Copy link
Contributor Author

@petrasovaa Can you review this one as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C Related code is in C CMake module raster Related to raster data processing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feat] Rewrite r.kappa JSON output to use parson library

2 participants