Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feat] Add JSON output to r.describe #4903

Open
NishantBansal2003 opened this issue Jan 1, 2025 · 3 comments · May be fixed by #4918
Open

[Feat] Add JSON output to r.describe #4903

NishantBansal2003 opened this issue Jan 1, 2025 · 3 comments · May be fixed by #4918
Labels
enhancement New feature or request

Comments

@NishantBansal2003
Copy link
Contributor

Add JSON output for easy parsing of r.describe output.

Describe the solution you'd like
Add an option for format, such as format=plain for the current output format and format=json for the JSON output.

A possible JSON layout could be:

[
  {
    "values": "0.996534-8.677654"
  },
  {
    "values": "8.677654-16.358774"
  },
  {
    "values": "16.358774-24.040000"
  }
]

Describe alternatives you've considered
Alternatively(helpful for numerical operations or parsing), the JSON layout could look like this:

[
  {
    "min": "0.996534",
    "max": "8.677654"
  },
  {
    "min": "8.677654",
    "max": "16.358774"
  },
  {
    "min": "16.358774",
    "max": "24.040000"
  }
]
@NishantBansal2003 NishantBansal2003 added the enhancement New feature or request label Jan 1, 2025
@NishantBansal2003
Copy link
Contributor Author

Hey @echoix, I was trying to write tests for the above change, and I am using this raster map:

map = if(row() == 5 && col() == 5, null(), if(row() % 2 == 0, col() * 0.5, -col() * 0.5))

When I run the following command:

r.describe -1 map

I get the following output:

*
-5.000000--4.960784
-4.529412--4.490196
-4.019608--3.980392
-3.509804--3.470588
-3.039216--3.000000
-2.529412--2.490196
-2.019608--1.980392
-1.549020--1.509804
-1.039216--1.000000
-0.529412--0.490196
0.450980-0.490196
0.960784-1.000000
1.470588-1.509804
1.941176-1.980392
2.450980-2.490196
2.960784-3.000000
3.431373-3.470588
3.941176-3.980392
4.450980-4.490196
4.960784-5.000000

Is this output format correct(for negative values)? Also, when should we use the "-" symbol and "thru" in the r.describe output?

@NishantBansal2003 NishantBansal2003 linked a pull request Jan 5, 2025 that will close this issue
@echoix
Copy link
Member

echoix commented Jan 5, 2025

Can another "expert" or someone knowing r.describe jump in? I don't know what to answer here

@neteler
Copy link
Member

neteler commented Jan 5, 2025

The thru of r.describe is understood by e.g. r.reclass and other commands. Hence, it is the official syntax (yes, looks oldish but works since ~1984).

The output of r.describe is also (to remain) machine readable:

ag --python r.describe
scripts/d.rast.leg/d.rast.leg.py
123:    cats = gs.read_command("r.describe", map=map, flags="1n")

scripts/r.grow/testsuite/test_r_grow.py
61:        shrined_range = SimpleModule("r.describe", flags="i", _map=self.mapShrunkNoNULL)

gui/wxpython/rdigit/controller.py
466:                        "r.describe", flags="1n", map=name, quiet=True

Of course, with increasing JSON support we get modern options here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants