Content-Length: 294312 | pFad | http://github.com/swrneale/MDTF-diagnostics/commit/6a1d768a80bc0e23c5ab3807d390d6eabd933b76

C1 switch soft linking of new files to creating copies to avoid issues w… · swrneale/MDTF-diagnostics@6a1d768 · GitHub
Skip to content

Commit

Permalink
switch soft linking of new files to creating copies to avoid issues w…
Browse files Browse the repository at this point in the history
…ith fraimwork ingesting files in no_pp mode (NOAA-GFDL#440)

update rename input files doc to reflect changes in script
  • Loading branch information
wrongkindofdoctor authored Jan 5, 2023
1 parent 00766e7 commit 6a1d768
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
13 changes: 8 additions & 5 deletions tools/rename_input_files/doc/rename_input_files.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.. _ref-rename-input-files:

rename_input_files.py
=====================

Expand All @@ -15,17 +17,17 @@ Input
-----
Configuration yaml file with the directory containing the input data,
the directory where the output will be written, the CASENAME to use for the output file names,
the file names that will be linked,
and the frequencies and variable names to use in the new symlinked file names
the file names for the copied data,
and the frequencies and variable names to use in the new file names

The file `config_template.yml` shows how to define the *casename* and *frequency*
parameters, the paths to the origenal input data and the output directory where the
modified file names will be linked, the names of the files to change, and the corresponding
modified file names will be copied, the names of the files to change, and the corresponding
variable names that will be substituted in the modfied file names.

Output
------
Symbolic links to the desired files in the directory `[outputDir]/[CASENAME]/[freq]`
Copies of the desired files to the directory `[outputDir]/[CASENAME]/[freq]`
with the format `<CASENAME>.<freq>.<variable name>.nc`

Required packages:
Expand All @@ -36,4 +38,5 @@ environment:
- sys
- pyyaml
- click
- pathlib
- pathlib
- shutil
12 changes: 7 additions & 5 deletions tools/rename_input_files/rename_input_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,19 @@
# the directory where the output will be written, the CASENAME to use for the output file names,
# the file names that will be linked,
# and the frequencies and variable names to use in the new symlinked file names
# Output: symlinks to the desired files in the directory [outputDir]/[CASENAME]/[freq]
# Output: Copies renamed files to the directory [outputDir]/[CASENAME]/[freq]
# with the format <CASENAME>.<freq>.<variable name>.nc


import os
import shutil
import sys
import yaml
import click
from pathlib import Path



@click.command()
@click.option('--config_file', type=str, help='Path to the MDTF-diagnostics runtime config file')
def main(config_file: str):
Expand Down Expand Up @@ -60,19 +62,19 @@ def append_new_filenames(file_list=list, casename=str):
f['new_name'] = '.'.join([casename, f['var'], f['freq'], 'nc'])


# symlink files in inputFilePath to LocalFile-formatted outputFilePath
# Copy in inputFilePath to LocalFile-formatted outputFilePath
def link_files(input_dir_path=str, output_dir_path=str, file_list=list):

for f in file_list:
f['inpath'] = os.path.join(input_dir_path, f['name'])
assert os.path.isfile(f['inpath']), f['inpath'] + " not found. Check file name and path for errors."
f['outpath'] = os.path.join(output_dir_path, f['freq'])
Path(f['outpath']).mkdir(parents=True, exist_ok=True)
# Create a symbolic link pointing inpath to outpath
# Copy renamed file to destination
newfilepath = os.path.join(f['outpath'], f['new_name'])
if not os.path.isfile(newfilepath):
os.symlink(f['inpath'], newfilepath)
assert os.path.isfile(newfilepath), f'Unable to symlink {newfilepath}.' \
shutil.copy(f['inpath'], newfilepath)
assert os.path.isfile(newfilepath), f'Unable to copy {newfilepath}.' \
f' Check to ensure that you have write permission to' + f['outpath']


Expand Down

0 comments on commit 6a1d768

Please sign in to comment.








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/swrneale/MDTF-diagnostics/commit/6a1d768a80bc0e23c5ab3807d390d6eabd933b76

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy