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

On ppan, use hsmget to copy model files before opening #144

Merged
merged 3 commits into from
Feb 13, 2025

Conversation

andrew-c-ross
Copy link
Contributor

@andrew-c-ross andrew-c-ross commented Feb 13, 2025

Another PR to build towards working with an updated historical simulation. This one adds a wrapper around the hsmget tool and uses it in the open_var function so that model data is opened from /vftmp instead of /archive.

The general usage is

hsmget = HSMGet()
ncfile = hsmget(Path('/archive/acr/fre/NWA/2025_01/NWA12_COBALT_2025_01/gfdl.ncrc6-intel23-prod-hdf5/pp/ocean_monthly/ts/monthly/5yr/ocean_monthly.199301-199712.ssh.nc'))
ds = xarray.open_dataset(ncfile) # etc

If the above is run on ppan, it will copy the file from archive to
/ptmp/$USER/archive/acr/fre/NWA/2025_01/NWA12_COBALT_2025_01/gfdl.ncrc6-intel23-prod-hdf5/pp/ocean_monthly/ts/monthly/5yr/ocean_monthly.199301-199712.ssh.nc

And then from there to
/vftmp/$USER/pid####/archive/acr/fre/NWA/2025_01/NWA12_COBALT_2025_01/gfdl.ncrc6-intel23-prod-hdf5/pp/ocean_monthly/ts/monthly/5yr/ocean_monthly.199301-199712.ssh.nc

Finally it will return the above /vftmp path as a Path.

Future runs of the script from the same ppan session will use the vftmp file immediately. Otherwise, the file will be quickly copied from ptmp as long as that hasn't been swept.

The biggest advantage of this function would be to work with the raw history files, since frepp will also cache those files in the same place on /ptmp. It's still an improvement to not read the post-processed files directly from archive, though.

If the hsmget module isn't loaded or the script isn't running on ppan, hsmget() should just do nothing and directly return the input path(s), allowing them to be opened as usual.

@andrew-c-ross andrew-c-ross added the enhancement New feature or request label Feb 13, 2025
Copy link
Collaborator

@uwagura uwagura left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ran this successfully with hsmget, everything looks good!


def __call__(self, path_or_paths):
if which('hsmget') is None or not self._dirs_exist():
# If hsmget or /archive, /ptmp, etc are not available, this will just return the input path(s).
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this assumes the user has already module loaded hsmget, maybe we should tell the user somewhere to run that command beforehand if they want to use hsmget?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea! I added a reminder to the log message, a comment, and a note in the README.

return xarray.open_mfdataset(files)[var]
# For now, replicate previous behavior by looking for a single file covering 1993--2019,
# and if not found then looking for multiple files written in either yearly or 5-yearly chunks.
# Later this can be replaced to more intelligently look for the right file(s).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this comment intelligently look for the right file(s) : )

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a PR ready for once this one is merged 😃

@yichengt900 yichengt900 merged commit 6445e87 into NOAA-GFDL:main Feb 13, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants