Skip to content

Commit

Permalink
ci: CLI fix and simplify obs & restart
Browse files Browse the repository at this point in the history
  • Loading branch information
tomsail committed Dec 10, 2024
1 parent 00cbff3 commit 9602347
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 37 deletions.
46 changes: 24 additions & 22 deletions pyposeidon/telemac.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,22 +366,23 @@ def write_meteo_selafin(outpath, input_atm_zarr):
remove(input_atm_zarr)


def get_boundary_settings(boundary_type, glo_node, bnd_node):
settings = {
"lihbor": 5 if boundary_type == "open" else 2,
"liubor": 6 if boundary_type == "open" else 2,
"livbor": 6 if boundary_type == "open" else 2,
"hbor": 0.0,
"ubor": 0.0,
"vbor": 0.0,
"aubor": 0.0,
"litbor": 5 if boundary_type == "open" else 2,
"tbor": 0.0,
"atbor": 0.0,
"btbor": 0.0,
"nbor": glo_node + 1,
"k": bnd_node + 1,
}
def get_boundary_settings(boundary_type, glo_node, bnd_node, module):
if module in ["telemac2d", "telemac3d", "tomawac"]:
settings = {
"lihbor": 5 if boundary_type == "open" else 2,
"liubor": 6 if boundary_type == "open" else 2,
"livbor": 6 if boundary_type == "open" else 2,
"hbor": 0.0,
"ubor": 0.0,
"vbor": 0.0,
"aubor": 0.0,
"litbor": 5 if boundary_type == "open" else 2,
"tbor": 0.0,
"atbor": 0.0,
"btbor": 0.0,
"nbor": glo_node + 1,
"k": bnd_node + 1,
}
return settings


Expand Down Expand Up @@ -456,7 +457,6 @@ def export_cli(ds: xr.Dataset, tel_path: str, outCli: str, tel_module: str = "te
lines = []
bnd_node = 0
contours, contours_idx = extract_contour(ds, tel_path)
print(contours_idx)
for bnd in contours_idx:
poly_bnd = []
coord_bnd = []
Expand All @@ -475,7 +475,7 @@ def export_cli(ds: xr.Dataset, tel_path: str, outCli: str, tel_module: str = "te
# If both adjacent nodes are not 'open', then bnd is closed
if prev_boundary_type != "open" and next_boundary_type != "open":
boundary_type = "Unknown"
boundary_settings = get_boundary_settings(boundary_type, glo_node, bnd_node)
boundary_settings = get_boundary_settings(boundary_type, glo_node, bnd_node, tel_module)

keys_order = [
"lihbor",
Expand All @@ -492,9 +492,8 @@ def export_cli(ds: xr.Dataset, tel_path: str, outCli: str, tel_module: str = "te
"nbor",
"k",
]
if tel_module == "telemac2d":
line = " ".join(str(boundary_settings[key]) for key in keys_order)
lines.append(line)
line = " ".join(str(boundary_settings[key]) for key in keys_order)
lines.append(line)
bnd_node += 1
poly_bnd.append((coord_bnd, bnd))
domains_bnd.append(poly_bnd)
Expand Down Expand Up @@ -1441,6 +1440,8 @@ def set_obs(self, **kwargs):
df.index += 1
df["ind"] = df.index
df["unique_id"] = tgn[id_str].values
if id_str != "unique_id":
df[id_str] = tgn[id_str].values
df["depth"] = self.mesh.Dataset.depth[df.mesh_index.values]

# convert to MERCATOR coordinates
Expand All @@ -1462,6 +1463,7 @@ def set_obs(self, **kwargs):
timestep=self.params["tstep"],
offset=offset,
)
self.stations = os.path.join(path, "stations.csv")

def get_output_data(self, **kwargs):
dic = self.__dict__
Expand All @@ -1471,7 +1473,7 @@ def get_output_data(self, **kwargs):
self.data = data.get_output(**dic)

def get_station_obs_data(self, **kwargs):
self.station_obs_data = get_obs_data(self.obs, self.start_date, self.end_date)
self.station_obs_data = pd.read_csv(self.stations)

def open_thalassa(self, **kwargs):
# open a Thalassa instance to visualize the output
Expand Down
25 changes: 10 additions & 15 deletions pyposeidon/utils/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ def __init__(self, **kwargs):
res_type = kwargs.get("result_type", "2D")
convert = kwargs.get("convert_results", True)
extract_TS = kwargs.get("extract_TS", False)
station_id_str = kwargs.get("id_str", "ioc_code")
id_str = kwargs.get("id_str", "ioc_code")
max_dist = kwargs.get("max_dist", 1000)

if res_type not in ["1D", "2D"]:
Expand Down Expand Up @@ -307,28 +307,23 @@ def __init__(self, **kwargs):

# export parquet time series
if extract_TS:
if "stations_mesh_id" in p.__dict__:
if isinstance(p.stations_mesh_id, dict):
stations = pd.DataFrame(p.stations_mesh_id)
elif isinstance(p.stations_mesh_id, pd.DataFrame):
stations = p.stations_mesh_id
else:
raise ValueError("stations_mesh_id format not supported")
if "stations" in p.__dict__:
file = p.stations
elif "stations.csv" in os.listdir(rpath):
stations = pd.read_csv(os.path.join(rpath, "stations.csv"))
file = os.path.join(rpath, "stations.csv")
elif "obs" in self.__dict__:
p.set_obs()
stations = p.stations_mesh_id
file = p.stations
else:
raise ValueError("no stations file info found")

stations = pd.read_csv(file)
logger.info("extracting parquet files from TELEMAC Selafin output \n")
for i_s, id_ in enumerate(stations[station_id_str]):
s = stations[stations[station_id_str] == id_]
for i_s, id_ in enumerate(stations[id_str]):
s = stations[stations[id_str] == id_]
mod, mlon, mlat = extract_t_elev_2D(
self.Dataset,
s.longitude.values[0],
s.latitude.values[0],
s.lon.values[0],
s.lat.values[0],
var,
model_xstr,
model_ystr,
Expand Down

0 comments on commit 9602347

Please sign in to comment.