Skip to content

Commit befcf21

Browse files
committed
Debug gravi reader for static file EIGEN-6C4
1 parent 840cd1f commit befcf21

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

lenapy/readers/gravi_reader.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -366,10 +366,10 @@ def _open_file(filename: str | os.PathLike) -> tuple[IO, str]:
366366
ext = os.path.splitext(filename)[-1]
367367

368368
if ext.lower() == ".gfc":
369-
return open(filename, "r"), ext
369+
return open(filename, "r", encoding="latin-1"), ext
370370

371371
elif ext in (".gz", ".gzip"):
372-
return gzip.open(filename, "rb"), ext
372+
return gzip.open(filename, "rb", encoding="latin-1"), ext
373373

374374
elif ext in (".zip", ".ZIP"):
375375
zip_file = zipfile.ZipFile(filename, "r")
@@ -927,8 +927,12 @@ def open_dataset(
927927

928928
lmax = header["max_degree"]
929929

930+
# -- Fortran-style double-precision float converter for pandas
931+
d_float = lambda x: float(x.replace("D", "e").replace("d", "e"))
932+
930933
# -- Load clm and slm data
931934
clm, slm = np.zeros((lmax + 1, lmax + 1, 1)), np.zeros((lmax + 1, lmax + 1, 1))
935+
convert = {"clm": d_float, "slm": d_float}
932936

933937
col_names = ["tag", "degree", "order", "clm", "slm"]
934938
if (
@@ -940,6 +944,7 @@ def open_dataset(
940944
eclm, eslm = np.zeros((lmax + 1, lmax + 1, 1)), np.zeros(
941945
(lmax + 1, lmax + 1, 1)
942946
)
947+
convert.update({"eclm": d_float, "eslm": d_float})
943948

944949
if "t" in legend:
945950
col_names.append("ref_time")
@@ -949,7 +954,7 @@ def open_dataset(
949954

950955
# Read file with pandas, delim_whitespace for variable space delimiters
951956
data = pd.read_csv(
952-
file, sep="\s+", header=None, names=col_names, engine="python"
957+
file, sep=r"\s+", header=None, names=col_names, engine="python", converters=convert
953958
)
954959

955960
# test if gfct key then have to deal with time
@@ -1089,8 +1094,8 @@ def _open_file(filename: str | os.PathLike) -> any:
10891094
"""
10901095
ext = os.path.splitext(filename)[-1]
10911096
if ext in (".gz", ".gzip"):
1092-
return gzip.open(filename, "rb")
1093-
return open(filename, "r")
1097+
return gzip.open(filename, "rb", encoding="latin-1")
1098+
return open(filename, "r", encoding="latin-1")
10941099

10951100
@staticmethod
10961101
def _read_cnes_header(file: any, ext: str) -> dict:

0 commit comments

Comments
 (0)