You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@climate.apache.org by jo...@apache.org on 2014/07/01 16:49:38 UTC
[14/56] [partial] gh-pages clean up
http://git-wip-us.apache.org/repos/asf/climate/blob/a53e3af5/ocw-ui/frontend/test/unit/controllers/DatasetDisplayCtrlTest.js
----------------------------------------------------------------------
diff --git a/ocw-ui/frontend/test/unit/controllers/DatasetDisplayCtrlTest.js b/ocw-ui/frontend/test/unit/controllers/DatasetDisplayCtrlTest.js
deleted file mode 100644
index b6fe620..0000000
--- a/ocw-ui/frontend/test/unit/controllers/DatasetDisplayCtrlTest.js
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http: *www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
-**/
-
-'use strict';
-
-describe('OCW Controllers', function() {
-
- beforeEach(module('ocw.controllers'));
- beforeEach(module('ocw.services'));
-
- describe('DatasetDisplayCtrl', function() {
- it('should initialize the removeDataset function', function() {
- inject(function($rootScope, $controller) {
- var scope = $rootScope.$new();
- var ctrl = $controller("DatasetDisplayCtrl", {$scope: scope});
-
- scope.datasets.push(1);
- scope.datasets.push(2);
-
- expect(scope.datasets[0]).toBe(1);
-
- scope.removeDataset(0);
-
- expect(scope.datasets[0]).toBe(2);
- });
- });
-
- it('should initialize the setRegridBase function', function() {
- inject(function($rootScope, $controller) {
- var scope = $rootScope.$new();
- var ctrl = $controller("DatasetDisplayCtrl", {$scope: scope});
-
- scope.datasets.push({regrid: false});
- scope.datasets.push({regrid: true});
- scope.datasets.push({regrid: true});
- scope.datasets.push({regrid: false});
-
- expect(scope.datasets[1].regrid).toBe(true);
- expect(scope.datasets[2].regrid).toBe(true);
-
- // setRegridBase should set all indices to 'false' if if it's not the passed index
- scope.setRegridBase(2);
-
- expect(scope.datasets[1].regrid).toBe(false);
- expect(scope.datasets[2].regrid).toBe(true);
- });
- });
- });
-});
http://git-wip-us.apache.org/repos/asf/climate/blob/a53e3af5/ocw-ui/frontend/test/unit/controllers/DatasetSelectCtrlTest.js
----------------------------------------------------------------------
diff --git a/ocw-ui/frontend/test/unit/controllers/DatasetSelectCtrlTest.js b/ocw-ui/frontend/test/unit/controllers/DatasetSelectCtrlTest.js
deleted file mode 100644
index 7091562..0000000
--- a/ocw-ui/frontend/test/unit/controllers/DatasetSelectCtrlTest.js
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http: *www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
-**/
-
-'use strict';
-
-describe('OCW Controllers', function() {
-
- beforeEach(module('ocw.controllers'));
- beforeEach(module('ocw.services'));
-
- describe('DatasetSelectCtrl', function() {
- it('should initialize the disable clear button function', function() {
- inject(function($rootScope, $controller, selectedDatasetInformation) {
- var scope = $rootScope.$new();
- var ctrl = $controller('DatasetSelectCtrl', {$scope: scope});
-
- expect(scope.shouldDisableClearButton()).toBe(true);
- selectedDatasetInformation.addDataset({});
- expect(scope.shouldDisableClearButton()).toBe(false);
- });
- });
-
- it('should initialize the clear datasets function', function() {
- inject(function($rootScope, $controller, selectedDatasetInformation) {
- var scope = $rootScope.$new();
- var ctrl = $controller('DatasetSelectCtrl', {$rootScope: $rootScope, $scope: scope});
-
- selectedDatasetInformation.addDataset({});
- expect(selectedDatasetInformation.getDatasetCount()).toBe(1);
- scope.clearDatasets();
- expect(selectedDatasetInformation.getDatasetCount()).toBe(0);
- });
- });
- });
-});
http://git-wip-us.apache.org/repos/asf/climate/blob/a53e3af5/ocw-ui/frontend/test/unit/controllers/ObservationSelectCtrlTest.js
----------------------------------------------------------------------
diff --git a/ocw-ui/frontend/test/unit/controllers/ObservationSelectCtrlTest.js b/ocw-ui/frontend/test/unit/controllers/ObservationSelectCtrlTest.js
deleted file mode 100644
index e076eb0..0000000
--- a/ocw-ui/frontend/test/unit/controllers/ObservationSelectCtrlTest.js
+++ /dev/null
@@ -1,151 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http: *www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
-**/
-
-'use strict';
-
-describe('OCW Controllers', function() {
-
- beforeEach(module('ocw.controllers'));
- beforeEach(module('ocw.services'));
-
- describe('ObservationSelectCtrl', function() {
- it('should grab the default set of selected datasets from the service', function() {
- inject(function($httpBackend, $rootScope, $controller) {
- $rootScope.baseURL = "http://localhost:8082"
- $httpBackend.expectJSONP($rootScope.baseURL + '/getPathLeader/?callback=JSON_CALLBACK').
- respond(200, {'leader': '/usr/local/rcmes'});
-
- var scope = $rootScope.$new();
- var ctrl = $controller("ObservationSelectCtrl", {$scope: scope});
- $httpBackend.flush();
-
- expect(typeof scope.datasetCount).toBe('object');
- expect(Object.keys(scope.datasetCount).length).toBe(0);
- });
- });
-
- it('should initialize option arrays and default to the first element', function() {
- inject(function($httpBackend, $rootScope, $controller) {
- $rootScope.baseURL = "http://localhost:8082"
- $httpBackend.expectJSONP($rootScope.baseURL + '/getPathLeader/?callback=JSON_CALLBACK').
- respond(200, {'leader': '/usr/local/rcmes'});
-
- var scope = $rootScope.$new();
- var ctrl = $controller("ObservationSelectCtrl", {$scope: scope});
- $httpBackend.flush();
-
- expect(scope.params.length).toBe(1);
- expect(scope.lats.length).toBe(1);
- expect(scope.lons.length).toBe(1);
- expect(scope.times.length).toBe(1);
-
- expect(scope.params[0]).toEqual("Please select a file above");
- expect(scope.lats[0]).toEqual("Please select a file above");
- expect(scope.lons[0]).toEqual("Please select a file above");
- expect(scope.times[0]).toEqual("Please select a file above");
- });
- });
-
- it('should initialize scope attributes properly', function() {
- inject(function($httpBackend, $rootScope, $controller) {
- $rootScope.baseURL = "http://localhost:8082"
- $httpBackend.expectJSONP($rootScope.baseURL + '/getPathLeader/?callback=JSON_CALLBACK').
- respond(200, {'leader': '/usr/local/rcmes'});
-
- var scope = $rootScope.$new();
- var ctrl = $controller("ObservationSelectCtrl", {$scope: scope});
- $httpBackend.flush();
-
- expect(scope.pathLeader).toEqual('/usr/local/rcmes');
- expect(scope.loadingFile).toBe(false);
- expect(scope.fileAdded).toBe(false);
- expect(typeof scope.latLonVals).toEqual('object');
- expect(scope.latLonVals.length).toBe(0);
- expect(typeof scope.timeVals).toEqual('object');
- expect(scope.timeVals.length).toEqual(0);
- expect(typeof scope.localSelectForm).toEqual('object');
- expect(Object.keys(scope.localSelectForm).length).toEqual(0);
- });
- });
-
- it('should initialize the uploadLocalFile function', function() {
- inject(function($httpBackend, $rootScope, $controller) {
- $rootScope.baseURL = "http://localhost:8082"
- $httpBackend.expectJSONP($rootScope.baseURL + '/getPathLeader/?callback=JSON_CALLBACK').
- respond(200, {'leader': '/usr/local/rcmes'});
-
- var scope = $rootScope.$new();
- var ctrl = $controller("ObservationSelectCtrl", {$scope: scope});
- $httpBackend.flush();
-
- $httpBackend.expectJSONP($rootScope.baseURL + '/list/vars/"/usr/local/rcmesundefined"?callback=JSON_CALLBACK').
- respond(200, {"variables": ["lat", "lon", "prec", "time" ]});
- $httpBackend.expectJSONP($rootScope.baseURL + '/list/latlon/"/usr/local/rcmesundefined"?callback=JSON_CALLBACK').
- respond(200, {'latMax': '75.25', 'success': 1, 'latname': 'lat', 'lonMax': '-29.75', 'lonMin': '-159.75', 'lonname': 'lon', 'latMin': '15.25'});
- $httpBackend.expectJSONP($rootScope.baseURL + '/list/time/"/usr/local/rcmesundefined"?callback=JSON_CALLBACK').
- respond(200, {"start_time": "1980-01-01 00:00:00", "timename": "time", "success": 1, "end_time": "2004-12-01 00:00:00"});
-
- scope.uploadLocalFile();
- $httpBackend.flush();
-
- expect(scope.latsSelect).toEqual("lat");
- expect(scope.lonsSelect).toEqual("lon");
- expect(scope.timeSelect).toEqual("time");
- expect(scope.paramSelect).toEqual("prec");
-
- // Simulate failure on one of the backend calls. Should
- $httpBackend.expectJSONP($rootScope.baseURL + '/list/vars/"/usr/local/rcmesundefined"?callback=JSON_CALLBACK').
- respond(200, {});
- $httpBackend.expectJSONP($rootScope.baseURL + '/list/latlon/"/usr/local/rcmesundefined"?callback=JSON_CALLBACK').
- respond(404, {});
- $httpBackend.expectJSONP($rootScope.baseURL + '/list/time/"/usr/local/rcmesundefined"?callback=JSON_CALLBACK').
- respond(200, {});
-
- scope.uploadLocalFile();
- $httpBackend.flush();
-
- expect(scope.paramSelect).toEqual("Unable to load variable(s)");
- expect(scope.params.length).toEqual(1);
- expect(scope.latsSelect).toEqual("Unable to load variable(s)");
- expect(scope.lats.length).toEqual(1);
- expect(scope.lonsSelect).toEqual("Unable to load variable(s)");
- expect(scope.lons.length).toEqual(1);
- expect(scope.timeSelect).toEqual("Unable to load variable(s)");
- expect(scope.times.length).toEqual(1);
- });
- });
-
- it('should initialize the addDatasets function', function() {
- inject(function($httpBackend, $rootScope, $controller) {
- $rootScope.baseURL = "http://localhost:8082"
- $httpBackend.expectJSONP($rootScope.baseURL + '/getPathLeader/?callback=JSON_CALLBACK').
- respond(200, {'leader': '/usr/local/rcmes'});
-
- var scope = $rootScope.$new();
- var ctrl = $controller("ObservationSelectCtrl", {$scope: scope});
- $httpBackend.flush();
-
- // Add a bunch of bogus data as a dataset
- scope.addDataSet();
-
- expect(scope.datasetCount.length).toBe(1);
- });
- });
- });
-});
http://git-wip-us.apache.org/repos/asf/climate/blob/a53e3af5/ocw-ui/frontend/test/unit/controllers/ParameterSelectCtrlTest.js
----------------------------------------------------------------------
diff --git a/ocw-ui/frontend/test/unit/controllers/ParameterSelectCtrlTest.js b/ocw-ui/frontend/test/unit/controllers/ParameterSelectCtrlTest.js
deleted file mode 100644
index 6845245..0000000
--- a/ocw-ui/frontend/test/unit/controllers/ParameterSelectCtrlTest.js
+++ /dev/null
@@ -1,269 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http: *www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
-**/
-
-'use strict';
-
-describe('OCW Controllers', function() {
-
- beforeEach(module('ocw.controllers'));
- beforeEach(module('ocw.services'));
-
-
- describe('ParameterSelectCtrl', function() {
- it('should initialize spatial and temporal range default values properly', function() {
- inject(function($rootScope, $controller) {
- var scope = $rootScope.$new();
- var ctrl = $controller("ParameterSelectCtrl", {$scope: scope});
-
- expect(scope.latMin).toBe(-90);
- expect(scope.latMax).toBe(90);
- expect(scope.lonMin).toBe(-180);
- expect(scope.lonMax).toBe(180);
- expect(scope.start).toBe("1980-01-01 00:00:00");
- expect(scope.end).toBe("2030-01-01 00:00:00");
- });
- });
-
- it('should grab the default set of selected datasets from the service', function() {
- inject(function($rootScope, $controller) {
- var scope = $rootScope.$new();
- var ctrl = $controller("ParameterSelectCtrl", {$scope: scope});
-
- // We should get an object with no keys since the user hasn't selected any
- // datasets by default. Object.keys returns an array of all the user defined
- // keys in the object.
- expect(typeof scope.datasets).toBe('object');
- expect(Object.keys(scope.datasets).length).toBe(0);
- });
- });
-
- it('should grab the default region select param object from the regionSelectParams service', function() {
- inject(function($rootScope, $controller) {
- var scope = $rootScope.$new();
- var ctrl = $controller("ParameterSelectCtrl", {$scope: scope});
-
- // The default display values aren't going to be changing any time soon. This test
- // is a bit of a duplicate since this is really testing functionality of the service.
- // Can't hurt to make sure that we're getting results though!
- expect(typeof scope.displayParams).toBe('object');
- expect(Object.keys(scope.displayParams).length).toBe(7);
- });
- });
-
- it('should initialize misc. values properly', function() {
- inject(function($rootScope, $controller) {
- var scope = $rootScope.$new();
- var ctrl = $controller("ParameterSelectCtrl", {$scope: scope});
-
- expect(scope.runningEval).toBe(false);
- expect(scope.areInUserRegridState).toBe(false);
- expect(scope.latSliderVal).toBe(0);
- expect(scope.lonSliderVal).toBe(0);
- });
- });
-
- it('should set the default datepicker settings', function() {
- inject(function($rootScope, $controller) {
- var scope = $rootScope.$new();
- var ctrl = $controller("ParameterSelectCtrl", {$scope: scope});
-
- // This tests the default values that get passed to the datepicker objects that we
- // initialize with a directive.
- expect(Object.keys(scope.datepickerSettings).length).toBe(2);
- expect(scope.datepickerSettings.changeMonth).toBe(true);
- expect(scope.datepickerSettings.changeYear).toBe(true);
- });
- });
-
- it('should define the slide "slide" callback functions', function() {
- inject(function($rootScope, $controller) {
- var scope = $rootScope.$new();
- var ctrl = $controller("ParameterSelectCtrl", {$scope: scope});
-
- expect(scope.latSliderVal).toBe(0);
- expect(scope.lonSliderVal).toBe(0);
- scope.updateLatSliderDisplayValue(1);
- scope.updateLonSliderDisplayValue(2);
- expect(scope.latSliderVal).toBe(1);
- expect(scope.lonSliderVal).toBe(2);
- });
- });
-
- it('should initialize the control disable function', function() {
- inject(function($rootScope, $controller) {
- var scope = $rootScope.$new();
- var ctrl = $controller("ParameterSelectCtrl", {$scope: scope});
-
- expect(scope.shouldDisableControls()).toBe(true);
- // Add to dummy values to datasets to make sure the disable function
- // triggers properly.
- scope.datasets.push(1);
- scope.datasets.push(2);
- expect(scope.shouldDisableControls()).toBe(false);
- });
- });
-
- it('should initialize the disable evaluation button function', function() {
- inject(function($rootScope, $controller) {
- var scope = $rootScope.$new();
- var ctrl = $controller("ParameterSelectCtrl", {$scope: scope});
-
- expect(scope.shouldDisableEvaluateButton()).toBe(true);
- scope.datasets.push(1);
- expect(scope.shouldDisableEvaluateButton()).toBe(true);
- scope.datasets.push(2);
- expect(scope.shouldDisableEvaluateButton()).toBe(false);
- scope.runningEval = true;
- expect(scope.shouldDisableEvaluateButton()).toBe(true);
- });
- });
-
- it('should initialize the disable results view function', function() {
- inject(function($rootScope, $controller) {
- $rootScope.evalResults = "";
- var scope = $rootScope.$new();
- var ctrl = $controller("ParameterSelectCtrl", {$rootScope: $rootScope, $scope: scope});
-
- expect(scope.shouldDisableResultsView()).toBe(true);
-
- // Set evalResults to something other than the default value
- $rootScope.evalResults = "this is not an empty string";
-
- expect(scope.shouldDisableResultsView()).toBe(false);
- });
- });
-
- it('should initialize the check parameters function', function() {
- inject(function($rootScope, $controller) {
- var scope = $rootScope.$new();
- var ctrl = $controller("ParameterSelectCtrl", {$scope: scope});
-
- // Set the displayParams values to be "out of bounds" values so checkParams
- // adjusts them properly.
- scope.displayParams.latMin = "-95";
- scope.displayParams.latMax = "95";
- scope.displayParams.lonMin = "-185";
- scope.displayParams.lonMax = "185";
- scope.displayParams.start = "1980-00-00 00:00:00";
- scope.displayParams.end = "2031-01-01 00:00:00";
-
- // If we don't remove the watch on datasets we end up with displayParam values
- // all being undefined (but only during testing, which is odd...)
- scope.unwatchDatasets();
- scope.checkParameters();
-
- expect(scope.displayParams.latMin).toBe(-90);
- expect(scope.displayParams.latMax).toBe(90);
- expect(scope.displayParams.lonMin).toBe(-180);
- expect(scope.displayParams.lonMax).toBe(180);
- expect(scope.displayParams.start).toBe('1980-01-01 00:00:00');
- expect(scope.displayParams.end).toBe('2030-01-01 00:00:00');
- });
- });
-
- it('should properly set the results of running an evaluation', function() {
- inject(function($rootScope, $controller, $httpBackend) {
- var scope = $rootScope.$new();
- var ctrl = $controller("ParameterSelectCtrl", {$scope: scope});
-
- // Seed rootScope with a known URL for test queries and holder for eval results
- $rootScope.baseURL = "http://localhost:9876";
- $rootScope.evalResults = {};
-
- // Seed the displayParams so the query is properly formatted
- scope.displayParams.lonMin = -180;
- scope.displayParams.lonMax = 180;
- scope.displayParams.latMin = -90;
- scope.displayParams.latMax = 90;
- scope.displayParams.start = "1980-01-01";
- scope.displayParams.end = "2030-01-01";
-
- // The expected URL string that the frontend generates given this example set
- var urlString = "http://localhost:9876/rcmes/run/?" +
- "callback=JSON_CALLBACK&" +
- "endTime=2030-01-01%2000%3A00%3A00&" +
- "filelist=%2Fusr%2Flocal%2Frcmes%2FmodelsForUI%2Fprec.HRM3.ncep.monavg.nc&" +
- "latMax=90&" +
- "latMin=-90&" +
- "lonMax=180&" +
- "lonMin=-180&" +
- "metricOption=bias&" +
- "modelLatVarName=lat&" +
- "modelLonVarName=lon&" +
- "modelTimeVarName=time&" +
- "modelVarName=prec&" +
- "obsDatasetId=3&" +
- "obsParameterId=36&" +
- "regridOption=model&" +
- "startTime=1980-01-01%2000%3A00%3A00&" +
- "timeRegridOption=monthly";
-
- // Example dataset configuration for the test.
- scope.datasets = [
- {
- "isObs" : 1,
- "id" : "3",
- "name" : "Tropical Rainfall Measuring Mission Dataset",
- "param" : "36",
- "paramName" : "TRMM v.6 Monthly Precipitation",
- "latlonVals" : {"latMin" : -90, "latMax" : 90, "lonMin" : -180, "lonMax" : 180},
- "lat" : "N/A",
- "lon" : "N/A",
- "timeVals" : {"start" : "1998-01-01 00:00:00",
- "end" : "2010-01-01 00:00:00"},
- "time" : "N/A",
- "shouldDisplay" : true,
- "regrid" : false
- },{
- "isObs" : 0,
- "id" : "/usr/local/rcmes/modelsForUI/prec.HRM3.ncep.monavg.nc",
- "name" : "prec.HRM3.ncep.monavg.nc",
- "param" : "prec",
- "paramName" : "prec",
- "lat" : "lat",
- "lon" : "lon",
- "latlonVals" : {"latMin" : "15.25",
- "latMax" : "75.25",
- "lonMin" : "-159.75",
- "lonMax" : "-29.75"},
- "time" : "time",
- "timeVals" : {"start":"1980-01-01 00:00:00",
- "end" : "2004-12-01 00:00:00"},
- "shouldDisplay" : true,
- "regrid" : false
- }
- ];
-
- // Mock return URLs that the frontend will parse
- $httpBackend.expectJSONP(urlString).respond(200,
- {'comparisonPath': '/fake/path1',
- 'modelPath': '/fake/path2',
- 'obsPath': '/fake/path3'});
-
-
- scope.runEvaluation();
- $httpBackend.flush();
-
- expect($rootScope.evalResults.comparisonPath).toBe('path1');
- expect($rootScope.evalResults.modelPath).toBe('path2');
- expect($rootScope.evalResults.obsPath).toBe('path3');
- });
- });
- });
-});
http://git-wip-us.apache.org/repos/asf/climate/blob/a53e3af5/ocw-ui/frontend/test/unit/controllers/RcmedSelectionCtrlTest.js
----------------------------------------------------------------------
diff --git a/ocw-ui/frontend/test/unit/controllers/RcmedSelectionCtrlTest.js b/ocw-ui/frontend/test/unit/controllers/RcmedSelectionCtrlTest.js
deleted file mode 100644
index 3279ecc..0000000
--- a/ocw-ui/frontend/test/unit/controllers/RcmedSelectionCtrlTest.js
+++ /dev/null
@@ -1,161 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http: *www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
-**/
-
-'use strict';
-
-describe('OCW Controllers', function() {
-
- beforeEach(module('ocw.controllers'));
- beforeEach(module('ocw.services'));
-
- describe('RcmedSelectionCtrl', function() {
- it('should automatically query RCMED on initialization', function() {
- inject(function($rootScope, $controller, $httpBackend) {
- $rootScope.baseURL = "http://localhost:8082"
- $httpBackend.expectJSONP($rootScope.baseURL + '/getObsDatasets?callback=JSON_CALLBACK').
- respond(200, [{longname: 1}, {longname: 2}]);
-
- var scope = $rootScope.$new();
- var ctrl = $controller("RcmedSelectionCtrl", {$scope: scope});
- $httpBackend.flush();
-
- expect(scope.availableObs.length).toBe(3);
- expect(scope.availableObs[0]).toEqual({longname: "Please select an option"});
- expect(scope.availableObs[1]).toEqual({longname: 1});
- });
- });
-
- it('should initialize the getObservations function', function() {
- inject(function($rootScope, $controller, $httpBackend) {
- $rootScope.baseURL = "http://localhost:8082"
- $httpBackend.expectJSONP($rootScope.baseURL + '/getObsDatasets?callback=JSON_CALLBACK').
- respond(200, [{longname: 1}, {longname: 2}]);
-
- var scope = $rootScope.$new();
- var ctrl = $controller("RcmedSelectionCtrl", {$scope: scope});
- $httpBackend.flush();
-
- expect(scope.availableObs.length).toBe(3);
- expect(scope.availableObs[0]).toEqual({longname: "Please select an option"});
- expect(scope.availableObs[1]).toEqual({longname: 1});
-
- // Set up a failed query
- $httpBackend.expectJSONP($rootScope.baseURL + '/getObsDatasets?callback=JSON_CALLBACK').
- respond(404);
- scope.getObservations();
- $httpBackend.flush();
-
- expect(scope.availableObs.length).toBe(1);
- expect(scope.availableObs[0]).toEqual('Unable to query RCMED');
-
- });
- });
-
- it('should initialze the getObservationTimeRange function', function() {
- inject(function($rootScope, $controller, $httpBackend) {
- $rootScope.baseURL = "http://localhost:8082"
- $httpBackend.expectJSONP($rootScope.baseURL + '/getObsDatasets?callback=JSON_CALLBACK').
- respond(200, [{longname: 1}, {longname: 2}]);
-
- var scope = $rootScope.$new();
- var ctrl = $controller("RcmedSelectionCtrl", {$scope: scope});
- $httpBackend.flush();
-
- expect(scope.getObservationTimeRange(1)).toEqual({'start' : '1989-01-01 00:00:00',
- 'end' : '2009-12-31 00:00:00'});
- expect(scope.getObservationTimeRange(-1)).toEqual(false);
- });
- });
-
- it('should initialize dataSelectUpdated function', function() {
- inject(function($rootScope, $controller, $httpBackend) {
- $rootScope.baseURL = "http://localhost:8082"
- $httpBackend.expectJSONP($rootScope.baseURL + '/getObsDatasets?callback=JSON_CALLBACK').
- respond(200, [{longname: 1}, {longname: 2}]);
-
- var scope = $rootScope.$new();
- var ctrl = $controller("RcmedSelectionCtrl", {$scope: scope});
- $httpBackend.flush();
-
- // Add the test dataset to our scope
- scope.datasetSelection = {shortname: 'TRMM'}
-
- // Test return with only single parameter
- $httpBackend.expectJSONP($rootScope.baseURL + '/getDatasetParam?dataset=' +
- scope.datasetSelection['shortname'] +
- '&callback=JSON_CALLBACK').
- respond(200, ['pcp']);
- scope.dataSelectUpdated();
- $httpBackend.flush();
-
- expect(scope.parameterSelection).toEqual('pcp');
-
- // Test return with multiple parameters
- $httpBackend.expectJSONP($rootScope.baseURL + '/getDatasetParam?dataset=' +
- scope.datasetSelection['shortname'] +
- '&callback=JSON_CALLBACK').
- respond(200, ['pcp', 'pcp2']);
- scope.dataSelectUpdated();
- $httpBackend.flush();
-
- expect(scope.parameterSelection).toEqual({shortname: 'Please select a parameter'});
- });
- });
-
- it('should initialze the addObservation function', function() {
- inject(function($rootScope, $controller, $httpBackend) {
- $rootScope.baseURL = "http://localhost:8082"
- $httpBackend.expectJSONP($rootScope.baseURL + '/getObsDatasets?callback=JSON_CALLBACK').
- respond(200, [{longname: 1}, {longname: 2}]);
-
- var scope = $rootScope.$new();
- var ctrl = $controller("RcmedSelectionCtrl", {$scope: scope});
- $httpBackend.flush();
-
- scope.datasetSelection = {
- "dataset_id" : "3",
- "shortname" : "TRMM",
- "longname" : "Tropical Rainfall Measuring Mission Dataset",
- "source" : "Readme for the Tropical Rainfall Measuring Mission (TRMM) Data Set"
- };
-
- scope.parameterSelection = {
- "parameter_id":"36",
- "shortname":"pcp",
- "datasetshortname":"TRMM",
- "longname":"TRMM v.6 Monthly Precipitation",
- "units":"mm\/day"
- };
-
- // addObservations does a refresh of the selections with a re-query of the backend
- // so we need to catch that call!
- $httpBackend.expectJSONP($rootScope.baseURL + '/getObsDatasets?callback=JSON_CALLBACK').
- respond(200, [{longname: 1}, {longname: 2}]);
-
- scope.addObservation();
- $httpBackend.flush();
-
- expect(scope.datasetCount.length).toBe(1);
- // The selection observation should be reset so we shouldn't have
- // any selected observation parameters.
- expect(scope.retrievedObsParams).toEqual([]);
- });
- });
- });
-});
http://git-wip-us.apache.org/repos/asf/climate/blob/a53e3af5/ocw-ui/frontend/test/unit/controllers/SettingsCtrlTest.js
----------------------------------------------------------------------
diff --git a/ocw-ui/frontend/test/unit/controllers/SettingsCtrlTest.js b/ocw-ui/frontend/test/unit/controllers/SettingsCtrlTest.js
deleted file mode 100644
index 12c133d..0000000
--- a/ocw-ui/frontend/test/unit/controllers/SettingsCtrlTest.js
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http: *www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
-**/
-
-'use strict';
-
-describe('OCW Controllers', function() {
-
- beforeEach(module('ocw.controllers'));
- beforeEach(module('ocw.services'));
-
- describe('SettingsCtrl', function() {
- it('should initialize settings object from evaluationSettings service', function() {
- inject(function($rootScope, $controller) {
- var scope = $rootScope.$new();
- var ctrl = $controller("SettingsCtrl", {$scope: scope});
-
- expect(Object.keys(scope.settings)).toEqual(["metrics", "temporal", "spatialSelect"]);
- });
- });
-
- it('should pull the dataset information', function() {
- inject(function($rootScope, $controller) {
- var scope = $rootScope.$new();
- var ctrl = $controller("SettingsCtrl", {$scope: scope});
-
- expect(typeof scope.datasets).toBe('object');
- expect(Object.keys(scope.datasets).length).toBe(0);
- });
- });
- });
-});
http://git-wip-us.apache.org/repos/asf/climate/blob/a53e3af5/ocw-ui/frontend/test/unit/controllers/WorldMapCtrlTest.js
----------------------------------------------------------------------
diff --git a/ocw-ui/frontend/test/unit/controllers/WorldMapCtrlTest.js b/ocw-ui/frontend/test/unit/controllers/WorldMapCtrlTest.js
deleted file mode 100644
index 805dc88..0000000
--- a/ocw-ui/frontend/test/unit/controllers/WorldMapCtrlTest.js
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http: *www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
-**/
-
-'use strict';
-
-describe('OCW Controllers', function() {
-
- beforeEach(module('ocw.controllers'));
- beforeEach(module('ocw.services'));
-
- describe('WorldMapCtrl', function() {
- it('should initialize the updateMap function', function() {
- inject(function($rootScope, $controller) {
- var scope = $rootScope.$new();
- var ctrl = $controller("WorldMapCtrl", {$scope: scope});
-
- // Set the important attributes for a fake dataset
- scope.datasets.push({shouldDisplay: true, latlonVals: {latMin: 0, latMax: 0, lonMin: 0, lonMax: 0}});
- // Don't try to add the user defined region since we don't have one
- scope.regionParams.areValid = false;
- // We need to fake the map object. The only thing we care about is faking the "addLayer" function
- // and the "fitBounds" functions which our map controllers makes use of.
- $rootScope.map = {addLayer: function(){}, fitBounds: function(){}};
- $rootScope.fillColors = ['#ff0000'];
-
- expect("rectangleGroup" in $rootScope).toBe(false);
- scope.updateMap();
- expect("rectangleGroup" in $rootScope).toBe(true);
- });
- });
- });
-});
http://git-wip-us.apache.org/repos/asf/climate/blob/a53e3af5/ocw-ui/frontend/test/unit/directives/BootstrapModalTest.js
----------------------------------------------------------------------
diff --git a/ocw-ui/frontend/test/unit/directives/BootstrapModalTest.js b/ocw-ui/frontend/test/unit/directives/BootstrapModalTest.js
deleted file mode 100644
index dacc74c..0000000
--- a/ocw-ui/frontend/test/unit/directives/BootstrapModalTest.js
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
-**/
-'use strict';
-
-describe('directives', function() {
- beforeEach(module('ocw'));
-
- describe('bootstrap-modal directive', function() {
- it('should create a div element of the correct form', function() {
- inject(function($compile, $rootScope) {
- var element = $compile('<bootstrap-modal modal-id="testmodal"></bootstrap-modal>')($rootScope);
- expect(element.hasClass("modal")).toBeTruthy();
- expect(element.hasClass("hide")).toBeTruthy();
- expect(element.attr("id")).toEqual('{{modalId}}');
- });
- });
-
- it('should properly wrap the interior html content' , function() {
- inject(function($compile, $rootScope) {
- var element = $compile('<bootstrap-modal modal-id="testmodal"><h3>Hello</h3></bootstrap-modal>')($rootScope);
- expect(element.html()).toEqual("<div ng-transclude=\"\"><h3 class=\"ng-scope\">Hello</h3></div>");
- });
- });
- });
-});
http://git-wip-us.apache.org/repos/asf/climate/blob/a53e3af5/ocw-ui/frontend/test/unit/directives/OnBlurTest.js
----------------------------------------------------------------------
diff --git a/ocw-ui/frontend/test/unit/directives/OnBlurTest.js b/ocw-ui/frontend/test/unit/directives/OnBlurTest.js
deleted file mode 100644
index c99b2c3..0000000
--- a/ocw-ui/frontend/test/unit/directives/OnBlurTest.js
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
-**/
-
-'use strict';
-
-describe('directives', function() {
- beforeEach(module('ocw'));
-
- describe('onBlur directive', function() {
- it('should call the supplied function on the blur event', function() {
- inject(function($compile, $rootScope) {
- // Set a rootScope variable to make sure that on-blur calls
- // the function that we pass to it.
- $rootScope.bogusFunction = function() {
- $rootScope.test = "hi"
- }
-
- var element = $compile('<input on-blur="bogusFunction();" />')($rootScope);
-
- expect($rootScope.test).toNotBe('hi');
- element.trigger('blur');
- expect($rootScope.test).toBe('hi');
- });
- });
- });
-});
http://git-wip-us.apache.org/repos/asf/climate/blob/a53e3af5/ocw-ui/frontend/test/unit/directives/PreviewMapTest.js
----------------------------------------------------------------------
diff --git a/ocw-ui/frontend/test/unit/directives/PreviewMapTest.js b/ocw-ui/frontend/test/unit/directives/PreviewMapTest.js
deleted file mode 100644
index a7991e6..0000000
--- a/ocw-ui/frontend/test/unit/directives/PreviewMapTest.js
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
-**/
-
-'use strict';
-
-describe('directives', function() {
- beforeEach(module('ocw'));
-
- describe('preview-map directive', function() {
- it('should set the proper class', function() {
- inject(function($compile, $rootScope) {
- $rootScope.dataset = {latlonVals: {latMax: 90, lonMax: 90, latMin: -90, lonMin: -90}, name: "TRMM"};
-
- var element = $compile('<div preview-map="dataset"></div>')($rootScope);
-
- expect(element.hasClass("preview-map")).toBeTruthy();
- });
- });
-
- it('should set the id of the template to the name of the dataset', function() {
- inject(function($compile, $rootScope) {
- $rootScope.dataset = {latlonVals: {latMax: 90, lonMax: 90, latMin: -90, lonMin: -90}, name: "TRMM"};
-
- var element = $compile('<div preview-map="dataset"></div>')($rootScope);
-
- expect(element.attr('id')).toEqual("{{dataset.name}}");
- });
- });
- });
-});
http://git-wip-us.apache.org/repos/asf/climate/blob/a53e3af5/ocw-ui/frontend/test/unit/filters/ISODateToMiddleEndianTest.js
----------------------------------------------------------------------
diff --git a/ocw-ui/frontend/test/unit/filters/ISODateToMiddleEndianTest.js b/ocw-ui/frontend/test/unit/filters/ISODateToMiddleEndianTest.js
deleted file mode 100644
index 9228765..0000000
--- a/ocw-ui/frontend/test/unit/filters/ISODateToMiddleEndianTest.js
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
-**/
-'use strict';
-
-describe('OCW Filters', function() {
- beforeEach(module('ocw.filters'));
-
- describe('ISODateToMiddleEndian', function() {
- it('should replace the ISO Date/Time stamp', function() {
- inject(function($filter) {
- var filter = $filter('ISODateToMiddleEndian');
- expect(filter('2012-01-02T00:00:00')).toEqual('01/02/2012');
- });
- });
-
- it('should replace the modified ISO Date/Time stamp', function() {
- inject(function($filter) {
- var filter = $filter('ISODateToMiddleEndian');
- expect(filter('2012-01-02 00:00:00')).toEqual('01/02/2012');
- });
- });
-
- it('should replace the ISO Date stamp', function() {
- inject(function($filter) {
- var filter = $filter('ISODateToMiddleEndian');
- expect(filter('2012-01-02')).toEqual('01/02/2012');
- });
- });
-
- it('should replace leading and trailing whitespace', function() {
- inject(function($filter) {
- var filter = $filter('ISODateToMiddleEndian');
- expect(filter(' 2012-01-02T00:00:00 ')).toEqual('01/02/2012');
- });
- });
-
- it('should do nothing when the date format has the incorrect number of hyphens', function() {
- inject(function($filter) {
- var filter = $filter('ISODateToMiddleEndian');
- expect(filter('2012-234T234')).toEqual('2012-234T234')
- });
- });
-
- it('should do nothing when the date format has no hyphens', function() {
- inject(function($filter) {
- var filter = $filter('ISODateToMiddleEndian');
- expect(filter('2012234T234')).toEqual('2012234T234')
- });
- });
- });
-});
http://git-wip-us.apache.org/repos/asf/climate/blob/a53e3af5/ocw-ui/frontend/test/unit/services/EvaluationSettingsTest.js
----------------------------------------------------------------------
diff --git a/ocw-ui/frontend/test/unit/services/EvaluationSettingsTest.js b/ocw-ui/frontend/test/unit/services/EvaluationSettingsTest.js
deleted file mode 100644
index b8d021a..0000000
--- a/ocw-ui/frontend/test/unit/services/EvaluationSettingsTest.js
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http: *www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
-**/
-
-'use strict';
-
-describe('OCW Services', function() {
-
- beforeEach(module('ocw.services'));
-
- describe('EvaluationSettings', function() {
-
- it('should initialize the evaluationSettings service', function() {
- inject(function(evaluationSettings) {
- expect(evaluationSettings).not.toEqual(null);
- });
- });
-
- it('should provide a getSettings function', function() {
- inject(function(evaluationSettings) {
- expect(evaluationSettings.getSettings()).not.toEqual(null);
- })
- })
- });
-});
http://git-wip-us.apache.org/repos/asf/climate/blob/a53e3af5/ocw-ui/frontend/test/unit/services/RegionSelectParamsTest.js
----------------------------------------------------------------------
diff --git a/ocw-ui/frontend/test/unit/services/RegionSelectParamsTest.js b/ocw-ui/frontend/test/unit/services/RegionSelectParamsTest.js
deleted file mode 100644
index 2b90ec3..0000000
--- a/ocw-ui/frontend/test/unit/services/RegionSelectParamsTest.js
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http: *www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
-**/
-
-'use strict';
-
-describe('OCW Services', function() {
-
- beforeEach(module('ocw.services'));
-
- describe('RegionSelectParams', function() {
-
- it('should initialize the regionSelectParams service', function() {
- inject(function(regionSelectParams) {
- expect(regionSelectParams).not.toEqual(null);
- });
- });
-
- it('should provide the getParameters function', function() {
- inject(function(regionSelectParams) {
- expect(regionSelectParams.getParameters()).not.toEqual(null);
- });
- });
- });
-});
-
http://git-wip-us.apache.org/repos/asf/climate/blob/a53e3af5/ocw-ui/frontend/test/unit/services/SelectedDatasetInfomationTest.js
----------------------------------------------------------------------
diff --git a/ocw-ui/frontend/test/unit/services/SelectedDatasetInfomationTest.js b/ocw-ui/frontend/test/unit/services/SelectedDatasetInfomationTest.js
deleted file mode 100644
index aeada3d..0000000
--- a/ocw-ui/frontend/test/unit/services/SelectedDatasetInfomationTest.js
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http: *www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
-**/
-
-'use strict';
-
-describe('OCW Services', function() {
-
- beforeEach(module('ocw.services'));
-
- describe('SelectedDatasetInformation', function() {
-
- it('should initialize the selectedDatasetInformation service', function() {
- inject(function(selectedDatasetInformation) {
- expect(selectedDatasetInformation).not.toEqual(null);
- });
- });
-
- it('should provide the getDatasets function', function() {
- inject(function(selectedDatasetInformation) {
- expect(selectedDatasetInformation.getDatasets()).not.toEqual(null);
- });
- });
-
- it('should provide the getDatasetCount function', function() {
- inject(function(selectedDatasetInformation) {
- expect(selectedDatasetInformation.getDatasetCount()).toEqual(0);
- });
- });
-
- it('should provide the addDataset function', function() {
- inject(function(selectedDatasetInformation) {
- selectedDatasetInformation.addDataset({});
- expect(selectedDatasetInformation.getDatasetCount()).toEqual(1);
- });
- });
-
- it('should set the shouldDisplay attribute when adding a dataset', function() {
- inject(function(selectedDatasetInformation) {
- selectedDatasetInformation.addDataset({});
- expect(selectedDatasetInformation.getDatasets()[0].shouldDisplay).toBe(false);
- });
- });
-
- it('should set the regrid attribute when adding a dataset', function() {
- inject(function(selectedDatasetInformation) {
- selectedDatasetInformation.addDataset({});
- expect(selectedDatasetInformation.getDatasets()[0].regrid).toBe(false);
- });
- });
-
- it('should provide the removeDataset function', function() {
- inject(function(selectedDatasetInformation) {
- selectedDatasetInformation.addDataset(1);
- selectedDatasetInformation.addDataset(2);
-
- expect(selectedDatasetInformation.getDatasets()[0]).toEqual(1);
- selectedDatasetInformation.removeDataset(0);
- expect(selectedDatasetInformation.getDatasets()[0]).toEqual(2);
- });
- });
-
- it('should provide the clearDatasets function', function() {
- inject(function(selectedDatasetInformation) {
- selectedDatasetInformation.addDataset({});
- expect(selectedDatasetInformation.getDatasetCount()).toEqual(1);
-
- selectedDatasetInformation.clearDatasets();
- expect(selectedDatasetInformation.getDatasetCount()).toEqual(0);
- });
- });
- });
-});
-
-
http://git-wip-us.apache.org/repos/asf/climate/blob/a53e3af5/ocw-vm/Vagrantfile
----------------------------------------------------------------------
diff --git a/ocw-vm/Vagrantfile b/ocw-vm/Vagrantfile
deleted file mode 100644
index 90f41a6..0000000
--- a/ocw-vm/Vagrantfile
+++ /dev/null
@@ -1,17 +0,0 @@
-# -*- mode: ruby -*-
-# vi: set ft=ruby :
-
-# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
-VAGRANTFILE_API_VERSION = "2"
-
-Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
- config.vm.box = "hashicorp/precise64"
-
- #Boot the VM into GUI mode.
- config.vm.provider "virtualbox" do |vb|
- # Don't boot with headless mode
- vb.gui = true
- # Use VBoxManage to customize the VM. For example to change memory:
- vb.customize ["modifyvm", :id, "--memory", "1024"]
- end
-end
http://git-wip-us.apache.org/repos/asf/climate/blob/a53e3af5/ocw-vm/init-ocw-vm.sh
----------------------------------------------------------------------
diff --git a/ocw-vm/init-ocw-vm.sh b/ocw-vm/init-ocw-vm.sh
deleted file mode 100755
index 658a494..0000000
--- a/ocw-vm/init-ocw-vm.sh
+++ /dev/null
@@ -1,103 +0,0 @@
-#!/bin/bash
-#
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-
-# Install some useful/necessary dependencies to make future installs easier
-sudo apt-get update
-sudo apt-get install -y make
-sudo apt-get install -y libblas-dev
-sudo apt-get install -y liblapack-dev
-sudo apt-get install -y gfortran
-sudo apt-get install -y g++
-sudo apt-get install -y build-essential
-sudo apt-get install -y python-dev
-sudo apt-get install -y ia32-libs --fix-missing
-sudo apt-get install -y git
-sudo apt-get install -y vim
-
-# GUI related installs
-sudo apt-get install -y lightdm
-
-# XFCE
-#sudo apt-get install -y xfce4
-#sudo apt-get install -y xdg-utils
-#sudo apt-get install -y eog
-
-# Ubuntu Unity
-sudo apt-get install -y ubuntu-desktop
-
-# Use the Easy-OCW Ubuntu install script to get everything
-# else installed!
-git clone http://git-wip-us.apache.org/repos/asf/climate.git
-
-# Copy the Easy-OCW install script for Ubuntu
-cp climate/easy-ocw/install-ubuntu-12_04.sh .
-# Copy the requirements files for conda and pip used by Easy-OCW
-cp climate/easy-ocw/*.txt .
-
-bash install-ubuntu-12_04.sh -q
-
-# Set symlink for the UI frontend code
-cd climate/ocw-ui/backend
-ln -s ../frontend/app app
-
-# Cleanup Anaconda and Basemap downloads from the install script
-cd
-sudo rm -f Anaconda-1.9.2-Linux-x86_64.sh
-sudo rm -f basemap-1.0.7.tar.gz
-sudo rm -rf basemap-1.0.7
-
-mkdir /home/vagrant/Desktop
-
-# These links will only work if we're using the Unity desktop.
-# If you want to use the XFCE desktop you will need to change
-# the references to 'nautilus' to whatever file browser you
-# will be using.
-cat >/home/vagrant/Desktop/climate.desktop <<CODELINK
-[Desktop Entry]
-Name=Climate-Code
-Icon=utilities-terminal
-Exec=nautilus /home/vagrant/climate
-Terminal=false
-Type=Application
-CODELINK
-
-cat >/home/vagrant/Desktop/ui.desktop <<UISTART
-[Desktop Entry]
-Name=Climate-UI
-Icon=utilities-terminal
-Exec=/home/vagrant/Desktop/.ui.sh
-Terminal=true
-Type=Application
-UISTART
-
-cat >/home/vagrant/Desktop/.ui.sh <<UIBOOTUP
-#!/bin/bash
-export PATH=/home/vagrant/anaconda/bin:$PATH
-export PYTHONPATH=/home/vagrant/climate:/home/vagrant/climate/ocw
-cd ~/climate/ocw-ui/backend && python run_webservices.py
-UIBOOTUP
-
-# It is possible that these commands will need to be rerun once
-# the desktop environment has been updated. You will notice that
-# they aren't recognized as shortcuts if you need to rerun these
-# commands. If all is working properly, you should see terminal
-# icons with the names listed above (Climate-Code or Climate-UI).
-chmod +x ~/Desktop/climate.desktop
-chmod +x ~/Desktop/.ui.sh
-chmod +x ~/Desktop/ui.desktop
http://git-wip-us.apache.org/repos/asf/climate/blob/a53e3af5/ocw/__init__.py
----------------------------------------------------------------------
diff --git a/ocw/__init__.py b/ocw/__init__.py
deleted file mode 100644
index e69de29..0000000
http://git-wip-us.apache.org/repos/asf/climate/blob/a53e3af5/ocw/data_source/__init__.py
----------------------------------------------------------------------
diff --git a/ocw/data_source/__init__.py b/ocw/data_source/__init__.py
deleted file mode 100644
index e69de29..0000000
http://git-wip-us.apache.org/repos/asf/climate/blob/a53e3af5/ocw/data_source/dap.py
----------------------------------------------------------------------
diff --git a/ocw/data_source/dap.py b/ocw/data_source/dap.py
deleted file mode 100644
index a4c413b..0000000
--- a/ocw/data_source/dap.py
+++ /dev/null
@@ -1,76 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-
-from pydap.client import open_url
-from netcdftime import utime
-import requests
-import numpy as np
-from ocw.dataset import Dataset
-
-def load(url, variable):
- '''Load a Dataset from an OpenDAP URL
-
- :param url: The OpenDAP URL for the dataset of interest.
- :type url: String
- :param variable: The name of the variable to read from the dataset.
- :type variable: String
-
- :returns: A Dataset object containing the dataset pointed to by the
- OpenDAP URL.
-
- :raises: ServerError
- '''
- # Grab the dataset information and pull the appropriate variable
- d = open_url(url)
- dataset = d[variable]
-
- # Grab the lat, lon, and time variable names.
- # We assume the variable order is (time, lat, lon)
- dataset_dimensions = dataset.dimensions
- time = dataset_dimensions[0]
- lat = dataset_dimensions[1]
- lon = dataset_dimensions[2]
-
- # Time is given to us in some units since an epoch. We need to convert
- # these values to datetime objects. Note that we use the main object's
- # time object and not the dataset specific reference to it. We need to
- # grab the 'units' from it and it fails on the dataset specific object.
- times = np.array(_convert_times_to_datetime(d[time]))
-
- lats = np.array(dataset[lat][:])
- lons = np.array(dataset[lon][:])
- values = np.array(dataset[:])
-
- return Dataset(lats, lons, times, values, variable)
-
-def _convert_times_to_datetime(time):
- '''Convert the OpenDAP time object's values to datetime objects
-
- The time values are stores as some unit since an epoch. These need to be
- converted into datetime objects for the OCW Dataset object.
-
- :param time: The time object's values to convert
- :type time: pydap.model.BaseType
-
- :returns: list of converted time values as datetime objects
- '''
- units = time.units
- # parse the time units string into a useful object.
- # NOTE: This assumes a 'standard' calendar. It's possible (likely?) that
- # users will want to customize this in the future.
- parsed_time = utime(units)
- return [parsed_time.num2date(x) for x in time[:]]
http://git-wip-us.apache.org/repos/asf/climate/blob/a53e3af5/ocw/data_source/local.py
----------------------------------------------------------------------
diff --git a/ocw/data_source/local.py b/ocw/data_source/local.py
deleted file mode 100644
index 79e3ba8..0000000
--- a/ocw/data_source/local.py
+++ /dev/null
@@ -1,268 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-
-import re
-import netCDF4
-from ocw.dataset import Dataset
-import numpy
-import numpy.ma as ma
-from datetime import timedelta ,datetime
-import calendar
-import string
-
-import ocw.utils as utils
-
-LAT_NAMES = ['x', 'rlat', 'rlats', 'lat', 'lats', 'latitude', 'latitudes']
-LON_NAMES = ['y', 'rlon', 'rlons', 'lon', 'lons', 'longitude', 'longitudes']
-TIME_NAMES = ['time', 'times', 'date', 'dates', 'julian']
-
-
-def _get_netcdf_variable_name(valid_var_names, netcdf, netcdf_var):
- '''Return valid variable from given netCDF object.
-
- Looks for an occurrence of a valid_var_name in the netcdf variable data.
- If multiple possible matches are found a ValueError is raised. If no
- matching variable names are found a Value is raised.
-
- :param valid_var_names: The possible variable names to search for in
- the netCDF object.
- :type valid_var_names: List of Strings
- :param netcdf: The netCDF object in which to check for valid_var_names.
- :type netcdf: netcdf4.Dataset
- :param netcdf_var: The relevant variable name to search over in the
- netcdf object.
-
- :returns: The variable from valid_var_names that it locates in
- the netCDF object.
-
- :raises: ValueError
- '''
-
- # Check for valid variable names in netCDF value variable dimensions
- dimensions = netcdf.variables[netcdf_var].dimensions
- dims_lower = [dim.encode().lower() for dim in dimensions]
-
- intersect = list(set(valid_var_names).intersection(dims_lower))
-
- if len(intersect) == 1:
- index = dims_lower.index(intersect[0])
- dimension_name = dimensions[index].encode()
-
- possible_vars = []
- for var in netcdf.variables.keys():
- var_dimensions = netcdf.variables[var].dimensions
-
- if len(var_dimensions) != 1:
- continue
-
- if var_dimensions[0].encode() == dimension_name:
- possible_vars.append(var)
-
- if len(possible_vars) == 1:
- return possible_vars[0]
-
- # Check for valid variable names in netCDF variable names
- variables = netcdf.variables.keys()
- vars_lower = [var.encode().lower() for var in variables]
-
- intersect = list(set(valid_var_names).intersection(vars_lower))
-
- if len(intersect) == 1:
- index = vars_lower.index(intersect[0])
- return variables[index]
-
- # If we couldn't find a single matching valid variable name, we're
- # unable to load the file properly.
- error = (
- "Unable to locate a single matching variable name in NetCDF object. "
- )
- raise ValueError(error)
-
-
-def _get_lat_name(variable_names):
- '''Find the latitude variable name
-
- :param variable_names: List of netCDF variables' name
- :type variable_names: List
-
- :returns: Latitude variable name
- :rtype: String
- '''
-
- common_name = set(['lat', 'lats', 'latitude', 'latitudes']).intersection(variable_names)
- if len(common_name) !=1:
- err = "Unable to autodetect latitude variable name."
- raise ValueError(err)
- else:
- lat_variable_name = common_name.pop()
-
- return lat_variable_name
-
-
-def _get_lon_name(variable_names):
- '''Find the longitude variable name
-
- :param variable_names: List of netCDF variables' name
- :type variable_names: List
-
- :returns: Longitude variable name
- :rtype: String
- '''
-
- common_name = set(['lon', 'lons', 'longitude', 'longitudes']).intersection(variable_names)
- if len(common_name) !=1:
- err = "Unable to autodetect longitude variable name."
- raise ValueError(err)
- else:
- lon_variable_name = common_name.pop()
-
- return lon_variable_name
-
-
-def _get_time_name(variable_names):
- '''Find the time variable name.
-
- :param: variableNameList: List of netCDF variables' name
- :type variable_names: List
-
- :returns: Time variable name
- :rtype: String
- '''
-
- common_name = set(['time', 'times', 'date', 'dates', 'julian']).intersection(variable_names)
-
- if len(common_name) !=1:
- err = "Unable to autodetect time variable name. These option(s) found: {0} ".format([each for each in common_name])
- raise ValueError(err)
- else:
- time_variable_name = common_name.pop()
-
- return time_variable_name
-
-
-def _get_level_name(variable_names):
- '''Find the level variable name.
-
- :param variable_names: List of netCDF variables' name
- type variable_names: List
-
- :returns: Level variable name
- :rtype: String
- '''
-
- level_variable_name = None
- common_name = set(['lev', 'level', 'levels', 'height', 'heights', 'elev', 'elevation', 'elevations']).intersection(variable_names)
- if len(common_name) !=1:
- pass
- else:
- level_variable_name = common_name.pop()
-
- return level_variable_name
-
-
-def _get_value_name(possible_value_name):
- '''Find the value variable name.
-
- :param possible_value_name: List of all value variable names
- :type possible_value_name: List
-
- :returns: Value variable name
- :rtype: String
- '''
-
- if len(possible_value_name) == 1:
- value_variable_name = possible_value_name[0]
- else:
- err = "The given value variable name does not match with existing variables name."
- raise ValueError(err)
-
- return value_variable_name
-
-
-def load_file(file_path, variable_name):
- '''Load netCDF file, get the all variables name and get the data.
-
- :param file_path: NetCDF directory with file name
- :type file_path: String
- :param variable_name: The given (by user) value variable name
- :type variable_name: String
-
- :returns: An OCW Dataset object containing the requested parameter data.
- :rtype: ocw.dataset.Dataset object
-
- :raises: ValueError
- '''
-
- try:
- netcdf = netCDF4.Dataset(file_path, mode='r')
- except:
- err = "The given file cannot be loaded (Only netCDF file can be supported)."
- raise ValueError(err)
-
- lat_name = _get_netcdf_variable_name(LAT_NAMES, netcdf, variable_name)
- lon_name = _get_netcdf_variable_name(LON_NAMES, netcdf, variable_name)
- time_name = _get_netcdf_variable_name(TIME_NAMES, netcdf, variable_name)
-
- #lat_variable_name = _get_lat_name(variable_names)
- #lon_variable_name = _get_lon_name(variable_names)
- #time_variable_name = _get_time_name(variable_names)
- #level_variable_name = _get_level_name(variable_names)
-
-
- # Check returned variable dimensions. lats, lons, and times should be 1D
- #
- # Check dimensions of the values
- # if != 3
- # find the indices for lat, lon, time
- # strip out everything else by select 1st of possible options
- #
- # Check the order of the variables
- # if not correct order (times, lats, lons)
- # reorder as appropriate
- #
- # Make new dataset object
-
- '''
- if variable_name in variable_names:
- value_variable_name = variable_name
- else:
- possible_value_name = list(set(variable_names) - set([lat_variable_name, lon_variable_name, time_variable_name, level_variable_name]))
- value_variable_name = _get_value_name(possible_value_name)
- '''
- lats = netcdf.variables[lat_name][:]
- lons = netcdf.variables[lon_name][:]
- time_raw_values = netcdf.variables[time_name][:]
- times = utils.decode_time_values(netcdf, time_name)
- times = numpy.array(times)
- values = ma.array(netcdf.variables[variable_name][:])
-
-
- if len(values.shape) == 4:
- #value_dimensions_names = list(netcdf.variables[variable_name].dimensions)
- value_dimensions_names = [dim_name.encode() for dim_name in netcdf.variables[variable_name].dimensions]
- lat_lon_time_var_names = [lat_name, lon_name, time_name]
- level_index = value_dimensions_names.index(list(set(value_dimensions_names) - set(lat_lon_time_var_names))[0])
- if level_index == 0:
- values = values [0,:,:,:]
- elif level_index == 1:
- values = values [:,0,:,:]
- elif level_index == 2:
- values = values [:,:,0,:]
- else:
- values = values [:,:,:,0]
-
- return Dataset(lats, lons, times, values, variable_name)
http://git-wip-us.apache.org/repos/asf/climate/blob/a53e3af5/ocw/data_source/rcmed.py
----------------------------------------------------------------------
diff --git a/ocw/data_source/rcmed.py b/ocw/data_source/rcmed.py
deleted file mode 100644
index 410bf48..0000000
--- a/ocw/data_source/rcmed.py
+++ /dev/null
@@ -1,349 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-
-'''
-Classes:
- RCMED - A class for retrieving data from Regional Climate Model Evalutaion Database (JPL).
-'''
-
-import urllib, urllib2
-import re
-import json
-import numpy as np
-import numpy.ma as ma
-from datetime import datetime
-import calendar
-from ocw.dataset import Dataset
-
-
-URL = 'http://rcmes.jpl.nasa.gov/query-api/query.php?'
-
-
-def get_parameters_metadata():
- '''Get the metadata of all parameter from RCMED.
-
- :returns: Dictionary of information for each parameter stored in one list
- :rtype: List of dictionaries
- '''
-
- param_info_list = []
- url = URL + "¶m_info=yes"
- string = urllib2.urlopen(url)
- data_string = string.read()
- json_format_data = json.loads(data_string)
- fields_name = json_format_data['fields_name']
- data = json_format_data['data']
- for row in data:
- dic = {}
- for name in fields_name:
- dic[name] = row[fields_name.index(name)]
- param_info_list.append(dic)
-
- return param_info_list
-
-
-def _make_mask_array(values, parameter_id, parameters_metadata):
- '''Created masked array to deal with missing values
-
- :param values: Numpy array of values which may contain missing values
- :type values: Numpy array
- :param parameter_id: Parameter's id
- :type parameter_id: Integer
- :param parameters_metadata: Metadata for all parameters
- :type parameters_metadata: List of dictionaries
-
- :returns: Masked array of values
- :rtype: Masked array
- '''
-
- for each in parameters_metadata:
- if each['parameter_id'].encode() == str(parameter_id):
- missing_values = each['missingdataflag'].encode()
- break
- # Need to encode the string to proper dtype so the mask is applied
- if 'float' in str(values.dtype):
- missing_values = float(missing_values)
- if 'int' in str(values.dtype):
- missing_values = int(missing_values)
-
- values = ma.masked_array(values, mask=(values == missing_values))
-
- return values
-
-
-def _reshape_values(values, unique_values):
- '''Reshape values into 4D array.
-
- :param values: Raw values data
- :type values: numpy array
- :param unique_values: Tuple of unique latitudes, longitudes and times data.
- :type unique_values: Tuple
-
- :returns: Reshaped values data
- :rtype: Numpy array
- '''
-
- lats_len = len(unique_values[0])
- lons_len = len(unique_values[1])
- times_len = len(unique_values[2])
-
- values = values.reshape(times_len, lats_len, lons_len)
-
- return values
-
-
-def _calculate_time(unique_times, time_step):
- '''Convert each time to the datetime object.
-
- :param unique_times: Unique time data
- :type unique_times: String
- :param time_step: Time step
- :type time_step: String
-
- :returns: Unique datetime objects of time data
- :rtype: Numpy array
- '''
-
- time_format = "%Y-%m-%d %H:%M:%S"
- unique_times = np.array([datetime.strptime(time, time_format) for time in unique_times])
- #There is no need to sort time.
- #This function may required still in RCMES
- #unique_times.sort()
- #This function should be moved to the data_process.
-
- return unique_times
-
-
-def _make_unique(lats, lons, times):
- '''Find the unique values of input data.
-
- :param lats: lats
- :type lats: Numpy array
- :param lons: lons
- :type lons: Numpy array
- :param times: times
- :type times: Numpy array
-
- :returns: Unique numpy arrays of latitudes, longitudes and times
- :rtype: Tuple
- '''
-
- unique_lats = np.unique(lats)
- unique_lons = np.unique(lons)
- unique_times = np.unique(times)
-
- return (unique_lats, unique_lons, unique_times)
-
-
-def _get_data(url):
- '''Reterive data from database.
-
- :param url: url to query from database
- :type url: String
-
- :returns: Latitudes, longitudes, times and values data
- :rtype: (Numpy array, Numpy array, Numpy array, Numpy array)
- '''
-
- string = urllib2.urlopen(url)
- data_string = string.read()
- index_of_data = re.search('data: \r\n', data_string)
- data = data_string[index_of_data.end():len(data_string)]
- data = data.split('\r\n')
-
- lats = []
- lons = []
- #levels = []
- values = []
- times = []
-
- for i in range(len(data) - 1): # Because the last row is empty, "len(data)-1" is used.
- row = data[i].split(',')
- lats.append(np.float32(row[0]))
- lons.append(np.float32(row[1]))
- # Level is not currently supported in Dataset class.
- #levels.append(np.float32(row[2]))
- times.append(row[3])
- values.append(np.float32(row[4]))
-
- lats = np.array(lats)
- lons = np.array(lons)
- times = np.array(times)
- values = np.array(values)
-
- return lats, lons, times, values
-
-
-def _beginning_of_date(time, time_step):
- '''Calculate the beginning of given time, based on time step.
-
- :param time: Given time
- :type time: Datetime
- :param time_step: Time step (monthly or daily)
- :type time_step: String
-
- :returns: Beginning of given time
- :rtype: Datetime
- '''
-
- if time_step.lower() == 'monthly':
- if time.day != 1:
- start_time_string = time.strftime('%Y%m%d')
- start_time_string = start_time_string[:6] + '01'
- time = datetime.strptime(start_time_string, '%Y%m%d')
- ##TODO: Change the 3 lines above with this line:
- ##time = datetime(time.year, time.month, 1)
- elif time_step.lower() == 'daily':
- if time.hour != 0 or time.minute != 0 or time.second != 0:
- start_time_string = time.strftime('%Y%m%d%H%M%S')
- start_time_string = start_time_string[:8] + '000000'
- time = datetime.strptime(start_time_string, '%Y%m%d%H%M%S')
- ##TODO: Change the 3 lines above with this line:
- ##time = datetime(time.year, time.month, time.day, 00, 00, 00)
-
- return time
-
-
-def _end_of_date(time, time_step):
- '''Calculate the end of given time, based on time step.
-
- :param time: Given time
- :type time: Datetime
- :param time_step: Time step (monthly or daily)
- :type time_step: String
-
- :returns: End of given time
- :rtype: Datetime
- '''
-
- last_day_of_month = calendar.monthrange(time.year, time.month)[1]
- if time.day != last_day_of_month:
- end_time_string = time.strftime('%Y%m%d')
- end_time_string = end_time_string[:6] + str(last_day_of_month)
- time = datetime.strptime(end_time_string, '%Y%m%d')
- ##TODO: Change the 3 lines above with this line:
- ##time = datetime(time.year, time.month, lastDayOfMonth)
- elif time_step.lower() == 'daily':
- end_time_string = time.strftime('%Y%m%d%H%M%S')
- end_time_string = end_time_string[:8] + '235959'
- time = datetime.strptime(end_time_string, '%Y%m%d%H%M%S')
- ##TODO: Change the 3 lines above with this line:
- ##time = datetime(time.year, time.month, end_time.day, 23, 59, 59)
-
- return time
-
-
-def _generate_query_url(dataset_id, parameter_id, min_lat, max_lat, min_lon, max_lon, start_time, end_time, time_step):
- '''Generate the url to query from database
-
- :param dataset_id: Dataset id.
- :type dataset_id: Integer
- :param parameter_id: Parameter id
- :type parameter_id: Integer
- :param min_lat: Minimum latitude
- :type min_lat: Float
- :param max_lat: Maximum latitude
- :type max_lat: Float
- :param min_lon: Minimum longitude
- :type min_lon: Float
- :param max_lon: Maximum longitude
- :type max_lon: Float
- :param start_time: Start time
- :type start_time: Datetime
- :param end_time: End time
- :type end_time: Datetime
- :param time_step: Time step
- :type time_step: String
-
- :returns: url to query from database
- :rtype: String
- '''
-
- start_time = _beginning_of_date(start_time, time_step)
- end_time = _end_of_date(end_time, time_step)
- start_time = start_time.strftime("%Y%m%dT%H%MZ")
- end_time = end_time.strftime("%Y%m%dT%H%MZ")
-
- query = [('datasetId',dataset_id), ('parameterId',parameter_id), ('latMin',min_lat), ('latMax',max_lat),
- ('lonMin', min_lon), ('lonMax',max_lon), ('timeStart', start_time), ('timeEnd', end_time)]
-
- query_url = urllib.urlencode(query)
- url_request = URL + query_url
-
- return url_request
-
-
-def _get_parameter_info(parameters_metadata, parameter_id):
- '''General information for given parameter id.
-
- :param parameters_metadata: Metadata for all parameters
- :type parameters_metadata: List of dictionaries
- :param parameter_id: Parameter id
- :type parameter_id: Integer
-
- :returns: Database name, time step, realm, instrument, start_date, end_date and unit for given parameter
- :rtype: (string, string, string, string, string, string, string)
- '''
-
- for dic in parameters_metadata:
- if int(dic['parameter_id']) == parameter_id:
- database = dic['database']
- time_step = dic['timestep']
- realm = dic['realm']
- instrument = dic['instrument']
- start_date = dic['start_date']
- end_date = dic['end_date']
- unit = dic['units']
-
- return (database, time_step, realm, instrument, start_date, end_date, unit)
-
-
-def parameter_dataset(dataset_id, parameter_id, min_lat, max_lat, min_lon, max_lon, start_time, end_time):
- '''Get data from one database(parameter).
-
- :param dataset_id: Dataset id.
- :type dataset_id: Integer
- :param parameter_id: Parameter id
- :type parameter_id: Integer
- :param min_lat: Minimum latitude
- :type min_lat: Float
- :param max_lat: Maximum latitude
- :type max_lat: Float
- :param min_lon: Minimum longitude
- :type min_lon: Float
- :param max_lon: Maximum longitude
- :type max_lon: Float
- :param start_time: Start time
- :type start_time: Datetime
- :param end_time: End time
- :type end_time: Datetime
-
- :returns: An OCW Dataset object contained the requested data from RCMED.
- :rtype: ocw.dataset.Dataset object
- '''
-
- parameters_metadata = get_parameters_metadata()
- parameter_name, time_step, _, _, _, _, _= _get_parameter_info(parameters_metadata, parameter_id)
- url = _generate_query_url(dataset_id, parameter_id, min_lat, max_lat, min_lon, max_lon, start_time, end_time, time_step)
- lats, lons, times, values = _get_data(url)
-
- unique_lats_lons_times = _make_unique(lats, lons, times)
- unique_times = _calculate_time(unique_lats_lons_times[2], time_step)
- values = _reshape_values(values, unique_lats_lons_times)
- values = _make_mask_array(values, parameter_id, parameters_metadata)
-
- return Dataset(unique_lats_lons_times[0], unique_lats_lons_times[1], unique_times, values, parameter_name)