简体   繁体   English

有没有办法从Web应用程序读取本地netcdf文件?

[英]Is there a way to read a local netcdf file from a web application?

We are building a web service for data analysis and would like to access netcdf files from the local machine where the browser is running. 我们正在构建一个用于数据分析的Web服务,并希望从运行浏览器的本地计算机访问netcdf文件。 Javascript offers a file browser, but (for security reasons as I learned) it will automatically upload a file after selection, instead of allowing (read-only) access to it. Javascript提供了文件浏览器,但是(出于安全方面的原因,据我了解),它会在选择后自动上传文件,而不是允许(只读)访问文件。 This presents a show-stopper, because the netcdf files can be HUGE . 由于netcdf文件可以是HUGE ,所以这显示了一个制止 Note, that the netcdf format and API explicitly allow slicing and extraction of individual variables, which is one reason why the format is so popular. 请注意,netcdf格式和API明确允许切片和提取单个变量,这是该格式如此流行的原因之一。

Now, some research into this issue revealed that the server-client architecture normally doesn't allow access to the local file structure to prevent spying. 现在,对该问题的一些研究表明,服务器-客户端体系结构通常不允许访问本地文件结构以防止间谍活动。 On the other hand, in HTML5 there is a file API which supports exactly the kind of operations we need -- except that you can access portions of a file by specifying byte ranges, but there is no netcdf API available; 另一方面,在HTML5中,有一个文件API完全支持我们所需的操作-除了您可以通过指定字节范围来访问文件的各个部分外,但没有可用的netcdf API。 hence one would be left again with copying the entire file before being able to slice it on the server. 因此,在将整个文件切片到服务器上之前,将不得不再复制整个文件。

Of course, the other option are web services such as OpenDAP which are meant to do exactly what we want, ie access parts of a netcdf file over the internet. 当然,另一种选择是诸如OpenDAP之类的Web服务,它们可以完全执行我们想要的操作,即通过Internet访问netcdf文件的一部分。 However, this of course requires that every user would have to install the OpenDAP server before they could access their local files from within the web service. 但是,这当然要求每个用户必须先安装OpenDAP服务器,然后才能从Web服务中访问其本地文件。 (Or, at a minimum they would have to install a web server so that one could access the file via http://localhost/... ). (或者,至少他们必须安装一个Web服务器,以便人们可以通过http://localhost/...访问该文件)。

So: does anyone know of a solution to read specific portions of a local netcdf file from a web application? 那么:有谁知道从Web应用程序读取本地netcdf文件特定部分的解决方案? Specifically, are there javascript tools available for this? 具体来说,有没有可用的javascript工具?

Currently you can use netcdfjs , that it's a javascript library that allows to read NetCDF v3 files. 当前,您可以使用netcdfjs ,它是一个允许读取NetCDF v3文件的javascript库。 Because it's a NodeJS package you can run it server side, and for regular size files you can read it online, here you have an example . 因为它是一个NodeJS软件包,所以您可以在服务器端运行它,对于常规大小的文件,您可以在线阅读它,这里有一个示例

There are no Javascript tools to read NetCDF, but there are Java libraries: http://www.unidata.ucar.edu/downloads/netcdf/index.jsp . 没有读取NetCDF的Javascript工具,但是有Java库: http : //www.unidata.ucar.edu/downloads/netcdf/index.jsp

You could deploy a Java Applet to read the NetCDF file locally. 您可以部署Java Applet在本地读取NetCDF文件。 From there you could have the Applet try to process the file, or communicate with a backend service, or even try to call on the Applet from Javascript: http://docs.oracle.com/javase/tutorial/deployment/applet/invokingAppletMethodsFromJavaScript.html . 从那里,您可以让Applet尝试处理文件,与后端服务进行通信,甚至尝试从Javascript调用Applet: http : //docs.oracle.com/javase/tutorial/deployment/applet/invokingAppletMethodsFromJavaScript .html

There are no specific Javascript libs for reading NetCDF, as far as I know. 据我所知,没有用于读取NetCDF的特定Javascript库。 But let me drop some thoughts: 但是,让我放弃一些想法:

  • As you say, you can install a local webserver, and use a server-side language to execute a program that reads the file in your disk. 如您所说,您可以安装本地Web服务器,并使用服务器端语言来执行读取磁盘中文件的程序。 You could use a command-line software called ncdump-json . 您可以使用名为ncdump-json的命令行软件。 I intentionally wrote this software for that purpose. 为此,我故意编写了该软件。
  • You say that you don't want to install software like OpenDAP or webservers, but maybe a desktop app, a standalone .exe would be OK for you. 您说您不想安装像OpenDAP或网络服务器之类的软件,但是也许是台式机应用程序,独立的.exe对您而言可以。 Using node.js plus chromium (this is called nw.js) you have a program that is at the same time a nodejs server, and a chromium browser. 使用node.js和chrome(称为nw.js),您可以同时拥有一个nodejs服务器程序和一个chrome浏览器。 This way you can write a web application that reads the data (eg using the embedded nodejs server and spawning ncdump-json...). 这样,您可以编写一个读取数据的Web应用程序(例如,使用嵌入式nodejs服务器并生成ncdump-json ...)。
  • And now the simplest scenario, a 100% client-side solution... I think this can only be achieved using Javascript... or anything that can "compile to" Javascript. 现在是最简单的情况,一个100%的客户端解决方案...我认为这只能使用Javascript或任何可以“编译为” Javascript的方法来实现。 We need to have the netCDF libraries in Javascript, is that possible? 我们需要用Javascript编写netCDF库,这可能吗? I guess so. 大概吧。 Emscripten is a LLVM-to-Javascript compiler, and netCDF is C so it has to be possible to compile it with clang/LLVM, therefore it has to be possible to use Emscripten to have a netCDF JS library version with almost no effort, without having to write from scratch (and also maintain) a JS port. Emscripten是LLVM到Javascript的编译器,而netCDF是C,因此必须可以用clang / LLVM进行编译,因此必须可以使用Emscripten轻松地拥有netCDF JS库版本,而无需必须从头开始编写(并维护)JS端口。 If I'm not wrong, to random access the files there's the method slice in the html5 file api, so that should not be a problem. 如果我没看错,要随机访问文件,则html5文件api中有方法切片 ,因此这应该不是问题。

Hope I helped. 希望我能帮上忙。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM