-
Notifications
You must be signed in to change notification settings - Fork 350
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
Add an initial version of WMSDataset #1965
base: main
Are you sure you want to change the base?
Conversation
@microsoft-github-policy-service agree |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like a great start! I commented on some of the immediately obvious software-y things. There are still a lot of technical questions (what happens if I change the CRS or res, how does WMS handle that?) but I'll save those for later. Thanks again for the PR!
requirements/required.txt
Outdated
@@ -9,6 +9,7 @@ lightly==1.5.2 | |||
lightning[pytorch-extra]==2.2.1 | |||
matplotlib==3.8.3 | |||
numpy==1.26.4 | |||
owsLib==0.30.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's make this optional instead of required. So it should listed in pyproject.toml
, requirements/datasets.txt
, and requirements/min-reqs.old
. The lower bound will have to be tested. Easiest way is to pip-install older and older versions until the tests fail.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also need to add to requirements/min-reqs.old
in order to get the minimum tests to pass.
torchgeo/datasets/wms.py
Outdated
@@ -0,0 +1,145 @@ | |||
# Copyright (c) Microsoft Corporation. All rights reserved. | |||
# Licensed under the MIT License. | |||
# Author: Ian Turton, Glasgow University [email protected] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't normally edit the license header. Your contribution will still be included in the git history though.
torchgeo/datasets/wms.py
Outdated
|
||
import torchvision.transforms as transforms | ||
from owslib.map.wms111 import ContentMetadata | ||
from owslib.wms import WebMapService |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Imports should be done lazily inside of the class so that the rest of TorchGeo still works even if owslib isn't installed. If you grep for any of our other optional dataset dependencies, you should see example code for this you can copy-n-paste.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ianturton you can check
torchgeo.datasets.chabud
as an example. See how we check if h5py is available in the constructor and then import h5py in the method that uses it.
|
||
|
||
class WMSDataset(GeoDataset): | ||
"""Allow models to fetch images from a WMS (at a good resolution).""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you clarify what "at a good resolution" means? Also would be good to explain what WMS is and why it is useful. For example, see the documentation for some of our other existing dataset base classes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, can you add:
.. versionadded:: 0.6
to the docstring? This will document what version of TorchGeo is required to use this feature.
def getlayer(self) -> ContentMetadata: | ||
"""Return the selected layer object.""" | ||
return self._layer | ||
|
||
def layers(self) -> list[str]: | ||
"""Return a list of availiable layers.""" | ||
return self._layers |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Getters/setters are generally considered to be bad practice in Python, especially if you don't actually need to do anything special. In this case, if we want the ability to access the attribute, let's just make it a public attribute.
) | ||
sample = {"crs": self.crs, "bbox": query} | ||
|
||
transform = transforms.Compose([transforms.ToTensor()]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't normally use torchvision transforms. What is the output from wms, a numpy array? Let's just convert that directly to PyTorch without relying on PIL
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a JPEG or PNG image can I convert that directly to a tensor?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
T.ToTensor() also automatically divides by 255 which we should leave up to the user to decide. You can convert the image to a tensor using torch.from_numpy(np.array(Image.open(path).astype(np.float32)))
. You can break this up over multiple lines so it's not too verbose
I can't work out what's going on with
and yes |
pre-commit creates and uses a separate isolated environment while running hooks and not your existing environment. To solve, this, you just need to add |
We recently updated the repo to use Python 3.10+. Some of your code uses Python 3.9 syntax. You can fix this with pyupgrade: https://torchgeo.readthedocs.io/en/stable/user/contributing.html#linters |
@ianturton is this still a work in progress? We're preparing for a new release in the next couple weeks. Trying to merge or close as many remaining PRs as possible. |
Fixes #1963