3. Excel
Before you open Excel, there is one procedure to perform first. Go back to the Panoply window, select the SST data row, and right-click it. Select “Export CSV”. You may rename the file (it’s a good idea to have the dates in the filename to make it easier to track what you are doing). Do this for both SST data rows, for January-March 2014 and January-March 2015. Then, for either year, export both the lat data as CSV and the lon data as CSV, the same way as for the SST data.
In the directory you stored the CSV data in, the files should appear as Excel files (with Excel installed on your system). There should be four files; SST for January-March 2014 and for January-March 2015, a lat data file, and a lon data file.
If you click on the icon that looks like this (below), the file should automatically open in Excel. Rename the files. In this case, we renamed them “2014_SST” and “2015_SST”. After renaming, open the data file with the data from January-March 2015. Save this file as an Excel workbook (.xlsx or .xlsm extension, but this workbook does not need to have macros enabled).
Now open the file with the January-March 2014 data. The single sheet with the data should have the same name as the data file. Right-click on this, and then click on “Move or Copy…”. At the top, you should be able to find the Excel workbook you just created with the 2015 data. Select this file and then click “OK”. The data will be copied to the new workbook. Save the workbook.
The next step is to calculate the differences, which is a simple procedure. In the workbook, create a new sheet and name it “Difference”. In the first cell of that sheet (A1), type the formula below. The sheet names will be whatever you named the two sheets with the SST data.
='2015_SST'!A1-'2014_SST'!A1
Once you have typed this formula into the cell, copy it. Make sure you copy the formula, not the numerical value in the A1 cell. Click in another cell, and a numerical value should appear in cell A1.
Now go to one of the two data arrays, and determine the size of the array. To do this, slide the vertical slider to the bottom, and the horizontal slider all the way to the right. Note the final column header (a letter or set of two or three letters) and the final row number. In this example, the final column header is JV, and the final row number is 173.
Go back to the Difference sheet. Select the same array size as the SST data sheets. (With the cursor in the A1 cell – you should see a “fat” white cross -- left-click and slide to the right until you reach the final column header, then slide down to the final row number. If you have a very large array, this will take a short time to do.) Copy the formula from the Menu bar.
With the entire array selected, click Ctrl-Enter. This will put the formula into all the cells, and the difference values will be calculated.
The final procedure is to construct a macro-enabled worksheet that will allow the conversion of the difference values data array into a list of lat-lon-difference value triads.
The next step is to calculate the differences, which is a simple procedure. In the workbook, create a new sheet and name it “Difference”. In the first cell of that sheet (A1), type this formula. The sheet names (shown in bold type below) will be whatever you named the two sheets with the SST data.
='2015_SST'!A1-'2014_SST'!A1
Once you have typed this formula into the cell, copy it. Make sure you copy the formula, not the numerical value in the A1 cell. Click in another cell, and a numerical value should appear in cell A1.
Now go to one of the two data arrays, and determine the size of the array. To do this, slide the vertical slider to the bottom, and the horizontal slider all the way to the right. Note the final column header (a letter or set of two or three letters) and the final row number. In this example, the final column header is JV, and the final row number is 173.
Go back to the Difference sheet. Select the same array size as the SST data sheets. (With the cursor in the A1 cell – you should see a “fat” white cross – left-click and slide to the right until you reach the final column header, then slide down to the final row number. If you have a very large array, this will take a short time to do.) Copy the formula from the Menu bar.
With the entire array selected, click Ctrl-Enter. This will put the formula into all the cells, and the difference values will be calculated.
The final procedure is to construct a macro-enabled worksheet that will allow the conversion of the difference values data array into a list of lat-lon-difference value triads.
4. Excel Macro
Open a blank Excel workbook. Copy the Difference values array into the new workbook. Save the workbook as a Macro-enabled Excel workbook.
The first thing to do with the new array is to convert the undefined values to a letter sequence. In the original SST data arrays, if a pixel had no data, the cell would have NaN in it. When the difference calculation is made, any cells with NaN will have an undefined result, which in the Difference array will appear as “#VALUE!”, indicating the failure of the formula. To fix this, under the Home tab, go to “Find and Select”, click “Go to Special”, and then click Formulas. Under Formulas, uncheck all the boxes except Errors. Then click “OK”. All of the undefined cells will be found. The formula for the first cell with the error will appear at the top. Delete the formula, type “NaN”, then click Ctrl-Enter. All of the cells with undefined values should now have NaN instead. Name the array (“SSTDiff” was chosen here), and save the workbook.
Now add two rows at top and one column at left to this array. In the A1 cell, type a name for the array (“SSTDiff” was used again). In the A2 cell, type “lat”. In the B1 cell, type “lon”. It is necessary to count the number of columns (lon data) now. In the B2 cell, type “1”. In the C2 cell, type “2”. Then select both cells, click and hold on the “Fill Handle” (the little green box at the bottom right of the two cells), and drag the fill handle to the last column of values. When you release it, the cells will be filled with consecutive values. Note the number in the last column. In this case, it’s under JW, because a column was added, and the number is 282.
Now add three more spreadsheets to the workbook. Name them lat, lon, and Results. You must have spreadsheets named lat, lon, and Results!
Open the latitude values CSV file, and copy the values. Go to the lat spreadsheet, click in the A1 cell, click the Paste icon, and select the Transpose option (at right in the second row). This will convert the data from a row to a column. Add a row, and type “lat” in the A1 cell. Follow the same procedure for the longitude data, except type “lon” in the A1 cell for that spreadsheet.
The next step is to install the macro.
The text of the macro “ReOrganizeSub” is given below. The important text (that will need to be edited) is in bold font. The instructions for installation follow. (You may wish to copy this into a text file before copying it into the Excel workbook.)
Note 1: The worksheets that contain the data must match the names of the worksheets in the code below, otherwise the code cannot find the data! That’s why the spreadsheets must be named lat, lon, and Results.
Note 2: The size of the MatrixAry array in the code must, at a minimum, be the size of the input lists and that of the For/Next loop.
Sub ReorganizeSub()
Dim MatrixAry(1 To 200, 1 To 300, 1 To 3) As String
Dim i As Integer
Dim j As Integer
Dim RowIvb As Long
Const LatNdx As Integer = 1
Const LongNdx As Integer = 2
Const ValueNdx As Integer = 3
For j = 1 To 282
For i = 1 To 173
MatrixAry(i, j, LatNdx) = Worksheets("lat").Range("A" & i + 1).Value
MatrixAry(i, j, LongNdx) = Worksheets("lon").Range("A" & j + 1).Value
MatrixAry(i, j, ValueNdx) = Worksheets("SSTDiff").Range(NumToLtr(j + 1) & i + 2).Value
Next i
Next j
For j = 1 To 282
For i = 1 To 173
RowIvb = RowIvb + 1
Worksheets("Results").Range("A" & RowIvb).Value = MatrixAry(i, j, LatNdx)
Worksheets("Results").Range("B" & RowIvb).Value = MatrixAry(i, j, LongNdx)
Worksheets("Results").Range("C" & RowIvb).Value = MatrixAry(i, j, ValueNdx)
Next i
Next j
End Sub
Function NumToLtr(ColNumIvb) As String
If ColNumIvb <= 26 Then 'if a single letter
NumToLtr = Chr(ColNumIvb + 64)
ElseIf ColNumIvb <= 702 Then 'if a two letters
NumToLtr = Chr(Int((ColNumIvb - 1) / 26) + 64) & Chr(((ColNumIvb - 1) Mod 26) + 65)
ElseIf ColNumIvb <= 18278 Then 'if a three letters
NumToLtr = Chr((Int((ColNumIvb - 703) / 676) Mod 26) + 65) & Chr((Int((ColNumIvb - 27) / 26) Mod 26) + 65) & Chr(Int((ColNumIvb - 1) Mod 26) + 65)
End If
End Function
Macro Installation Instructions
Go to File Options
Activate the Developer tab under “Customize Ribbon” and close Options
Go to Developer tab
Go to the Visual Basic icon (at left)
Go to Insert, drop down to Module, click on Module.
At this point, there will be an empty space. Copy the text of ReorganizeSub into this space.
The macro will retain the name ReorganizeSub, but once it has been imported, the module can be named to save the workbook for future use with the module installed.
- To adapt the macro to the data array, the final values will be entered for the array size, and the data set name will be entered from the data value sheet. In this case, the number of latitude values, i, is 173 (two less than the total number of rows in the SSTDiff array), so in both occurrences of “For i = 1 To final”, change final to 173. The number of longitude values is 282, so in both occurrences of “For j = 1 to final”, change final to 282. (These values are for the example; for other array sizes, they will be changed as appropriate for the number of lat and lon values in the array).
Then change data set name to “SSTDiff”.
Now the macro is ready. There are two different ways to run the macro. (1) In the Developer pane, click on Run, then click Run Sub/User Form. (2) If the spreadsheet has been saved with the macro, then under the Developer tab, click Macros (at left), which will open the macro (and the name
ReOrganizeSub will be highlighted), then click "Run Macro". The lat-lon-difference value triads should be written to the Results spreadsheet. Below is what they look like. “NaN” was a pixel with no data.
Additional Info
There are a lot of steps in these procedures, but note that making the difference maps with Panoply is quite fast. The difference mapping can be done until the best results are obtained, and then the quantification with Excel can be performed. Quantifying with Excel is only necessary if the actual values are needed.
There is a limit of how many rows can be written in an Excel file. The maximum number is 1,048,576 rows. That may seem like a lot, but with higher-resolution data (like 4 km ocean color data), it can easily be exceeded. If attempting to get values for a very large area, the region may have to be subset and these subsets analyzed with separate spreadsheets.
Make sure there are no blank cells in the Results array. If there are, either the lat value or lon value for the number of values is incorrect.