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

Adding raster compression option #106

Merged
merged 37 commits into from
Dec 17, 2024
Merged

Conversation

Antsalacia
Copy link
Collaborator

Added a compression option in set_query_parameters and put new key in the output_metadata dictionary.
Method get_raster_compression added with a try and except.

earthspy/earthspy.py Fixed Show resolved Hide resolved
@AdrienWehrle
Copy link
Owner

Thanks for working on this @Antsalacia! You create a get_raster_compression() method but never use it.

I guess you'd want this:

self.compress_mode = compression

to rather be something like:

self.get_raster_compression()

with self.compression being set inside the method, just like e.g. :

def get_data_collection(self) -> shb.DataCollection:
"""Get Sentinel Hub DataCollection object from data collection name.
:return: DataCollection object containing all information needed for
download (such as bands, sensor type...).
:rtype: shb.DataCollection
"""
# set Sentinel Hub data collection object
if self.algorithm == "SICE":
self.data_collection = shb.DataCollection.SENTINEL3_OLCI
else:
self.data_collection = shb.DataCollection[self.data_collection_str]
return self.data_collection

@Antsalacia Antsalacia marked this pull request as ready for review November 29, 2024 10:35
@Antsalacia
Copy link
Collaborator Author

Solved #84

@AdrienWehrle
Copy link
Owner

AdrienWehrle commented Nov 29, 2024

For now this code isn't working, but it's not visible since we can't run earthspy properly in tests at the moment (I'm working on getting credentials for testing purposes).

That's because in get_raster_compression() you're calling a compress_mode which is not passed as an argument to the function. So you need to pass compression_mode in the function just like evaluation_script is passed in self.get_evaluation_script(evaluation_script) right below.

Actually compress_mode doesn't exist anywhere else. You have a compression variable in set_query_parameters but compress_mode doesn't exist anywhere else than in the function.

Remember to run your modifications before pushing your code! If it doesn't work, please make a note that it will be fixed later! :)

@AdrienWehrle
Copy link
Owner

AdrienWehrle commented Nov 29, 2024

Also, could you:

  • rename compression for raster_compression
  • add documentation for the new raster_compression argument in the docstring of set_query_parameters
  • add a few tests for the new raster_compression in test_earthspy.py

@AdrienWehrle AdrienWehrle self-requested a review November 29, 2024 11:02
@Antsalacia
Copy link
Collaborator Author

What kind of test should I add in test_earthspy for raster_compression ?

earthspy/earthspy.py Outdated Show resolved Hide resolved
@AdrienWehrle AdrienWehrle added the enhancement New feature or request label Nov 29, 2024
earthspy/earthspy.py Fixed Show resolved Hide resolved
earthspy/earthspy.py Outdated Show resolved Hide resolved
@AdrienWehrle
Copy link
Owner

Have you tested if the raster saving works fine with "compress" to None in the metadata? You could try on the earthspy example in the README.

@Antsalacia
Copy link
Collaborator Author

The raster saving works fine when no argument is pass to raster_compress and thus equal to None

@AdrienWehrle
Copy link
Owner

The raster saving works fine when no argument is pass to raster_compress and thus equal to None

Cool thanks!

Then what remains is to resolve the discussion with CodeQL further up here and then you'd need to run the pre-commit hooks and pytest.

See CONTRIBUTING.md for details. :)

@AdrienWehrle
Copy link
Owner

I just added a commit to address CodeQL alert that raster_compression == None should be raster_compression is None.

I see you fixed pre-commit issues, do you still have any or does everything pass? Is pytest also passing all tests?

@AdrienWehrle
Copy link
Owner

Don't hesitate to git add all the files modified by black once you've run pre-commit. As you can see here black would like to format the code but you haven't pushed the results.

One would usually run pre-commit run --al-files twice, first to format, then to make sure formatting fixed all issues.

@AdrienWehrle
Copy link
Owner

closes #84

@AdrienWehrle
Copy link
Owner

Now that I think about it, we could only update the metadata dictionary to add the compression when raster_compression is not none, so that it doesn't unnecessarily write compression to None.

tests/conftest.py Fixed Show fixed Hide fixed
tests/conftest.py Fixed Show fixed Hide fixed
tests/conftest.py Dismissed Show dismissed Hide dismissed
@AdrienWehrle
Copy link
Owner

I just added more comments and fixed a couple more things.

So I think the only thing missing here is to get test_get_raster_compression ton run on t3 and t4!

@Antsalacia
Copy link
Collaborator Author

How can I check raster_compression when I try this it doesn't work:
comp_def = t4.get_raster_compression()
error:
AttributeError: 'function' object has no attribute 'get_raster_compression'

@AdrienWehrle
Copy link
Owner

Maybe earthspy hasn't been reloaded. Can you try pip install -e . and then again?

@Antsalacia
Copy link
Collaborator Author

Still the same after pip

@AdrienWehrle
Copy link
Owner

Can you share where you're running this t4? Can you try on a simple example too where you just setup a job and then try access the function?

@Antsalacia
Copy link
Collaborator Author

I am running it in the test_get_raster_compression and t4 is in conftest. It works with the job.

@Antsalacia
Copy link
Collaborator Author

All good now was just testing the wrong way thanks for helping.

tests/test_earthspy.py Fixed Show fixed Hide fixed
tests/test_earthspy.py Fixed Show fixed Hide fixed
@AdrienWehrle
Copy link
Owner

Nice to hear! Now please modify the tests to compliy with github-advanced-security

# assert all(isinstance(item, str) for item in self.t3.output_filenames_renamed)
# # check that one output per split box was created
# assert len(self.t3.outputs) == len(self.t3.split_boxes)
# check raster compression sith mode specified
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's a typo left :) "sith"

@AdrienWehrle AdrienWehrle merged commit 15d3c93 into AdrienWehrle:main Dec 17, 2024
4 of 7 checks passed
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 this pull request may close these issues.

2 participants