Skip to content
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

string constructor #1008

Merged
merged 9 commits into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
replace StringConstructor from genutil to that from PMP
  • Loading branch information
lee1043 committed Dec 18, 2023
commit 143d8b31e0bb2121c498629b2d087f02f93e29d6
4 changes: 2 additions & 2 deletions cmec/scripts/climatologies.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import subprocess
import sys

import genutil
from pcmdi_metrics.utils import StringConstructor


def make_climatologies(settings, model_dir, wk_dir):
Expand All @@ -12,7 +12,7 @@ def make_climatologies(settings, model_dir, wk_dir):
realization = settings.get("realization", "")
period = settings.get("period", "")
tmp = os.path.join(model_dir, filename_template)
model_file = genutil.StringConstructor(tmp)
model_file = StringConstructor(tmp)
model_file.period = period
model_file.realization = realization
out_base = os.path.join(wk_dir, "AC")
Expand Down
3 changes: 1 addition & 2 deletions pcmdi_metrics/enso/enso_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
defCollection,
)
from EnsoMetrics.EnsoComputeMetricsLib import ComputeCollection
from genutil import StringConstructor

from pcmdi_metrics import resources
from pcmdi_metrics.enso.lib import (
Expand All @@ -25,8 +24,8 @@
get_file,
match_obs_name,
metrics_to_json,
sort_human,
)
from pcmdi_metrics.utils import StringConstructor, sort_human

# To avoid below error when using multi cores
# OpenBLAS blas_thread_init: pthread_create failed for thread XX of 96: Resource temporarily unavailable
Expand Down
4 changes: 1 addition & 3 deletions pcmdi_metrics/enso/scripts_pcmdi/enso_driver_obsOnly.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,16 @@
# =================================================
# Dependencies
# -------------------------------------------------
from __future__ import print_function

import glob
import json
import os

from EnsoMetrics.EnsoCollectionsLib import ReferenceObservations, defCollection
from EnsoMetrics.EnsoComputeMetricsLib import ComputeCollection_ObsOnly
from genutil import StringConstructor

from pcmdi_metrics import resources
from pcmdi_metrics.enso.lib import AddParserArgument, metrics_to_json
from pcmdi_metrics.utils import StringConstructor

# To avoid below error when using multi cores
# OpenBLAS blas_thread_init: pthread_create failed for thread XX of 96: Resource temporarily unavailable
Expand Down
3 changes: 1 addition & 2 deletions pcmdi_metrics/enso/scripts_pcmdi/post_process_merge_jsons.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
import json
import os

from genutil import StringConstructor

from pcmdi_metrics.utils import StringConstructor
from pcmdi_metrics.variability_mode.lib import dict_merge


Expand Down
3 changes: 2 additions & 1 deletion pcmdi_metrics/graphics/deprecated/portraits.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
import numpy
import pkg_resources
import vcs
from genutil import StringConstructor

from pcmdi_metrics.utils import StringConstructor

pmp_egg_path = pkg_resources.resource_filename(
pkg_resources.Requirement.parse("pcmdi_metrics"), "share"
Expand Down
7 changes: 4 additions & 3 deletions pcmdi_metrics/io/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import pcmdi_metrics
from pcmdi_metrics import LOG_LEVEL
from pcmdi_metrics.utils import StringConstructor

value = 0
cdms2.setNetcdfShuffleFlag(value) # where value is either 0 or 1
Expand Down Expand Up @@ -143,9 +144,9 @@ def default(self, o):
return {o.id: "cdutil.region.domain(%s)" % args}


class Base(cdp.cdp_io.CDPIO, genutil.StringConstructor):
class Base(cdp.cdp_io.CDPIO, StringConstructor):
def __init__(self, root, file_template, file_mask_template=None):
genutil.StringConstructor.__init__(self, root + "/" + file_template)
StringConstructor.__init__(self, root + "/" + file_template)
self.target_grid = None
self.mask = None
self.target_mask = None
Expand All @@ -156,7 +157,7 @@ def __init__(self, root, file_template, file_mask_template=None):
self.setup_cdms2()

def __call__(self):
path = os.path.abspath(genutil.StringConstructor.__call__(self))
path = os.path.abspath(StringConstructor.__call__(self))
if self.type in path:
return path
else:
Expand Down
10 changes: 5 additions & 5 deletions pcmdi_metrics/mean_climate/lib/pmp_parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import os

import cdp.cdp_parameter
import genutil

from pcmdi_metrics import LOG_LEVEL
from pcmdi_metrics.utils import StringConstructor

try:
basestring # noqa
Expand All @@ -17,12 +17,12 @@ def __init__(self):
logging.getLogger("pmp").setLevel(LOG_LEVEL)

def process_templated_argument(self, name, default_value="*", extras=None):
"""Applies arg parse values to a genutil.StringConstructor template type argument
"""Applies arg parse values to a StringConstructor template type argument
Input:
name: name of the argument to process
extra: other object(s) to get keys from, superseeds argparse object
Output:
formatted argument as a genutil.StringConstructor
formatted argument as a StringConstructor
"""

process = getattr(self, name, None)
Expand All @@ -31,7 +31,7 @@ def process_templated_argument(self, name, default_value="*", extras=None):
): # Ok not an argument from arg_parse maybe a template or string constructor itself
if isinstance(name, basestring):
process = name
elif isinstance(name, genutil.StringConstructor):
elif isinstance(name, StringConstructor):
process = name.template
else:
raise RuntimeError(
Expand All @@ -49,7 +49,7 @@ def process_templated_argument(self, name, default_value="*", extras=None):
sources = [extras]

sources.insert(0, self) # will use itself as default source
process = genutil.StringConstructor(process)
process = StringConstructor(process)
for key in process.keys():
for source in sources:
setattr(process, key, getattr(source, key, default_value))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
import cdp
import cdtime
import cdutil
import genutil
import numpy

from pcmdi_metrics.mean_climate.lib.pmp_parser import PMPParser
from pcmdi_metrics.utils import StringConstructor

try:
import cmor
Expand Down Expand Up @@ -201,7 +201,7 @@ def load_parser(parser):

for A in As:
for tmpl in [A.modpath, A.filename_template, A.output_filename_template]:
con = genutil.StringConstructor(tmpl)
con = StringConstructor(tmpl)
print("TEMPLE:", con.template)
for k in con.keys():
print("ADDING OPTION:", k)
Expand Down Expand Up @@ -648,7 +648,7 @@ def runClim(A):
print(B1.tocomp(cal), "<", t, "<", B2.tocomp(cal))
bounds.append([B1.torel(Tunits, cal).value, B2.torel(Tunits, cal).value])

fnmout = genutil.StringConstructor(A.output_filename_template)
fnmout = StringConstructor(A.output_filename_template)

if "model_id" in fnmout.keys():
model_id = checkCMORAttribute("model_id")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
import json
import os

from genutil import StringConstructor

from pcmdi_metrics.utils import StringConstructor
from pcmdi_metrics.variability_mode.lib import dict_merge


Expand Down
3 changes: 1 addition & 2 deletions pcmdi_metrics/mjo/scripts/parallel_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@
import os
from argparse import RawTextHelpFormatter

from genutil import StringConstructor

from pcmdi_metrics.mean_climate.lib.pmp_parser import PMPParser
from pcmdi_metrics.misc.scripts import parallel_submitter
from pcmdi_metrics.mjo.lib import AddParserArgument
from pcmdi_metrics.utils import StringConstructor
from pcmdi_metrics.variability_mode.lib import sort_human

# =================================================
Expand Down
5 changes: 1 addition & 4 deletions pcmdi_metrics/mjo/scripts/post_process_merge_jsons.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
#!/usr/bin/env python

from __future__ import print_function

import copy
import glob
import json
import os

from genutil import StringConstructor

from pcmdi_metrics.mjo.lib import dict_merge
from pcmdi_metrics.utils import StringConstructor


def main():
Expand Down
4 changes: 2 additions & 2 deletions pcmdi_metrics/monsoon_wang/monsoon_wang_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
import os

import cdms2
import genutil
import numpy
from genutil import statistics

import pcmdi_metrics
from pcmdi_metrics import resources
from pcmdi_metrics.mean_climate.lib.pmp_parser import PMPParser
from pcmdi_metrics.monsoon_wang import mpd, mpi_skill_scores
from pcmdi_metrics.utils import StringConstructor


def create_monsoon_wang_parser():
Expand Down Expand Up @@ -78,7 +78,7 @@ def create_monsoon_wang_parser():

def monsoon_wang_runner(args):
# args = P.parse_args(sys.argv[1:])
modpath = genutil.StringConstructor(args.test_data_path)
modpath = StringConstructor(args.test_data_path)
modpath.variable = args.modvar
outpathdata = args.results_dir
if isinstance(args.modnames, str):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import MV2 as MV
import xarray as xr
from genutil import StringConstructor

from pcmdi_metrics.mean_climate.lib.pmp_parser import PMPParser
from pcmdi_metrics.precip_distribution.lib import (
Expand All @@ -15,6 +14,7 @@
precip_distribution_cum,
precip_distribution_frq_amt,
)
from pcmdi_metrics.utils import StringConstructor

# Read parameters
P = PMPParser()
Expand Down
2 changes: 1 addition & 1 deletion pcmdi_metrics/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from .create_land_sea_mask import apply_landmask, create_land_sea_mask
from .create_target_grid import create_target_grid
from .sort_human import sort_human
from .string_constructor import fill_template
from .string_constructor import StringConstructor, fill_template
from .tree_dict import tree
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
import os
from argparse import RawTextHelpFormatter

from genutil import StringConstructor

from pcmdi_metrics.mean_climate.lib.pmp_parser import PMPParser
from pcmdi_metrics.misc.scripts import parallel_submitter
from pcmdi_metrics.utils import StringConstructor
from pcmdi_metrics.variability_mode.lib import (
AddParserArgument,
VariabilityModeCheck,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
import json
import os

from genutil import StringConstructor

from pcmdi_metrics.utils import StringConstructor
from pcmdi_metrics.variability_mode.lib import dict_merge


Expand Down
4 changes: 1 addition & 3 deletions pcmdi_metrics/variability_mode/variability_modes_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@

from pcmdi_metrics import resources
from pcmdi_metrics.mean_climate.lib import pmp_parser
from pcmdi_metrics.utils import fill_template
from pcmdi_metrics.utils import fill_template, sort_human, tree
from pcmdi_metrics.variability_mode.lib import (
AddParserArgument,
VariabilityModeCheck,
Expand All @@ -78,8 +78,6 @@
linear_regression_on_globe_for_teleconnection,
plot_map,
read_data_in,
sort_human,
tree,
variability_metrics_to_json,
write_nc_output,
)
Expand Down
Loading