Пример #1
0
        public void GetMaxHourlyWindSpeeds_Test()
        {
            Continuum thisInst = new Continuum("");

            string Filename = testingFolder + "\\GetMaxHourlyWindSpeeds\\GetMaxHourlyWindSpeeds test.cfm";

            thisInst.Open(Filename);

            double thisLat  = 41.0;
            double thisLong = -83.75;

            MERRA thisMERRA = thisInst.merraList.GetMERRA(thisLat, thisLong);

            thisMERRA.GetMERRADataFromDB(thisInst);
            thisMERRA.GetInterpData(thisInst.UTM_conversions);

            Met.MaxYearlyWind[] theseMaxWS = thisMERRA.GetMaxHourlyWindSpeeds();

            Assert.AreEqual(theseMaxWS[0].maxWS, 19.948, 0.001, "Wrong Max WS Year 2000");
            Assert.AreEqual(theseMaxWS[2].maxWS, 23.496, 0.001, "Wrong Max WS Year 2002");
            Assert.AreEqual(theseMaxWS[6].maxWS, 21.704, 0.001, "Wrong Max WS Year 2006");
            Assert.AreEqual(theseMaxWS[10].maxWS, 20.305, 0.001, "Wrong Max WS Year 2010");

            thisInst.Close();
        }
Пример #2
0
        public void Calc_Avg_or_LT_Test()
        {
            Continuum thisInst = new Continuum("");

            string Filename = testingFolder + "\\MERRA_Testing.cfm";

            thisInst.Open(Filename);

            Met thisMet = thisInst.metList.metItem[0];

            UTM_conversion.Lat_Long theseLL = thisInst.UTM_conversions.UTMtoLL(thisInst.metList.metItem[0].UTMX, thisInst.metList.metItem[0].UTMY);
            MERRA merra = thisInst.merraList.GetMERRA(theseLL.latitude, theseLL.longitude);

            if (merra.interpData.TS_Data.Length == 0)
            {
                merra.GetMERRADataFromDB(thisInst);
                merra.GetInterpData(thisInst.UTM_conversions);
            }

            // Test 1
            double thisAvg = merra.Calc_Avg_or_LT(merra.interpData.TS_Data, 100, 100, "50 m WS");

            Assert.AreEqual(6.670311915, thisAvg, 0.001, "Wrong 50m WS all data");

            // Test 2
            thisAvg = merra.Calc_Avg_or_LT(merra.interpData.TS_Data, 100, 100, "Surface Pressure");
            Assert.AreEqual(98.72393837, thisAvg, 0.001, "Wrong Pressure");

            // Test 3
            thisAvg = merra.Calc_Avg_or_LT(merra.interpData.TS_Data, 100, 100, "10 m Temp"); // all data
            Assert.AreEqual(10.33596373, thisAvg, 0.001, "Wrong 10m Temp");

            // Test 4
            thisAvg = merra.Calc_Avg_or_LT(merra.interpData.TS_Data, 1, 2008, "50 m WS"); // jan 2008
            Assert.AreEqual(8.938906452, thisAvg, 0.001, "Wrong 50m WS");

            // Test 5
            thisAvg = merra.Calc_Avg_or_LT(merra.interpData.TS_Data, 100, 2010, "50 m WS"); // avg 2010
            Assert.AreEqual(6.421752226, thisAvg, 0.001, "Wrong 50 m WS");

            // Test 6
            thisAvg = merra.Calc_Avg_or_LT(merra.interpData.TS_Data, 1, 100, "50 m WS"); // avg all january's
            Assert.AreEqual(7.639244713, thisAvg, 0.001, "Wrong 50m WS");

            thisInst.Close();
        }
        /// <summary> Adds new MERRA object to list. Figures out if additional MERRA nodes need to be uploaded from textfiles.
        ///    Runs MCP at Met site (if thisMet not null) if have all MERRA node data. Calls BW worker to upload additional data if needed. </summary>
        public void AddMERRA_GetDataFromTextFiles(double thisLat, double thisLong, int offset, Continuum thisInst, Met thisMet, bool isTest)
        {
            // Create new MERRA object and assign lat, long, and node lat/long
            MERRA thisMERRA = new MERRA();

            thisMERRA.Set_Interp_LatLon_Dates_Offset(thisLat, thisLong, offset, thisInst);
            thisMERRA.numMERRA_Nodes = numMERRA_Nodes;
            thisMERRA.MERRA_Nodes    = new MERRA.MERRA_Node_Data[numMERRA_Nodes];

            if (thisMet.name == null)
            {
                thisMERRA.isUserDefined = true;
            }

            if (MERRAfolder == "")
            {
                try
                {
                    MessageBox.Show("Please select folder containing MERRA2 data .ascii files.");
                    if (thisInst.fbd_MERRAData.ShowDialog() == DialogResult.OK)
                    {
                        MERRAfolder = thisInst.fbd_MERRAData.SelectedPath;
                    }
                    else
                    {
                        return;
                    }

                    SetMERRA2LatLong(thisInst);
                }
                catch
                {
                    MessageBox.Show("Folder path not valid.", "", MessageBoxButtons.OK);
                    return;
                }
            }

            // Figure out if MERRA textfile has the necessary lat/long range and get MERRA node coordinates
            bool gotCoords = thisMERRA.Find_MERRA_Coords(MERRAfolder);

            if (gotCoords == false)
            {
                return;
            }

            DialogResult doMCP = DialogResult.No;

            if (thisMet.name != null && isTest == false && (thisInst.metList.ThisCount == 1 || thisInst.metList.isMCPd == false))
            {
                doMCP = MessageBox.Show("Do you want to conduct MCP at selected met?", "Continuum 3.0", MessageBoxButtons.YesNo);
            }
            else if (thisMet.name != "" && isTest == false && thisInst.metList.ThisCount > 1 && thisInst.metList.isMCPd == true)
            {
                doMCP = DialogResult.Yes;
            }
            else if (isTest == true)
            {
                doMCP = DialogResult.No;
            }

            if (doMCP == DialogResult.Yes)
            {
                thisInst.metList.isMCPd = true;
                thisInst.modelList.ClearAllExceptImported();
                thisInst.turbineList.ClearAllWSEsts();
                thisInst.turbineList.ClearAllGrossEsts();
                thisInst.turbineList.ClearAllNetEsts();
                thisInst.mapList.ClearAllMaps();
                thisInst.metPairList.ClearAll();
            }

            // Figure out what MERRA nodes need to be downloaded
            UTM_conversion.Lat_Long[] requiredMERRANode = GetRequiredNewMERRANodeCoords(thisLat, thisLong, thisInst);

            if (requiredMERRANode.Length != 0)
            {
                MERRA.MERRA_Pull[] nodesToPull = new MERRA.MERRA_Pull[requiredMERRANode.Length];

                for (int i = 0; i < requiredMERRANode.Length; i++)
                {
                    nodesToPull[i].Coords.latitude  = requiredMERRANode[i].latitude;
                    nodesToPull[i].Coords.longitude = requiredMERRANode[i].longitude;
                    nodesToPull[i].UTM = thisInst.UTM_conversions.LLtoUTM(nodesToPull[i].Coords.latitude, nodesToPull[i].Coords.longitude);
                }

                // Check to see that MERRA data files have required lat/long and assign XInd and YInd
                bool gotIndices = thisMERRA.GetMERRAPullXYIndices(ref nodesToPull, MERRAfolder);

                if (gotIndices == false)
                {
                    return;
                }

                BackgroundWork.Vars_for_MERRA Vars_for_MERRA = new BackgroundWork.Vars_for_MERRA();
                Vars_for_MERRA.thisInst    = thisInst;
                Vars_for_MERRA.thisMERRA   = thisMERRA;
                Vars_for_MERRA.MCP_type    = thisInst.Get_MCP_Method();
                Vars_for_MERRA.thisMet     = thisMet;
                Vars_for_MERRA.nodesToPull = nodesToPull;

                thisInst.BW_worker = new BackgroundWork();
                thisInst.BW_worker.Call_BW_MERRA2_Import(Vars_for_MERRA);
            }
            else
            {
                // Have all necessary MERRA nodes and user wants to do MCP so.... Run MCP!

                // Add MERRA object to list
                Array.Resize(ref merraData, numMERRA_Data + 1);
                merraData[numMERRA_Data - 1] = thisMERRA;
                thisMERRA.GetMERRADataFromDB(thisInst);
                thisMERRA.GetInterpData(thisInst.UTM_conversions);

                if (doMCP == DialogResult.Yes)
                {
                    thisMet.WSWD_Dists = new Met.WSWD_Dist[0];
                    thisInst.metList.RunMCP(ref thisMet, thisMERRA, thisInst, thisInst.Get_MCP_Method());
                    thisMet.CalcAllLT_WSWD_Dists(thisInst, thisMet.mcp.LT_WS_Ests); // Calculates LT wind speed / wind direction distributions for using all day and using each season and each time of day (Day vs. Night)
                    thisInst.updateThe.AllTABs(thisInst);
                }
                else
                {
                    thisInst.updateThe.MERRA_Dropdowns(thisInst);
                    thisInst.updateThe.MERRA_TAB(thisInst);
                }
            }
        }