-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* docs: bump `docutils` to latest
- Loading branch information
1 parent
10bdc56
commit d796b3f
Showing
12 changed files
with
519 additions
and
111 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
""" | ||
def_to_json.py (07/2024) | ||
Converts a definition file to a json file | ||
""" | ||
import re | ||
import json | ||
import pathlib | ||
import argparse | ||
|
||
def read_definition_file(definition_file): | ||
parameters = {} | ||
fid = open(definition_file, 'r') | ||
for fileline in fid: | ||
# Splitting the input line between parameter name and value | ||
part = fileline.rstrip().split(maxsplit=1) | ||
# filling the parameter definition variable | ||
parameters[part[0]] = part[1] | ||
fid.close() | ||
return parameters | ||
|
||
# PURPOSE: create argument parser | ||
def arguments(): | ||
parser = argparse.ArgumentParser( | ||
description="""Converts a definition file to a json file" | ||
""", | ||
fromfile_prefix_chars="@" | ||
) | ||
# command line parameters | ||
parser.add_argument('infile', | ||
type=pathlib.Path, nargs='+', | ||
help='Definition file to convert') | ||
parser.add_argument('--pretty', '-p', | ||
action='store_true', | ||
help='Pretty print the json file') | ||
parser.add_argument('--verbose', '-v', | ||
action='store_true', | ||
help='Verbose output') | ||
parser.add_argument('--cleanup', '-c', | ||
action='store_true', | ||
help='Remove original definition files') | ||
return parser | ||
|
||
def main(): | ||
# Read the system arguments listed after the program | ||
parser = arguments() | ||
args,_ = parser.parse_known_args() | ||
# iterate over each input file | ||
for definition_file in args.infile: | ||
print(f'{definition_file} -->') if args.verbose else None | ||
# Reading each definition file | ||
parameters = read_definition_file(definition_file) | ||
if re.search(r';', parameters['model_file']): | ||
# split model into list of files for each direction | ||
model_file_u, model_file_v = parameters['model_file'].split(';') | ||
parameters['model_file'] = dict( | ||
u=re.split(r'[\s\,]+', model_file_u), | ||
v=re.split(r'[\s\,]+', model_file_v) | ||
) | ||
elif re.search(r',', parameters['model_file']): | ||
# split model into list of files | ||
parameters['model_file'] = re.split(r'[\s\,]+', parameters['model_file']) | ||
if 'constituents' in parameters and re.search(r',', parameters['constituents']): | ||
parameters['constituents'] = re.split(r'[\s\,]+', parameters['constituents']) | ||
if 'type' in parameters and re.search(r',', parameters['type']): | ||
parameters['type'] = re.split(r'[\s\,]+', parameters['type']) | ||
if 'compressed' in parameters: | ||
parameters['compressed'] = eval(parameters['compressed']) | ||
if 'scale' in parameters: | ||
parameters['scale'] = float(parameters['scale']) | ||
# Writing the parameters to a json file | ||
json_file = definition_file.with_suffix('.json') | ||
print(f'\t{json_file}') if args.verbose else None | ||
with open(json_file, 'w') as fid: | ||
indent = 4 if args.pretty else None | ||
json.dump(parameters, fid, indent=indent) | ||
# Removing the definition file | ||
if args.cleanup: | ||
definition_file.unlink() | ||
|
||
if __name__ == '__main__': | ||
main() |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"format": "OTIS", "name": "CATS2008", "model_file": "CATS2008/hf.CATS2008.out", "grid_file": "CATS2008/grid_CATS2008", "projection": "CATS2008", "type": "z", "variable": "tide_ocean", "reference": "https://doi.org/10.15784/601235"} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"format": "FES", "name": "FES2012", "model_file": "fes2012/*_FES2012_SLEV.nc.gz", "type": "z", "version": "FES2012", "variable": "tide_ocean", "scale": 0.01, "compressed": true, "reference": "https://www.aviso.altimetry.fr/en/data/products/auxiliary-products/global-tide-fes.html"} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"format": "FES", "name": "FES2014", "model_file": ["fes2014/ocean_tide/2n2.nc.gz", "fes2014/ocean_tide/eps2.nc.gz", "fes2014/ocean_tide/j1.nc.gz", "fes2014/ocean_tide/k1.nc.gz", "fes2014/ocean_tide/k2.nc.gz", "fes2014/ocean_tide/l2.nc.gz", "fes2014/ocean_tide/la2.nc.gz", "fes2014/ocean_tide/m2.nc.gz", "fes2014/ocean_tide/m3.nc.gz", "fes2014/ocean_tide/m4.nc.gz", "fes2014/ocean_tide/m6.nc.gz", "fes2014/ocean_tide/m8.nc.gz", "fes2014/ocean_tide/mf.nc.gz", "fes2014/ocean_tide/mks2.nc.gz", "fes2014/ocean_tide/mm.nc.gz", "fes2014/ocean_tide/mn4.nc.gz", "fes2014/ocean_tide/ms4.nc.gz", "fes2014/ocean_tide/msf.nc.gz", "fes2014/ocean_tide/msqm.nc.gz", "fes2014/ocean_tide/mtm.nc.gz", "fes2014/ocean_tide/mu2.nc.gz", "fes2014/ocean_tide/n2.nc.gz", "fes2014/ocean_tide/n4.nc.gz", "fes2014/ocean_tide/nu2.nc.gz", "fes2014/ocean_tide/o1.nc.gz", "fes2014/ocean_tide/p1.nc.gz", "fes2014/ocean_tide/q1.nc.gz", "fes2014/ocean_tide/r2.nc.gz", "fes2014/ocean_tide/s1.nc.gz", "fes2014/ocean_tide/s2.nc.gz", "fes2014/ocean_tide/s4.nc.gz", "fes2014/ocean_tide/sa.nc.gz", "fes2014/ocean_tide/ssa.nc.gz", "fes2014/ocean_tide/t2.nc.gz"], "constituents": ["2n2", "eps2", "j1", "k1", "k2", "l2", "lambda2", "m2", "m3", "m4", "m6", "m8", "mf", "mks2", "mm", "mn4", "ms4", "msf", "msqm", "mtm", "mu2", "n2", "n4", "nu2", "o1", "p1", "q1", "r2", "s1", "s2", "s4", "sa", "ssa", "t2"], "type": "z", "version": "FES2014", "variable": "tide_ocean", "scale": 0.01, "compressed": true, "reference": "https://www.aviso.altimetry.fr/en/data/products/auxiliary-products/global-tide-fes.html"} |
Oops, something went wrong.