From 3e70bbd62a25d7ca5fff8142af69ebdb5debefa3 Mon Sep 17 00:00:00 2001 From: David Minton Date: Tue, 6 Sep 2022 16:54:11 -0400 Subject: [PATCH] Added ability to save initial conditions as NetCDF files extracted from a bin.nc file at a given timestep --- python/swiftest/swiftest/io.py | 74 +++++++++++++++++++++++----------- 1 file changed, 51 insertions(+), 23 deletions(-) diff --git a/python/swiftest/swiftest/io.py b/python/swiftest/swiftest/io.py index ae12125b6..5cd294246 100644 --- a/python/swiftest/swiftest/io.py +++ b/python/swiftest/swiftest/io.py @@ -7,6 +7,7 @@ import re newfeaturelist = ("FRAGMENTATION", "ROTATION", "TIDES", "ENERGY", "GR", "YARKOVSKY", "YORP", "IN_FORM") +string_varnames = ["name", "particle_type", "status", "origin_type"] def real2float(realstr): """ @@ -714,6 +715,16 @@ def swiftest2xr(param, verbose=True): return ds +def xstrip(a): + func = lambda x: np.char.strip(x) + return xr.apply_ufunc(func, a.str.decode(encoding='utf-8')) + +def string_converter(da): + if da.dtype == np.dtype(object): + da = da.astype('