Skip to content
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

Add subsetting to plot specification. #109

Merged
merged 1 commit into from
Apr 26, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 26 additions & 5 deletions static/cdatweb/vtk_view/js/cdat.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,20 @@
*
* @param {object} config A plot configuration object
*
* BEGIN simplified interface
* @param {string} config.file data file where to read the variables from
* @param {string} config.variable variable or list of variables to plot (from config.file)
* @param {object} config.subset same as subset in config.variables.
* Subset is applied to all variables, so we assume
* all variables have the same grid.
* END simplified interface
* @param {object[]} config.variables The variable from the file to display
* A variable contains:
* - name: the name of the attribute to plot
* - file: the data file where to read the variable from
* - subset: a list of dictionary elements, each element has
* - name: index variable name
* - range: list with lower and upper range for the index variable
* @param {string} config.template The plot template to use
* @param {string} config.type The plot type to create
* @param {string} config.method The plot method to use
Expand All @@ -146,7 +159,7 @@
* @returns {$.Deferred} A promise-like object for attaching handlers
*
* @example
* var view = cdat.open({
* var view = cdat.show({
* }).then(
* function () { console.log('success'); },
* function () { console.log('fail'); }
Expand All @@ -166,9 +179,9 @@

var defer = new $.Deferred();
var promise = defer.promise();
var view, v;
var view, v, i;

// backward compatibility
// simplified interface
if (config.file && config.variable) {
if (typeof config.variable === 'string') {
config.variables = [{
Expand All @@ -184,6 +197,12 @@
});
}
}
if (config.subset) {
for (i = 0; i < config.variables.length; ++i) {
v = config.variables[i];
v.subset = config.subset;
}
}
}

open.then(
Expand Down Expand Up @@ -306,7 +325,7 @@
* @param {string} method A graphics method
* @param {string} template A graphics template
*/
create_plot: function (file, variable, type, method, template) {
create_plot: function (file, variable, type, method, template, subset) {
console.log(
"Opening file: " + file +
" variable: " + variable +
Expand All @@ -326,7 +345,8 @@
variable: variable,
type: type,
method: method,
template: template
template: template,
subset: subset
})
}
);
Expand Down Expand Up @@ -364,6 +384,7 @@

/**
* Prints the result from get_variables to the console.
* @param {string? filename An absolute path to a netcdf file
*/
print_variables: function (filename) {
var fileVars = cdat.get_variables(filename);
Expand Down
10 changes: 7 additions & 3 deletions templates/vtk_view/cdat_viewer.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,14 @@
<ul class="dropdown-menu">
<li><a onclick="cdat.create_plot('http://test.opendap.org/opendap/data/nc/coads_climatology.nc', 'SST', 'isofill', 'robinson', 'no_legend')" href="javascript:void(0)">Isofill example</a></li>
<!-- Need a 3D variable for this: <li><a onclick="cdat.create_plot('http://test.opendap.org/opendap/data/nc/coads_climatology.nc', 'AIRT', '3d_scalar', 'default', 'default')" href="javascript:void(0)">Volume example</a></li> -->
<li><a onclick="cdat.create_plot('http://test.opendap.org/opendap/data/nc/coads_climatology.nc', ['UWND', 'VWND'], 'vector', 'default', 'default')" href="javascript:void(0)">Vector example</a></li>
<li><a onclick="cdat.create_plot('http://test.opendap.org/opendap/data/nc/coads_climatology.nc', ['UWND', 'VWND'], 'vector', 'default', 'default')"
href="javascript:void(0)">Vector example</a></li>
<li><a onclick="cdat.create_plot('http://test.opendap.org/opendap/data/nc/coads_climatology.nc', ['UWND', 'VWND'], 'vector', 'default', 'default', {'COADSX': [60, 180], 'COADSY': [0, 90]})"
href="javascript:void(0)">Vector subsetting example</a></li>
<li><a id="variables-example" onclick="cdat.print_variables('http://test.opendap.org/opendap/data/nc/coads_climatology.nc')">Rectilinear grid variables example</a></li>
<li><a id="variables-example" onclick="cdat.print_variables('/home/danlipsa/build/uvcdat/install/share/uvcdat/sample_data/sampleCurveGrid4.nc')">Curvilinear grid variable example</a></li>
<li><a id="variables-example" onclick="cdat.print_variables('/home/danlipsa/build/uvcdat/install/share/uvcdat/sample_data/sampleGenGrid3.nc')">Generic grid variable example</a></li>
<li><a id="variables-example" onclick="cdat.print_variables('/home/danlipsa/projects/uvcdat/build/install/share/uvcdat/sample_data/clt.nc')">clt.nc variables example</a></li>
<li><a id="variables-example" onclick="cdat.print_variables('/home/danlipsa/projects/uvcdat/build/install/share/uvcdat/sample_data/sampleCurveGrid4.nc')">Curvilinear grid variable example</a></li>
<li><a id="variables-example" onclick="cdat.print_variables('/home/danlipsa/projects/uvcdat/build/install/share/uvcdat/sample_data/sampleGenGrid3.nc')">Generic grid variable example</a></li>
</ul>
</li>
{% endblock navbar-right %}
Expand Down
10 changes: 7 additions & 3 deletions vis_server/protocols/VisFinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,13 @@ def create(self, plottype, plotmethod, variable, template, opts={}):
all_vars = []
for obj in variable:
f = FileLoader().get_reader(obj['file'])
all_vars.append(
f[obj['name']]
)
var = f[obj['name']]
if ('subset' in obj):
kargs = obj['subset']
print obj['name']
print kargs
var = var(**kargs)
all_vars.append(var)
vis.loadVariable(all_vars)
view = vis.getView()
id = self.getGlobalId(view)
Expand Down