Skip to content

Commit

Permalink
standardised import statements in inputs, run_scripts, and data_assim…
Browse files Browse the repository at this point in the history
…ilation #25

untested, may contain typos
  • Loading branch information
ray-chew committed Mar 23, 2024
1 parent 62bb688 commit 4d83eca
Show file tree
Hide file tree
Showing 16 changed files with 101 additions and 149 deletions.
2 changes: 0 additions & 2 deletions docs/source/apis/inputs.rising_bubble.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@

.. autosummary::

hydrostatic_state
set_explicit_boundary_data
sol_init


Expand Down
6 changes: 0 additions & 6 deletions docs/source/apis/run_scripts.test_suite.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,6 @@



.. rubric:: Classes

.. autosummary::

compare_sol




Expand Down
6 changes: 0 additions & 6 deletions docs/source/apis/src.data_assimilation.blending.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,12 @@

blending_after_timestep
blending_before_timestep
colored
compressibility
deepcopy
do_comp_to_psinc_conv
do_hydro_to_nonhydro_conv
do_lake_to_swe_conv
do_nonhydro_to_hydro_conv
do_psinc_to_comp_conv
do_swe_to_lake_conv
is_compressible
is_nonhydrostatic
nonhydrostasy



Expand Down
8 changes: 0 additions & 8 deletions docs/source/apis/src.data_assimilation.letkf.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,9 @@
.. autosummary::

bin_func
convolve2d
da_interface
deepcopy
interpn
interpolation_func
map_coordinates
none_func
sliding_window_view
spsolve



Expand All @@ -32,8 +26,6 @@

.. autosummary::

BdryType
ProgressBar
analysis
prepare_rloc

Expand Down
6 changes: 0 additions & 6 deletions docs/source/apis/src.data_assimilation.localisation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@



.. rubric:: Classes

.. autosummary::

BdryType




Expand Down
7 changes: 0 additions & 7 deletions docs/source/apis/src.data_assimilation.params.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,6 @@



.. rubric:: Functions

.. autosummary::

set_explicit_boundary_data
set_ghostnodes_p2




Expand Down
2 changes: 0 additions & 2 deletions docs/source/apis/src.data_assimilation.utils.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
HSprojector_2t3D
HSprojector_3t2D
boundary_mask
deepcopy
ensemble_inflation
obs_noiser
set_p2_nodes
Expand All @@ -32,7 +31,6 @@

.. autosummary::

BdryType
ensemble


Expand Down
2 changes: 1 addition & 1 deletion docs/source/apis/src.dycore.discretisation.time_update.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
colored
data_init
deepcopy
do
dynamic_timestep
euler_backward_non_advective_expl_part
euler_backward_non_advective_impl_part
euler_forward_non_advective
is_nonhydrostatic
nonhydrostasy
recompute_advective_fluxes
time_update



Expand Down
8 changes: 4 additions & 4 deletions inputs/rising_bubble.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import numpy as np
from dycore.physics.hydrostatics import hydrostatic_state
from dycore.utils.boundary import set_explicit_boundary_data
import dycore.physics.hydrostatics as hydro
import dycore.utils.boundary as bdry

class UserData(object):
# Nsq_ref = grav * 1.3e-05
Expand Down Expand Up @@ -51,7 +51,7 @@ def sol_init(Sol, mpv, elem, node, th, ud, seed=None):
g = ud.gravity_strength[1]
# print(ud.rho_ref)

hydrostatic_state(mpv, elem, node, th, ud)
hydro.hydrostatic_state(mpv, elem, node, th, ud)

x = elem.x
y = elem.y
Expand Down Expand Up @@ -94,6 +94,6 @@ def sol_init(Sol, mpv, elem, node, th, ud, seed=None):
rhoY = mpv.HydroState_n.rhoY0[0]
mpv.p2_nodes[...] = (p - mpv.HydroState_n.p0[0]) / rhoY / ud.Msq

set_explicit_boundary_data(Sol,elem,ud,th,mpv)
bdry.set_explicit_boundary_data(Sol,elem,ud,th,mpv)

return Sol
8 changes: 4 additions & 4 deletions run_scripts/test_suite.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# %%
from run import run_params as rp
from pybella.tests.diagnostics import compare_sol
import pybella.tests.diagnostics as td
import json

# The first run MUST have gen_targets = True
# This is to generate the target outputs
# so that a comparison can be made
gen_targets = True
gen_targets = False

# Only set this to True if the diagnostic targets
# are to be updated. Required for the first run.
updt_targets = True
updt_targets = False

# define run instance
rp = rp()
Expand Down Expand Up @@ -39,7 +39,7 @@
rp.queue_run()

if updt_targets:
diag = compare_sol("gen_target")
diag = td.compare_sol("gen_target")
diag.update_targets()


Expand Down
54 changes: 24 additions & 30 deletions src/data_assimilation/blending.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
import numpy as np
from scipy import signal
import scipy.sparse.linalg as la

from dycore.physics.gas_dynamics.eos import (
nonhydrostasy,
compressibility,
is_compressible,
is_nonhydrostatic,
)
import logging

from termcolor import colored
from copy import deepcopy
import dycore.physics.gas_dynamics as eos

import logging
import termcolor
import copy


class Blend(object):
Expand Down Expand Up @@ -112,7 +106,7 @@ def update_p2n(self, Sol, mpv, node, th, ud):


def do_comp_to_psinc_conv(Sol, mpv, bld, elem, node, th, ud, label, writer):
logging.info(colored("Converting COMP to PSINC", "blue"))
logging.info(termcolor.colored("Converting COMP to PSINC", "blue"))
dp2n = mpv.p2_nodes
bld.convert_p2n(dp2n)
bld.update_Sol(Sol, elem, node, th, ud, mpv, "bef", label=label, writer=writer)
Expand All @@ -126,9 +120,9 @@ def do_psinc_to_comp_conv(
):
from dycore.discretisation import time_update

logging.info(colored("Blending... step = %i" % step, "blue"))
Sol_freeze = deepcopy(Sol)
mpv_freeze = deepcopy(mpv)
logging.info(termcolor.colored("Blending... step = %i" % step, "blue"))
Sol_freeze = copy.deepcopy(Sol)
mpv_freeze = copy.deepcopy(mpv)

ret = time_update.time_update(
Sol,
Expand Down Expand Up @@ -169,7 +163,7 @@ def do_psinc_to_comp_conv(

if writer != None:
writer.populate(str(label) + "_after_full_step", "dp2n", dp2n)
logging.info(colored("Converting PSINC to COMP", "blue"))
logging.info(termcolor.colored("Converting PSINC to COMP", "blue"))
bld.convert_p2n(dp2n)
bld.update_Sol(Sol, elem, node, th, ud, mpv, "aft", label=label, writer=writer)
bld.update_p2n(Sol, mpv, node, th, ud)
Expand All @@ -183,7 +177,7 @@ def do_psinc_to_comp_conv(


def do_swe_to_lake_conv(Sol, mpv, elem, node, ud, th, writer, label, debug):
logging.info(colored("swe to lake conversion...", "blue"))
logging.info(termcolor.colored("swe to lake conversion...", "blue"))

H1 = Sol.rho[
:,
Expand Down Expand Up @@ -227,10 +221,10 @@ def do_lake_to_swe_conv(
if debug == True:
writer.write_all(Sol, mpv, elem, node, th, str(label) + "_after_lake_time_step")

Sol_freeze = deepcopy(Sol)
mpv_freeze = deepcopy(mpv)
Sol_freeze = copy.deepcopy(Sol)
mpv_freeze = copy.deepcopy(mpv)

logging.info(colored("doing lake-to-swe time-update...", "blue"))
logging.info(termcolor.colored("doing lake-to-swe time-update...", "blue"))
ret = time_update.time_update(
Sol,
flux,
Expand Down Expand Up @@ -260,13 +254,13 @@ def do_lake_to_swe_conv(
else:
assert 0, "incorrect ud.blending_type"

Sol = deepcopy(Sol_freeze)
mpv = deepcopy(mpv_freeze)
Sol = copy.deepcopy(Sol_freeze)
mpv = copy.deepcopy(mpv_freeze)

mpv.p2_nodes[...] = dp2n

H10 = mpv.p2_nodes[:, 2:-2, :].mean(axis=1)
logging.info(colored("lake to swe conversion...", "blue"))
logging.info(termcolor.colored("lake to swe conversion...", "blue"))
H10 -= H10.mean()

# define 2D kernel
Expand Down Expand Up @@ -301,7 +295,7 @@ def do_nonhydro_to_hydro_conv(
Sol, flux, mpv, bld, elem, node, th, ud, label, writer, step, window_step, t, dt
):

logging.info(colored("nonhydrostatic to hydrostatic conversion...", "blue"))
logging.info(termcolor.colored("nonhydrostatic to hydrostatic conversion...", "blue"))
# bld.convert_p2n(mpv.p2_nodes)
# bld.update_Sol(Sol,elem,node,th,ud,mpv,'bef',label=label,writer=writer)
# Sol.rhov = Sol.rhov_half
Expand Down Expand Up @@ -331,8 +325,8 @@ def do_hydro_to_nonhydro_conv(
Sol, flux, mpv, bld, elem, node, th, ud, label, writer, step, window_step, t, dt
):

logging.info(colored("hydrostatic to nonhydrostatic conversion...", "blue"))
logging.info(colored("Blending... step = %i" % step, "blue"))
logging.info(termcolor.colored("hydrostatic to nonhydrostatic conversion...", "blue"))
logging.info(termcolor.colored("Blending... step = %i" % step, "blue"))

# Sol_tmp = deepcopy(Sol)
# flux_tmp = deepcopy(flux)
Expand Down Expand Up @@ -542,10 +536,10 @@ def blending_before_timestep(
ud.is_nonhydrostatic = 1
ud.nonhydrostasy = 1.0
else:
ud.is_compressible = is_compressible(ud, window_step)
ud.compressibility = compressibility(ud, t, window_step)
ud.is_nonhydrostatic = is_nonhydrostatic(ud, window_step)
ud.nonhydrostasy = nonhydrostasy(ud, t, window_step)
ud.is_compressible = eos.is_compressible(ud, window_step)
ud.compressibility = eos.compressibility(ud, t, window_step)
ud.is_nonhydrostatic = eos.is_nonhydrostatic(ud, window_step)
ud.nonhydrostasy = eos.nonhydrostasy(ud, t, window_step)

return swe_to_lake, Sol, mpv, t

Expand Down
2 changes: 0 additions & 2 deletions src/data_assimilation/etpf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import numpy as np

import logging

def da_interface(results, obs, obs_attributes, delta, times, tout, N, loc=0):
Expand All @@ -11,7 +10,6 @@ def da_interface(results, obs, obs_attributes, delta, times, tout, N, loc=0):
# local_ens = np.array([mem[inner] for mem in local_ens])
# local_ens = analysis(local_ens,attr)
# print(results[:,0,...][0].rho)

attributes = ['rho','rhou','rhov','rhow','rhoY','rhoX']
# attributes = ['rho', 'rhou', 'rhov']
tmp = np.array([getattr(results[:,loc,...][n],obs_attributes[0])[inner] for n in range(N)])
Expand Down
Loading

0 comments on commit 4d83eca

Please sign in to comment.