diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 467e1e9eaafa8f69a9ebe3c0d6ebe6672a19e8a7..d6c268605f07eb1e8dcd3c8188a5e01c32d274c5 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -4,6 +4,19 @@ CHANGELOG .. start-here +1.1.11 +============ + +* Release date: 2025/07/07 +* Changes and new features: + + * New Command Line Interface nes with: + + * nes nc2geostructure + * nes check + * nes reorder + * nes interpolate + 1.1.10 ============ diff --git a/nes/cli/checker.py b/nes/cli/checker.py index fb81228738d8ccd04ad07d51e71ad8055a6f9b06..3651710701c8cd603facf021cdb9c425c385d2eb 100644 --- a/nes/cli/checker.py +++ b/nes/cli/checker.py @@ -2,13 +2,13 @@ from nes.load_nes import open_netcdf from numpy import isinf, isnan -def run_checks(file: str, check_nan: bool = True, check_inf: bool = True): +def run_checks(input_file: str, check_nan: bool = True, check_inf: bool = True): """ Check for NaN and/or Inf values in all variables of a NetCDF file. Parameters ---------- - file : str + input_file : str Path to the input NetCDF file. check_nan : bool, optional Whether to check for NaN (Not a Number) values. Default is True. @@ -27,7 +27,7 @@ def run_checks(file: str, check_nan: bool = True, check_inf: bool = True): reads all variables into memory before performing the checks. """ # Open the NetCDF file with NES (metadata only) - dataset = open_netcdf(file) + dataset = open_netcdf(input_file) # Load all variable data into memory dataset.load() diff --git a/nes/cli/cli.py b/nes/cli/cli.py index 124af48e298561009376020cc43547d95fa71caa..7574a6755646ebf14fa2310803be17f16471089e 100644 --- a/nes/cli/cli.py +++ b/nes/cli/cli.py @@ -19,8 +19,8 @@ def _add_nc2geostructure_subparser(subparsers): # TODO: TEST geo_parser = subparsers.add_parser("nc2geostructure", help="Convert NetCDF to geospatial structure (GeoJSON, shapefile) (TESTING PHASE)") - geo_parser.add_argument("-i", "--input", required=True, help="Path to input NetCDF file") - geo_parser.add_argument("-o", "--output", required=True, help="Path to output geostructure") + geo_parser.add_argument("-i", "--input_file", required=True, help="Path to input NetCDF file") + geo_parser.add_argument("-o", "--output_file", required=True, help="Path to output geostructure") geo_parser.add_argument( "--var-list", nargs="+", help="List of variable names to include in the geostructure. If omitted, all variables will be included." @@ -49,8 +49,8 @@ def _add_interpolate_subparser(subparsers): # Main input/output general = interp_parser.add_argument_group("General options") - general.add_argument("-i", "--input", required=True, help="Path to source NetCDF file") - general.add_argument("-o", "--output", help="Path to output NetCDF file") + general.add_argument("-i", "--input_file", required=True, help="Path to source NetCDF file") + general.add_argument("-o", "--output_file", help="Path to output NetCDF file") general.add_argument("--axis", choices=["horizontal", "vertical"], default="horizontal", help="Interpolation axis (default: horizontal)") @@ -127,7 +127,7 @@ def _add_check_subparser(subparsers): from nes.cli import run_checks check_parser = subparsers.add_parser("check", help="Run checks on a NetCDF file") - check_parser.add_argument("-i", "--input", required=True, help="Input NetCDF file path") + check_parser.add_argument("-i", "--input_file", required=True, help="Input NetCDF file path") check_parser.add_argument("--nan", dest="check_nan", action="store_true", help="Check for NaN values") check_parser.add_argument("--no-nan", dest="check_nan", action="store_false", help="Do not check NaN values") check_parser.add_argument("--inf", dest="check_inf", action="store_true", help="Check for Inf values") @@ -151,8 +151,8 @@ def _add_reorder_subparser(subparsers): # TODO: Add support for parallel version reorder_parser = subparsers.add_parser("reorder", help="Reorder longitudes in a NetCDF file (ONLY SERIAL)") - reorder_parser.add_argument("-i", "--input", required=True, help="Input NetCDF file path") - reorder_parser.add_argument("-o", "--output", help="Output NetCDF file path") + reorder_parser.add_argument("-i", "--input_file", required=True, help="Input NetCDF file path") + reorder_parser.add_argument("-o", "--output_file", help="Output NetCDF file path") reorder_parser.set_defaults(func=reorder_longitudes) @@ -177,6 +177,7 @@ def _filter_args(func, args_namespace): arg_keys = set(sig.parameters.keys()) args_dict = vars(args_namespace) filtered = {k: args_dict[k] for k in arg_keys if k in args_dict} + return filtered diff --git a/nes/cli/geostructure.py b/nes/cli/geostructure.py index 40e49a1ac9f5ff92fcc997e2ab5eea57dadf4743..ca4810a9e6e036f45117a62fcbedfee533142ffd 100644 --- a/nes/cli/geostructure.py +++ b/nes/cli/geostructure.py @@ -42,17 +42,17 @@ def nc2geostructure(input_file: str, output_file: str, var_list: list=None, time nessy.sel( time_min=nessy.time[time_step], # Minimum time index to extract time_max=nessy.time[time_step], # Maximum time index to extract (same as min for single step) - level_min=level, # Minimum vertical level to extract - level_max=level # Maximum vertical level to extract (same as min for single level) + lev_min=level, # Minimum vertical level to extract + lev_max=level # Maximum vertical level to extract (same as min for single level) ) # Filter to keep only the specified variables and load the data into memory - nessy.keep(var_list) + nessy.keep_vars(var_list) nessy.load() # Create the base geospatial structure (shapefile) and attach the selected variables nessy.create_shapefile() - nessy.add_variables_to_shapefile(idx_time=0, idx_lev=0) + nessy.add_variables_to_shapefile(idx_time=0, idx_lev=0, var_list=var_list) # Write the geospatial structure to the output shapefile nessy.write_shapefile(output_file) diff --git a/nes/cli/reorder_longitudes.py b/nes/cli/reorder_longitudes.py index 111e1987640ddc41aa4b8ae4fdf3c220022fa71a..b40d17fb7e69f33774199f9290f9c8fecb2b0b7a 100644 --- a/nes/cli/reorder_longitudes.py +++ b/nes/cli/reorder_longitudes.py @@ -2,13 +2,13 @@ from nes.load_nes import open_netcdf from mpi4py import MPI -def reorder_longitudes(infile: str, outfile: str): +def reorder_longitudes(input_file: str, output_file: str): """ Convert longitudes in a NetCDF file to the [-180, 180] range and save the modified file. Parameters ---------- - infile : str + input_file : str Path to the input NetCDF file. outfile : str Path where the reordered NetCDF file will be saved. @@ -30,7 +30,7 @@ def reorder_longitudes(infile: str, outfile: str): raise ValueError("This script must be run with a single process (serial mode only).") # Open the input NetCDF file - nc = open_netcdf(infile) + nc = open_netcdf(input_file) # Load data into memory nc.load()