diff --git a/instat/clsRecentFiles.vb b/instat/clsRecentFiles.vb index a01cd0916c2..658ae8aa339 100644 --- a/instat/clsRecentFiles.vb +++ b/instat/clsRecentFiles.vb @@ -147,24 +147,29 @@ Public Class clsRecentFiles AddHandler clsItem.Click, AddressOf mnuFile_Click 'insert into the dropdownitems mnuTbShowLast10.DropDownItems.Insert(mnuTbShowLast10.DropDownItems.Count - 1, clsItem) - Next - - 'displays items (_in reverse order) for recent files - For iCounter As Integer = strListMRU.Count - 1 To 0 Step -1 - Dim sPath As String = strListMRU(iCounter) + Next + + 'displays items (_in reverse order) for recent files + Dim strPath As String + Dim strFileName As String + For iCounter As Integer = strListMRU.Count - 1 To 0 Step -1 + strPath = strListMRU(iCounter) + strFileName = Path.GetFileName(strPath) ' create new ToolStripItem, displaying the name of the file... - Dim clsItem As New ToolStripMenuItem(Path.GetFileName(sPath)) - Dim clsItemIcon As New ToolStripMenuItem(Path.GetFileName(sPath)) - ' set the tag - identifies the ToolStripItem as an MRU item and - ' contains the full path so it can be opened later... - clsItem.Tag = "MRU:" & sPath - clsItemIcon.Tag = "MRU:" & sPath + Dim clsItem As New ToolStripMenuItem(strFileName) + Dim clsItemIcon As New ToolStripMenuItem(strFileName) + clsItem.ToolTipText = strPath + clsItemIcon.ToolTipText = strPath + ' set the tag - identifies the ToolStripItem as an MRU item and + ' contains the full path so it can be opened later... + clsItem.Tag = "MRU:" & strPath + clsItemIcon.Tag = "MRU:" & strPath ' hook into the click event handler so we can open the file later... AddHandler clsItem.Click, AddressOf mnuFileMRU_Click AddHandler clsItemIcon.Click, AddressOf mnuFileMRU_Click ' insert into DropDownItems list... mnuFile.DropDownItems.Insert(mnuFile.DropDownItems.Count - 1, clsItem) - mnuFileIcon.DropDownItems.Insert(mnuFileIcon.DropDownItems.Count, clsItemIcon) + mnuFileIcon.DropDownItems.Insert(mnuFileIcon.DropDownItems.Count, clsItemIcon) Next ' show separator diff --git a/instat/dlgBoxPlot.vb b/instat/dlgBoxPlot.vb index e8390b885dd..ddbf9a03437 100644 --- a/instat/dlgBoxPlot.vb +++ b/instat/dlgBoxPlot.vb @@ -14,7 +14,6 @@ ' You should have received a copy of the GNU General Public License ' along with this program. If not, see . - Imports instat.Translations Public Class dlgBoxplot Private clsRggplotFunction As New RFunction @@ -50,7 +49,9 @@ Public Class dlgBoxplot bReset = False autoTranslate(Me) TestOkEnabled() + SetOptionsButtonstext() + End Sub Private Sub InitialiseDialog() @@ -116,7 +117,6 @@ Public Class dlgBoxplot ucrSaveBoxplot.SetDataFrameSelector(ucrSelectorBoxPlot.ucrAvailableDataFrames) ucrSaveBoxplot.SetAssignToIfUncheckedValue("last_graph") - 'this control exists but diabled for now ucrChkSwapParameters.SetText("swap Parameters") 'ucrSecondFactorReceiver.AddToLinkedControls(ucrChkSwapParameters, {ucrSecondFactorReceiver.IsEmpty = False}, bNewLinkedHideIfParameterMissing:=True) @@ -153,7 +153,8 @@ Public Class dlgBoxplot clsRgeomPlotFunction.SetPackageName("ggplot2") clsRgeomPlotFunction.SetRCommand("geom_boxplot") - clsRgeomPlotFunction.AddParameter("varwidth", "FALSE") + clsRgeomPlotFunction.AddParameter("varwidth", "FALSE", iPosition:=0) + clsRgeomPlotFunction.AddParameter("outlier.colour", Chr(34) & "red" & Chr(34), iPosition:=1) 'clsLocalRaesFunction.SetPackageName("ggplot2") 'clsLocalRaesFunction.SetRCommand("aes") @@ -257,16 +258,32 @@ Public Class dlgBoxplot 'Sets geom function, fill and colour aesthetics and ucrsave prefix If rdoBoxplot.Checked Then clsRgeomPlotFunction.SetRCommand("geom_boxplot") + clsRgeomPlotFunction.AddParameter("outlier.colour", Chr(34) & "red" & Chr(34), iPosition:=1) + clsRgeomPlotFunction.RemoveParameterByName("Height") + clsRgeomPlotFunction.RemoveParameterByName("width") ucrSaveBoxplot.SetPrefix("boxplot") ucrSecondFactorReceiver.ChangeParameterName("fill") + + SetOptionsButtonText() + ElseIf rdoJitter.Checked Then clsRgeomPlotFunction.SetRCommand("geom_jitter") + clsRgeomPlotFunction.RemoveParameterByName("outlier.colour") + clsRgeomPlotFunction.AddParameter("Height", 0.2, iPosition:=1) + clsRgeomPlotFunction.AddParameter("width", 0.0, iPosition:=2) ucrSaveBoxplot.SetPrefix("jitter") ucrSecondFactorReceiver.ChangeParameterName("colour") + + SetOptionsButtonText() + Else clsRgeomPlotFunction.SetRCommand("geom_violin") + clsRgeomPlotFunction.RemoveParameterByName("outlier.colour") + clsRgeomPlotFunction.RemoveParameterByName("Height") + clsRgeomPlotFunction.RemoveParameterByName("width") ucrSaveBoxplot.SetPrefix("violin") ucrSecondFactorReceiver.ChangeParameterName("fill") + End If SetOptionsButtonstext() End Sub @@ -278,9 +295,22 @@ Public Class dlgBoxplot cmdBoxPlotOptions.Text = "Jitter Options" Else cmdBoxPlotOptions.Text = "Violin Options" + + SetOptionsButtonText() + End If End Sub + + Private Sub SetOptionsButtonText() + If rdoBoxplot.Checked Then + cmdBoxPlotOptions.Text = "Boxplot Options" + ElseIf rdoJitter.Checked Then + cmdBoxPlotOptions.Text = "Jitter Options" + Else + cmdBoxPlotOptions.Text = "Violin Options" + End If + End Sub Private Sub TempOptionsDisabledInMultipleVariablesCase() If ucrVariablesAsFactorForBoxplot.bSingleVariable Then cmdBoxPlotOptions.Enabled = True diff --git a/instat/dlgClimaticSummary.vb b/instat/dlgClimaticSummary.vb index c430d40613e..2337e3925ac 100644 --- a/instat/dlgClimaticSummary.vb +++ b/instat/dlgClimaticSummary.vb @@ -168,6 +168,7 @@ Public Class dlgClimaticSummary clsDayFilterCalc.AddParameter("calculated_from", clsRFunctionParameter:=clsDayFilterCalcFromConvert, iPosition:=2) clsFromAndToConditionOperator.SetOperation("&") + clsFromAndToConditionOperator.bBrackets = False clsFromAndToConditionOperator.AddParameter("from", clsROperatorParameter:=clsFromConditionOperator, iPosition:=0) clsFromConditionOperator.SetOperation(">=") ' doy = DOYreceiver in position 0. This is always the case clsFromConditionOperator.AddParameter("from", 1, iPosition:=1) diff --git a/instat/dlgHistogram.vb b/instat/dlgHistogram.vb index 405add7f440..5c067cef4fc 100644 --- a/instat/dlgHistogram.vb +++ b/instat/dlgHistogram.vb @@ -36,7 +36,6 @@ Public Class dlgHistogram Private Sub dlgHistogram_Load(sender As Object, e As EventArgs) Handles MyBase.Load If bFirstLoad Then - 'setdefaults InitialiseDialog() bFirstLoad = False End If @@ -49,7 +48,8 @@ Public Class dlgHistogram bReset = False autoTranslate(Me) TestOkEnabled() - SetOptionsButtonstext() + + SetOptionsButtonstext() End Sub Private Sub InitialiseDialog() @@ -183,12 +183,17 @@ Public Class dlgHistogram If rdoHistogram.Checked Then clsRgeomPlotFunction.SetRCommand("geom_histogram") ucrFactorReceiver.ChangeParameterName("fill") + + If Not ucrSaveHist.bUserTyped Then ucrSaveHist.SetPrefix("histogram") End If ElseIf rdoDensity.Checked Then clsRgeomPlotFunction.SetRCommand("geom_density") ucrFactorReceiver.ChangeParameterName("colour") + + SetOptionsButtonText() + If Not ucrSaveHist.bUserTyped Then ucrSaveHist.SetPrefix("density") End If @@ -196,6 +201,8 @@ Public Class dlgHistogram clsRgeomPlotFunction.SetRCommand("geom_freqpoly") ucrFactorReceiver.ChangeParameterName("colour") + + If Not ucrSaveHist.bUserTyped Then ucrSaveHist.SetPrefix("frequency_polygon") End If @@ -218,6 +225,21 @@ Public Class dlgHistogram End If End Sub + Private Sub SetOptionsButtonText() + If rdoHistogram.Checked Then + cmdHistogramOptions.Text = "Histogram Options" + cmdHistogramOptions.Size = New Size(120, 25) + ElseIf rdoDensity.Checked Then + cmdHistogramOptions.Size = New Size(120, 25) + cmdHistogramOptions.Text = "Density Options" + + ElseIf rdoFrequencyPolygon.Checked Then + cmdHistogramOptions.Size = New Size(160, 25) + cmdHistogramOptions.Text = "Frequency Polygon Options" + End If + End Sub + + Private Sub TempOptionsDisabledInMultipleVariablesCase() If ucrVariablesAsFactorforHist.bSingleVariable Then cmdHistogramOptions.Enabled = True diff --git a/instat/sdgOpenNetCDF.Designer.vb b/instat/sdgOpenNetCDF.Designer.vb index f12cf3f9257..2d5cf3af69c 100644 --- a/instat/sdgOpenNetCDF.Designer.vb +++ b/instat/sdgOpenNetCDF.Designer.vb @@ -56,9 +56,20 @@ Partial Class sdgOpenNetCDF Me.ucrChkKeepRawTime = New instat.ucrCheck() Me.ucrChkIncludeMetadata = New instat.ucrCheck() Me.ucrBase = New instat.ucrButtonsSubdialogue() + Me.grpLocation = New System.Windows.Forms.GroupBox() + Me.ucrPnlLocation = New instat.UcrPanel() + Me.rdoRange = New System.Windows.Forms.RadioButton() + Me.rdoPoints = New System.Windows.Forms.RadioButton() + Me.rdoSinglePoint = New System.Windows.Forms.RadioButton() + Me.ucrInputPointX = New instat.ucrInputTextBox() + Me.ucrInputPointY = New instat.ucrInputTextBox() + Me.ucrReceiverPointsX = New instat.ucrReceiverSingle() + Me.ucrReceiverPointsY = New instat.ucrReceiverSingle() + Me.ucrSelectorPoints = New instat.ucrSelectorByDataFrameAddRemove() Me.tbNetCDF.SuspendLayout() Me.tbSubset.SuspendLayout() Me.tbOptions.SuspendLayout() + Me.grpLocation.SuspendLayout() Me.SuspendLayout() ' 'tbNetCDF @@ -71,12 +82,12 @@ Partial Class sdgOpenNetCDF ' 'tbSubset ' + Me.tbSubset.Controls.Add(Me.ucrSelectorPoints) + Me.tbSubset.Controls.Add(Me.grpLocation) Me.tbSubset.Controls.Add(Me.lblMaxS) Me.tbSubset.Controls.Add(Me.lblMinS) Me.tbSubset.Controls.Add(Me.lblS) Me.tbSubset.Controls.Add(Me.lblZ) - Me.tbSubset.Controls.Add(Me.lblY) - Me.tbSubset.Controls.Add(Me.lblMinX) Me.tbSubset.Controls.Add(Me.dtpMinT) Me.tbSubset.Controls.Add(Me.dtpMaxT) Me.tbSubset.Controls.Add(Me.lblMaxT) @@ -85,18 +96,10 @@ Partial Class sdgOpenNetCDF Me.tbSubset.Controls.Add(Me.ucrInputMaxS) Me.tbSubset.Controls.Add(Me.lblMaxZ) Me.tbSubset.Controls.Add(Me.ucrInputMaxZ) - Me.tbSubset.Controls.Add(Me.lblMaxY) - Me.tbSubset.Controls.Add(Me.ucrInputMaxY) - Me.tbSubset.Controls.Add(Me.lblMaxX) - Me.tbSubset.Controls.Add(Me.ucrInputMaxX) Me.tbSubset.Controls.Add(Me.lblT) Me.tbSubset.Controls.Add(Me.ucrInputMinS) Me.tbSubset.Controls.Add(Me.lblMinZ) Me.tbSubset.Controls.Add(Me.ucrInputMinZ) - Me.tbSubset.Controls.Add(Me.lblMinY) - Me.tbSubset.Controls.Add(Me.ucrInputMinY) - Me.tbSubset.Controls.Add(Me.lblX) - Me.tbSubset.Controls.Add(Me.ucrInputMinX) resources.ApplyResources(Me.tbSubset, "tbSubset") Me.tbSubset.Name = "tbSubset" Me.tbSubset.UseVisualStyleBackColor = True @@ -290,6 +293,98 @@ Partial Class sdgOpenNetCDF resources.ApplyResources(Me.ucrBase, "ucrBase") Me.ucrBase.Name = "ucrBase" ' + 'grpLocation + ' + Me.grpLocation.Controls.Add(Me.ucrReceiverPointsY) + Me.grpLocation.Controls.Add(Me.ucrReceiverPointsX) + Me.grpLocation.Controls.Add(Me.ucrInputPointY) + Me.grpLocation.Controls.Add(Me.ucrInputPointX) + Me.grpLocation.Controls.Add(Me.rdoSinglePoint) + Me.grpLocation.Controls.Add(Me.rdoPoints) + Me.grpLocation.Controls.Add(Me.rdoRange) + Me.grpLocation.Controls.Add(Me.ucrPnlLocation) + Me.grpLocation.Controls.Add(Me.lblX) + Me.grpLocation.Controls.Add(Me.ucrInputMinX) + Me.grpLocation.Controls.Add(Me.ucrInputMinY) + Me.grpLocation.Controls.Add(Me.lblMinY) + Me.grpLocation.Controls.Add(Me.ucrInputMaxX) + Me.grpLocation.Controls.Add(Me.lblY) + Me.grpLocation.Controls.Add(Me.lblMaxX) + Me.grpLocation.Controls.Add(Me.lblMinX) + Me.grpLocation.Controls.Add(Me.ucrInputMaxY) + Me.grpLocation.Controls.Add(Me.lblMaxY) + resources.ApplyResources(Me.grpLocation, "grpLocation") + Me.grpLocation.Name = "grpLocation" + Me.grpLocation.TabStop = False + ' + 'ucrPnlLocation + ' + resources.ApplyResources(Me.ucrPnlLocation, "ucrPnlLocation") + Me.ucrPnlLocation.Name = "ucrPnlLocation" + ' + 'rdoRange + ' + resources.ApplyResources(Me.rdoRange, "rdoRange") + Me.rdoRange.Name = "rdoRange" + Me.rdoRange.TabStop = True + Me.rdoRange.UseVisualStyleBackColor = True + ' + 'rdoPoints + ' + resources.ApplyResources(Me.rdoPoints, "rdoPoints") + Me.rdoPoints.Name = "rdoPoints" + Me.rdoPoints.TabStop = True + Me.rdoPoints.UseVisualStyleBackColor = True + ' + 'rdoSinglePoint + ' + resources.ApplyResources(Me.rdoSinglePoint, "rdoSinglePoint") + Me.rdoSinglePoint.Name = "rdoSinglePoint" + Me.rdoSinglePoint.TabStop = True + Me.rdoSinglePoint.UseVisualStyleBackColor = True + ' + 'ucrInputPointX + ' + Me.ucrInputPointX.AddQuotesIfUnrecognised = True + Me.ucrInputPointX.IsMultiline = False + Me.ucrInputPointX.IsReadOnly = False + resources.ApplyResources(Me.ucrInputPointX, "ucrInputPointX") + Me.ucrInputPointX.Name = "ucrInputPointX" + ' + 'ucrInputPointY + ' + Me.ucrInputPointY.AddQuotesIfUnrecognised = True + Me.ucrInputPointY.IsMultiline = False + Me.ucrInputPointY.IsReadOnly = False + resources.ApplyResources(Me.ucrInputPointY, "ucrInputPointY") + Me.ucrInputPointY.Name = "ucrInputPointY" + ' + 'ucrReceiverPointsX + ' + Me.ucrReceiverPointsX.frmParent = Me + resources.ApplyResources(Me.ucrReceiverPointsX, "ucrReceiverPointsX") + Me.ucrReceiverPointsX.Name = "ucrReceiverPointsX" + Me.ucrReceiverPointsX.Selector = Nothing + Me.ucrReceiverPointsX.strNcFilePath = "" + Me.ucrReceiverPointsX.ucrSelector = Nothing + ' + 'ucrReceiverPointsY + ' + Me.ucrReceiverPointsY.frmParent = Me + resources.ApplyResources(Me.ucrReceiverPointsY, "ucrReceiverPointsY") + Me.ucrReceiverPointsY.Name = "ucrReceiverPointsY" + Me.ucrReceiverPointsY.Selector = Nothing + Me.ucrReceiverPointsY.strNcFilePath = "" + Me.ucrReceiverPointsY.ucrSelector = Nothing + ' + 'ucrSelectorPoints + ' + Me.ucrSelectorPoints.bDropUnusedFilterLevels = False + Me.ucrSelectorPoints.bShowHiddenColumns = False + Me.ucrSelectorPoints.bUseCurrentFilter = True + resources.ApplyResources(Me.ucrSelectorPoints, "ucrSelectorPoints") + Me.ucrSelectorPoints.Name = "ucrSelectorPoints" + ' 'sdgOpenNetCDF ' resources.ApplyResources(Me, "$this") @@ -304,6 +399,8 @@ Partial Class sdgOpenNetCDF Me.tbSubset.ResumeLayout(False) Me.tbSubset.PerformLayout() Me.tbOptions.ResumeLayout(False) + Me.grpLocation.ResumeLayout(False) + Me.grpLocation.PerformLayout() Me.ResumeLayout(False) End Sub @@ -340,4 +437,14 @@ Partial Class sdgOpenNetCDF Friend WithEvents ucrInputMinY As ucrInputTextBox Friend WithEvents lblX As Label Friend WithEvents ucrInputMinX As ucrInputTextBox + Friend WithEvents grpLocation As GroupBox + Friend WithEvents rdoSinglePoint As RadioButton + Friend WithEvents rdoPoints As RadioButton + Friend WithEvents rdoRange As RadioButton + Friend WithEvents ucrPnlLocation As UcrPanel + Friend WithEvents ucrReceiverPointsY As ucrReceiverSingle + Friend WithEvents ucrReceiverPointsX As ucrReceiverSingle + Friend WithEvents ucrInputPointY As ucrInputTextBox + Friend WithEvents ucrInputPointX As ucrInputTextBox + Friend WithEvents ucrSelectorPoints As ucrSelectorByDataFrameAddRemove End Class diff --git a/instat/sdgOpenNetCDF.resx b/instat/sdgOpenNetCDF.resx index 5a975fa0b12..c6d6ec8d2f5 100644 --- a/instat/sdgOpenNetCDF.resx +++ b/instat/sdgOpenNetCDF.resx @@ -117,13 +117,548 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 486, 197 + + + + 0, 0, 0, 0 + + + 210, 180 + + + 27 + + + ucrSelectorPoints + + + instat.ucrSelectorByDataFrameAddRemove, instat, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + + + tbSubset + + + 0 + + + True + + + 6, 13 + + + 839, 468 + + + 176, 433 + + + 142, 30 + + + 1 + + + ucrBase + + + instat.ucrButtonsSubdialogue, instat, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + + + $this + + + 0 + + + CenterParent + + + NetCDF Options + + + sdgOpenNetCDF + + + System.Windows.Forms.Form, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 119, 77 + + + 0, 0, 0, 0 + + + 120, 20 + + + 18 + + + ucrReceiverPointsY + + + instat.ucrReceiverSingle, instat, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + + + grpLocation + + + 0 + + + 119, 50 + + + 0, 0, 0, 0 + + + 120, 20 + + + 17 + + + ucrReceiverPointsX + + + instat.ucrReceiverSingle, instat, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + + + grpLocation + + + 1 + + + 119, 77 + + + 90, 21 + + + 16 + + + ucrInputPointY + + + instat.ucrInputTextBox, instat, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + + + grpLocation + + + 2 + + + 119, 50 + + + 90, 21 + + + 15 + + + ucrInputPointX + + + instat.ucrInputTextBox, instat, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + + + grpLocation + + + 3 + + + True + + + NoControl + + + 310, 19 + + + 81, 17 + + + 14 + + + Single Point + + + rdoSinglePoint + + + System.Windows.Forms.RadioButton, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + grpLocation + + + 4 + + + True + + + NoControl + + + 190, 19 + + + 54, 17 + + + 13 + + + Points + + + rdoPoints + + + System.Windows.Forms.RadioButton, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + grpLocation + + + 5 + + + True + + + 70, 19 + + + 57, 17 + + + 12 + + + Range + + + rdoRange + + + System.Windows.Forms.RadioButton, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + grpLocation + + + 6 + + + 60, 11 + + + 354, 33 + + + 11 + + + ucrPnlLocation + + + instat.UcrPanel, instat, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + + + grpLocation + + + 7 + + + True + + + 5, 53 + + + 17, 13 + + + 1 + + + X: + + + lblX + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + grpLocation + + + 8 + + + 146, 50 + + + 90, 21 + + + 3 + + + ucrInputMinX + + + instat.ucrInputTextBox, instat, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + + + grpLocation + + + 9 + + + 146, 77 + + + 90, 21 + + + 8 + + + ucrInputMinY + + + instat.ucrInputTextBox, instat, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + + + grpLocation + + + 10 + + + True + + + 117, 80 + + + 27, 13 + + + 7 + + + Min: + + + lblMinY + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + grpLocation + + + 11 + + + 325, 50 + + + 90, 21 + + + 5 + + + ucrInputMaxX + + + instat.ucrInputTextBox, instat, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + + + grpLocation + + + 12 + + + True + + + 5, 80 + + + 17, 13 + + + 6 + + + Y: + + + lblY + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + grpLocation + + + 13 + + + True + + + 293, 53 + + + 30, 13 + + + 4 + + + Max: + + + lblMaxX + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + grpLocation + + + 14 + + + True + + + 117, 53 + + + 27, 13 + + + 2 + + + Min: + + + lblMinX + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + grpLocation + + + 15 + + + 325, 77 + + + 90, 21 + + + 10 + + + ucrInputMaxY + + + instat.ucrInputTextBox, instat, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + + + grpLocation + + + 16 + + + True + + + 293, 80 + + + 30, 13 + + + 9 + + + Max: + + + lblMaxY + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + grpLocation + + + 17 + + + 11, 174 + + + 434, 106 + + + 26 + + + Location + + + grpLocation + + + System.Windows.Forms.GroupBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + tbSubset + + + 1 + True - - 296, 258 + 303, 332 30, 13 @@ -144,13 +679,13 @@ tbSubset - 0 + 2 True - 120, 257 + 127, 331 27, 13 @@ -171,13 +706,13 @@ tbSubset - 1 + 3 True - 8, 258 + 15, 332 17, 13 @@ -198,91 +733,37 @@ tbSubset - 2 + 4 True - 8, 231 - - - 17, 13 - - - 11 - - - Z: - - - lblZ - - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - tbSubset - - - 3 - - - True - - - 8, 204 - - - 17, 13 - - - 6 - - - Y: - - - lblY - - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - tbSubset - - - 4 - - - True - - - 120, 177 - - - 27, 13 + 15, 305 - - 2 + + 17, 13 - - Min: + + 11 - - lblMinX + + Z: - + + lblZ + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + tbSubset - + 5 - 149, 282 + 156, 357 133, 20 @@ -303,7 +784,7 @@ 6 - 328, 282 + 335, 356 133, 20 @@ -327,7 +808,7 @@ True - 296, 285 + 303, 359 30, 13 @@ -375,7 +856,7 @@ True - 120, 285 + 127, 359 27, 13 @@ -399,7 +880,7 @@ 10 - 328, 255 + 335, 329 90, 21 @@ -423,7 +904,7 @@ True - 296, 231 + 303, 305 30, 13 @@ -447,7 +928,7 @@ 12 - 328, 228 + 335, 302 90, 21 @@ -467,107 +948,11 @@ 13 - - True - - - 296, 204 - - - 30, 13 - - - 9 - - - Max: - - - lblMaxY - - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - tbSubset - - - 14 - - - 328, 201 - - - 90, 21 - - - 10 - - - ucrInputMaxY - - - instat.ucrInputTextBox, instat, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null - - - tbSubset - - - 15 - - - True - - - 296, 177 - - - 30, 13 - - - 4 - - - Max: - - - lblMaxX - - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - tbSubset - - - 16 - - - 328, 174 - - - 90, 21 - - - 5 - - - ucrInputMaxX - - - instat.ucrInputTextBox, instat, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null - - - tbSubset - - - 17 - True - 8, 285 + 15, 359 17, 13 @@ -588,10 +973,10 @@ tbSubset - 18 + 14 - 149, 255 + 156, 329 90, 21 @@ -609,13 +994,13 @@ tbSubset - 19 + 15 True - 120, 231 + 127, 305 27, 13 @@ -636,10 +1021,10 @@ tbSubset - 20 + 16 - 149, 228 + 156, 302 90, 21 @@ -657,113 +1042,16 @@ tbSubset - 21 - - - True - - - 120, 204 - - - 27, 13 - - - 7 - - - Min: - - - lblMinY - - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - tbSubset - - - 22 - - - 149, 201 - - - 90, 21 - - - 8 - - - ucrInputMinY - - - instat.ucrInputTextBox, instat, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null - - - tbSubset - - - 23 - - - True - - - 8, 177 - - - 17, 13 - - - 1 - - - X: - - - lblX - - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - tbSubset - - - 24 - - - 149, 174 - - - 90, 21 - - - 3 - - - ucrInputMinX - - - instat.ucrInputTextBox, instat, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null - - - tbSubset - - - 25 + 17 4, 22 - 3, 3, 3, 3 - 475, 397 + 711, 397 0 @@ -877,7 +1165,7 @@ 8, 8 - 483, 423 + 719, 423 0 @@ -894,46 +1182,4 @@ 1 - - 176, 433 - - - 142, 30 - - - 1 - - - ucrBase - - - instat.ucrButtonsSubdialogue, instat, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null - - - $this - - - 0 - - - True - - - 6, 13 - - - 494, 468 - - - CenterParent - - - NetCDF Options - - - sdgOpenNetCDF - - - System.Windows.Forms.Form, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - \ No newline at end of file diff --git a/instat/sdgOpenNetCDF.vb b/instat/sdgOpenNetCDF.vb index 0cb19be0506..fc518157c0c 100644 --- a/instat/sdgOpenNetCDF.vb +++ b/instat/sdgOpenNetCDF.vb @@ -14,6 +14,7 @@ ' You should have received a copy of the GNU General Public License ' along with this program. If not, see . +Imports instat Imports instat.Translations Imports RDotNet @@ -30,6 +31,8 @@ Public Class sdgOpenNetCDF Private lstDims As List(Of String) Private lstFunctions As List(Of RFunction) Private strFilePath As String + Private dctAxesNames As Dictionary(Of String, String) + Private bUpdating As Boolean = False Private Sub sdgOpenNetCDF_Load(sender As Object, e As EventArgs) Handles MyBase.Load autoTranslate(Me) @@ -46,34 +49,42 @@ Public Class sdgOpenNetCDF ucrInputMinX.SetValidationTypeAsNumeric() ucrInputMinX.AddQuotesIfUnrecognised = False ucrInputMinX.Focus() + ucrInputMinX.SetLinkedDisplayControl(lblMinX) ucrInputMaxX.SetParameter(New RParameter("max", 1, bNewIncludeArgumentName:=False)) ucrInputMaxX.SetValidationTypeAsNumeric() ucrInputMaxX.AddQuotesIfUnrecognised = False + ucrInputMaxX.SetLinkedDisplayControl(lblMaxX) ucrInputMinY.SetParameter(New RParameter("min", 0, bNewIncludeArgumentName:=False)) ucrInputMinY.SetValidationTypeAsNumeric() ucrInputMinY.AddQuotesIfUnrecognised = False + ucrInputMinY.SetLinkedDisplayControl(lblMinY) ucrInputMaxY.SetParameter(New RParameter("max", 1, bNewIncludeArgumentName:=False)) ucrInputMaxY.SetValidationTypeAsNumeric() ucrInputMaxY.AddQuotesIfUnrecognised = False + ucrInputMaxY.SetLinkedDisplayControl(lblMaxY) ucrInputMinZ.SetParameter(New RParameter("min", 0, bNewIncludeArgumentName:=False)) ucrInputMinZ.SetValidationTypeAsNumeric() ucrInputMinZ.AddQuotesIfUnrecognised = False + ucrInputMinZ.SetLinkedDisplayControl(lblMinZ) ucrInputMaxZ.SetParameter(New RParameter("max", 1, bNewIncludeArgumentName:=False)) ucrInputMaxZ.SetValidationTypeAsNumeric() ucrInputMaxZ.AddQuotesIfUnrecognised = False + ucrInputMaxZ.SetLinkedDisplayControl(lblMaxZ) ucrInputMinS.SetParameter(New RParameter("min", 0, bNewIncludeArgumentName:=False)) ucrInputMinS.SetValidationTypeAsNumeric() ucrInputMinS.AddQuotesIfUnrecognised = False + ucrInputMinS.SetLinkedDisplayControl(lblMinS) ucrInputMaxS.SetParameter(New RParameter("max", 1, bNewIncludeArgumentName:=False)) ucrInputMaxS.SetValidationTypeAsNumeric() ucrInputMaxS.AddQuotesIfUnrecognised = False + ucrInputMaxS.SetLinkedDisplayControl(lblMaxS) 'Temp disabled until code is stable with only_data_vars = False ucrChkOnlyDataVariables.Enabled = False @@ -90,6 +101,30 @@ Public Class sdgOpenNetCDF ucrChkIncludeMetadata.SetText("Include Metadata") ucrChkIncludeMetadata.SetRDefault("TRUE") + ucrReceiverPointsX.Selector = ucrSelectorPoints + ucrReceiverPointsY.Selector = ucrSelectorPoints + + ucrPnlLocation.AddRadioButton(rdoRange) + ucrPnlLocation.AddRadioButton(rdoPoints) + ucrPnlLocation.AddRadioButton(rdoSinglePoint) + + ucrPnlLocation.AddParameterPresentCondition(rdoRange, "lon_points", False) + ucrPnlLocation.AddParameterPresentCondition(rdoPoints, "lon_points", True) + ucrPnlLocation.AddParameterIsRFunctionCondition(rdoPoints, "lon_points", True) + ucrPnlLocation.AddParameterPresentCondition(rdoSinglePoint, "lon_points", True) + ucrPnlLocation.AddParameterIsRFunctionCondition(rdoSinglePoint, "lon_points", False) + + ucrPnlLocation.AddToLinkedControls(ucrInputMinX, {rdoRange}, bNewLinkedHideIfParameterMissing:=True) + ucrPnlLocation.AddToLinkedControls(ucrInputMaxX, {rdoRange}, bNewLinkedHideIfParameterMissing:=True) + ucrPnlLocation.AddToLinkedControls(ucrInputMinY, {rdoRange}, bNewLinkedHideIfParameterMissing:=True) + ucrPnlLocation.AddToLinkedControls(ucrInputMaxY, {rdoRange}, bNewLinkedHideIfParameterMissing:=True) + + ucrPnlLocation.AddToLinkedControls(ucrReceiverPointsX, {rdoPoints}, bNewLinkedHideIfParameterMissing:=True) + ucrPnlLocation.AddToLinkedControls(ucrReceiverPointsY, {rdoPoints}, bNewLinkedHideIfParameterMissing:=True) + + ucrPnlLocation.AddToLinkedControls(ucrInputPointX, {rdoSinglePoint}, bNewLinkedHideIfParameterMissing:=True) + ucrPnlLocation.AddToLinkedControls(ucrInputPointY, {rdoSinglePoint}, bNewLinkedHideIfParameterMissing:=True) + lstDims = New List(Of String)(New String() {"X", "Y", "Z", "S", "T"}) lstMinTextBoxes = New List(Of ucrInputTextBox)(New ucrInputTextBox() {ucrInputMinX, ucrInputMinY, ucrInputMinZ, ucrInputMinS}) lstMaxTextBoxes = New List(Of ucrInputTextBox)(New ucrInputTextBox() {ucrInputMaxX, ucrInputMaxY, ucrInputMaxZ, ucrInputMaxS}) @@ -97,6 +132,7 @@ Public Class sdgOpenNetCDF lstMinLabels = New List(Of Label)(New Label() {lblMinX, lblMinY, lblMinZ, lblMinS, lblMinT}) lstMaxLabels = New List(Of Label)(New Label() {lblMaxX, lblMaxY, lblMaxZ, lblMaxS, lblMaxT}) InitialiseTabs() + bControlsInitialised = True End Sub Public Sub SetRFunction(clsNewImportNetcdfFunction As RFunction, clsNewNcOpenFunction As RFunction, strNewFilePath As String, clsNewBoundaryListFunction As RFunction, clsNewXLimitsFunction As RFunction, clsNewYLimitsFunction As RFunction, clsNewZLimitsFunction As RFunction, clsNewSLimitsFunction As RFunction, clsNewTLimitsFunction As RFunction, strNewShortDescription As String, Optional bReset As Boolean = False) @@ -112,22 +148,23 @@ Public Class sdgOpenNetCDF Dim clsGetDimNames As New RFunction Dim clsGetBoundsFunction As New RFunction Dim expTemp As SymbolicExpression - Dim strDimNames() As String - Dim strDimAxes() As String Dim bShowDimension As Boolean Dim dtMin As DateTime Dim dtMax As DateTime Dim strTemp As String Dim strScript As String = "" + Dim strDimNames() As String + Dim strDimAxes() As String + bUpdating = True If Not bControlsInitialised Then InitialiseControls() End If clsImportNetcdfFunction = clsNewImportNetcdfFunction clsNcOpenFunction = clsNewNcOpenFunction clsBoundaryListFunction = clsNewBoundaryListFunction - clsYLimitsFunction = clsNewYLimitsFunction clsXLimitsFunction = clsNewXLimitsFunction + clsYLimitsFunction = clsNewYLimitsFunction clsZLimitsFunction = clsNewZLimitsFunction clsSLimitsFunction = clsNewSLimitsFunction clsTLimitsFunction = clsNewTLimitsFunction @@ -148,6 +185,12 @@ Public Class sdgOpenNetCDF If expTemp IsNot Nothing AndAlso expTemp.Type <> Internals.SymbolicExpressionType.Null Then strDimNames = expTemp.AsCharacter.Names.ToArray strDimAxes = expTemp.AsCharacter.ToArray + dctAxesNames = New Dictionary(Of String, String) + For i As Integer = 0 To strDimNames.Count - 1 + If strDimAxes(i) IsNot Nothing Then + dctAxesNames.Add(strDimAxes(i), strDimNames(i)) + End If + Next Else strDimNames = Nothing strDimAxes = Nothing @@ -260,6 +303,14 @@ Public Class sdgOpenNetCDF ucrChkOnlyDataVariables.SetRCode(clsImportNetcdfFunction, bReset, bCloneIfNeeded:=True) ucrChkKeepRawTime.SetRCode(clsImportNetcdfFunction, bReset, bCloneIfNeeded:=True) ucrChkIncludeMetadata.SetRCode(clsImportNetcdfFunction, bReset, bCloneIfNeeded:=True) + + ucrPnlLocation.SetRCode(clsImportNetcdfFunction, bReset, bCloneIfNeeded:=True) + + If bReset Then + ucrReceiverPointsX.SetMeAsReceiver() + End If + bUpdating = False + SetLocationParameters() End Sub Private Sub InitialiseTabs() @@ -278,4 +329,38 @@ Public Class sdgOpenNetCDF clsAsDateMax.AddParameter("x", Chr(34) & dtpMaxT.Value.Year & "-" & dtpMaxT.Value.Month & "-" & dtpMaxT.Value.Day & Chr(34), iPosition:=0) clsAsDateMax.AddParameter("format", Chr(34) & "%Y-%m-%d" & Chr(34), iPosition:=1) End Sub + + Private Sub ucrPnlLocation_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucrPnlLocation.ControlValueChanged, ucrInputPointX.ControlValueChanged, ucrInputPointY.ControlValueChanged, ucrReceiverPointsX.ControlValueChanged, ucrReceiverPointsY.ControlValueChanged + SetLocationParameters() + End Sub + + Private Sub SetLocationParameters() + If Not bUpdating Then + If rdoRange.Checked Then + If dctAxesNames.ContainsKey("X") Then + clsBoundaryListFunction.AddParameter(dctAxesNames("X"), clsRFunctionParameter:=clsXLimitsFunction) + End If + If dctAxesNames.ContainsKey("Y") Then + clsBoundaryListFunction.AddParameter(dctAxesNames("Y"), clsRFunctionParameter:=clsYLimitsFunction) + End If + clsImportNetcdfFunction.RemoveParameterByName("lon_points") + clsImportNetcdfFunction.RemoveParameterByName("lat_points") + ElseIf rdoPoints.Checked OrElse rdoSinglePoint.Checked Then + If dctAxesNames.ContainsKey("X") Then + clsBoundaryListFunction.RemoveParameterByName(dctAxesNames("X")) + End If + If dctAxesNames.ContainsKey("Y") Then + clsBoundaryListFunction.RemoveParameterByName(dctAxesNames("Y")) + End If + If rdoPoints.Checked Then + clsImportNetcdfFunction.AddParameter("lon_points", clsRFunctionParameter:=ucrReceiverPointsX.GetVariables()) + clsImportNetcdfFunction.AddParameter("lat_points", clsRFunctionParameter:=ucrReceiverPointsY.GetVariables()) + Else + clsImportNetcdfFunction.AddParameter("lon_points", ucrInputPointX.GetText()) + clsImportNetcdfFunction.AddParameter("lat_points", ucrInputPointY.GetText()) + End If + End If + ucrSelectorPoints.Visible = (rdoPoints.Checked) + End If + End Sub End Class \ No newline at end of file diff --git a/instat/static/InstatObject/R/instat_object_R6.R b/instat/static/InstatObject/R/instat_object_R6.R index cb6057baec2..934bdcfefd7 100644 --- a/instat/static/InstatObject/R/instat_object_R6.R +++ b/instat/static/InstatObject/R/instat_object_R6.R @@ -1170,7 +1170,7 @@ instat_object$set("public","make_inventory_plot", function(data_name, date_col, } ) -instat_object$set("public", "import_NetCDF", function(nc, name, only_data_vars = TRUE, keep_raw_time = TRUE, include_metadata = TRUE, boundary) { +instat_object$set("public", "import_NetCDF", function(nc, name, only_data_vars = TRUE, keep_raw_time = TRUE, include_metadata = TRUE, boundary, lon_points = NULL, lat_points = NULL) { if(only_data_vars) { all_var_names <- ncdf4.helpers::nc.get.variable.list(nc) } @@ -1203,7 +1203,7 @@ instat_object$set("public", "import_NetCDF", function(nc, name, only_data_vars = else curr_boundary <- NULL curr_name <- make.names(curr_name) curr_name <- next_default_item(curr_name, self$get_data_names(), include_index = FALSE) - data_list[[curr_name]] <- nc_as_data_frame(nc, var_groups[[i]], keep_raw_time = keep_raw_time, include_metadata = include_metadata, boundary = curr_boundary) + data_list[[curr_name]] <- nc_as_data_frame(nc, var_groups[[i]], keep_raw_time = keep_raw_time, include_metadata = include_metadata, boundary = curr_boundary, lon_points = lon_points, lat_points = lat_points) tmp_list <- list() tmp_list[[curr_name]] <- data_list[[curr_name]] data_names <- c(data_names, curr_name) diff --git a/instat/static/InstatObject/R/stand_alone_functions.R b/instat/static/InstatObject/R/stand_alone_functions.R index 4d6789c05f9..5fb467731d1 100644 --- a/instat/static/InstatObject/R/stand_alone_functions.R +++ b/instat/static/InstatObject/R/stand_alone_functions.R @@ -247,7 +247,10 @@ nc_get_dim_min_max <- function(nc, dimension, time_as_date = TRUE) { return(bounds) } -nc_as_data_frame <- function(nc, vars, keep_raw_time = TRUE, include_metadata = TRUE, boundary = NULL) { +nc_as_data_frame <- function(nc, vars, keep_raw_time = TRUE, include_metadata = TRUE, boundary = NULL, lon_points = NULL, lat_points = NULL) { + if(sum(is.null(lon_points), is.null(lat_points)) == 1) stop("You must specificy both lon_points and lat_points") + has_points <- (sum(is.null(lon_points), is.null(lat_points)) == 0) + if(has_points && length(lon_points) != length(lat_points)) stop("lon_points and lat_points have unequal lengths.") dim_names <- ncdf4.helpers::nc.get.dim.names(nc, vars[1]) dim_values <- list() for(dim_name in dim_names) { @@ -256,8 +259,8 @@ nc_as_data_frame <- function(nc, vars, keep_raw_time = TRUE, include_metadata = #This is not recommended but appears in tutorials #ncdf4::ncvar_get(nc, dim_name) } + dim_axes <- ncdf4.helpers::nc.get.dim.axes(nc, vars[1]) if(!is.null(boundary)) { - dim_axes <- ncdf4.helpers::nc.get.dim.axes(nc, vars[1]) if(!all(names(boundary) %in% dim_names)) stop("boundary contains dimensions not associated with", vars[1]) if(anyNA(dim_axes)) { warning("Cannot subset data when some dimension axes cannot be identified.") @@ -271,7 +274,7 @@ nc_as_data_frame <- function(nc, vars, keep_raw_time = TRUE, include_metadata = if(dim %in% dim_axes) { dim_var <- names(dim_axes)[which(dim_axes == dim)] curr_dim_values <- dim_values[[dim_var]] - if(dim_var %in% names(boundary)) { + if(dim_var %in% names(boundary) && !(has_points && dim %in% c("X", "Y"))) { if(dim == "T") { ind <- integer(0) try({ @@ -282,10 +285,10 @@ nc_as_data_frame <- function(nc, vars, keep_raw_time = TRUE, include_metadata = }) } else ind <- which(curr_dim_values >= boundary[[dim_var]][1] & curr_dim_values <= boundary[[dim_var]][2]) + # TODO This is temporary solution for when there is only one value for a dimension and there are rounding difference + if(length(ind) == 0 && length(curr_dim_values) == 1 && round(curr_dim_values, 3) == round(boundary[[dim_var]][1], 3) && round(curr_dim_values, 3) == round(boundary[[dim_var]][2], 3)) ind <- 1 if(length(ind) == 0) { - warning("No values within the range specified for", dim_var, "All values will be included.") - start <- c(start, 1) - count <- c(count, length(curr_dim_values)) + stop("No values within the range specified for ", dim_var, ".") } else { start <- c(start, min(ind)) @@ -300,56 +303,96 @@ nc_as_data_frame <- function(nc, vars, keep_raw_time = TRUE, include_metadata = } } if(length(start) == 0) { - start <- NA - count <- NA + start <- rep(1, length(dim_axes)) + count <- rep(-1, length(dim_axes)) } } } else { - start <- NA - count <- NA - } - var_data <- expand.grid(dim_values, KEEP.OUT.ATTRS = FALSE) - for(i in seq_along(var_data)) { - attr(var_data[[i]], "dim") <- NULL + start <- rep(1, length(dim_axes)) + count <- rep(-1, length(dim_axes)) } - names(var_data) <- dim_names - included_vars <- dim_names - for(var in vars) { - curr_dim_names <- ncdf4.helpers::nc.get.dim.names(nc, var) - if(!setequal(curr_dim_names, dim_names)) { - warning("The dimensions of", var, "do not match the other variables.", var, "will be dropped.") - } - else { - included_vars <- c(included_vars, var) - var_data[[var]] <- as.vector(ncdf4::ncvar_get(nc, var, start = start, count = count)) + start_list <- list() + count_list <- list() + dim_values_list <- list() + if(has_points) { + dim_axes <- ncdf4.helpers::nc.get.dim.axes(nc, vars[1]) + x_var <- names(dim_axes)[which(dim_axes == "X")] + y_var <- names(dim_axes)[which(dim_axes == "Y")] + if(length(x_var) == 0 || length(y_var) == 0) stop("Cannot select points because dimensions are not labelled correctly in the nc file. Modify the nc file or remove the points to import all data.") + xs <- dim_values[[x_var]] + ys <- dim_values[[y_var]] + for(i in seq_along(lon_points)) { + curr_start <- start + curr_count <- count + curr_dim_values <- dim_values + xy_possible <- expand.grid(xs, ys) + point_ind <- which.min(sp::spDistsN1(pts = as.matrix(xy_possible), pt = c(lon_points[i], lat_points[i]), longlat = TRUE)) + x_ind <- which(xs == xy_possible[point_ind, 1])[1] + curr_start[1] <- x_ind + curr_count[1] <- 1 + curr_dim_values[[x_var]] <- curr_dim_values[[x_var]][x_ind] + y_ind <- which(ys == xy_possible[point_ind, 2]) + curr_start[2] <- y_ind + curr_count[2] <- 1 + curr_dim_values[[y_var]] <- curr_dim_values[[y_var]][y_ind] + + start_list[[i]] <- curr_start + count_list[[i]] <- curr_count + dim_values_list[[i]] <- curr_dim_values } } - + else { + start_list[[1]] <- start + count_list[[1]] <- count + dim_values_list[[1]] <- dim_values + } + dim_axes <- ncdf4.helpers::nc.get.dim.axes(nc) time_dims <- names(dim_axes[which(dim_axes == "T" & names(dim_axes) %in% dim_names)]) - if(length(time_dims) == 1) { - time_var <- time_dims - raw_time_full <- nc$dim[[time_var]]$vals - raw_time <- dim_values[[time_var]] - attr(raw_time, "dim") <- NULL - df_names <- time_var - time_df <- data.frame(raw_time) - names(time_df) <- time_var - try({ - # need to subset this if time var has been subsetted - time_ind <- which(raw_time_full %in% raw_time) - pcict_time <- ncdf4.helpers::nc.get.time.series(nc, time.dim.name = time_var) - pcict_time <- pcict_time[time_ind] - posixct_time <- PCICt::as.POSIXct.PCICt(pcict_time) - time_df[[paste0(time_var, "_full")]] <- posixct_time - time_df[[paste0(time_var, "_date")]] <- as.Date(posixct_time) - }) - if(ncol(time_df) > 1) var_data <- dplyr::full_join(var_data, time_df, by = time_var) - if(!keep_raw_time) { - var_data[[time_var]] <- NULL - included_vars <- included_vars[-which(included_vars == time_var)] + var_data_list <- list() + for(i in seq_along(start_list)) { + curr_dim_values <- dim_values_list[[i]] + curr_var_data <- expand.grid(curr_dim_values, KEEP.OUT.ATTRS = FALSE) + for(j in seq_along(curr_var_data)) { + attr(curr_var_data[[j]], "dim") <- NULL } + names(curr_var_data) <- dim_names + included_vars <- dim_names + for(var in vars) { + curr_dim_names <- ncdf4.helpers::nc.get.dim.names(nc, var) + if(!setequal(curr_dim_names, dim_names)) { + warning("The dimensions of", var, "do not match the other variables.", var, "will be dropped.") + } + else { + included_vars <- c(included_vars, var) + curr_var_data[[var]] <- as.vector(ncdf4::ncvar_get(nc, var, start = start_list[[i]], count = count_list[[i]])) + } + } + if(length(time_dims) == 1) { + time_var <- time_dims + raw_time_full <- nc$dim[[time_var]]$vals + raw_time <- curr_dim_values[[time_var]] + attr(raw_time, "dim") <- NULL + df_names <- time_var + time_df <- data.frame(raw_time) + names(time_df) <- time_var + try({ + # need to subset this if time var has been subsetted + time_ind <- which(raw_time_full %in% raw_time) + pcict_time <- ncdf4.helpers::nc.get.time.series(nc, time.dim.name = time_var) + pcict_time <- pcict_time[time_ind] + posixct_time <- PCICt::as.POSIXct.PCICt(pcict_time) + time_df[[paste0(time_var, "_full")]] <- posixct_time + time_df[[paste0(time_var, "_date")]] <- as.Date(posixct_time) + }) + if(ncol(time_df) > 1) curr_var_data <- dplyr::full_join(curr_var_data, time_df, by = time_var) + if(!keep_raw_time) { + var_data[[time_var]] <- NULL + included_vars <- included_vars[-which(included_vars == time_var)] + } + } + var_data_list[[i]] <- curr_var_data } # # Following conventions in http://www.unidata.ucar.edu/software/netcdf/docs/attribute_conventions.html # if(replace_missing) { @@ -393,6 +436,11 @@ nc_as_data_frame <- function(nc, vars, keep_raw_time = TRUE, include_metadata = # if(missing_value[[1]]) var_data[[inc_var]][var_data[[inc_var]] %in% missing_value[[2]]] <- NA # } # } + if(length(var_data_list) > 1) { + var_data <- dplyr::bind_rows(var_data_list) + } + else if(length(var_data_list) == 1) var_data <- var_data_list[[1]] + else var_data_list <- data.frame() if(include_metadata) { for(col_name in included_vars) {