Skip to content

Merge refactor into develop #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*output_*
*_old*
*copy.py*
package*json

# Sphinx html build
**_build*
Expand Down
54 changes: 36 additions & 18 deletions __main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,24 @@
# test module
from tests import diagnostics as diag

import logging


logging.basicConfig(level=logging.DEBUG,
format='%(asctime)s %(name)-12s %(levelname)-8s %(message)s',
datefmt='%m-%d %H:%M',
filename='./RKLM_Python/logs/output.log',
filemode='w')
# define a Handler which writes INFO messages or higher to the sys.stderr
console = logging.StreamHandler()
console.setLevel(logging.INFO)
# set a format which is simpler for console use
formatter = logging.Formatter('%(name)-12s: %(levelname)-8s %(message)s')
# tell the handler to use this format
console.setFormatter(formatter)
# add the handler to the root logger
logging.getLogger().addHandler(console)

debug = gparams.debug
da_debug = gparams.da_debug
output_timesteps = False
Expand Down Expand Up @@ -73,8 +91,7 @@
mpv = MPV(elem, node, ud)
bld = blending.Blend(ud)

print("Input file is%s" %ud.output_base_name.replace('_',' '))

logging.info("Input file is%s" %ud.output_base_name.replace('_',' '))
##########################################################
# Initialise test module
##########################################################
Expand All @@ -97,15 +114,15 @@
if dap.da_type == 'rloc' and N > 1:
rloc = prepare_rloc(ud, elem, node, dap, N)

print(colored("Generating initial ensemble...",'yellow'))
logging.info(colored("Generating initial ensemble...",'yellow'))
sol_ens = np.zeros((N), dtype=object)

# Set random seed for reproducibility
np.random.seed(gparams.random_seed)

seeds = np.random.randint(10000,size=N) if N > 1 else None
if seeds is not None and restart == False:
print("Seeds used in generating initial ensemble spread = ", seeds)
logging.info("Seeds used in generating initial ensemble spread = ", seeds)
for n in range(N):
Sol0 = deepcopy(Sol)
mpv0 = deepcopy(mpv)
Expand Down Expand Up @@ -207,17 +224,17 @@
######################################################
# Forecast step
######################################################
print('##############################################')
print(colored('Next tout = %.3f' %tout,'yellow'))
print(colored("Starting forecast...", 'green'))
logging.info('##############################################')
logging.info(colored('Next tout = %.3f' %tout,'yellow'))
logging.info(colored("Starting forecast...", 'green'))
mem_cnt = 0
for mem in ens.members(ens):
# future = client.submit(time_update, *[mem[0],mem[1],mem[2], t, tout, ud, elem, node, mem[3], th, bld, None, False])

# handling of DA window step counter
if N > 1 : mem[3][0] = 0 if tout_old in dap.da_times else mem[3][0]
if N == 1 : mem[3][0] = mem[3][1]
print(colored("For ensemble member = %i..." %mem_cnt,'yellow'))
logging.info(colored("For ensemble member = %i..." %mem_cnt,'yellow'))
future = time_update(mem[0],mem[1],mem[2], t, tout, ud, elem, node, mem[3], th, blend, wrtr, debug)

if ud.diag:
Expand Down Expand Up @@ -258,7 +275,7 @@
######################################################
# Write output before assimilating data
######################################################
print(colored("Starting output...",'yellow'))
logging.info(colored("Starting output...",'yellow'))
for n in range(N):
Sol = ens.members(ens)[n][0]
mpv = ens.members(ens)[n][2]
Expand All @@ -275,9 +292,10 @@
# LETKF with batch observations
##################################################
if dap.da_type == 'batch_obs':
print("Starting analysis... for batch observations")
logging.info("Starting analysis... for batch observations")
for attr in dap.obs_attributes:
print("Assimilating %s..." %attr)
logging.info("Assimilating %s..." %attr)
logging.info("Assimilating %s..." %attr)
# future = client.submit(da_interface, *[s_res,obs_current,dap.inflation_factor,attr,N,ud,dap.loc[attr]])
future = da_interface(results,dap,obs,attr,tout,N,ud)
futures.append(future)
Expand All @@ -286,7 +304,7 @@
analysis = futures
# analysis = np.array(analysis)

print("Writing analysis...")
logging.info("Writing analysis...")
cnt = 0
for attr in dap.obs_attributes:
current = analysis[cnt]
Expand All @@ -298,7 +316,7 @@
# LETKF with grid-point localisation
##################################################
elif dap.da_type == 'rloc':
print(colored("Starting analysis... for rloc algorithm",'green'))
logging.info(colored("Starting analysis... for rloc algorithm",'green'))
results = HSprojector_3t2D(results, elem, dap, N)
results = rloc.analyse(results,obs,obs_covar,obs_mask,N,tout)
results = HSprojector_2t3D(results, elem, node, dap, N)
Expand Down Expand Up @@ -338,7 +356,7 @@
######################################################
# Write output at tout
######################################################
print(colored("Starting output...",'yellow'))
logging.info(colored("Starting output...",'yellow'))
for n in range(N):
Sol = ens.members(ens)[n][0]
mpv = ens.members(ens)[n][2]
Expand All @@ -353,13 +371,13 @@
# synchronise_variables(mpv, Sol, elem, node, ud, th)
t = tout
tout_old = np.copy(tout)
print(colored('tout = %.3f' %tout,'yellow'))

logging.info(colored('tout = %.3f' %tout,'yellow'))
tout_cnt += 1
outer_step += 1
if outer_step > ud.stepmax: break

toc = time()
print(colored("Time taken = %.6f" %(toc-tic),'yellow'))

logging.info(colored("Time taken = %.6f" %(toc-tic),'yellow'))
writer.close_everything()
Loading