Пример #1
0
def upload():

    if request.files['hru-file'].filename == '' or request.form['row'] == '' or request.form['column'] == '' or request.form['epsg'] == '':
        return render_template('share/files.html', InputErrorMessage = "Please upload required files and/or fill in all the fields")

    numberOfRows = int(request.form['row'])
    numberOfColumns = int(request.form['column'])
    epsgValue = int(request.form['epsg'])
    inputFileName = str(request.form['input'])
    hruFile = request.files['hru-file']
    new_mr_uuid = str(request.form['uuid'])

    if hruFile:
        hruFileName = secure_filename(hruFile.filename)
        hruFile.save(os.path.join(app.config['UPLOAD_FOLDER'], hruFileName))

    with open(os.path.join(app.config['UPLOAD_FOLDER'], hruFileName)) as f:
        numberOfLines = len(f.readlines())

    product = numberOfRows * numberOfColumns

    if product == numberOfLines:
        hruFileHandle = open(os.path.join(app.config['UPLOAD_FOLDER'], hruFileName), 'r')
        values = util.findAverageResolution(hruFileHandle, numberOfRows, numberOfColumns)

        inputFileHandle = open(os.path.join(app.config['UPLOAD_FOLDER'], inputFileName), 'r')
        copyParameterSectionFromInputFile(inputFileHandle)

        readncFile(numberOfRows, numberOfColumns, epsgValue, values[0], values[1], values[2], values[3])
        readtifFile(numberOfRows, numberOfColumns, epsgValue, values[0], values[1], values[2], values[3])
        util.generateMetaData()
        util.moveFilesToANewDirectory()

        dirList = os.listdir(app.config['DOWNLOAD_FOLDER'])
        for fname in dirList:
            print "uploading " + fname
            res = VW_CLIENT.upload(new_mr_uuid, os.path.join(app.config['DOWNLOAD_FOLDER'], fname))

            input_file = fname
            parent_uuid = new_mr_uuid
            description = 'Lehman Creek PRMS Data'
            watershed_name = 'Lehman Creek'
            state = 'Nevada'
            start_datetime = '2010-01-01 00:00:00'
            end_datetime = '2010-01-01 01:00:00'
            model_name = 'prms'

            # create XML FGDC-standard metadata that gets included in VW metadata
            fgdc_metadata = make_fgdc_metadata(input_file, None, new_mr_uuid, start_datetime, end_datetime, model=model_name)

            # create VW metadata
            watershed_metadata = metadata_from_file(input_file, parent_uuid, new_mr_uuid, description, watershed_name, state, start_datetime=start_datetime, end_datetime=end_datetime, model_name=model_name, fgdc_metadata=fgdc_metadata)

            response = VW_CLIENT.insert_metadata(watershed_metadata)

        return render_template("share/files.html", Success_Message = "Successfully Inserted into the Virtual Watershed")
    else:
        return render_template("share/files.html", Error_Message = "The product of the number of rows and columns do not match the number of parameter values")
def uploadFile(file_path,starttime,endtime,northbound,southbound,eastbound,westbound): 
    # upload file to VWDE
    upl_res = vw_client.upload(new_mr_uuid, file_path)

    print upl_res  # <Response [200]>
    print upl_res.text  # u'OK'

    # create XML FGDC-standard metadata that gets included in VW metadata
    fgdc_metadata = make_fgdc_metadata(file_path, None,new_mr_uuid,
        start_datetime, end_datetime, model=model_name)

    # create VW metadata
    parent_uuid = new_mr_uuid

    watershed_metadata = metadata_from_file(  file_path, 
                                          parent_uuid, 
                                          new_mr_uuid, 
                                          description, 
                                          watershed_name,
                                          state, 
                                          start_datetime=starttime, 
                                          end_datetime=endtime,
                                          model_name=model_name, 
                                          # fgdc_metadata=fgdc_metadata, # -- Not Necessary Right now
                                          # north_bound=northbound,
                                          # south_bound=southbound,
                                          # east_bound=eastbound,
                                          # west_bound=westbound,
                                          model_set_type=model_set_type, 
                                          model_set=model_set,
                                          taxonomy=taxonomy,
                                          model_set_taxonomy=model_set_taxonomy,
                                          file_ext=file_ext, 
                                          orig_epsg=orig_epsg,
                                          wcs=wcs,
                                          wms=wms,
                                          model_vars='flow',
                                          # wfs='wfs',
                                          epsg=epsg)

    response = vw_client.insert_metadata(watershed_metadata)
    assert response.status_code == 200, "Code not 200, Insert failed! with " + str(response)
Пример #3
0
def upload():

    if request.files['hru-file'].filename == '' or request.form[
            'row'] == '' or request.form['column'] == '' or request.form[
                'epsg'] == '':
        return render_template(
            'share/files.html',
            InputErrorMessage=
            "Please upload required files and/or fill in all the fields")

    numberOfRows = int(request.form['row'])
    numberOfColumns = int(request.form['column'])
    epsgValue = int(request.form['epsg'])
    inputFileName = str(request.form['input'])
    hruFile = request.files['hru-file']
    new_mr_uuid = str(request.form['uuid'])

    if hruFile:
        hruFileName = secure_filename(hruFile.filename)
        hruFile.save(os.path.join(app.config['UPLOAD_FOLDER'], hruFileName))

    with open(os.path.join(app.config['UPLOAD_FOLDER'], hruFileName)) as f:
        numberOfLines = len(f.readlines())

    product = numberOfRows * numberOfColumns

    if product == numberOfLines:
        hruFileHandle = open(
            os.path.join(app.config['UPLOAD_FOLDER'], hruFileName), 'r')
        values = util.findAverageResolution(hruFileHandle, numberOfRows,
                                            numberOfColumns)

        inputFileHandle = open(
            os.path.join(app.config['UPLOAD_FOLDER'], inputFileName), 'r')
        copyParameterSectionFromInputFile(inputFileHandle)

        readncFile(numberOfRows, numberOfColumns, epsgValue, values[0],
                   values[1], values[2], values[3])
        readtifFile(numberOfRows, numberOfColumns, epsgValue, values[0],
                    values[1], values[2], values[3])
        util.generateMetaData()
        util.moveFilesToANewDirectory()

        dirList = os.listdir(app.config['DOWNLOAD_FOLDER'])
        for fname in dirList:
            print "uploading " + fname
            res = VW_CLIENT.upload(
                new_mr_uuid, os.path.join(app.config['DOWNLOAD_FOLDER'],
                                          fname))

            input_file = fname
            parent_uuid = new_mr_uuid
            description = 'Lehman Creek PRMS Data'
            watershed_name = 'Lehman Creek'
            state = 'Nevada'
            start_datetime = '2010-01-01 00:00:00'
            end_datetime = '2010-01-01 01:00:00'
            model_name = 'prms'

            # create XML FGDC-standard metadata that gets included in VW metadata
            fgdc_metadata = make_fgdc_metadata(input_file,
                                               None,
                                               new_mr_uuid,
                                               start_datetime,
                                               end_datetime,
                                               model=model_name)

            # create VW metadata
            watershed_metadata = metadata_from_file(
                input_file,
                parent_uuid,
                new_mr_uuid,
                description,
                watershed_name,
                state,
                start_datetime=start_datetime,
                end_datetime=end_datetime,
                model_name=model_name,
                fgdc_metadata=fgdc_metadata)

            response = VW_CLIENT.insert_metadata(watershed_metadata)

        return render_template(
            "share/files.html",
            Success_Message="Successfully Inserted into the Virtual Watershed")
    else:
        return render_template(
            "share/files.html",
            Error_Message=
            "The product of the number of rows and columns do not match the number of parameter values"
        )
Пример #4
0
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)
# create XML FGDC-standard metadata that gets included in VW metadata
fgdc_metadata = make_fgdc_metadata(file_path, None, new_mr_uuid,
    start_datetime, end_datetime, model=model_name)

# create VW metadata
parent_uuid = new_mr_uuid

watershed_metadata = metadata_from_file(  file_path, 
                                          parent_uuid, 
                                          new_mr_uuid, 
                                          description, 
                                          watershed_name, 
                                          state, 
                                          start_datetime=start_datetime, 
                                          end_datetime=end_datetime,
                                          model_name=model_name, 
                                          # fgdc_metadata=fgdc_metadata, # -- Not Necessary Right now
                                          model_set_type=model_set_type, 
                                          model_set=model_set,
                                          taxonomy=taxonomy,
                                          model_set_taxonomy=model_set_taxonomy,
                                          file_ext=file_ext, 
                                          orig_epsg=orig_epsg,
                                          wcs=wcs,
                                          wms=wms,
                                          # wfs='wfs',
                                          epsg=epsg)

response = vw_client.insert_metadata(watershed_metadata)
assert response.status_code == 200, "Code not 200, Insert failed!"
Пример #6
0
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)