Skip to content

Commit a79433c

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 7dc9bd7 commit a79433c

File tree

2 files changed

+33
-20
lines changed

2 files changed

+33
-20
lines changed

src/virtualship/cli/commands.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"--mfp_file",
2929
type=str,
3030
default=None,
31-
help="Partially initialise a project from an exported xlsx or csv file from NIOZ' Marine Facilities Planning tool (specifically the \"Export Coordinates > DD\" option). User edits are required after initialisation.",
31+
help='Partially initialise a project from an exported xlsx or csv file from NIOZ\' Marine Facilities Planning tool (specifically the "Export Coordinates > DD" option). User edits are required after initialisation.',
3232
)
3333
def init(path, mfp_file):
3434
"""
@@ -53,11 +53,13 @@ def init(path, mfp_file):
5353
)
5454

5555
config.write_text(utils.get_example_config())
56-
56+
5757
if mfp_file:
5858
# Generate schedule.yaml from the MPF file
5959
click.echo(f"Generating schedule from {mfp_file}...")
60-
mfp_to_yaml(mfp_file, str(path)) # Pass the path to save in the correct directory
60+
mfp_to_yaml(
61+
mfp_file, str(path)
62+
) # Pass the path to save in the correct directory
6163
else:
6264
# Create a default example schedule
6365
schedule.write_text(utils.get_example_schedule())

src/virtualship/utils.py

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
import os
12
from functools import lru_cache
23
from importlib.resources import files
34
from typing import TextIO
4-
import pandas as pd
5-
import numpy as np
6-
import os
75

6+
import numpy as np
7+
import pandas as pd
88
import yaml
99
from pydantic import BaseModel
1010

@@ -42,12 +42,12 @@ def _generic_load_yaml(data: str, model: BaseModel) -> BaseModel:
4242
return model.model_validate(yaml.safe_load(data))
4343

4444

45-
4645
def mfp_to_yaml(excel_file_path: str, save_directory: str):
4746
"""
4847
Generates a YAML file (`schedule.yaml`) with spatial and temporal information based on instrument data from MFP excel file.
4948
50-
Parameters:
49+
Parameters
50+
----------
5151
- excel_file_path (str): Path to the Excel file containing coordinate and instrument data.
5252
- save_directory (str): Directory where `schedule.yaml` will be saved.
5353
@@ -56,10 +56,13 @@ def mfp_to_yaml(excel_file_path: str, save_directory: str):
5656
2. Determines the maximum depth and buffer based on the instruments present.
5757
3. Ensures longitude and latitude values remain valid after applying buffer adjustments.
5858
4. Saves `schedule.yaml` in the specified directory.
59-
"""
6059
60+
"""
6161
# Read data from Excel
62-
coordinates_data = pd.read_excel(excel_file_path, usecols=["Station Type", "Name", "Latitude", "Longitude", "Instrument"])
62+
coordinates_data = pd.read_excel(
63+
excel_file_path,
64+
usecols=["Station Type", "Name", "Latitude", "Longitude", "Instrument"],
65+
)
6366
coordinates_data = coordinates_data.dropna()
6467

6568
# Define maximum depth and buffer for each instrument
@@ -70,14 +73,22 @@ def mfp_to_yaml(excel_file_path: str, save_directory: str):
7073
}
7174

7275
# Extract unique instruments from dataset
73-
unique_instruments = np.unique(np.hstack(coordinates_data["Instrument"].apply(lambda a: a.split(", ")).values))
76+
unique_instruments = np.unique(
77+
np.hstack(coordinates_data["Instrument"].apply(lambda a: a.split(", ")).values)
78+
)
7479

7580
# Determine the maximum depth based on the unique instruments
76-
maximum_depth = max(instrument_properties.get(inst, {"depth": 0})["depth"] for inst in unique_instruments)
81+
maximum_depth = max(
82+
instrument_properties.get(inst, {"depth": 0})["depth"]
83+
for inst in unique_instruments
84+
)
7785
minimum_depth = 0
7886

7987
# Determine the buffer based on the maximum buffer of the instruments present
80-
buffer = max(instrument_properties.get(inst, {"buffer": 0})["buffer"] for inst in unique_instruments)
88+
buffer = max(
89+
instrument_properties.get(inst, {"buffer": 0})["buffer"]
90+
for inst in unique_instruments
91+
)
8192

8293
# Adjusted spatial range
8394
min_longitude = coordinates_data["Longitude"].min() - buffer
@@ -98,10 +109,10 @@ def mfp_to_yaml(excel_file_path: str, save_directory: str):
98109
},
99110
"time_range": {
100111
"start_time": "", # Blank start time
101-
"end_time": "", # Blank end time
102-
}
112+
"end_time": "", # Blank end time
113+
},
103114
},
104-
"waypoints": []
115+
"waypoints": [],
105116
}
106117

107118
# Populate waypoints
@@ -112,16 +123,16 @@ def mfp_to_yaml(excel_file_path: str, save_directory: str):
112123
"instrument": instrument,
113124
"location": {
114125
"latitude": row["Latitude"],
115-
"longitude": row["Longitude"]
126+
"longitude": row["Longitude"],
116127
},
117-
"time": "" # Blank time
128+
"time": "", # Blank time
118129
}
119130
yaml_output["waypoints"].append(waypoint)
120131

121132
# Ensure save directory exists
122133
os.makedirs(save_directory, exist_ok=True)
123-
134+
124135
# Save the YAML file
125136
yaml_file_path = os.path.join(save_directory, SCHEDULE)
126-
with open(yaml_file_path, 'w') as file:
137+
with open(yaml_file_path, "w") as file:
127138
yaml.dump(yaml_output, file, default_flow_style=False)

0 commit comments

Comments
 (0)