Corrected Conversion Algorithm for CalCOFI Station Grid And Their Implementation in Several Computer Languages by Edward Weber & Thomas Moorem, NOAA Fisheries, 2013 CalCOFI Report v 54.
Matlab scripts by Robert Thombley, SIO-CalCOFI with Sep2014 error correction by Augusto Valencia, UABC; based on Weber & Moor 2013.
For individual language - Java, Perl, Python, or R - implementations & downloads, see sections below
|Java Implementation (Java Download): objects of the Java class CalcofiCoordConverter hold coordinates as either “longlat” or “calcofi.” Coordinates may be retrieved using the “getCoords” method. The current coordinate system may be retrieved using the “getProjection” method. The “reproject” method accepts either “longlat” or “calcofi ” as an argument and converts to the appropriate coordinate system.|
To Convert Lat Lon to Line Sta
To Convert Line Sta to Lat Lon:
> java TestCalcofiCoordConverter 50 120 calcofi
|PERL Implementation (Perl Download): the Perl code is designed to read input data from a file (coords.in) and write the converted output coordinates (along with the original input coordinate data) to a file (coords.out). The section of the code that begins with “USER-MODIFIED SETTINGS” can be changed to use different filenames and identify the direction of the conversion (“cc2geo” for CalCOFI station grid coordinates to geographic coordinates and “geo2cc” for geographic coordinates to CalCOFI station grid coordinates).|
Contents for cc2geo_coords.in:
Contents for cc2geo_coords.out:
Contents for geo2cc_coords.in:
Contents for geo2cc_coords.out:
|Python Implementation (Python Download): the Python functions perform the conversions on single coordinate pairs as x and y arguments, or multiple points by entering tuples, lists, or arrays from the numeric python module numpy. The functions always return numpy arrays.|
> line, station = latlontostation(-121.15, 34.15)
> stationtolatlon(line, station)
array([-121.15000055, 34.15 ])
> lon, lat = stationtolatlon(50, 120)
array([ 49.99999878, 120.00000635])
Multiple points may be converted equivalently using tuples:
All three of these examples return:
R Implementation (R Download): the R functions listed in Appendix IV work similar.
> lineandstation <- latlon.to.station(c(-121.15,34.15))
[1,] 80 60.0000
line -121.15 34.1
> latlon <- station.to.latlon(c(50, 120))
[1,] -129.2795 37.3461
lon 50 120
The R functions will accept matrices of two columns
to perform conversions on multiple points at the same
time. For example,
> mat <- matrix(c(80, 50, 60, 120), 2, 2)
[1,] 80 60
[2,] 50 120
[1,] -121.1500 34.15000
[2,] -129.2795 37.34615
By default, R uses fewer significant digits than Python
or Java but this could be adjusted in the R options
MatLab Scripts (MatLab Download) by Robert Thombley; gridlib.m
function [lat, lon] = cc2lat(li,st)
INPUT: The calcofi line and station values
function [line, sta] = lat2cc(la,lo)
DESCRIPTION: Use this function to convert from degree decimal lat and long to calcofi grid coordinates. This uses the CalCOFI de-gridding algorithm (Eber and Hewitt 1979). This is the inverse of the function cc2lat. It is more complicated because this one requires some non-algebraic iteration.
INPUT: latitude and longitude values in decimal degrees to be converted
OUTPUT: This function outputs a line and station value
ASSUMPTIONS: All lat/long and station values are from the Northwestern hemisphere and within the middle latitudes.
REFERENCE: Based on Weber & Moore 2013; Eber and Hewitt 1979, Conversion Algorithms for the CalCOFI Station Grid
WRITTEN BY: Robert Thombley (2006), Scripps Institution of Oceanography, SIO-CalCOFI
MODIFIED BY: Augusto Valencia (2014), Universidad de Baja California-UABC (02Sep2014).