当前位置: 首页>>代码示例>>Python>>正文


Python HydroShare.getResourceFile方法代码示例

本文整理汇总了Python中hs_restclient.HydroShare.getResourceFile方法的典型用法代码示例。如果您正苦于以下问题:Python HydroShare.getResourceFile方法的具体用法?Python HydroShare.getResourceFile怎么用?Python HydroShare.getResourceFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在hs_restclient.HydroShare的用法示例。


在下文中一共展示了HydroShare.getResourceFile方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: start_file_download

# 需要导入模块: from hs_restclient import HydroShare [as 别名]
# 或者: from hs_restclient.HydroShare import getResourceFile [as 别名]
def start_file_download(request):
    global temp_dir, prediction_data, rp_data, total_prediction_comids, total_rp_comids, sorted_prediction_comids, \
        sorted_rp_comids, time
    if request.method == 'GET':
        get_data = request.GET
        this_script_path = inspect.getfile(inspect.currentframe())
        try:
            if get_data['res_id'] is not None:
                temp_dir = tempfile.mkdtemp()
                file_path = get_data['res_id']

            if get_data['src'] == 'iRODS':
                download = requests.get(file_path, stream=True)
                filename = os.path.basename(file_path)
                local_file_path = os.path.join(temp_dir, filename)
                with open(local_file_path, 'wb') as fd:
                    for chunk in download.iter_content(1024):
                        fd.write(chunk)
                prediction_data = nc.Dataset(local_file_path, mode="r")

            elif get_data['src'] == 'hs':
                auth = HydroShareAuthBasic(username='username', password='*****')
                hs = HydroShare(auth=auth, hostname="playground.hydroshare.org", use_https=False)
                resource_data = hs.getSystemMetadata(file_path)
                filename = resource_data['resource_title']
                # this will only work if there is only one file in the resource and if
                # the resource title is the same as filename
                hs.getResourceFile(file_path, filename, destination=temp_dir)
                local_file_path = temp_dir + "/" + filename
                prediction_data = nc.Dataset(local_file_path, mode="r")
            else:
                testfile_path = this_script_path.replace('controllers.py', 'public/data/test.nc')
                prediction_data = nc.Dataset(testfile_path, mode="r")

            # Sort the RAPID netCDF file by COMID
            qout_dimensions = prediction_data.variables['Qout'].dimensions
            if qout_dimensions[0].lower() == 'comid' and qout_dimensions[1].lower() == 'time':
                sorted_prediction_comids = sorted(enumerate(prediction_data.variables['COMID'][:]),
                                                  key=lambda comid: comid[1])
                total_prediction_comids = len(sorted_prediction_comids)
            else:
                return JsonResponse({'error': "Invalid netCDF file"})
            variables = prediction_data.variables.keys()
            if 'time' in variables:
                time = [t * 1000 for t in prediction_data.variables['time'][:]]
            else:
                return JsonResponse({'error': "Invalid netCDF file"})

            rp_data_path = this_script_path.replace('controllers.py', 'public/data/return_period_data.nc')
            rp_data = nc.Dataset(rp_data_path, mode="r")
            sorted_rp_comids = sorted(enumerate(rp_data.variables['COMID'][:]), key=lambda comid: comid[1])
            total_rp_comids = len(sorted_rp_comids)
            return JsonResponse({'success': "The file is ready to go."})
        except Exception, err:
            return JsonResponse({'error': err})
开发者ID:shawncrawley,项目名称:tethysapp-nfie_data_viewer,代码行数:57,代码来源:controllers.py

示例2: test_create_get_delete_resource_file

# 需要导入模块: from hs_restclient import HydroShare [as 别名]
# 或者: from hs_restclient.HydroShare import getResourceFile [as 别名]
    def test_create_get_delete_resource_file(self):
        hs = HydroShare()
        # Add
        res_id = '511debf8858a4ea081f78d66870da76c'
        fpath = 'mocks/data/another_resource_file.txt'
        fname = os.path.basename(fpath)
        resp = hs.addResourceFile(res_id, fpath)
        self.assertEqual(resp, res_id)

        # Get
        tmpdir = tempfile.mkdtemp()
        res_file = hs.getResourceFile(res_id, fname, destination=tmpdir)
        self.assertTrue(filecmp.cmp(res_file, fpath, shallow=False))
        shutil.rmtree(tmpdir)

        # Delete
        delres = hs.deleteResourceFile(res_id, fname)
        self.assertEqual(delres, res_id)
开发者ID:mtpain,项目名称:hs_restclient,代码行数:20,代码来源:test_hs_restclient.py

示例3: HydroShare

# 需要导入模块: from hs_restclient import HydroShare [as 别名]
# 或者: from hs_restclient.HydroShare import getResourceFile [as 别名]
                        print "Bad Zip file"+ id

    # this block of code will add a time series to the legend and graph the result
    if (request.POST and "add_ts" in request.POST):

        if not outside_input:
            Current_r = request.POST['select_r_script']

        if request.POST.get('hydroshare_resource') != None and request.POST.get('hydroshare_file')!= None:
            try:
                #adding a hydroshare resource
                hs = HydroShare()
                hs_resource = request.POST['hydroshare_resource']
                hs_file = request.POST['hydroshare_file']
                #hs_text =hs.getResourceFile("b29ac5ce06914752aaac74685ba0f682","DemoReferencedTimeSeries-wml_1.xml")
                hs_text =hs.getResourceFile(hs_resource,hs_file)
                # hs_lst =[] This was an old methond to extract the data from the resource. Probably obsolete
                # for line in hs_text:
                #     hs_lst.append(line)
                # xml = ''.join(hs_lst)
                url_hs_resource = "https://www.hydroshare.org/resource/"+hs_resource+"/data/contents/"+hs_file
                #graph_original = Original_Checker(xml)
                session = SessionMaker()
                url1 = URL(url = url_hs_resource)
                session.add(url1)
                session.commit()
                session.close()
            except etree.XMLSyntaxError as e: #checks to see if data is an xml
                print "Error:Not XML"
                #quit("not valid xml")
            except ValueError, e: #checks to see if Url is valid
开发者ID:mmbayles,项目名称:TimeSeries-Converter,代码行数:33,代码来源:controllers.py


注:本文中的hs_restclient.HydroShare.getResourceFile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。