Ejemplo n.º 1
0
        public void Calc_MERRA2_WS_WD_Test()
        {
            string       UVfile = testingFolder + "\\Calc_MERRA_WS_WD\\U50_V50_WS.csv";
            StreamReader srUVs  = new StreamReader(UVfile);

            MERRA.East_North_WSs[] theseUVs = new MERRA.East_North_WSs[3];
            MERRA thisMERRA = new MERRA();

            thisMERRA.Size_East_North_WS_Data(ref theseUVs, 2);

            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 2; j++)
                {
                    string   theseUVstr = srUVs.ReadLine();
                    string[] UVs        = theseUVstr.Split(',');

                    theseUVs[i].U50[j] = Convert.ToDouble(UVs[0]);
                    theseUVs[i].V50[j] = Convert.ToDouble(UVs[1]);
                }
            }

            MERRA.MERRA_Pull[] theseMERRA = new MERRA.MERRA_Pull[3];
            Array.Resize(ref theseMERRA[0].Data, 2);
            Array.Resize(ref theseMERRA[1].Data, 2);
            Array.Resize(ref theseMERRA[2].Data, 2);

            thisMERRA.Calc_MERRA2_WS_WD(ref theseMERRA, theseUVs);

            Assert.AreEqual(4.07736, theseMERRA[0].Data[0].WS50m, 0.01, "Wrong WS Node 1 Hour 1");
            Assert.AreEqual(284.9041, theseMERRA[0].Data[0].WD50m, 0.01, "Wrong WD Node 1 Hour 1");

            Assert.AreEqual(5.18769, theseMERRA[0].Data[1].WS50m, 0.01, "Wrong WS Node 1 Hour 2");
            Assert.AreEqual(237.5902, theseMERRA[0].Data[1].WD50m, 0.01, "Wrong WD Node 1 Hour 2");

            Assert.AreEqual(4.7727, theseMERRA[1].Data[0].WS50m, 0.01, "Wrong WS Node 2 Hour 1");
            Assert.AreEqual(81.1243, theseMERRA[1].Data[0].WD50m, 0.01, "Wrong WD Node 2 Hour 1");

            Assert.AreEqual(5.70873, theseMERRA[1].Data[1].WS50m, 0.01, "Wrong WS Node 2 Hour 2");
            Assert.AreEqual(99.0641, theseMERRA[1].Data[1].WD50m, 0.01, "Wrong WD Node 2 Hour 2");

            Assert.AreEqual(1.24520, theseMERRA[2].Data[0].WS50m, 0.01, "Wrong WS Node 3 Hour 1");
            Assert.AreEqual(342.719, theseMERRA[2].Data[0].WD50m, 0.01, "Wrong WD Node 3 Hour 1");

            Assert.AreEqual(5.0064, theseMERRA[2].Data[1].WS50m, 0.01, "Wrong WS Node 3 Hour 2");
            Assert.AreEqual(272.743, theseMERRA[2].Data[1].WD50m, 0.01, "Wrong WD Node 3 Hour 2");

            srUVs.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);
                }
            }
        }