Skip to content

Commit

Permalink
remove hard-coded paths and filenames
Browse files Browse the repository at this point in the history
all paths and filenames should import from local_paths; although I have not been thorough with checking this, and not all run scripts have been updated accordingly
  • Loading branch information
ray-chew committed May 14, 2024
1 parent df9274f commit 034cda8
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 34 deletions.
13 changes: 7 additions & 6 deletions inputs/icon_regional_run.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import numpy as np
from src import var
from src import var, utils
from inputs import local_paths

params = var.params()

params.output_path = "/home/ray/git-projects/spec_appx/outputs/"
params.output_fn = "icon_merit_reg"
params.fn_grid = "../data/icon_compact.nc"
params.fn_topo = "../data/topo_compact.nc"
params.fn_output = "icon_merit_reg"
utils.transfer_attributes(params, local_paths.paths, prefix="path")

print(True)

### alaska
params.lat_extent = [48.0, 64.0, 64.0]
Expand All @@ -16,7 +17,7 @@
params.lat_extent = [-38.0, -56.0, -56.0]
params.lon_extent = [-76.0, -76.0, -53.0]

### Tierra del Fuego
### South Pole
params.lat_extent = [-75.0, -61.0, -61.0]
params.lon_extent = [-77.0, -50.0, -50.0]

Expand Down
19 changes: 11 additions & 8 deletions inputs/lam_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,24 @@
"""

import numpy as np
from src import var
from src import var, utils
from inputs import local_paths

params = var.params()
utils.transfer_attributes(params, local_paths.paths, prefix="path")


run_case = "R2B4"
# run_case = "R2B5"
# run_case = "R2B4_STRW"

run_case = "R2B4_NN"
run_case = "R2B4_NE"
run_case = "R2B4_SE"
run_case = "R2B4_SS"
run_case = "R2B4_SW"
run_case = "R2B4_WW"
run_case = "R2B4_NW"
# run_case = "R2B4_NN"
# run_case = "R2B4_NE"
# run_case = "R2B4_SE"
# run_case = "R2B4_SS"
# run_case = "R2B4_SW"
# run_case = "R2B4_WW"
# run_case = "R2B4_NW"

if run_case == "R2B4":
coarse = True
Expand Down
12 changes: 12 additions & 0 deletions inputs/local_paths_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from src import var

paths = var.obj()

paths.compact_grid = "..."
paths.compact_topo = "..."

paths.icon_grid = "..."
paths.output = "..."

paths.merit = "..."
paths.rema = "..."
4 changes: 3 additions & 1 deletion inputs/selected_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
"""

import numpy as np
from src import var
from src import var, utils
from inputs import local_paths

params = var.params()
utils.transfer_attributes(params, local_paths.paths, prefix="path")

# potential biases study
# run_case = "POT_BIAS"
Expand Down
11 changes: 4 additions & 7 deletions runs/delaunay_runs.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,10 @@ def autoreload():
if ipython is not None:
ipython.run_line_magic("autoreload", "2")


autoreload()

# %%
# from inputs.lam_run import params
from inputs.selected_run import params

autoreload()
# from params.debug_run import params
from copy import deepcopy

Expand All @@ -44,19 +41,19 @@ def autoreload():

# read grid
reader = io.ncdata(padding=params.padding, padding_tol=(60 - params.padding))
reader.read_dat(params.fn_grid, grid)
reader.read_dat(params.path_compact_grid, grid)
grid.apply_f(utils.rad2deg)

# writer object
writer = io.writer(params.output_fn, params.rect_set, debug=params.debug_writer)
writer = io.writer(params.fn_output, params.rect_set, debug=params.debug_writer)

# we only keep the topography that is inside this lat-lon extent.
lat_verts = np.array(params.lat_extent)
lon_verts = np.array(params.lon_extent)

# read topography
if not params.enable_merit:
reader.read_dat(params.fn_topo, topo)
reader.read_dat(params.path_compact_topo, topo)
reader.read_topo(topo, topo, lon_verts, lat_verts)
else:
reader.read_merit_topo(topo, params)
Expand Down
6 changes: 4 additions & 2 deletions runs/icon_merit_regional.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ def autoreload():
if params.self_test():
params.print()

print(params.path_compact_topo)

grid = var.grid()
topo = var.topo_cell()

Expand All @@ -45,7 +47,7 @@ def autoreload():
# writer object
writer = io.nc_writer(params)

reader.read_dat(params.fn_grid, grid)
reader.read_dat(params.path_compact_grid, grid)

clat_rad = np.copy(grid.clat)
clon_rad = np.copy(grid.clon)
Expand Down Expand Up @@ -219,7 +221,7 @@ def autoreload():
axs[1, 1] = fig_obj.freq_panel(axs[1, 1], uw, title="PMF spectrum")

plt.tight_layout()
plt.savefig("../output/T%i.pdf" % tri_idx)
plt.savefig("%sT%i.pdf" % (params.path_output, tri_idx))
plt.show()

ideal = physics.ideal_pmf(U=params.U, V=params.V)
Expand Down
6 changes: 3 additions & 3 deletions src/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def __init__(self, cell, params, verbose=False):
verbose : bool, optional
prints loading progression, by default False
"""
self.dir = params.merit_path
self.dir = params.path_merit
self.verbose = verbose

self.fn_lon = np.array(
Expand Down Expand Up @@ -559,12 +559,12 @@ class nc_writer(object):

def __init__(self, params):

self.fn = params.output_fn
self.fn = params.fn_output

if self.fn[-3:] != ".nc":
self.fn += '.nc'

self.path = params.output_path
self.path = params.path_output
self.rect_set = params.rect_set
self.debug = params.debug_writer

Expand Down
11 changes: 11 additions & 0 deletions src/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -808,3 +808,14 @@ def __stencil(gam):

stencil = (1.0 - gam) * stencil_iso + gam * stencil_aniso
return stencil


def transfer_attributes(params, cls, prefix=""):
for key, value in vars(cls).items():
if len(prefix) > 0:
key = prefix + '_' + key

if not hasattr(params, key):
setattr(params, key, value)
elif getattr(params, key) == None:
setattr(params, key, value)
14 changes: 7 additions & 7 deletions src/var.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,15 +299,15 @@ def __init__(self):
"""
# Define filenames
self.run_case = ""
self.path = "../data/"
self.fn_grid = self.path + "icon_compact.nc"
self.fn_topo = self.path + "topo_compact.nc"
self.path_compact_grid = None
self.path_compact_topo = None

self.output_fn = None
self.path_output = None
self.fn_output = None

self.enable_merit = True
self.merit_cg = 10
self.merit_path = "/home/ray/Documents/orog_data/MERIT/"
self.path_merit = None

# Domain size
self.lat_extent = None
Expand Down Expand Up @@ -368,8 +368,8 @@ def self_test(self):
bool
True if test passed, False otherwise
"""
if self.output_fn is None:
self.output_fn = io.fn_gen(self)
if self.fn_output is None:
self.fn_output = io.fn_gen(self)

self.check_init()

Expand Down

0 comments on commit 034cda8

Please sign in to comment.