Created
August 4, 2020 11:40
-
-
Save Ovewh/ecb6b85ffcff8c25fe8b3847fe149b05 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
from IPython import embed | |
import pandas as pd | |
import argparse as ap | |
""" | |
DESCRIPTION | |
=========== | |
Creates file containing the paths to the forcing required to run FLEXPART | |
USAGE | |
===== | |
$ python gen_available.py --filename=NAME_OF_OUTFILE path/to/parent/directory EA | |
AUTHOR | |
====== | |
Ove Haugvaldstad | |
ovehaugv@outlook.com | |
""" | |
if __name__ == "__main__": | |
parser = ap.ArgumentParser(description='Create file containing paths to the FLEXPART WINDFIELDS') | |
parser.add_argument('path', help='path to parent directory containing the FLEXPART windfields') | |
parser.add_argument('tag', help='''Characters at the beging of the forcing file, | |
used to seperate foricing file from other files''') | |
parser.add_argument('--filename', '--fn', default='AVAILABLE_WINDFIELDS') | |
args = parser.parse_args() | |
path_to_dir = args.path | |
tag = args.tag | |
outfile_name = args.filename | |
pathFile = open(outfile_name, 'w') | |
pathFile.write('DATE TIME FILENAME SPECIFICATIONS\n') | |
pathFile.write(' YYYYMMDD HHMISS\n') | |
pathFile.write(' ________ ______ __________________ __________________\n') | |
paths = [] | |
for dirPath, dirName, filenames in os.walk(path_to_dir): | |
if filenames: | |
for filename in filenames: | |
if filename.startswith(tag): | |
paths.append('{}/{}'.format(dirPath,filename)) | |
paths.sort() | |
for path in paths: | |
timesrt = path[-8:] | |
time_stamp = pd.to_datetime(timesrt, format='%y%m%d%H') | |
if path == paths[-1]: | |
pathFile.write('{} '.format(time_stamp.strftime(format='%Y%m%d %H%M%S')) +path + ' ON DISC') | |
else: | |
pathFile.write('{} '.format(time_stamp.strftime(format='%Y%m%d %H%M%S')) +path + ' ON DISC\n') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment