Skip to content

Commit 9201186

Browse files
authored
Merge pull request #25 from FrontierDevelopmentLab/bugfix/corrupted-bands
Fix rescaling bug
2 parents 1d5e699 + 65b139c commit 9201186

File tree

6 files changed

+16
-20
lines changed

6 files changed

+16
-20
lines changed

.gcloudignore

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ tests
44
*.pyo
55
*.pyd
66
notebooks
7-
outputs
7+
output
8+
images
89
docs
910
htmlcov
1011
dist
@@ -14,6 +15,8 @@ ci
1415
.vscode
1516
.mypy_cache
1617
.ipynb_checkpoints
17-
uis
1818
__pycache__
1919
.pytest_cache
20+
.hydra
21+
ui
22+
*.ipynb

providers/gcp/main.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ def extract_patches():
106106
# common data
107107
storage_gs_path = request_json["storage_gs_path"]
108108
bands = request_json["bands"]
109-
resolution = request_json["resolution"]
110109
job_id = request_json["job_id"]
111110

112111
fs = gcsfs.GCSFileSystem()
@@ -150,16 +149,16 @@ def extract_patches():
150149
"Environment variable MONITOR_TABLE not set. Unable to push task status to Monitor",
151150
)
152151

152+
archive_resolution = int(
153+
min([b["gsd"] for _, b in BAND_INFO[constellation].items()]),
154+
)
155+
153156
patches = task_mosaic_patches(
154157
cloud_fs=fs,
155158
download_f=download_blob,
156159
task=task,
157160
method="first",
158-
resolution=resolution,
159-
)
160-
161-
archive_resolution = int(
162-
min([b["gsd"] for kk, b in BAND_INFO[constellation].items()]),
161+
resolution=archive_resolution,
163162
)
164163

165164
logger.info(f"Ready to store {len(patches)} patches at {storage_gs_path}.")
@@ -169,7 +168,6 @@ def extract_patches():
169168
patches,
170169
task,
171170
bands,
172-
resolution,
173171
archive_resolution,
174172
)
175173

src/satextractor/builder/gcp_builder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ def build_docker_image(self):
150150
"--tag",
151151
f"{self.image_region_code}/{self.project}/{self.user_id}-stacextractor",
152152
]
153-
153+
logger.info(cmd)
154154
p = run(cmd, text=True, stdout=subprocess.DEVNULL)
155155
p.check_returncode()
156156

src/satextractor/deployer/gcp_deployer.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ def deploy_tasks(credentials, extraction_tasks, storage_path, chunk_size, topic)
2929
extraction_task=extraction_task_data,
3030
bands=list(BAND_INFO[task.constellation].keys()),
3131
chunks=(1, 1, chunk_size, chunk_size),
32-
resolution=int(BAND_INFO[task.constellation][task.band]["gsd"]),
3332
)
3433
data = json.dumps(data, default=str)
3534

src/satextractor/extractor/extractor.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from osgeo import osr
1313
from rasterio import warp
1414
from rasterio.crs import CRS
15+
from rasterio.enums import Resampling
1516
from rasterio.merge import merge as riomerge
1617
from satextractor.models import ExtractionTask
1718
from satextractor.models import Tile
@@ -106,6 +107,7 @@ def download_and_extract_tiles_window_COG(
106107
# set the transforms for the output file
107108
dst_transform = Affine(resolution, 0.0, left, 0.0, -resolution, top)
108109
out_shp = (int((right - left) / resolution), int((top - bottom) / resolution))
110+
logger.debug(f"Affine with resolution: {dst_transform} and out_shp {out_shp} ")
109111

110112
outfiles = []
111113

@@ -136,6 +138,7 @@ def download_and_extract_tiles_window_COG(
136138
transform=dst_transform,
137139
crs=CRS.from_epsg(epsg),
138140
dtype=rst_arr.dtype,
141+
resampling=Resampling.bilinear,
139142
) as dst:
140143

141144
dst.write(rst_arr, indexes=1)
@@ -196,8 +199,8 @@ def download_and_extract_tiles_window(
196199
projWin=proj_win,
197200
projWinSRS=f"EPSG:{epsg}",
198201
xRes=resolution,
199-
yRes=resolution,
200-
resampleAlg="cubic",
202+
yRes=-resolution,
203+
resampleAlg="bilinear",
201204
creationOptions=["QUALITY=100", "REVERSIBLE=YES"],
202205
)
203206
file = None

src/satextractor/storer/storer.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import numpy as np
66
import zarr
77
from satextractor.models import ExtractionTask
8-
from scipy.ndimage import zoom
98

109

1110
def store_patches(
@@ -14,7 +13,6 @@ def store_patches(
1413
patches: List[np.ndarray],
1514
task: ExtractionTask,
1615
bands: List[str],
17-
patch_resolution: int,
1816
archive_resolution: int,
1917
):
2018
"""Store a list of patches in storage path.
@@ -48,11 +46,6 @@ def store_patches(
4846
timestamp_idx = timestamps.index(task.sensing_time)
4947
patch = patches[i]
5048

51-
# maybe resize -> bicubic upsample
52-
if patch_resolution != archive_resolution:
53-
patch = zoom(patch, int(patch_resolution / archive_resolution), order=3)
54-
55-
# in patch resolution
5649
if patch.shape != size:
5750
pad_x = int(size[0] - patch.shape[0])
5851
pad_y = int(size[1] - patch.shape[1])

0 commit comments

Comments
 (0)