Skip to content

Commit ef0a030

Browse files
resolve issues with tracer imports
1 parent 974c911 commit ef0a030

1 file changed

Lines changed: 21 additions & 5 deletions

File tree

schimpy/schism_hotstart.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ def map_to_schism(self):
561561
nc_dataset = nc_dataset.drop_vars(var_values)
562562

563563
if self.modules:
564-
nc_dataset["tracer_list"] = tr_mname
564+
nc_dataset["tracer_list"] = np.array(tr_mname, dtype='U')
565565
self.nc_dataset = nc_dataset
566566

567567

@@ -1163,7 +1163,7 @@ def obs_points(self, ini_meta=None, inpoly=None): # 1D observational points
11631163
"""
11641164
obs_file includes Lat, Lon, and values for the variable.
11651165
"""
1166-
from . import interp_2d # now onl 2D interpolation IDW is implemented.
1166+
from schimpy import interp_2d # now onl 2D interpolation IDW is implemented.
11671167

11681168
if ini_meta:
11691169
obs_file = ini_meta["data"]
@@ -2027,16 +2027,32 @@ def create_hotstart_cli(input):
20272027
h.create_hotstart()
20282028
output_fn = h.output_fn
20292029
hnc = h.nc_dataset
2030-
hnc.to_netcdf(output_fn)
2030+
# Ensure tracer_list is numpy string array, not ArrowStringArray
2031+
if 'tracer_list' in hnc.coords:
2032+
# Force conversion by dropping and recreating with object dtype
2033+
tracer_values = [str(x) for x in hnc['tracer_list'].values]
2034+
hnc = hnc.drop_vars('tracer_list')
2035+
hnc = hnc.assign_coords(tracer_list=('tracer_list', np.array(tracer_values, dtype=object)))
2036+
hnc.to_netcdf(output_fn, encoding={'tracer_list': {'dtype': 'S10'}})
20312037
print(f"output to {output_fn} ")
20322038

20332039

20342040
if __name__ == "__main__":
20352041
create_hotstart_cli()
2036-
# os.chdir("PATH/TO/HOTSTART/FILES")
2037-
# h = hotstart("./hotstart_2018.yaml")
2042+
# os.chdir(r"PATH/TO/YAML")
2043+
# h = hotstart("./hotstart_2013.yaml")
20382044
# h.read_yaml()
20392045
# h.create_hotstart()
2046+
# output_fn = h.output_fn
2047+
# hnc = h.nc_dataset
2048+
# # Ensure tracer_list is numpy string array, not ArrowStringArray
2049+
# if 'tracer_list' in hnc.coords:
2050+
# # Force conversion by dropping and recreating with object dtype
2051+
# tracer_values = [str(x) for x in hnc['tracer_list'].values]
2052+
# hnc = hnc.drop_vars('tracer_list')
2053+
# hnc = hnc.assign_coords(tracer_list=('tracer_list', np.array(tracer_values, dtype=object)))
2054+
# hnc.to_netcdf(output_fn, encoding={'tracer_list': {'dtype': 'S10'}})
2055+
# print(f"output to {output_fn} ")
20402056

20412057
# # %% making plot
20422058
# v1 = h.nc_dataset

0 commit comments

Comments
 (0)