From 5f635141d8c6663bc377eb0643da97cdb49f19dc Mon Sep 17 00:00:00 2001 From: Hannah Zafar Date: Wed, 6 May 2026 15:52:05 -0400 Subject: [PATCH 1/4] Notes on data reader/syntax changes --- projects/EarthNow/bin/plotall.py | 36 +++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/projects/EarthNow/bin/plotall.py b/projects/EarthNow/bin/plotall.py index 0d6ea65..abf36ab 100755 --- a/projects/EarthNow/bin/plotall.py +++ b/projects/EarthNow/bin/plotall.py @@ -37,6 +37,9 @@ def parse_args(): # ------------------------------------------------------------------------- # Core required args # ------------------------------------------------------------------------- + # FIX: THIS ENTIRE ARG IS AN ISSUE - the data reader should be determined by the dates + # Also, just specifying the data reader won't override the other defaults (exp-path, collection, etc.) + # I'm assuming he just added this so he could plot GEOS-AI separately? parser.add_argument( "--data-reader", default="geos_cycled_replays", @@ -178,18 +181,16 @@ def create_data_reader(args): Handles different initialization signatures for different readers. """ - ReaderClass = DATA_READERS[args.data_reader] + ReaderClass = DATA_READERS[ + args.data_reader + ] # FIX: He returns the reader twice? Here and in the if statement - if args.data_reader == "geos_forward_processing": - # Forward Processing reader uses different parameters - reader = ReaderClass( - base_path=args.fp_base_path, - exp_id=args.exp_id, - collection=( - args.collection if args.collection != "inst1_2d_asm_Nx" else None - ), - ) - elif args.data_reader == "geos_cycled_replays": + # FIX: # I think this is if you put all the option fields: data-reader, exp_id, and collection - but if you only specify the data reader and nothing else it will still use defaults. So it will never have a args.data_reader be fp since its set via defaults... + # Ok for geos replay: this is the default inputs, but isn't this just duplicating what is already in the reader? + # OK WAIT ----- this second "call" specifies the map type from args I guess + # Is there a default map type? Like is the intial reader call even necessary + + if args.data_reader == "geos_cycled_replays": # Cycled Replays reader reader = ReaderClass( exp_path=args.exp_path, @@ -198,13 +199,24 @@ def create_data_reader(args): collection=args.collection, map_type=args.map_type, ) + elif args.data_reader == "geos_forward_processing": + # Forward Processing reader uses different parameters + reader = ReaderClass( + base_path=args.fp_base_path, + exp_id=args.exp_id, + collection=( + args.collection if args.collection != "inst1_2d_asm_Nx" else None + ), + ) elif args.data_reader == "gencast_geos_fp": # GenCast reader reader = ReaderClass( exp_path=args.exp_path, exp_res=args.exp_res, exp_id=args.exp_id ) + else: # Generic fallback - try all parameters and let reader handle it + # If no reader specified, try defaults #FIX: But the defaults is the replay????? try: reader = ReaderClass( exp_path=args.exp_path, @@ -214,7 +226,7 @@ def create_data_reader(args): map_type=args.map_type, ) except TypeError: - # If that fails, try minimal parameters + # If that fails, try minimal parameters # FIX: So i guess the reader doesn't need the maptype but would it still return data? reader = ReaderClass(exp_path=args.exp_path, exp_id=args.exp_id) return reader From b0314f5a2c94f672c64bc60fc14e75bd4441e616 Mon Sep 17 00:00:00 2001 From: Hannah Zafar Date: Tue, 5 May 2026 15:43:31 -0400 Subject: [PATCH 2/4] Add colorlog package for logging help --- projects/EarthNow/bin/plotall.py | 58 ++++++++++++++++++++++++++++++++ projects/EarthNow/pyproject.toml | 5 +++ projects/EarthNow/uv.lock | 20 +++++++++++ 3 files changed, 83 insertions(+) diff --git a/projects/EarthNow/bin/plotall.py b/projects/EarthNow/bin/plotall.py index abf36ab..02bfad7 100755 --- a/projects/EarthNow/bin/plotall.py +++ b/projects/EarthNow/bin/plotall.py @@ -22,6 +22,47 @@ from earthnow.data_readers import DATA_READERS from earthnow.products import PRODUCTS +import logging + + +# Create logger and colored handler function +def setup_logger(logger_level, enabled=True): + import logging + from colorlog import ColoredFormatter + from pathlib import Path + + # Set logger name to the script name for clarity in logs + script_name = Path(__file__).stem + logger = logging.getLogger(script_name) + + if not enabled: + logger.disabled = True + return logger + + logging.basicConfig( + # Change this based on what level you want to see + # level=logging.DEBUG, + level=logger_level, + ) + + handler = logging.StreamHandler() + handler.setFormatter( + ColoredFormatter("\n%(log_color)s %(levelname)s: %(name)s: %(message)s\n") + ) + logger.propagate = ( + False # Prevent logs from duplicating when using the colored formatting + ) + logger.addHandler(handler) + + # Silence matplotlib debug logs + logging.getLogger("matplotlib").setLevel(logging.WARNING) + + return logger + + +# Change this to logging.WARNING or logging.DEBUG to see more logs, or set enabled=False to disable all logging +logger = setup_logger(logging.DEBUG, enabled=True) + # ----------------------------------------------------------------------------- # ARGPARSE # ----------------------------------------------------------------------------- @@ -184,6 +225,7 @@ def create_data_reader(args): ReaderClass = DATA_READERS[ args.data_reader ] # FIX: He returns the reader twice? Here and in the if statement + logger.debug(f"Initial Reader: {ReaderClass=}") # FIX: # I think this is if you put all the option fields: data-reader, exp_id, and collection - but if you only specify the data reader and nothing else it will still use defaults. So it will never have a args.data_reader be fp since its set via defaults... # Ok for geos replay: this is the default inputs, but isn't this just duplicating what is already in the reader? @@ -232,6 +274,15 @@ def create_data_reader(args): return reader +def return_valid_directory(reader, args): + if reader.resolve_file(args.fdate, args.pdate) is not None: + return "Data reader directory found" + else: + raise FileNotFoundError( + f"Data reader could not find directory for fdate {args.fdate} and pdate {args.pdate}" + ) + + # ----------------------------------------------------------------------------- # STYLE BUILDER # ----------------------------------------------------------------------------- @@ -280,6 +331,13 @@ def plot_single_pdate(pdate, args, style, map_config): # Create reader for this worker reader = create_data_reader(local_args) + logger.debug( + f"Reader returned: {reader=}" + ) # This returns GEOS replay reader always + + # Test reader returns a valid directory + logger.debug(return_valid_directory(reader, local_args)) + sys.exit() # Call product function local_args.contour_label_size = map_config.contour_label_size diff --git a/projects/EarthNow/pyproject.toml b/projects/EarthNow/pyproject.toml index de2f62f..293d2df 100644 --- a/projects/EarthNow/pyproject.toml +++ b/projects/EarthNow/pyproject.toml @@ -49,3 +49,8 @@ exclude = [ "**/.DS_Store", "test*.py", ] + +[dependency-groups] +dev = [ + "colorlog>=6.10.1", +] diff --git a/projects/EarthNow/uv.lock b/projects/EarthNow/uv.lock index 79cba0b..f2f96e4 100644 --- a/projects/EarthNow/uv.lock +++ b/projects/EarthNow/uv.lock @@ -236,6 +236,18 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/d1/d6/3965ed04c63042e047cb6a3e6ed1a63a35087b6a609aa3a15ed8ac56c221/colorama-0.4.6-py2.py3-none-any.whl", hash = "sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6", size = 25335, upload-time = "2022-10-25T02:36:20.889Z" }, ] +[[package]] +name = "colorlog" +version = "6.10.1" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "colorama", marker = "sys_platform == 'win32'" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/a2/61/f083b5ac52e505dfc1c624eafbf8c7589a0d7f32daa398d2e7590efa5fda/colorlog-6.10.1.tar.gz", hash = "sha256:eb4ae5cb65fe7fec7773c2306061a8e63e02efc2c72eba9d27b0fa23c94f1321", size = 17162, upload-time = "2025-10-16T16:14:11.978Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/6d/c1/e419ef3723a074172b68aaa89c9f3de486ed4c2399e2dbd8113a4fdcaf9e/colorlog-6.10.1-py3-none-any.whl", hash = "sha256:2d7e8348291948af66122cff006c9f8da6255d224e7cf8e37d8de2df3bad8c9c", size = 11743, upload-time = "2025-10-16T16:14:10.512Z" }, +] + [[package]] name = "comm" version = "0.2.3" @@ -407,6 +419,11 @@ dev = [ { name = "xarray" }, ] +[package.dev-dependencies] +dev = [ + { name = "colorlog" }, +] + [package.metadata] requires-dist = [ { name = "astropy" }, @@ -429,6 +446,9 @@ requires-dist = [ ] provides-extras = ["dev"] +[package.metadata.requires-dev] +dev = [{ name = "colorlog", specifier = ">=6.10.1" }] + [[package]] name = "executing" version = "2.2.1" From 5410f9b1963a03562a5668f7d8f02c0779c7e63e Mon Sep 17 00:00:00 2001 From: Hannah Zafar Date: Wed, 6 May 2026 15:53:45 -0400 Subject: [PATCH 3/4] Default logger to false --- projects/EarthNow/bin/plotall.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/EarthNow/bin/plotall.py b/projects/EarthNow/bin/plotall.py index 02bfad7..559f53a 100755 --- a/projects/EarthNow/bin/plotall.py +++ b/projects/EarthNow/bin/plotall.py @@ -61,7 +61,7 @@ def setup_logger(logger_level, enabled=True): # Change this to logging.WARNING or logging.DEBUG to see more logs, or set enabled=False to disable all logging -logger = setup_logger(logging.DEBUG, enabled=True) +logger = setup_logger(logging.DEBUG, enabled=False) # ----------------------------------------------------------------------------- # ARGPARSE From 3a359bbf53cdc436fc66d4c6f258a244165144db Mon Sep 17 00:00:00 2001 From: Hannah Zafar Date: Wed, 6 May 2026 16:30:37 -0400 Subject: [PATCH 4/4] Remove exit line --- projects/EarthNow/bin/plotall.py | 1 - 1 file changed, 1 deletion(-) diff --git a/projects/EarthNow/bin/plotall.py b/projects/EarthNow/bin/plotall.py index 559f53a..5a97521 100755 --- a/projects/EarthNow/bin/plotall.py +++ b/projects/EarthNow/bin/plotall.py @@ -337,7 +337,6 @@ def plot_single_pdate(pdate, args, style, map_config): # Test reader returns a valid directory logger.debug(return_valid_directory(reader, local_args)) - sys.exit() # Call product function local_args.contour_label_size = map_config.contour_label_size