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

Handling moving of the base folder #13

Open
lan13005 opened this issue Feb 19, 2025 · 0 comments
Open

Handling moving of the base folder #13

lan13005 opened this issue Feb 19, 2025 · 0 comments

Comments

@lan13005
Copy link
Owner

lan13005 commented Feb 19, 2025

Everything in these fits are dumped relative to a specific folder. If this folder is moved, everything breaks since all the paths are now broken.

In general the main update that should occur is just to update the base directory in the yaml pair.

At some point we should copy the pyamptools.yaml and iftpwa.yaml files to the base directory and update the auto-copied yaml files to point to each other. niftyresults.pkl file also stores a copy of the yaml file, perhaps giving it the path to the yaml file is better than the dictionary itself (have IntensityCalculator search a relative path for the yaml_file)

Below shows example of what needs to be updated in the yaml pair and the pkl result file

import os

orig_dir = "/w/halld-scshelf2101/lng/WORK/PyAmpTools9/OTHER_CHANNELS/ETAPI0_ZACH/"
new_dir = "/w/halld-scshelf2101/lng/WORK/PyAmpTools9/OTHER_CHANNELS/ETAPI0_ZACH/5tbins_v0/"
PYAMPTOOLS_HOME = os.environ["PYAMPTOOLS_HOME"]

for i in range(4):
    
    os.system(f"rm -rf {new_dir}/RESULTS_t{i}")
    os.system(f"mkdir -p {new_dir}/RESULTS_t{i}")
    os.system(f"cp -r {new_dir}/RESULTS_t{i}_backup/NiftyFits {new_dir}/RESULTS_t{i}/")
    os.system(f"cp -r {new_dir}/RESULTS_t{i}_backup/*.pkl {new_dir}/RESULTS_t{i}/")
    os.system(f"cp -r {new_dir}/RESULTS_t{i}_backup/*.cfg {new_dir}/RESULTS_t{i}/")
    os.system(f"ln -s {new_dir}/RESULTS_t{i}_backup/AmpToolsFits {new_dir}/RESULTS_t{i}/")

    #### Automatically copied yaml file locations ####
    pya_yaml = f"RESULTS_t{i}/NiftyFits/.pyamptools_tdep.yaml"
    ift_yaml = f"RESULTS_t{i}/NiftyFits/.nifty_expanded.yaml"
    
    #### update pyamptools.yaml ####
    os.system(f"sed -i 's|{orig_dir}|{new_dir}|g' {pya_yaml}")
    # yaml: /w/halld-scshelf2101/lng/WORK/PyAmpTools9/OTHER_CHANNELS/ETAPI0_ZACH/5tbins_v0/iftpwa_tdep.yaml
    src = f"yaml: {new_dir}iftpwa_tdep.yaml"
    rep = f"yaml: {new_dir}/{ift_yaml}"
    os.system(f"sed -i 's|{src}|{rep}|g' {pya_yaml}")
    print(f"updated {new_dir}/{pya_yaml}")
    
    #### update nifty_expanded.yaml ####
    os.system(f"sed -i 's|{orig_dir}|{new_dir}|g' {ift_yaml}")
    src = f"yaml_file: {new_dir}pyamptools_tdep.yaml"
    rep = f"yaml_file: {new_dir}/{pya_yaml}"
    os.system(f"sed -i 's|{src}|{rep}|g' {ift_yaml}")
    print(f"updated {new_dir}/{ift_yaml}")
    
    pkl_floc = f"RESULTS_t{i}/NiftyFits/niftypwa_fit.pkl"
    # update stored pyamptools yaml file in pkl file
    os.system(f"python {PYAMPTOOLS_HOME}/bin/update_ift_pkl.py {pkl_floc} 'base_directory' '{new_dir}/RESULTS_t{i}/'")
    os.system(f"python {PYAMPTOOLS_HOME}/bin/update_ift_pkl.py {pkl_floc} 'yaml' '{new_dir}/RESULTS_t{i}/NiftyFits/.nifty_expanded.yaml'")
    # update stored iftpwa yaml file in pkl file
    os.system(f"python {PYAMPTOOLS_HOME}/bin/update_ift_pkl.py {pkl_floc} 'outputFolder' '{new_dir}/RESULTS_t{i}/NiftyFits/'")
    os.system(f"python {PYAMPTOOLS_HOME}/bin/update_ift_pkl.py {pkl_floc} 'fitResultPath' '{new_dir}/RESULTS_t{i}/NiftyFits/niftypwa_fit.pkl'")
    os.system(f"python {PYAMPTOOLS_HOME}/bin/update_ift_pkl.py {pkl_floc} 'yaml_file' '{new_dir}/RESULTS_t{i}/NiftyFits/.pyamptools_tdep.yaml'")
    os.system(f"python {PYAMPTOOLS_HOME}/bin/update_ift_pkl.py {pkl_floc} 'niftyCache' '{new_dir}/RESULTS_t{i}/NiftyFits/'")
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

No branches or pull requests

1 participant