Exemplo n.º 1
0
        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)));
        }
Exemplo n.º 2
0
 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));
     }
 }
Exemplo n.º 3
0
 public PointTimeSeriesNcFile(string location, string ncSeriesIdentifier)
     : base(location)
 {
     this.ncVarnameIdentifier = ncSeriesIdentifier;
     this.identifiers         = NetCdfHelper.GetOneDimArray <string>(this.findVariable(ncVarnameIdentifier).read());
     this.identifiersIndices  = identifiers.ToDictionary(x => x, y => Array.IndexOf(identifiers, y));
     //if (timeSeriesIdentifierVar == null)
     //    throw new NullReferenceException(string.Format("Could not find variable '{0}' in the netcdf file", ncVarnameIdentifier));
     this.timeCoords   = NetCdfHelper.GetTimeCoordinates(this);
     variables         = new Dictionary <string, ucar.nc2.Variable>();
     missingValueCodes = new Dictionary <string, double>();
 }
        protected BaseTimeSeriesByIdentifierWriteable(string filename, DataType dataType, string[] variableName, string[] units, double[] missingVal, string[] longName, DateTime startDate, int timeLength, string itemIndexDimname = ITEM_INDEX_DIMNAME, string itemIndexVarname = ITEM_INDEX_VARNAME, int maxLengthStrings = DEFAULT_STRING_LEN, Dictionary <string, Dictionary <string, string> > additionalAttributes = null, Dictionary <string, string> globalAttributes = null)
        {
            if (dataType != DataType.FLOAT && dataType != DataType.DOUBLE)
            {
                throw new NotSupportedException("Time series storage data type in netCDF must be DOUBLE or FLOAT");
            }

            this.dataType         = dataType;
            this.variableName     = variableName;
            this.itemIndexDimname = itemIndexDimname;
            this.itemIndexVarname = itemIndexVarname;
            this.timeLength       = timeLength;

            writeableFile = NetcdfFileWriteable.createNew(filename);

            // define dimensions
            timeDim = writeableFile.addDimension(NetCdfHelper.TimeVarName, timeLength);
            var svarLen = writeableFile.addDimension(NetCdfHelper.seriesIdName, maxLengthStrings);

            seriesIdDim = writeableFile.addUnlimitedDimension(itemIndexDimname);

            // define Dimension Variables
            writeableFile.addVariable(itemIndexDimname, DataType.INT, new Dimension[] { seriesIdDim });
            writeableFile.addVariable(NetCdfHelper.seriesIdName, DataType.INT, new Dimension[] { svarLen });
            NetCdfHelper.createTimeVariableDaily(writeableFile, timeDim, startDate);
            writeableFile.addVariableAttribute(NetCdfHelper.seriesIdName, NetCdfHelper.LongNameAttName, NetCdfHelper.seriesIdName);
            writeableFile.addVariableAttribute(itemIndexDimname, NetCdfHelper.LongNameAttName, itemIndexDimname);
            writeableFile.addVariableAttribute(itemIndexDimname, NetCdfHelper.UnitsAttName, "count");
            //writeableFile.addVariable("CatNo", DataType.INT, new Dimension[] { seriesIdDim });

            if (globalAttributes != null)
            {
                foreach (var att in globalAttributes)
                {
                    writeableFile.addGlobalAttribute(att.Key, att.Value);
                }
            }

            // Now onto the non-dimension variables.
            for (int i = 0; i < variableName.Length; i++)
            {
                writeableFile.addVariable(variableName[i], dataType, new Dimension[] { seriesIdDim, timeDim });
                writeableFile.addVariableAttribute(variableName[i], NetCdfHelper.LongNameAttName, longName[i]);
                writeableFile.addVariableAttribute(variableName[i], NetCdfHelper.UnitsAttName, units[i]);
                //NetCdfHelper.addMissingValueDefinition(variableName[i], writeableFile);
                writeableFile.addVariableAttribute(variableName[i], NetCdfHelper.MissingValueAttName, new java.lang.Float(missingVal[i]));
                writeableFile.addVariableAttribute(variableName[i], NetCdfHelper.FillValueAttName, new java.lang.Float(missingVal[i]));
            }
            if (additionalAttributes != null)
            {
                foreach (var variableAtt in additionalAttributes)
                {
                    foreach (var att in variableAtt.Value)
                    {
                        writeableFile.addVariableAttribute(variableAtt.Key, att.Key, att.Value);
                    }
                }
            }

            if (globalAttributes != null)
            {
                foreach (var att in globalAttributes)
                {
                    writeableFile.addGlobalAttribute(att.Key, att.Value);
                }
            }

            writeableFile.addVariable(itemIndexVarname, DataType.CHAR, new Dimension[] { seriesIdDim, svarLen });
            writeableFile.addVariableAttribute(itemIndexVarname, NetCdfHelper.LongNameAttName, itemIndexVarname);

            var daysSinceStart = new int[timeLength];

            for (int i = 0; i < daysSinceStart.Length; i++)
            {
                daysSinceStart[i] = i;
            }

            writeableFile.create();

            // write out the non-record variables
            writeableFile.write(NetCdfHelper.TimeVarName, ucar.ma2.Array.factory(daysSinceStart));
            writeableFile.write(NetCdfHelper.seriesIdName, ucar.ma2.Array.makeArray(DataType.INT, maxLengthStrings, 1, 1));
        }