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

TypeError encountered when running file_regrid.py #278

Closed
3 tasks done
yantosca opened this issue Dec 7, 2023 · 1 comment · Fixed by #279
Closed
3 tasks done

TypeError encountered when running file_regrid.py #278

yantosca opened this issue Dec 7, 2023 · 1 comment · Fixed by #279
Assignees
Labels
category: Bug Something isn't working topic: Regridding Issues pertaining to horizontal & vertical regridding
Milestone

Comments

@yantosca
Copy link
Contributor

yantosca commented Dec 7, 2023

Name and Institution (Required)

Name: Bob Yantosca
Institution: Harvard + GCST

Confirm you have reviewed the following documentation

Description of your issue or question

When using the file_regrid.py script as described in the documentation, a TypeError is encountered.

To reproduce

$ python -m gcpy.file_regrid                                       \
    --filein         ./GEOSChem.Restart.Hg.20190101_0000z.nc4      \
    --dim_format_in  classic                                       \ 
    --fileout        ./GEOSChem.Restart.Hg.20190101_0000z.c24.nc4  \
    --cs_res_out     24                                            \
    --dim_format_out checkpoint

... etc...

Traceback (most recent call last):
  File "/n/jacob_lab/Users/ryantosca/mamba/envs/gcpy_env/lib/python3.9/runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/n/jacob_lab/Users/ryantosca/mamba/envs/gcpy_env/lib/python3.9/runpy.py", line 87, in _run_code    exec(code, run_globals)
  File "/n/home09/ryantosca/python/gcpy/gcpy/file_regrid.py", line 1565, in <module>
    main()
  File "/n/home09/ryantosca/python/gcpy/gcpy/file_regrid.py", line 1549, in main
    file_regrid(
  File "/n/home09/ryantosca/python/gcpy/gcpy/file_regrid.py", line 174, in file_regrid
    dset = regrid_ll_to_cssg(
  File "/n/home09/ryantosca/python/gcpy/gcpy/file_regrid.py", line 644, in regrid_ll_to_cssg
    regridders = make_regridder_L2S(
  File "/n/home09/ryantosca/python/gcpy/gcpy/regrid.py", line 298, in make_regridder_L2S
    weightsfile = os.path.join(
  File "/n/jacob_lab/Users/ryantosca/mamba/envs/gcpy_env/lib/python3.9/posixpath.py", line 76, in join
    a = os.fspath(a)
TypeError: expected str, bytes or os.PathLike object, not bool

Explanation

I have traced this to this block of code where the command-line arguments are parsed:

    parser.add_argument(
        "-w", "--weightsdir",
        metavar="WGT",
        type=str,
        default=False,
        help="Directory where regridding weights are found (or will be created)"
    )
    args = parser.parse_args()

Note that the regridding weights directory (--weightsdir argument) should be a string but it has a default value of False (which is of type bool). This was likely a cut-n-paste error.

Solution

Changing the

default=False

to

default="."

fixes the issue. I will prepare a PR with this fix.

Temporary workaround

This error only happens when the --weightsdir argument is not supplied, which causes the default value to be used. Until we can fix this issue, make sure to call file_regrid.py with e.g. --weightsdir ".".

@yantosca yantosca added category: Bug Something isn't working topic: Regridding Issues pertaining to horizontal & vertical regridding labels Dec 7, 2023
@yantosca yantosca added this to the 1.4.1 milestone Dec 7, 2023
@yantosca yantosca self-assigned this Dec 7, 2023
yantosca added a commit that referenced this issue Dec 7, 2023
This commit fixes the bug described in #278.

gcpy/file_regrid.py
- Change the default value for weightsdir from False to "." where
  command line arguments are parsed.  This will prevent a TypeError.
  This bug was likely caused by a cut-n-paste error.

Signed-off-by: Bob Yantosca <[email protected]>
yantosca added a commit that referenced this issue Dec 8, 2023
This is the official release commit for GCPy 1.4.1.

This is a bugfix release that fixes the issue that was described in
issue #278.  This was resolved with PR #279.

Signed-off-by: Bob Yantosca <[email protected]>
@yantosca
Copy link
Contributor Author

yantosca commented Dec 8, 2023

This is now fixed by PR #279, which has been included in GCPy 1.4.1.

@yantosca yantosca closed this as completed Dec 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category: Bug Something isn't working topic: Regridding Issues pertaining to horizontal & vertical regridding
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant