-
Notifications
You must be signed in to change notification settings - Fork 24
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
Bugfix 2428 python embedding with MET_PYTHON_EXE defined #2462
Changes from 10 commits
51aed28
550f473
7c9f16d
8017e01
5ee645e
339803a
7634474
9912f42
d7dabde
4b6e032
72cd3fb
447ac0b
4eba029
61bf6d9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
######################################################################## | ||
# | ||
# Reads temporary file into memory. | ||
# | ||
# usage: /path/to/python read_tmp_dataplane.py dataplane.tmp | ||
# | ||
######################################################################## | ||
|
||
import os | ||
import sys | ||
|
||
met_base_dir = os.getenv('MET_BASE',None) | ||
if met_base_dir is not None: | ||
sys.path.append(os.path.join(met_base_dir, 'python')) | ||
|
||
# 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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
######################################################################## | ||
# | ||
# Adapted from a script provided by George McCabe | ||
# Adapted by Randy Bullock | ||
# | ||
# usage: /path/to/python write_tmp_point.py \ | ||
# tmp_output_filename <user_python_script>.py <args> | ||
# | ||
######################################################################## | ||
|
||
import os | ||
import sys | ||
import importlib.util | ||
|
||
met_base_dir = os.getenv('MET_BASE',None) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think these 3 lines are necessary since the path is appended using the relative path of the script below. |
||
if met_base_dir is not None: | ||
sys.path.append(os.path.join(met_base_dir, 'python')) | ||
|
||
# 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] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A lot of this logic looks to be the same as other scripts in the data/wrappers directory. We should consider pulling out duplicate code into a function. This isn't required for this PR and could be done during a bigger refactor of the Python Embedding logic. |
||
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)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think these 3 lines are necessary since the path is appended using the relative path of the script below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MET_BASE was removed at read_tmp_point_nc.py and write_tmp_point_nc.py