public double[] GetSeries(string ncVarName, string identifier) { // TODO: check is daily ucar.nc2.Variable v = getVariable(ncVarName); int[] origin; int[] shape; GetTimeSeriesSpecForIdentifier(identifier, out origin, out shape); var temp = v.read(origin, shape); return(NetCdfHelper.GetOneDimArray <double>(v.read(origin, shape))); }
public double GetMissingValueCode(string ncVarName) { if (missingValueCodes.ContainsKey(ncVarName)) { return(missingValueCodes[ncVarName]); } else { ucar.nc2.Variable v = getVariable(ncVarName); return(NetCdfHelper.GetMissingValueAttributeDouble(this, v, double.NaN)); } }
private List <float[]> _getFloatData(string itemName, int timeStep) { float[] itemFloatData = null; List <float[]> itemFloatDataList = new List <float[]>(); object[] ncVars = _util.GetVariables(); ucar.ma2.Array xData = null; ucar.ma2.Array yData = null; foreach (object ncVar in ncVars) { ucar.nc2.Variable var = ((ucar.nc2.Variable)ncVar); string varName = var.getFullName(); if (varName == _settings.ZAxisName) { yData = _util.GetAllVariableData(var); } } foreach (object ncVar in ncVars) { ucar.nc2.Variable var = ((ucar.nc2.Variable)ncVar); string varName = var.getFullName(); if (varName == _settings.XAxisName) { xData = _util.GetAllVariableData(var); } } foreach (object ncVar in ncVars) { ucar.nc2.Variable var = ((ucar.nc2.Variable)ncVar); string varName = var.getFullName(); if (varName == itemName) { List <ucar.ma2.Array> itemDataLst = _util.Get2DVariableDataTrans(var, _settings.ZLayer, _settings.ZAxisName, timeStep, _settings.TimeAxisName, _settings.XAxisName, _settings.YAxisName, _settings.TransectPoints, _settings.TransectSpaceStepsNumber); for (int i = 0; i < itemDataLst.Count; i++) { ucar.ma2.Array itemData = itemDataLst[i]; itemData = _util.ProcessedVariableData(var, itemData); java.util.List ncVarAtt = var.getAttributes(); itemFloatData = _util.GetFloatData(itemData, ncVarAtt, _fdel); itemFloatDataList.Add(itemFloatData); } } } return(itemFloatDataList); }
private void _getGridOrigo(out double x0, out double y0, out double dx, out double dy, out double j, out double k, List <float[]> dataList) { x0 = 0; y0 = 0; dx = 0; dy = 0; j = 0; k = 0; object[] ncDims = _util.GetDimensions(); List <double> interpolatedYVals = new List <double>(); List <double> originalYVals = new List <double>(); ucar.nc2.Variable depthVar = null; foreach (object ncDim in ncDims) { string dimName = ((ucar.nc2.Dimension)ncDim).getName(); if (_settings.XAxisName == dimName) //number of points is x axis { ucar.nc2.Variable ncVar = (ucar.nc2.Variable)_util.GetVariable(dimName); List <double> interpolatedXVals = new List <double>(); List <double> originalXVals = new List <double>(); _getMinAndInterval(ncVar, out dx, out x0, out interpolatedXVals, out originalXVals); //x0 = _settings.TransectPoints[0].X; x0 = 0; j = dataList.Count; } else if (_settings.ZAxisName == dimName) //depth is y axis { ucar.nc2.Variable ncVar = (ucar.nc2.Variable)_util.GetVariable(dimName); depthVar = ncVar; _getMinAndInterval(ncVar, out dy, out y0, out interpolatedYVals, out originalYVals); if (interpolatedYVals.Count != 0) { k = interpolatedYVals.Count; y0 = interpolatedYVals[0]; } else { k = originalYVals.Count; y0 = originalYVals[0]; } } } //calculate the size of the possible float array and limit it to _settings.MaxBlockSizeMB _floatArraySize = j * k * 4 / 1024 / 1024; //in mb if (_floatArraySize > _settings.MaxBlockSizeMB) { _settings.DZ = (float)(originalYVals.Max() / (_settings.MaxBlockSizeMB / j / k / 4 * 1024 * 1024)); _getMinAndInterval(depthVar, null, out dy, out y0, out interpolatedYVals, out originalYVals, true); y0 = 0; } }
private float[] _getFloatData(string itemName, int timeStep, double j, double k, double lat0, double lon0, double dx, double dy) { try { float[] itemFloatData = null; object[] ncVars = _util.GetVariables(); ucar.ma2.Array xData = null; ucar.ma2.Array yData = null; ucar.ma2.Array zData = null; foreach (object ncVar in ncVars) { ucar.nc2.Variable var = ((ucar.nc2.Variable)ncVar); string varName = var.getFullName(); if (varName == _settings.YAxisName) { yData = _util.GetAllVariableData(var); } } foreach (object ncVar in ncVars) { ucar.nc2.Variable var = ((ucar.nc2.Variable)ncVar); string varName = var.getFullName(); if (varName == _settings.XAxisName) { xData = _util.GetAllVariableData(var); } } foreach (object ncVar in ncVars) { ucar.nc2.Variable var = ((ucar.nc2.Variable)ncVar); string varName = var.getFullName(); if (varName == _settings.ZAxisName) { zData = _util.GetAllVariableData(var); } } foreach (object ncVar in ncVars) { ucar.nc2.Variable var = ((ucar.nc2.Variable)ncVar); string varName = var.getFullName(); java.util.List varDims = ((ucar.nc2.Variable)var).getDimensions(); int zPosition = -1, xAxisPosition = -1, yAxisPosition = -1; for (int i = 0; i < varDims.size(); i++) { string dimName = ((ucar.nc2.Dimension)varDims.get(i)).getName(); if (_settings.ZAxisDimensionName == dimName) { zPosition = i; } if (_settings.XAxisDimensionName == dimName) { xAxisPosition = i; } if (_settings.YAxisDimensionName == dimName) { yAxisPosition = i; } } if (varName == itemName) { ucar.ma2.Array itemData = _util.Get3DVariableData(var, _settings.ZAxisName, timeStep, _settings.TimeAxisName, _settings.XLayer, _settings.XAxisName, _settings.YLayer, _settings.YAxisName); itemData = _util.ProcessedVariableData(var, itemData); java.util.List ncVarAtt = var.getAttributes(); itemFloatData = _util.GetFloatData(itemData, xData, yData, zData, ncVarAtt, _fdel, _zValues); if (_customDFSGrid) { //reassign the data to the grid (nearest neighbour) itemFloatData = _reassignData(itemData, xData, yData, zData, ncVarAtt, _fdel, _zValues, j, k, lat0, lon0, dx, dy, xAxisPosition, yAxisPosition, zPosition); } } } return(itemFloatData); } catch (Exception ex) { throw new Exception("_getFloatData Error: " + ex.Message); } }
private void _getMinAndInterval(ucar.nc2.Variable ncDim, string minMaxStr, out double interval, out double minVal, out List <double> interpolatedVal, out List <double> originalVal, bool useDefinedDZ) { ucar.ma2.Array dataArr = _util.GetAllVariableData(ncDim); int minCount = 0, maxCount = (int)dataArr.getSize() - 1; minVal = double.MaxValue; double maxVal = double.MinValue; double prevVal = 0.0; List <double> intervals = new List <double>(); interpolatedVal = new List <double>(); originalVal = new List <double>(); interval = 0.0; if (!string.IsNullOrEmpty(minMaxStr)) { minCount = Convert.ToInt32(minMaxStr.Split(':')[0]); maxCount = Convert.ToInt32(minMaxStr.Split(':')[1]); } java.util.List ncVarAtt = ncDim.getAttributes(); bool stepExists = false; for (int attCount = 0; attCount < ncVarAtt.size(); attCount++) { ucar.nc2.Attribute varAtt = (ucar.nc2.Attribute)ncVarAtt.get(attCount); string attName = varAtt.getName(); if (attName == "step") { java.lang.Number attVal = (java.lang.Number)varAtt.getValue(0); interval = attVal.doubleValue(); stepExists = true; } } for (int dCount = minCount; dCount <= maxCount; dCount++) { ucar.ma2.Index dIndex = dataArr.getIndex(); double data = dataArr.getDouble(dIndex.set(dCount)); originalVal.Add(data); if (minVal >= data) { minVal = data; } if (maxVal <= data) { maxVal = data; } if (!stepExists) { if (dCount > 0) { prevVal = dataArr.getDouble(dIndex.set(dCount - 1)); interval = data - prevVal; intervals.Add(interval); } } } if (!stepExists) { if (intervals.Average() != interval) { if (useDefinedDZ) { for (double min = minVal; min <= maxVal; min += Convert.ToDouble(_settings.DZ)) { interpolatedVal.Add(min); } interval = Convert.ToDouble(_settings.DZ); } else { //generate a list of interpolatedVal for (double min = minVal; min <= maxVal; min += intervals.Min()) { interpolatedVal.Add(min); } interval = intervals.Min(); } } } }
private void _getGridOrigo(out double x0, out double y0, out double z0, out double dx, out double dy, out double dz, out double j, out double k, out double l, out double lat0, out double lon0) { x0 = 0; y0 = 0; z0 = 0; dx = 0; dy = 0; dz = 0; j = 0; k = 0; l = 0; lat0 = 0; lon0 = 0; object[] ncDims = _util.GetDimensions(); List <double> interpolatedZVals = new List <double>(); List <double> originalZVals = new List <double>(); ucar.nc2.Variable depthVar = null; foreach (object ncDim in ncDims) { string dimName = ((ucar.nc2.Dimension)ncDim).getName(); if (_settings.XAxisName == dimName) { ucar.nc2.Variable ncVar = (ucar.nc2.Variable)_util.GetVariable(dimName); List <double> interpolatedYVals = new List <double>(); List <double> originalYVals = new List <double>(); _getMinAndInterval(ncVar, _settings.XLayer, out dx, out lon0, out interpolatedYVals, out originalYVals, false); j = originalYVals.Count; x0 = 0;// originalYVals[0]; //overwrite dx, j if (_settings.NumberXCells > 0) { j = _settings.NumberXCells; //if (!double.TryParse(_settings.NumberXCells, out j)) //throw new Exception("Cannot convert " + _settings.NumberXCells + " to double"); _customDFSGrid = true; } if (_settings.DX > 0) { dx = _settings.DX; //if (!double.TryParse(_settings.DX, out dx)) //throw new Exception("Cannot convert " + _settings.DX + " to double"); _customDFSGrid = true; } if (!String.IsNullOrEmpty(_settings.ProjectionEastNorthMultiplier)) { Microsoft.JScript.Vsa.VsaEngine myEngine = Microsoft.JScript.Vsa.VsaEngine.CreateEngine(); double result = (double)Microsoft.JScript.Eval.JScriptEvaluate(_settings.ProjectionEastNorthMultiplier, myEngine); dx = dx * result; } } else if (_settings.YAxisName == dimName) { ucar.nc2.Variable ncVar = (ucar.nc2.Variable)_util.GetVariable(dimName); List <double> interpolatedYVals = new List <double>(); List <double> originalYVals = new List <double>(); _getMinAndInterval(ncVar, _settings.YLayer, out dy, out lat0, out interpolatedYVals, out originalYVals, false); k = originalYVals.Count; y0 = 0;// originalYVals[0]; //overwrite dy, k if (_settings.NumberYCells > 0) { k = _settings.NumberYCells; //if (!double.TryParse(_settings.NumberYCells, out k)) //throw new Exception("Cannot convert " + _settings.NumberYCells + " to double"); _customDFSGrid = true; } if (_settings.DY > 0) { dy = _settings.DY; //if (!double.TryParse(_settings.DY, out dy)) //throw new Exception("Cannot convert " + _settings.DY + " to double"); _customDFSGrid = true; } if (!String.IsNullOrEmpty(_settings.ProjectionEastNorthMultiplier)) { Microsoft.JScript.Vsa.VsaEngine myEngine = Microsoft.JScript.Vsa.VsaEngine.CreateEngine(); double result = (double)Microsoft.JScript.Eval.JScriptEvaluate(_settings.ProjectionEastNorthMultiplier, myEngine); dy = dy * result; } } else if (_settings.ZAxisName == dimName) //depth is y axis { depthVar = (ucar.nc2.Variable)_util.GetVariable(dimName); if (_settings.DZ == 0) { _getMinAndInterval(depthVar, null, out dz, out z0, out interpolatedZVals, out originalZVals, false); if (interpolatedZVals.Count != 0) { l = interpolatedZVals.Count; _zValues = interpolatedZVals; } else { l = originalZVals.Count; _zValues = originalZVals; } z0 = 0; } else { _getMinAndInterval(depthVar, null, out dz, out z0, out interpolatedZVals, out originalZVals, true); if (interpolatedZVals.Count != 0) { l = interpolatedZVals.Count; _zValues = interpolatedZVals; z0 = interpolatedZVals[interpolatedZVals.Count - 1]; } else { l = originalZVals.Count; _zValues = originalZVals; z0 = originalZVals[originalZVals.Count - 1]; } z0 = 0; } } } if (_settings.OverwriteOriginX != -999 && _settings.OverwriteOriginX != -999) { lon0 = _settings.OverwriteOriginX; lat0 = _settings.OverwriteOriginY; } //calculate the size of the possible float array and limit it to _settings.MaxBlockSizeMB double floatArraySize = j * k * l * 4 / 1024 / 1024; //in mb if (floatArraySize > _settings.MaxBlockSizeMB) { _settings.DZ = (float)(originalZVals.Max() / (_settings.MaxBlockSizeMB / j / k / 4 * 1024 * 1024)); _getMinAndInterval(depthVar, null, out dz, out z0, out interpolatedZVals, out originalZVals, true); if (interpolatedZVals.Count != 0) { l = interpolatedZVals.Count; _zValues = interpolatedZVals; } else { l = originalZVals.Count; _zValues = originalZVals; } z0 = 0; } }
private float[] _processFloatData(List <float[]> floatDataList) { try { List <float> compiledData = new List <float>(); double y0 = 0, dy = 0; List <double> interpolatedYVals = new List <double>(); List <double> originalYVals = new List <double>(); ucar.nc2.Variable depthVar = null; object[] ncDims = _util.GetDimensions(); foreach (object ncDim in ncDims) { string dimName = ((ucar.nc2.Dimension)ncDim).getName(); if (_settings.ZAxisName == dimName) //depth is y axis { ucar.nc2.Variable ncVar = (ucar.nc2.Variable)_util.GetVariable(dimName); depthVar = ncVar; _getMinAndInterval(ncVar, out dy, out y0, out interpolatedYVals, out originalYVals); } } if (_floatArraySize > _settings.MaxBlockSizeMB) { _getMinAndInterval(depthVar, null, out dy, out y0, out interpolatedYVals, out originalYVals, true); y0 = 0; } //loop through original depths if (interpolatedYVals.Count == 0) { for (int i = originalYVals.Count - 1; i >= 0; i--) { foreach (float[] data in floatDataList) { compiledData.Add(data[i]); } } } else { int originalValCount = originalYVals.Count - 1; //int prevOriginalValCount = 0; for (int i = interpolatedYVals.Count - 1; i >= 0; i--) { //find originalYValCount closest to interpolatedYVal double closest = originalYVals.Aggregate((x, y) => Math.Abs(x - interpolatedYVals[i]) < Math.Abs(y - interpolatedYVals[i]) ? x : y); originalValCount = originalYVals.IndexOf(closest); /*if (interpolatedYVals[i] < originalYVals[originalValCount]) * { * originalValCount--; * prevOriginalValCount = originalValCount-1; * } * if (originalValCount <= 0) originalValCount = 0; * if (prevOriginalValCount <= 0) prevOriginalValCount = 0;*/ foreach (float[] data in floatDataList) { //interpolation //y = y0 + (y1-y0)*((x-x0)/(x1-x0)) float interpolatedData = 0; /*if (prevOriginalValCount != originalValCount) * { * if (data[prevOriginalValCount] != _fdel && data[originalValCount] != _fdel) * { * interpolatedData = data[originalValCount] + * (float)((data[prevOriginalValCount] - data[originalValCount]) * ((interpolatedYVals[i] - originalYVals[originalValCount]) / (originalYVals[prevOriginalValCount] - originalYVals[originalValCount]))); * * if (((Math.Abs(data[originalValCount]) - Math.Abs(interpolatedData)) / Math.Abs(data[originalValCount]) * 100) <= _deleteValTolerancePercent) * interpolatedData = data[originalValCount]; * } * else * interpolatedData = data[originalValCount]; * } * else*/ interpolatedData = data[originalValCount]; compiledData.Add(interpolatedData); } } } return(compiledData.ToArray()); } catch (Exception ex) { throw new Exception("Process data error: " + ex.Message); } }
private void _getMinAndInterval(ucar.nc2.Variable ncDim, out double interval, out double minVal, out List <double> interpolatedVal, out List <double> originalVal) { ucar.ma2.Array dataArr = _util.GetAllVariableData(ncDim); minVal = double.MaxValue; double maxVal = double.MinValue; double prevVal = 0.0; List <double> intervals = new List <double>(); interpolatedVal = new List <double>(); originalVal = new List <double>(); interval = 0.0; for (int dCount = 0; dCount < dataArr.getSize(); dCount++) { ucar.ma2.Index dIndex = dataArr.getIndex(); double data = dataArr.getDouble(dIndex.set(dCount)); originalVal.Add(data); if (minVal >= data) { minVal = data; } if (maxVal <= data) { maxVal = data; } if (dCount > 0) { prevVal = dataArr.getDouble(dIndex.set(dCount - 1)); interval = data - prevVal; intervals.Add(interval); } } double dz; if (_settings.DZ > 0) { dz = _settings.DZ; if (intervals.Average() != interval) { //generate a list of interpolatedVal for (double min = minVal; min <= maxVal; min += dz) { interpolatedVal.Add(min); } interval = dz; } } else { if (intervals.Average() != interval) { //generate a list of interpolatedVal for (double min = minVal; min <= maxVal; min += intervals.Min()) { interpolatedVal.Add(min); } interval = intervals.Min(); } } }