-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2462 from dtcenter/bugfix_2428_python_from_env_2
Bugfix 2428 python embedding with MET_PYTHON_EXE defined
- Loading branch information
Showing
16 changed files
with
942 additions
and
306 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
######################################################################## | ||
# | ||
# Reads temporary point obs. file into memory. | ||
# | ||
# usage: /path/to/python read_tmp_point_nc.py tmp_output_filename | ||
# | ||
######################################################################## | ||
|
||
import os | ||
import sys | ||
|
||
# add share/met/python directory to system path to find met_point_obs | ||
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), | ||
os.pardir, 'python'))) | ||
from met_point_obs import met_point_obs | ||
from met_point_obs_nc import nc_point_obs | ||
|
||
netcdf_filename = sys.argv[1] | ||
|
||
# read NetCDF file | ||
print('{p} reading{f}'.format(p=met_point_obs.get_prompt(), f=netcdf_filename)) | ||
point_obs_data = nc_point_obs() | ||
point_obs_data.read_data(netcdf_filename) | ||
|
||
met_point_data = point_obs_data.get_point_data() | ||
met_point_data['met_point_data'] = point_obs_data |
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,55 @@ | ||
######################################################################## | ||
# | ||
# Adapted from a script provided by George McCabe | ||
# Adapted by Howard Soh | ||
# | ||
# usage: /path/to/python write_tmp_point_nc.py \ | ||
# tmp_output_filename <user_python_script>.py <args> | ||
# | ||
######################################################################## | ||
|
||
import os | ||
import sys | ||
import importlib.util | ||
|
||
# add share/met/python directory to system path to find met_point_obs | ||
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), | ||
os.pardir, 'python'))) | ||
|
||
from met_point_obs import met_point_obs | ||
from met_point_obs_nc import nc_point_obs | ||
|
||
PROMPT = met_point_obs.get_prompt() | ||
print("{p} Python Script:\t".format(p=PROMPT) + repr(sys.argv[0])) | ||
print("{p} User Command:\t".format(p=PROMPT) + repr(' '.join(sys.argv[2:]))) | ||
print("{p} Temporary File:\t".format(p=PROMPT) + repr(sys.argv[1])) | ||
|
||
tmp_filename = sys.argv[1] | ||
pyembed_module_name = sys.argv[2] | ||
sys.argv = sys.argv[2:] | ||
|
||
# append user script dir to system path | ||
pyembed_dir, pyembed_file = os.path.split(pyembed_module_name) | ||
if pyembed_dir: | ||
sys.path.insert(0, pyembed_dir) | ||
|
||
if not pyembed_module_name.endswith('.py'): | ||
pyembed_module_name += '.py' | ||
|
||
user_base = os.path.basename(pyembed_module_name).replace('.py','') | ||
|
||
spec = importlib.util.spec_from_file_location(user_base, pyembed_module_name) | ||
met_in = importlib.util.module_from_spec(spec) | ||
spec.loader.exec_module(met_in) | ||
|
||
if hasattr(met_in, 'point_obs_data'): | ||
met_in.point_obs_data.save_ncfile(tmp_filename) | ||
else: | ||
if hasattr(met_in.met_point_data, 'point_obs_data'): | ||
met_in.met_point_data['point_obs_data'].save_ncfile(tmp_filename) | ||
else: | ||
tmp_point_obs = nc_point_obs() | ||
tmp_point_obs.put_data(met_in.met_point_data) | ||
tmp_point_obs.save_ncfile(tmp_filename) | ||
|
||
#print('{p} writing {f}'.format(p=PROMPT, f=tmp_filename)) |
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
Oops, something went wrong.