Skip to content

Commit

Permalink
Add function to parse tile ids from a file path
Browse files Browse the repository at this point in the history
  • Loading branch information
vikineema committed Dec 1, 2023
1 parent bf24ec7 commit 6410526
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion deafrica_conflux/text.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Text formatting functions"""

import os
from datetime import datetime


Expand Down Expand Up @@ -89,3 +89,24 @@ def make_parquet_file_name(drill_name: str, uuid: str, centre_date: datetime) ->
parquet_file_name = f"{drill_name}_{uuid}_{datestring}.pq"

return parquet_file_name


def parse_tile_ids(file_path: str) -> str:
"""
Parse tile ids from a file path.
Parameters
----------
file_path : str
File path to get the tile id from.
Returns
-------
str
Tile id
"""
file_name = os.path.splitext(os.path.basename(file_path))[0]
x_id = int(file_name.split("_")[0].lstrip("x"))
y_id = int(file_name.split("_")[1].lstrip("y"))
tile_id = (x_id, y_id)
return tile_id

0 comments on commit 6410526

Please sign in to comment.