-
Notifications
You must be signed in to change notification settings - Fork 0
Adjusting Coordinates in Cell bin JSON Files
This script provides a utility to adjust the coordinates in JSON files based on the offsets provided in a CSV file. The coordinates are adjusted by subtracting the corresponding x_min and y_min values from each x and y coordinate in the JSON file, respectively.
pandasjsonosre
- Ensure you have the necessary libraries installed:
pip install pandas-
Place the script in your project directory.
-
Set the path to your
off_set.csvfile and the folder containing your JSON files in the example usage section at the bottom of the script. -
Run the script.
-
extract_pattern(filename):- This function extracts a specific pattern (e.g.,
_lr_D01158C2) from the filename using regular expressions. - The pattern is used to match filenames in the CSV data.
- This function extracts a specific pattern (e.g.,
-
adjust_coordinates_v3(json_path, csv_data):- This function adjusts the coordinates in a given JSON file using the offset values provided in the CSV data.
- It matches files based on the specific substring pattern extracted from the filename.
- The adjusted JSON file is saved in a subfolder named
offset_jsonwithin the original folder.
-
process_folder(csv_path, json_folder):- This function processes all JSON files in the specified folder.
- It reads the offset values from the CSV file, adjusts the coordinates in each JSON file, and saves the adjusted files in the
offset_jsonsubfolder.
Replace the placeholders in the example usage section with your specific paths:
csv_path = "path_to_off_set.csv"
json_folder = "path_to_folder_containing_json_files"
process_folder(csv_path, json_folder)Uncomment these lines and run the script to adjust the coordinates in all JSON files within the specified folder.