Skip to content

Commit c177911

Browse files
Merging updates from main
Signed-off-by: João Lucas de Sousa Almeida <[email protected]>
2 parents 5868f82 + bbef2dc commit c177911

33 files changed

+803
-128
lines changed
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
name: Feature request
3+
about: Suggest an idea for this project
4+
title: ''
5+
labels: ''
6+
assignees: ''
7+
8+
---
9+
10+
**Is your feature request related to a problem? Please describe.**
11+
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
12+
13+
**Describe the solution you'd like**
14+
A clear and concise description of what you want to happen.
15+
16+
**Describe alternatives you've considered (optional)**
17+
A clear and concise description of any alternative solutions or features you've considered.
18+
19+
**Additional context (optional)**
20+
Add any other context or screenshots about the feature request here.
+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
name: Issue report
3+
about: Create a report to help us improve
4+
title: ''
5+
labels: ''
6+
assignees: ''
7+
8+
---
9+
10+
**Describe the issue**
11+
A clear and concise description of what the issue is.
12+
13+
**To Reproduce (optional, but appreciated)**
14+
Steps to reproduce the behavior:
15+
1. Go to '...'
16+
2. Click on '....'
17+
3. Scroll down to '....'
18+
4. See error
19+
20+
**Screenshots or log output (optional)**
21+
If applicable, add screenshots or log output to help explain your problem.
22+
<details><summary>Log Output</summary>
23+
<pre>
24+
Paste the log output here.
25+
</pre>
26+
</details>
27+
28+
**Expected behavior (optional)**
29+
A clear and concise description of what you expected to happen.
30+
31+
**Deployment information (optional)**
32+
Describe what you've deployed and how:
33+
- TerraTorch version: [e.g. 1.5.3]
34+
- Installation source: [e.g. git, pip]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
name: " Report a vulnerability "
3+
about: " Report a vulnerability "
4+
title: ''
5+
labels: ''
6+
assignees: ''
7+
8+
---
9+
10+
### Summary
11+
_Short summary of the problem. Make the impact and severity as clear as possible. For example: An unsafe deserialization vulnerability allows any unauthenticated user to execute arbitrary code on the server._
12+
13+
### Details
14+
_Give all details on the vulnerability. Pointing to the incriminated source code is very helpful for the maintainer._
15+
16+
### Impact
17+
_What kind of vulnerability is it? Who is impacted?_

.github/workflows/crosshair.yaml

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# This workflow will install Python dependencies, run tests and lint with a single version of Python
2+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
3+
4+
name: Dynamic Code Analysis
5+
6+
on:
7+
push:
8+
branches: [ "main" ]
9+
pull_request:
10+
branches: [ "main" ]
11+
12+
permissions:
13+
contents: read
14+
15+
jobs:
16+
build:
17+
18+
runs-on: ubuntu-latest
19+
20+
steps:
21+
- uses: actions/checkout@v3
22+
- name: Set up Python 3.11
23+
uses: actions/setup-python@v3
24+
with:
25+
python-version: "3.11"
26+
- name: Install dependencies
27+
run: |
28+
python -m pip install --upgrade pip
29+
pip install crosshair-tool
30+
pip install -r requirements/required.txt
31+
- name: Test with pytest
32+
run: |
33+
crosshair watch ./terratorch

.github/workflows/pylint.yml

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Static Code Analysis (Pylint)
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
pull_request:
7+
branches: [ "main" ]
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
strategy:
13+
matrix:
14+
python-version: ["3.10","3.11"]
15+
steps:
16+
- uses: actions/checkout@v3
17+
- name: Set up Python ${{ matrix.python-version }}
18+
uses: actions/setup-python@v3
19+
with:
20+
python-version: ${{ matrix.python-version }}
21+
- name: Install dependencies
22+
run: |
23+
python -m pip install --upgrade pip
24+
pip install pylint
25+
- name: Analysing the code with pylint
26+
run: |
27+
pylint $(git ls-files '*.py')
28+
pylint $(git ls-files '*.ipynb')

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@ dist/*
77
**/*.pt
88
*.ipynb_checkpoints
99
**/*pth
10+
.venv/*
11+
venv/*

CODEOWNERS

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@CarlosGomes98
2+
@Joao-L-S-Almeida
3+
@PedroConrado
4+
@biancazadrozny
5+
@romeokienzler

CODE_OF_CONDUCT.md

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
## TerraTorch Community Code of Conduct 1.0
2+
3+
4+
### Our Pledge
5+
6+
As contributors and maintainers of this project, and in the interest of fostering
7+
an open and welcoming community, we pledge to respect all people who contribute
8+
through reporting issues, posting feature requests, updating documentation,
9+
submitting pull requests or patches, and other activities.
10+
11+
We are committed to making participation in this project a harassment-free experience for
12+
everyone, regardless of level of experience, gender, gender identity and expression,
13+
sexual orientation, disability, personal appearance, body size, race, ethnicity, age,
14+
religion, or nationality.
15+
16+
We pledge to act and interact in ways that contribute to an open, welcoming, diverse,
17+
inclusive, and healthy community.
18+
19+
### Our Standards
20+
21+
Examples of behavior that contributes to a positive environment for our community include:
22+
23+
* Demonstrating empathy and kindness toward other people
24+
* Being respectful of differing opinions, viewpoints, and experiences
25+
* Giving and gracefully accepting constructive feedback
26+
* Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
27+
* Focusing on what is best not just for us as individuals, but for the overall community
28+
29+
Examples of unacceptable behavior include:
30+
31+
* The use of sexualized language or imagery, and sexual attention or
32+
advances of any kind
33+
* Trolling, insulting or derogatory comments, and personal or political attacks
34+
* Public or private harassment
35+
* Publishing others' private information, such as a physical or email
36+
address, without their explicit permission
37+
* Other conduct which could reasonably be considered inappropriate in a
38+
professional setting
39+
40+
## Enforcement Responsibilities
41+
42+
Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior
43+
and will take appropriate and fair corrective action in response to any behavior that they deem
44+
inappropriate, threatening, offensive, or harmful.
45+
46+
Community leaders have the right and responsibility to remove, edit, or reject comments, commits,
47+
code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct,
48+
and will communicate reasons for moderation decisions when appropriate.
49+
50+
## Scope
51+
52+
This Code of Conduct applies within all community spaces including Matrix, issue trackers, wikis,
53+
blogs, Twitter, and any other communication channels used by our community, and also applies when
54+
an individual is officially representing the community in public spaces. Examples of representing
55+
our community include using an official e-mail address, posting via an official social media account,
56+
or acting as an appointed representative at an online or offline event.
57+
58+
## Enforcement
59+
60+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community
61+
leaders responsible for enforcement via Matrix channel to the CLAIMED Project Management Committee at
62+
#claimed-pmc:matrix.org. All complaints will be reviewed and investigated promptly and fairly.
63+
64+
All community leaders are obligated to respect the privacy and security of the reporter of any incident.
65+
66+
67+
## Attribution
68+
69+
This Code of Conduct is adapted from the [Contributor Covenant](https://www.contributor-covenant.org/),
70+
version 2.0, available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.

CONTRIBUTING.md

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<!--
2+
{% comment %}
3+
Copyright 2018-2024 IBM
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
{% endcomment %}
17+
-->
18+
19+
# Contributing
20+
21+
Welcome to TerraTorch! If you are interested in contributing to the [TerraTorch code repo](README.md)
22+
then checkout the [Contribution Process](contribution_process.md) and
23+
the [Code of Conduct](CODE_OF_CONDUCT.md)).
24+
25+
The [erraTorch code repo]([https://github.com/IBM/terratorch/blob/main/README.md)) contains information on how the community
26+
is organized and other information that is pertinent to contributing.
27+
28+
### Getting Started
29+
30+
It's encouraged that you look under the [Issues]([https://github.com/IBM/terratorch/issues)) tab for contribution opportunites.
31+
32+
Please also take the opportunity to join our [weekly community call](https://teams.microsoft.com/l/meetup-join/19%3ameeting_MWJhMThhMTMtMjc3MS00YjAyLWI3NTMtYTI0NDQ3NWY3ZGU2%40thread.v2/0?context=%7b%22Tid%22%3a%22fcf67057-50c9-4ad4-98f3-ffca64add9e9%22%2c%22Oid%22%3a%227f7ab87a-680c-4c93-acc5-fbd7ec80823a%22%7d) every Thursday 7 AM PST, 10 AM EST, **2 PM UTC**, 4 PM CET, 7:30 PM IST, 11 PM JST, 12 AM AEST

VULNERABILITIES.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# VULNERABILITIES reporting process
2+
3+
Vulnerabilities can be reported on the GitHub Issue Tracker.
4+
We are working on a more generic channel and update this information accordingly

contribution_process.md

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Contribution Process
2+
3+
If you want to contribute to this project, there are many valuable ways in doing so
4+
5+
1. Join the weekly community calls as indicated in [CONTRIBUTING.md](CONTRIBUTING.md)
6+
1. Use / test TerraTorch and create an [Issue](https://github.com/IBM/terratorch/issues) if something is not working properly or if you have an idea for a feature request.
7+
1. Pick an [Issue](https://github.com/IBM/terratorch/issues) and start contributing
8+
9+
Contributions are welcome as pull requests on a [fork](https://github.com/IBM/terratorch/fork) of this project. Ideally, pull requests are backed by an [Issue](https://github.com/IBM/terratorch/issues). You can also tag the [code owners](https://github.com/IBM/terratorch/blob/main/CODEOWNERS) in the issue before you start, so we can talk about the details (in case you can't join one of the community calls).

docs/models.md

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ By passing a list of bands being used to the constructor, we automatically filte
6161

6262
## Model Factory
6363
### :::terratorch.models.PrithviModelFactory
64+
### :::terratorch.models.SMPModelFactory
6465

6566
# Adding new model types
6667
Adding new model types is as simple as creating a new factory that produces models. See for instance the example below for a potential `SMPModelFactory`

pyproject.toml

+3-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ dependencies = [
4343
"geobench>=1.0.0",
4444
"mlflow>=2.12.1",
4545
# broken due to https://github.com/Lightning-AI/pytorch-lightning/issues/19977
46-
"lightning>=2, <=2.2.5"
46+
"lightning>=2, <=2.2.5",
47+
# see issue #64
48+
"albumentations<=1.4.10"
4749
]
4850

4951
[project.optional-dependencies]

terratorch/cli_tools.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def write_on_epoch_end(self, trainer, pl_module, predictions, batch_indices): #
123123
output_dir = self.output_dir
124124

125125
if not os.path.exists(output_dir):
126-
os.mkdir(output_dir)
126+
os.makedirs(output_dir, exist_ok=True)
127127

128128
for pred_batch, filename_batch in predictions:
129129
for prediction, file_name in zip(torch.unbind(pred_batch, dim=0), filename_batch, strict=False):
@@ -467,4 +467,4 @@ def inference(self, file_path: Path) -> torch.Tensor:
467467
prediction, file_name = self.inference_on_dir(
468468
tmpdir,
469469
)
470-
return prediction.squeeze(0)
470+
return prediction.squeeze(0)

terratorch/datasets/generic_pixel_wise_dataset.py

+5-8
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from torch import Tensor
2121
from torchgeo.datasets import NonGeoDataset
2222

23-
from terratorch.datasets.utils import HLSBands, filter_valid_files, to_tensor
23+
from terratorch.datasets.utils import HLSBands, default_transform, filter_valid_files
2424

2525

2626
class GenericPixelWiseDataset(NonGeoDataset, ABC):
@@ -136,7 +136,7 @@ def __init__(
136136
self.filter_indices = None
137137

138138
# If no transform is given, apply only to transform to torch tensor
139-
self.transform = transform if transform else lambda **batch: to_tensor(batch)
139+
self.transform = transform if transform else default_transform
140140
# self.transform = transform if transform else ToTensorV2()
141141

142142
def __len__(self) -> int:
@@ -155,14 +155,15 @@ def __getitem__(self, index: int) -> dict[str, Any]:
155155
"image": image.astype(np.float32) * self.constant_scale,
156156
"mask": self._load_file(self.segmentation_mask_files[index], nan_replace=self.no_label_replace).to_numpy()[
157157
0
158-
],
159-
"filename": self.image_files[index],
158+
]
160159
}
161160

162161
if self.reduce_zero_label:
163162
output["mask"] -= 1
164163
if self.transform:
165164
output = self.transform(**output)
165+
output["filename"] = self.image_files[index]
166+
166167
return output
167168

168169
def _load_file(self, path, nan_replace: int | float | None = None) -> xr.DataArray:
@@ -185,10 +186,6 @@ def _generate_bands_intervals(self, bands_intervals: list[int | str | HLSBands |
185186
bands.extend(expanded_element)
186187
else:
187188
bands.append(element)
188-
# check the expansion didnt result in duplicate elements
189-
if len(set(bands)) != len(bands):
190-
msg = "Duplicate indices detected. Indices must be unique."
191-
raise Exception(msg)
192189
return bands
193190

194191

terratorch/datasets/generic_scalar_label_dataset.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
from torchgeo.datasets.utils import rasterio_loader
2727
from torchvision.datasets import ImageFolder
2828

29-
from terratorch.datasets.utils import HLSBands, filter_valid_files, to_tensor
29+
from terratorch.datasets.utils import HLSBands, default_transform, filter_valid_files
3030

3131

3232
class GenericScalarLabelDataset(NonGeoDataset, ImageFolder, ABC):
@@ -128,7 +128,7 @@ def is_valid_file(x):
128128
else:
129129
self.filter_indices = None
130130
# If no transform is given, apply only to transform to torch tensor
131-
self.transforms = transform if transform else lambda **batch: to_tensor(batch)
131+
self.transforms = transform if transform else default_transform
132132
# self.transform = transform if transform else ToTensorV2()
133133

134134
def __len__(self) -> int:
@@ -143,13 +143,12 @@ def __getitem__(self, index: int) -> dict[str, Any]:
143143

144144
output = {
145145
"image": image.astype(np.float32) * self.constant_scale,
146-
"label": label,
147-
"filename": self.samples[index][
148-
0
149-
], # samples is an attribute of ImageFolder. Contains a tuple of (Path, Target)
146+
"label": label, # samples is an attribute of ImageFolder. Contains a tuple of (Path, Target)
150147
}
151148
if self.transforms:
152149
output = self.transforms(**output)
150+
output["filename"] = self.image_files[index]
151+
153152
return output
154153

155154
def _load_file(self, path) -> xr.DataArray:

0 commit comments

Comments
 (0)