Skip to content

Commit eda9536

Browse files
committed
Feedback from Gwen on assert_year changes
1 parent ea689f4 commit eda9536

File tree

2 files changed

+26
-13
lines changed

2 files changed

+26
-13
lines changed

examples/mineral-extract-sites-detection/config_trne.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ prepare_data.py:
1212
# 2-Fetch of tiles and split into 3 datasets: train, test, validation
1313
generate_tilesets.py:
1414
debug_mode:
15-
enable: True # sample of tiles
15+
enable: False # sample of tiles
1616
nb_tiles_max: 1000
1717
working_directory: output
1818
datasets:
@@ -29,6 +29,7 @@ generate_tilesets.py:
2929
# location: https://wms.geo.admin.ch/service
3030
# layers: ch.swisstopo.swissimage
3131
# srs: "EPSG:2056"
32+
# # year: 2020
3233
# ############
3334
type: XYZ # supported values: 1. MIL = Map Image Layer 2. WMS 3. XYZ 4. FOLDER
3435
year: multi-year # supported values: 1. multi-year (tiles of different year), 2. <year> (i.e. 2020)

scripts/generate_tilesets.py

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -197,24 +197,26 @@ def assert_year(img_src, year, tiles_gdf):
197197
tiles_gdf (GeoDataframe): tiles geodataframe
198198
"""
199199

200-
201200
try:
202-
assert year=='multi-year' and 'year_tile' in tiles_gdf.keys() or str(year).isnumeric() and 'year_tile' not in tiles_gdf.keys()
201+
assert (year=='multi-year' and 'year_tile' in tiles_gdf.keys()) or (str(year).isnumeric() and 'year_tile' not in tiles_gdf.keys() and img_src!='WMS' and img_src!='MIL')
203202
except:
204203
if year=='multi-year':
205-
logger.error("Option 'multi-year' chosen but the tile geodataframe does not contain a year column. "
206-
"Please add it or set a numeric year in the configuration file.")
204+
logger.error("Option 'multi-year' chosen but the tile geodataframe does not contain a 'year' column."
205+
"Please add it while producing the tile geodtaframe or set a numeric year in the configuration file.")
207206
sys.exit(1)
208207
elif year:
209-
logger.error("Option 'year' chosen but the tile geodataframe contains a year column. "
210-
"Please delete it or set the 'multi-year' option in the configuration file. ")
211-
sys.exit(1)
208+
if img_src=='WMS' or img_src=='MIL':
209+
logger.error("The connectors WMS and MIL do not support year information. The input year will be ignored.")
210+
else:
211+
logger.error("Option 'year' chosen but the tile geodataframe contains a 'year' column."
212+
"Please delete it while producing the tile geodtaframe or set the 'multi-year' option in the configuration file.")
213+
sys.exit(1)
212214
elif 'year_tile' in tiles_gdf.keys():
213-
if img_src=='WMS':
214-
logger.error("Connector=WMS, delete the year column in the tile geodataframe")
215+
if img_src=='WMS' or img_src=='MIL':
216+
logger.error("The connectors WMS and MIL do not support year information. Please provide a tile geodataframe without it.")
215217
else:
216-
logger.error("Option 'year' not chosen but the tile geodataframe contains a year column. "
217-
"Please delete it or set the 'year: multi-year' in the configuration file.")
218+
logger.error("Option 'year' not chosen but the tile geodataframe contains a 'year' column. "
219+
"Please delete it while producing the tile geodtaframe or set the 'multi-year' option in the configuration file.")
218220
sys.exit(1)
219221

220222

@@ -489,7 +491,11 @@ def main(cfg_file_path):
489491
if IM_SOURCE_TYPE == 'MIL':
490492

491493
logger.info("(using the MIL connector)")
492-
494+
495+
assert_year(IM_SOURCE_TYPE, YEAR, aoi_tiles_gdf)
496+
if YEAR:
497+
YEAR = None
498+
493499
job_dict = MIL.get_job_dict(
494500
tiles_gdf=aoi_tiles_gdf.to_crs(IM_SOURCE_SRS), # <- note the reprojection
495501
mil_url=IM_SOURCE_LOCATION,
@@ -508,6 +514,8 @@ def main(cfg_file_path):
508514
logger.info("(using the WMS connector)")
509515

510516
assert_year(IM_SOURCE_TYPE, YEAR, aoi_tiles_gdf)
517+
if YEAR:
518+
YEAR = None
511519

512520
job_dict = WMS.get_job_dict(
513521
tiles_gdf=aoi_tiles_gdf.to_crs(IM_SOURCE_SRS), # <- note the reprojection
@@ -799,6 +807,10 @@ def main(cfg_file_path):
799807
for dst in split_aoi_tiles_with_img_md_gdf.dataset.to_numpy():
800808
os.makedirs(os.path.join(OUTPUT_DIR, f'{dst}-images{f"-{TILE_SIZE}" if TILE_SIZE else ""}'), exist_ok=True)
801809

810+
for src_file, dataset in zip(split_aoi_tiles_with_img_md_gdf.img_file, split_aoi_tiles_with_img_md_gdf.dataset):
811+
print(src_file)
812+
print(dataset)
813+
# exit()
802814
split_aoi_tiles_with_img_md_gdf['dst_file'] = [
803815
src_file.replace('all', dataset)
804816
for src_file, dataset in zip(split_aoi_tiles_with_img_md_gdf.img_file, split_aoi_tiles_with_img_md_gdf.dataset)

0 commit comments

Comments
 (0)