Skip to content

Commit

Permalink
Merge pull request #28 from MarjanAsgari/main
Browse files Browse the repository at this point in the history
fixing bbox issue. closes #24
  • Loading branch information
mpelchat04 authored Oct 24, 2024
2 parents ff4fed8 + c365de6 commit 2bbe63d
Show file tree
Hide file tree
Showing 45 changed files with 20 additions and 10 deletions.
Empty file modified .dockerignore
100644 → 100755
Empty file.
Empty file modified .github/workflows/test.yml
100644 → 100755
Empty file.
Empty file modified .gitignore
100644 → 100755
Empty file.
Empty file modified Dockerfile
100644 → 100755
Empty file.
Empty file modified LICENSE
100644 → 100755
Empty file.
Empty file modified MANIFEST.in
100644 → 100755
Empty file.
Empty file modified README.md
100644 → 100755
Empty file.
Empty file modified VERSION
100644 → 100755
Empty file.
Empty file modified examples/run_geo_inference_with_scripted_model.ipynb
100644 → 100755
Empty file.
Empty file modified examples/script_model.py
100644 → 100755
Empty file.
Empty file modified examples/test_small.tif
100644 → 100755
Empty file.
Empty file modified geo_inference/__init__.py
100644 → 100755
Empty file.
Empty file modified geo_inference/config/__init__.py
100644 → 100755
Empty file.
Empty file modified geo_inference/config/log_config.yaml
100644 → 100755
Empty file.
Empty file modified geo_inference/config/logging_config.py
100644 → 100755
Empty file.
Empty file modified geo_inference/config/sample.yaml
100644 → 100755
Empty file.
Empty file modified geo_inference/geo_dask.py
100644 → 100755
Empty file.
16 changes: 13 additions & 3 deletions geo_inference/geo_inference.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -298,11 +298,21 @@ async def async_run_inference(self,
top=bbox[3],
transform=self.raster_meta["transform"],
)
col_off, row_off = roi_window.col_off, roi_window.row_off
width, height = roi_window.width, roi_window.height
self.bbox_transform = from_origin(bbox[0],
bbox[3],
self.raster_meta["transform"].a,
self.raster_meta["transform"].e if self.raster_meta["transform"].e > 0 else -1 * self.raster_meta["transform"].e
)
col_off, row_off = int(self.roi_window.col_off), int(self.roi_window.row_off)
width, height = int(self.roi_window.width), int(self.roi_window.height)
aoi_dask_array = aoi_dask_array[
:, row_off : row_off + height, col_off : col_off + width
]
self.raster_meta.update({
'transform': self.bbox_transform,
'width': aoi_dask_array.shape[2],
'height': aoi_dask_array.shape[1]
})
self.original_shape = aoi_dask_array.shape
# Pad the array to make dimensions multiples of the patch size
pad_height = (
Expand Down Expand Up @@ -353,7 +363,7 @@ async def async_run_inference(self,
pbar.register()
import rioxarray
logger.info("Inference is running:")
aoi_dask_array = xr.DataArray(aoi_dask_array[: self.original_shape[1], : self.original_shape[2]], dims=("y", "x"), attrs= self.json if self.json is not None else xarray_profile_info(self.raster))
aoi_dask_array = xr.DataArray(aoi_dask_array[: self.original_shape[1], : self.original_shape[2]], dims=("y", "x"), attrs= self.json if self.json is not None else xarray_profile_info(self.raster_meta))
aoi_dask_array.rio.to_raster(mask_path, tiled=True, lock=threading.Lock())

total_time = time.time() - start_time
Expand Down
Empty file modified geo_inference/utils/__init__.py
100644 → 100755
Empty file.
Empty file modified geo_inference/utils/geo.py
100644 → 100755
Empty file.
Empty file modified geo_inference/utils/geo_transforms.py
100644 → 100755
Empty file.
14 changes: 7 additions & 7 deletions geo_inference/utils/helpers.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ def select_model_device(gpu_id: int, multi_gpu: bool, device: str="cpu"):


def xarray_profile_info(
raster,
raster_meta
):
"""
Save mask to file.
Expand All @@ -286,14 +286,14 @@ def xarray_profile_info(
Returns:
None
"""
driver = 'GTiff' if raster.driver == 'VRT' else raster.driver
raster_meta["driver"] = 'GTiff' if raster_meta["driver"] == 'VRT' else raster_meta["driver"]
profile_kwargs = {
'crs': raster.crs.to_string(), # Coordinate Reference System, using src.crs.to_string() to get a string representation
'transform': raster.transform, # Affine transformation matrix
'crs': raster_meta["crs"], # Coordinate Reference System, using src.crs.to_string() to get a string representation
'transform': raster_meta['transform'], # Affine transformation matrix
'count': 1, # Number of bands
'width': raster.width, # Width of the raster
'height': raster.height, # Height of the raster
'driver': driver, # Raster format driver
'width': raster_meta['width'], # Width of the raster
'height': raster_meta['height'], # Height of the raster
'driver': raster_meta["driver"], # Raster format driver
'dtype': "uint8", # Data type (use dtype directly if it's a valid format for xarray)
'BIGTIFF': 'YES', # BigTIFF option
'compress': 'lzw' # Compression type
Expand Down
Empty file modified geo_inference/utils/polygon.py
100644 → 100755
Empty file.
Empty file modified pyproject.toml
100644 → 100755
Empty file.
Empty file modified requirements.txt
100644 → 100755
Empty file.
Empty file modified tests/__init__.py
100644 → 100755
Empty file.
Empty file modified tests/data/0.tif
100644 → 100755
Empty file.
Empty file modified tests/data/0_coco.json
100644 → 100755
Empty file.
Empty file modified tests/data/0_corrupt.tif
100644 → 100755
Empty file.
Empty file modified tests/data/0_mask.tif
100644 → 100755
Empty file.
Empty file modified tests/data/0_polygons.geojson
100644 → 100755
Empty file.
Empty file modified tests/data/0_yolo.csv
100644 → 100755
Empty file.
Empty file modified tests/data/aff_gdf_result.csv
100644 → 100755
Empty file.
Empty file modified tests/data/gj_to_px_result.geojson
100644 → 100755
Empty file.
Binary file added tests/data/inference/test_model/test_model.pt
Binary file not shown.
Empty file modified tests/data/sample.csv
100644 → 100755
Empty file.
Empty file modified tests/data/sample.geojson
100644 → 100755
Empty file.
Empty file modified tests/data/sample.yaml
100644 → 100755
Empty file.
Empty file modified tests/test_geo_dask.py
100644 → 100755
Empty file.
Empty file modified tests/test_geo_inference.py
100644 → 100755
Empty file.
Empty file modified tests/utils/__init__.py
100644 → 100755
Empty file.
Empty file modified tests/utils/test_geo.py
100644 → 100755
Empty file.
Empty file modified tests/utils/test_geo_transforms.py
100644 → 100755
Empty file.
Empty file modified tests/utils/test_helpers.py
100644 → 100755
Empty file.
Empty file modified tests/utils/test_polygon.py
100644 → 100755
Empty file.

0 comments on commit 2bbe63d

Please sign in to comment.