Skip to content

Commit

Permalink
remove subprocess and fix era5 calculation formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
ashjbarnes committed Nov 28, 2023
1 parent 3190caa commit 1685d2c
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions regional_mom6/regional_mom6.py
Original file line number Diff line number Diff line change
Expand Up @@ -1243,10 +1243,6 @@ def setup_run_directory(self, use_default="era5", using_payu=False):
f"{use_default}_surface"
)
shutil.copytree(rundir_src, self.mom_run_dir, dirs_exist_ok=True)
subprocess.run(
f"cp {str(rundir_src)}/* {str(self.mom_run_dir)}",
shell=True,
)
## Make symlinks between run and input directories
inputdir_in_rundir = self.mom_run_dir / "inputdir"
rundir_in_inputdir = self.mom_input_dir / "rundir"
Expand All @@ -1258,7 +1254,10 @@ def setup_run_directory(self, use_default="era5", using_payu=False):
rundir_in_inputdir.symlink_to(self.mom_run_dir)

## Get mask table information
mask_table = None
for p in self.mom_input_dir.glob("mask_table.*"):
if mask_table != None:
print(f"WARNING: Multiple mask tables found. Defaulting to {p}. If this is not what you want, remove it from the run directory and try again.")
mask_table, masked, layout = p.name.split(".")
x, y = (int(v) for v in layout.split("x"))
ncpus = (x * y) - masked
Expand Down Expand Up @@ -1399,20 +1398,16 @@ def setup_era5(self, era5_path):

if fname == "2d":
## Calculate specific humidity from dewpoint temperature
dewpoint = 8.07131 - 1730.63 / (233.426 + rawdata["2d"]["d2m"] - 273.15)
humidity = (
(0.622 / rawdata["sp"]["sp"]) * (10**dewpoint) * 101325 / 760
)
q = xr.Dataset(
data_vars={
"q": (0.622 / rawdata["sp"]["sp"])
* (
10
** (
8.07131
- 1730.63 / (233.426 + rawdata["2d"]["d2m"] - 273.15)
)
)
* 101325
/ 760
"q": humidity
}
)

q.q.attrs = {"long_name": "Specific Humidity", "units": "kg/kg"}
q.to_netcdf(
f"{self.mom_input_dir}/forcing/q_ERA5",
Expand Down

0 comments on commit 1685d2c

Please sign in to comment.