def insert(): if request.files['file'].filename == '' or request.form[ 'watershed'] == '' or request.form[ 'description'] == '' or request.form['state'] == '': return render_template( 'share/f.html', InputErrorMessage= "Please upload required file and/or fill in all the fields") uploadedFile = request.files['file'] watershed_name = str(request.form['watershed']) model_name = str(request.form['model']) description = str(request.form['description']) state = str(request.form['state']) model_run_uuid = str(request.form['uuid']) if uploadedFile: # FIXME a bit of a hack to fix timeout issues; can fix when fixed # on VW HTTP _local_vw_client = default_vw_client() uploadedFileName = secure_filename(uploadedFile.filename) uploaded_file_path = os.path.join(app.config['UPLOAD_FOLDER'], uploadedFileName) uploadedFile.save(uploaded_file_path) _local_vw_client.upload( model_run_uuid, os.path.join(app.config['UPLOAD_FOLDER'], uploadedFileName)) input_file = uploadedFileName parent_uuid = model_run_uuid start_datetime = '2010-01-01 00:00:00' end_datetime = '2010-01-01 01:00:00' # create XML FGDC-standard metadata that gets included in VW metadata fgdc_metadata = \ make_fgdc_metadata(input_file, None, model_run_uuid, start_datetime, end_datetime, model=model_name) # create VW metadata watershed_metadata = metadata_from_file(uploaded_file_path, parent_uuid, model_run_uuid, description, watershed_name, state, start_datetime=start_datetime, end_datetime=end_datetime, model_name=model_name, fgdc_metadata=fgdc_metadata, taxonomy='geoimage', model_set_taxonomy='grid') _local_vw_client.insert_metadata(watershed_metadata) time.sleep(1) rData = _local_vw_client.dataset_search(model_run_uuid=model_run_uuid) dataResults = rData.records model_run_record = \ VW_CLIENT.modelrun_search(model_run_id=model_run_uuid).records[0] model_run_uuid = model_run_record['Model Run UUID'] model_run_desc = model_run_record['Description'] model_run_name = model_run_record['Model Run Name'] return render_template('share/f.html', model_run_name=model_run_name, model_run_desc=model_run_desc, model_run_uuid=model_run_uuid, dataResults=dataResults)
def resources(): """" Initialize a resource container for either uploading files or an external resource (FTP, TRHEDDS, eventually more) """ # TODO Display current resources that have been shared by the current user # Display form for sharing a data resource form = ResourceForm() print form.validate_on_submit() if form.validate_on_submit(): _local_vw_client = default_vw_client() # initialize: post to virtual watershed common_kwargs = { 'description': form.description.data, 'keywords': form.keywords.data } extra_vw_kwargs = { 'researcher_name': current_user.name, 'model_run_name': form.title.data, } vw_kwargs = {} vw_kwargs.update(common_kwargs) vw_kwargs.update(extra_vw_kwargs) print vw_kwargs # in VW language, the database focuses on 'model_runs'. # however, modelers don't just want to share data associated with a # particular model import uuid UUID = str(uuid.uuid4()) try: result_of_vwpost = _local_vw_client.initialize_modelrun( **vw_kwargs) UUID = result_of_vwpost except: pass # get UUID and add full record to the 'resources' table in DB along with # user ID url = (form.url.data or _local_vw_client.dataset_search_url + '&model_run_uuid=' + UUID) resource = Resource(user_id=current_user.id, title=form.title.data, uuid=UUID, url=url, **common_kwargs) db.session.add(resource) print resource try: db.session.commit() flash('Your submission has been accepted') form.reset() except: db.session.rollback() flash('Your submission has been rejected') # When it's been submitted, give URL to view on the Virtual Watershed and # add it to the list above (i.e. reload the page) return render_template('share/index.html', form=form)
file_ext = 'tif' orig_epsg = 26911 epsg = 4326 taxonomy = 'grid' model_set_taxonomy = 'geoimage' wcs=True, wms=True, wfs='wfs', # Create Connection import getpass #username = get_raw("Enter Username: "******"Enter VWP Password: ") #vw_client = VWClient('https://vwp-dev.unm.edu', username, password) vw_client = default_vw_client() # create a new model run new_mr_uuid = vw_client.initialize_modelrun( model_run_name=model_run_name, description=description, researcher_name=researcher_name, keywords=keywords) print new_mr_uuid # something like u'0a3e8c1f-c09a-46a3-8acb-6816ebd25e69' mr_search_results = vw_client.modelrun_search() new_mr = [r for r in mr_search_results.records if r['Model Run UUID'] == new_mr_uuid] print new_mr # upload file to VWDE upl_res = vw_client.upload(new_mr_uuid, file_path)
from flask import render_template, flash, redirect, url_for, request from flask_login import login_required, current_user from flask import current_app as app from werkzeug import secure_filename from . import share from .forms import ResourceForm from .. import db from ..models import Resource from wcwave_adaptors import default_vw_client from wcwave_adaptors import make_fgdc_metadata, metadata_from_file import os, osr, gdal, util, numpy import time VW_CLIENT = default_vw_client() def allowed_file(filename): return '.' in filename and filename.rsplit( '.', 1)[1] in app.config['ALLOWED_EXTENSIONS'] @share.route('/', methods=['GET', 'POST']) @login_required def resources(): """" Initialize a resource container for either uploading files or an external resource (FTP, TRHEDDS, eventually more) """ # TODO Display current resources that have been shared by the current user
def resources(): """" Initialize a resource container for either uploading files or an external resource (FTP, TRHEDDS, eventually more) """ # TODO Display current resources that have been shared by the current user # Display form for sharing a data resource form = ResourceForm() print form.validate_on_submit() if form.validate_on_submit(): _local_vw_client = default_vw_client() # initialize: post to virtual watershed common_kwargs = { 'description': form.description.data, 'keywords': form.keywords.data } extra_vw_kwargs = { 'researcher_name': current_user.name, 'model_run_name': form.title.data, } vw_kwargs = {} vw_kwargs.update(common_kwargs) vw_kwargs.update(extra_vw_kwargs) print vw_kwargs # in VW language, the database focuses on 'model_runs'. # however, modelers don't just want to share data associated with a # particular model import uuid UUID = str(uuid.uuid4()) try: result_of_vwpost = _local_vw_client.initialize_modelrun(**vw_kwargs) UUID = result_of_vwpost except: pass # get UUID and add full record to the 'resources' table in DB along with # user ID url = (form.url.data or _local_vw_client.dataset_search_url + '&model_run_uuid=' + UUID) resource = Resource(user_id=current_user.id, title=form.title.data, uuid=UUID, url=url, **common_kwargs) db.session.add(resource) print resource try: db.session.commit() flash('Your submission has been accepted') form.reset() except: db.session.rollback() flash('Your submission has been rejected') # When it's been submitted, give URL to view on the Virtual Watershed and # add it to the list above (i.e. reload the page) return render_template('share/index.html', form=form)
def insert(): if request.files['file'].filename == '' or request.form['watershed'] == '' or request.form['description'] == '' or request.form['state'] == '': return render_template('share/f.html', InputErrorMessage = "Please upload required file and/or fill in all the fields") uploadedFile = request.files['file'] watershed_name = str(request.form['watershed']) model_name = str(request.form['model']) description = str(request.form['description']) state = str(request.form['state']) model_run_uuid = str(request.form['uuid']) if uploadedFile: # FIXME a bit of a hack to fix timeout issues; can fix when fixed # on VW HTTP _local_vw_client = default_vw_client() uploadedFileName = secure_filename(uploadedFile.filename) uploaded_file_path = os.path.join(app.config['UPLOAD_FOLDER'], uploadedFileName) uploadedFile.save(uploaded_file_path) _local_vw_client.upload(model_run_uuid, os.path.join(app.config['UPLOAD_FOLDER'], uploadedFileName)) input_file = uploadedFileName parent_uuid = model_run_uuid start_datetime = '2010-01-01 00:00:00' end_datetime = '2010-01-01 01:00:00' # create XML FGDC-standard metadata that gets included in VW metadata fgdc_metadata = \ make_fgdc_metadata(input_file, None, model_run_uuid, start_datetime, end_datetime, model=model_name) # create VW metadata watershed_metadata = metadata_from_file(uploaded_file_path, parent_uuid, model_run_uuid, description, watershed_name, state, start_datetime=start_datetime, end_datetime=end_datetime, model_name=model_name, fgdc_metadata=fgdc_metadata, taxonomy='geoimage', model_set_taxonomy='grid') _local_vw_client.insert_metadata(watershed_metadata) time.sleep(1) rData = _local_vw_client.dataset_search(model_run_uuid = model_run_uuid) dataResults = rData.records model_run_record = \ VW_CLIENT.modelrun_search(model_run_id=model_run_uuid).records[0] model_run_uuid = model_run_record['Model Run UUID'] model_run_desc = model_run_record['Description'] model_run_name = model_run_record['Model Run Name'] return render_template('share/f.html', model_run_name=model_run_name, model_run_desc=model_run_desc, model_run_uuid = model_run_uuid, dataResults = dataResults)
from flask import render_template, flash, redirect, url_for, request from flask_login import login_required, current_user from flask import current_app as app from werkzeug import secure_filename from . import share from .forms import ResourceForm from .. import db from ..models import Resource from wcwave_adaptors import default_vw_client from wcwave_adaptors import make_fgdc_metadata, metadata_from_file import os, osr, gdal, util, numpy import time VW_CLIENT = default_vw_client() def allowed_file(filename): return '.' in filename and filename.rsplit('.', 1)[1] in app.config['ALLOWED_EXTENSIONS'] @share.route('/', methods=['GET', 'POST']) @login_required def resources(): """" Initialize a resource container for either uploading files or an external resource (FTP, TRHEDDS, eventually more) """ # TODO Display current resources that have been shared by the current user # Display form for sharing a data resource form = ResourceForm()
from flask import Flask from flask_moment import Moment from flask_sqlalchemy import SQLAlchemy from flask_login import LoginManager from config import config from wcwave_adaptors import default_vw_client moment = Moment() db = SQLAlchemy() login_manager = LoginManager() login_manager.session_protection = 'strong' login_manager.login_view = 'auth.login' vw_client = default_vw_client() def create_app(config_name): app = Flask(__name__) app.config.from_object(config[config_name]) config[config_name].init_app(app) moment.init_app(app) db.init_app(app) login_manager.init_app(app) from .main import main as main_blueprint app.register_blueprint(main_blueprint) from .auth import auth as auth_blueprint
#import gdal #import ogr # some local fileness #sys.path.append('../../vwplatform/wcwave_adaptors/wcwave_adaptors/') #import watershed import getpass from wcwave_adaptors import default_vw_client from wcwave_adaptors import make_fgdc_metadata, metadata_from_file #import watershed.metadata_from_file #import watershed.default_vw_client #vwc = watershed.VWClient #print ("Enter your credentials!") #uname = raw_input("Enter your username: "******"Enter your password: "******"http://vwp-dev.unm.edu",uname,upass) vw_client = default_vw_client(config_file="./wcwave_adaptors/default.conf") # In[20]: # Specifiy necessary Variables file_name = 'Hillshade.tif' file_path = '/Users/appleseed/Desktop/InterdisplinaryModelingData/data/Hillshade.tif' #dataset = gdal.Open(file_path) import datetime model_run_name = 'animation FlowDCEW' # str(datetime.datetime.now()) + ' Dry Creek Flow' description = 'update Flow Dry Creek animation' researcher_name = 'Nolan Burfield' keywords = 'DryCreek, flow, animation' watershed_name = 'Dry Creek'