Sitelet https://github.com/SHTOOLS/SHTOOLS/pull/449
Skip to content

Add pathlib support to input and output - #449

Merged
MarkWieczorek merged 4 commits into
SHTOOLS:developfrom
jschmaia:master
Mar 15, 2024
Merged

MarkWieczorek merged 4 commits into
SHTOOLS:developfrom
jschmaia:master

Conversation

@jschmaia

@jschmaia jschmaia commented Mar 2, 2024

Copy link
Copy Markdown

With this change you can pass pathlib.Path to shread and other input/output functions, including SHCoeffs.to/from_file, SHGravCoeffs.to/from_file and SHMagCoeffs.to/from_file.

  • Base all changes on the develop branch: the master branch is used only when releasing new versions.
  • Run make check to ensure that the python code follows standard formatting conventions.
  • If adding new features, update the docstring to provide all information that is required to use the feature.

@MarkWieczorek

Copy link
Copy Markdown
Member

This looks good to me! But could you also make a few small changes so that this works in other routines as well?

  • shclasses.shgeoid.to_netcdf() - we just need to update the docstring so that people know you can also use a Path.
  • shio.shwrite(), read_igrf(), read_icgem(), read_dov(), write_dov(), read bshc(), write_bshc() - just copy to path to string conversion at the begging of each method.

And...

I noticed theshcoeffs.to_file() is a bit odd when using .gz files. This calls the shio method, which can deal with .gz files fine. However, shcoeffs.to_file() writes a text file by calling shio.write_xxx and then gzips it afterwards. I think that we can just remove all the gz and filebase stuff in shcoeffs.to_file() and just pass the Path directly to the dedicated write routine. If you don't want to make so many changes, I can easily do this myself later.

@jschmaia

Copy link
Copy Markdown
Author

I did a new commit with the small changes you suggested:

  • updating the docstring of shclasses.shgeoid.to_netcdf()
  • adding the path to str conversion and associated docstring changes to the methods: read_bshc(), write_bshc(), read_dov, write_dov, read_icgem_gfc(), write_icgem_gfc(), read_igrf(),shio.shwrite()

@MarkWieczorek
MarkWieczorek merged commit 96caf54 into SHTOOLS:develop Mar 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants