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] grass.jupyter.Map3D lacks save() method #5454

Open
petrasovaa opened this issue Mar 26, 2025 · 5 comments
Open

[Feat] grass.jupyter.Map3D lacks save() method #5454

petrasovaa opened this issue Mar 26, 2025 · 5 comments
Labels
enhancement New feature or request

Comments

@petrasovaa
Copy link
Contributor

Is your feature request related to a problem? Please describe.
Unlike gj.Map, gj.Map3D doesn't have save method.

Describe the solution you'd like
To have consistent API, I suggest adding save method. Unlike gj.Map, gj.Map3D renders the image into tiff, but the save method should allow any image format. Pillow library could be used, it's already dependency.

@petrasovaa petrasovaa added the enhancement New feature or request label Mar 26, 2025
@Aterg264
Copy link
Contributor

To solve this issue, would it be better to create a new save() function to save the image in the required format or modify the render() function to render it in the desired format?

@petrasovaa
Copy link
Contributor Author

To solve this issue, would it be better to create a new save() function to save the image in the required format or modify the render() function to render it in the desired format?

I would just convert it inside the save function, keep the render as is.

@Aterg264
Copy link
Contributor

I think about creating a save() function as follows:

def save(self, filename):
"""Saves a PNG image of map3d to the specified filename"""
img = Image.open(self._filename)
img.save(filename)

In this implementation, I did not import the IPython.display library because, as far as I understand it, it is already a dependency. Furthermore, I was considering implementing a test similar to the 'gj.Map' test, such as the following:

def test_save_file(self):
"""Test saving of file"""
grass_renderer = gj.Map3D()
# Add a vector and a raster to the map
grass_renderer.run("d.rast", map="elevation")
custom_filename = "test_filename_save.png"
grass_renderer.save(custom_filename)
# Add files to self for cleanup later
self.files.append(custom_filename)
# Ensure the image was created
self.assertFileExists(custom_filename)

@petrasovaa
Copy link
Contributor Author

I think about creating a save() function as follows:

def save(self, filename): """Saves a PNG image of map3d to the specified filename""" img = Image.open(self._filename) img.save(filename)

In this implementation, I did not import the IPython.display library because, as far as I understand it, it is already a dependency. Furthermore, I was considering implementing a test similar to the 'gj.Map' test, such as the following:

def test_save_file(self): """Test saving of file""" grass_renderer = gj.Map3D() # Add a vector and a raster to the map grass_renderer.run("d.rast", map="elevation") custom_filename = "test_filename_save.png" grass_renderer.save(custom_filename) # Add files to self for cleanup later self.files.append(custom_filename) # Ensure the image was created self.assertFileExists(custom_filename)

Thanks for working on this. Just to clarify, the expectation is that you actually test your solution, refine it and post the solution in a PR.
Your suggested solution is a good start but the test will obviously not run, because gj.Map3D has no run method.

@Aterg264
Copy link
Contributor

Aterg264 commented Apr 2, 2025

I created a PR: #5494

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

No branches or pull requests

2 participants