|
1 | 1 | """Clients for other cloud run functions"""
|
2 | 2 | import asyncio
|
3 | 3 | import json
|
4 |
| -import logging |
5 | 4 | import os
|
6 | 5 | import zipfile
|
7 | 6 | from base64 import b64encode
|
@@ -74,65 +73,38 @@ async def get_base_tile_inference(
|
74 | 73 | self, tile: morecantile.Tile, semaphore: asyncio.Semaphore, rescale=(0, 255)
|
75 | 74 | ) -> InferenceResultStack:
|
76 | 75 | """fetch inference for base tiles"""
|
77 |
| - logging.basicConfig(level=logging.INFO) |
78 | 76 | async with semaphore:
|
79 |
| - logging.info("Fetching base tile.") |
80 | 77 | img_array = await self.titiler_client.get_base_tile(
|
81 | 78 | sceneid=self.sceneid, tile=tile, scale=self.scale, rescale=rescale
|
82 | 79 | )
|
83 | 80 |
|
84 |
| - logging.info("Reshaping image array.") |
85 | 81 | img_array = reshape_as_raster(img_array)
|
86 | 82 |
|
87 |
| - logging.info("Getting tile bounds.") |
88 | 83 | bounds = list(TMS.bounds(tile))
|
89 | 84 |
|
90 |
| - logging.info("Reading auxiliary datasets.") |
91 | 85 | with self.aux_datasets.open() as src:
|
92 | 86 | window = rasterio.windows.from_bounds(*bounds, transform=src.transform)
|
93 | 87 | height, width = img_array.shape[1:]
|
94 | 88 | aux_ds = src.read(window=window, out_shape=(height, width))
|
95 | 89 |
|
96 |
| - logging.info("Concatenating image arrays.") |
97 | 90 | img_array = np.concatenate([img_array[0:1, :, :], aux_ds], axis=0)
|
98 | 91 |
|
99 |
| - logging.info("Encoding image to base64.") |
100 | 92 | encoded = img_array_to_b64_image(img_array)
|
101 | 93 |
|
102 |
| - logging.info("Preparing payload for prediction.") |
103 | 94 | inf_stack = [InferenceInput(image=encoded, bounds=TMS.bounds(tile))]
|
104 |
| - |
105 |
| - logging.info("Preparing payload for prediction.") |
106 |
| - |
107 |
| - # Log the length of inf_stack |
108 |
| - logging.info(f"Length of inf_stack: {len(inf_stack)}") |
109 |
| - |
110 |
| - # Log a sample from inf_stack |
111 |
| - logging.info( |
112 |
| - f"Sample from inf_stack: {inf_stack[:1]}" |
113 |
| - ) # adjust the slice as needed |
114 |
| - |
115 |
| - # Log inf_parms |
116 |
| - logging.info(f"inf_parms: {self.inference_parms}") |
117 |
| - |
118 |
| - # Create and log the entire payload |
119 | 95 | payload = PredictPayload(
|
120 | 96 | inf_stack=inf_stack, inf_parms=self.inference_parms
|
121 | 97 | )
|
122 |
| - logging.info(f"Complete PredictPayload: {payload.dict()}") |
123 |
| - |
124 |
| - logging.info(f"Sending request to {self.url + '/predict'}.") |
125 | 98 | res = await self.client.post(
|
126 | 99 | self.url + "/predict", json=payload.dict(), timeout=None
|
127 | 100 | )
|
128 |
| - |
129 |
| - logging.info("Processing response.") |
130 |
| - print(f"DEBUG len(inf_stack): {len(inf_stack)}") |
131 |
| - print(f"DEBUG inf_stack[:1]: {inf_stack[:1]}") |
132 |
| - print(f"DEBUG self.url + '/predict': {self.url + '/predict'}") |
133 |
| - print(f"DEBUG payload.dict(): {payload.dict()}") |
134 |
| - print(f"DEBUG res: {res}") |
135 |
| - return InferenceResultStack(**res.json()) |
| 101 | + if res.status_code == 200: |
| 102 | + return InferenceResultStack(**res.json()) |
| 103 | + else: |
| 104 | + print(f"XXX Received unexpected status code: {res.status_code}") |
| 105 | + print(f"XXX HTTP content: {res.content}") |
| 106 | + print(f"XXX Issue was found in: {self.sceneid}") |
| 107 | + return InferenceResultStack([]) |
136 | 108 |
|
137 | 109 | async def get_offset_tile_inference(
|
138 | 110 | self, bounds: List[float], semaphore: asyncio.Semaphore, rescale=(0, 255)
|
@@ -161,7 +133,13 @@ async def get_offset_tile_inference(
|
161 | 133 | res = await self.client.post(
|
162 | 134 | self.url + "/predict", json=payload.dict(), timeout=None
|
163 | 135 | )
|
164 |
| - return InferenceResultStack(**res.json()) |
| 136 | + if res.status_code == 200: |
| 137 | + return InferenceResultStack(**res.json()) |
| 138 | + else: |
| 139 | + print(f"XXX Received unexpected status code: {res.status_code}") |
| 140 | + print(f"XXX HTTP content: {res.content}") |
| 141 | + print(f"XXX Issue was found in: {self.sceneid}") |
| 142 | + return InferenceResultStack([]) |
165 | 143 |
|
166 | 144 |
|
167 | 145 | def get_scene_date_month(scene_id: str) -> str:
|
|
0 commit comments