Skip to content

Commit

Permalink
Read surfex geometry from file
Browse files Browse the repository at this point in the history
  • Loading branch information
trygveasp committed Nov 5, 2024
1 parent 224b426 commit 94ae3c5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
2 changes: 2 additions & 0 deletions pysurfex/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,8 @@ def __init__(self, env, conf):
self.update_setting("SURFEX#ASSIM#SCHEMES#ISBA", "EKF")
if anasurf == "ENKF":
self.update_setting("SURFEX#ASSIM#SCHEMES#ISBA", "ENKF")
if anasurf == "ISBA_NONE":
self.update_setting("SURFEX#ASSIM#SCHEMES#ISBA", "NONE")

# Active EKF control variables from CVAR_M
if "NNCV" in env:
Expand Down
15 changes: 15 additions & 0 deletions pysurfex/geo.py
Original file line number Diff line number Diff line change
Expand Up @@ -912,6 +912,21 @@ def get_geo_object(from_json):
raise KeyError("nam_pgd_grid not set!")


def get_geo_object_from_json_file(fname):
"""Get a surfex geometry object from a dictionary.
Args:
fname (str): Domain definition file.
Returns:
surfex.Geo: Surfex geometry.
"""
with open(fname, mode="r", encoding="utf8") as fh:
domain_dict = json.load(fh)
return get_geo_object(domain_dict)


def set_domain(settings, domain, hm_mode=False):
"""Set domain.
Expand Down
4 changes: 2 additions & 2 deletions pysurfex/variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from .datetime_utils import as_timedelta
from .fa import Fa
from .file import SurfexFileVariable, get_surfex_io_object
from .geo import get_geo_object
from .geo import get_geo_object_from_json_file
from .grib import Grib, Grib1Variable, Grib2Variable
from .input_methods import get_datasources
from .netcdf import Netcdf, NetCDFReadVariable
Expand Down Expand Up @@ -127,7 +127,7 @@ def get_filehandler(self, validtime, cache=None, previoustime=None):
geo_in = self.var_dict["geo_input"]
elif "geo_input_file" in self.var_dict:
geo_in_file = self.var_dict["geo_input_file"]
geo_in = get_geo_object(open(geo_in_file, "r", encoding="utf-8"))
geo_in = get_geo_object_from_json_file(geo_in_file)

file_handler = get_surfex_io_object(
filename, fileformat=fileformat, filetype=filetype, geo=geo_in
Expand Down

0 comments on commit 94ae3c5

Please sign in to comment.