{"id":776,"date":"2014-02-19T21:39:19","date_gmt":"2014-02-19T21:39:19","guid":{"rendered":"https:\/\/info.calcofi.com\/2014\/02\/19\/2013-line-sta-algorithm\/"},"modified":"2014-02-19T21:39:19","modified_gmt":"2014-02-19T21:39:19","slug":"2013-line-sta-algorithm","status":"publish","type":"post","link":"https:\/\/mindwander.com\/index.php\/2014\/02\/19\/2013-line-sta-algorithm\/","title":{"rendered":"Line.Sta Algorithms"},"content":{"rendered":"<p>\n\t<strong><a href=\"https:\/\/info.calcofi.com\/wp-content\/uploads\/2014\/02\/Vol_54_Weber_97-106.pdf\" target=\"_blank\" rel=\"noopener\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\" alignright size-full wp-image-768\" alt=\"Click for larger Image\" src=\"https:\/\/i0.wp.com\/info.calcofi.com\/wp-content\/uploads\/2014\/02\/LineStaMap.JPG?resize=530%2C618&#038;ssl=1\" style=\"width: 250px; height: 292px; float: right;\" title=\"Click for larger Image\" width=\"530\" height=\"618\" \/>Corrected Conversion Algorithm for CalCOFI Station Grid And Their Implementation in Several Computer Languages<\/a><\/strong> by Edward Weber &amp; Thomas Moorem, NOAA Fisheries, 2013 CalCOFI Report v 54.<\/p>\n<p>\n\t<a href=\"https:\/\/info.calcofi.com\/wp-content\/uploads\/2014\/02\/CalCOFICoordCode.zip\"><strong>Link to downloadable code (Java, Perl, Python &amp; R) file presented in the CalCOFI Report vol 54, pages 102-106.<\/strong><\/a><\/p>\n<p>\n\t<a href=\"https:\/\/info.calcofi.com\/wp-content\/uploads\/2014\/02\/CalCOFILineStationMatLab.zip\"><strong><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\" size-full wp-image-291\" alt=\"\" src=\"https:\/\/i0.wp.com\/info.calcofi.com\/wp-content\/uploads\/2017\/02\/updated.gif?resize=36%2C9&#038;ssl=1\" style=\"width: 36px; height: 9px;\" width=\"36\" height=\"9\" \/> Matlab scripts<\/strong><\/a> <strong>by Robert Thombley, SIO-CalCOFI with Sep2014 error correction by Augusto Valencia, UABC<\/strong>; based on Weber &amp; Moor 2013.<\/p>\n<p>\n\t<a href=\"https:\/\/info.calcofi.com\/wp-content\/uploads\/2014\/02\/CalCOFILineStationMatLab.zip\"><strong>Link to MatLab downloadable code authored by Robert Thombley, SIO-CalCOFI<\/strong><\/a><\/p>\n<p>\n\t(Abstract from pdf) &#8220;Converting between geographic coordinates in latitude and longitude and the line and station sampling pattern of the California Cooperative Fisheries Investigations (CalCOFI) program is a commonly required task for conducting research on the California Current ecosystem. This note presents several corrections and clarifications to the previously published algorithms for performing these conversions. We include computer code to implement the algorithms in Java\u21221, Perl, Python, and R. We note that freely available code to conduct the conversions in Fortran, Matlab\u00ae2, JavaScript\u2122, and Visual Basic\u00ae6 has previously been published, and an online conversion tool is also available. A future version of the PROJ.4 cartographic projections library will also include support for CalCOFI conversions, thereby allowing for convenient conversions using the GRASS GIS, PostGIS, Python, Perl, R, and many other programs and programming languages.&#8221;<\/p>\n<p>\n\t<strong>For individual language &#8211; Java, Perl, Python, or R &#8211; implementations &amp; downloads, see sections below<\/strong><\/p>\n<p><!--more--><\/p>\n<p>\n\t&nbsp;<\/p>\n<table align=\"left\" border=\"1\" cellpadding=\"1\" cellspacing=\"1\" style=\"width: 95%;\">\n<tbody>\n<tr>\n<td colspan=\"2\" style=\"vertical-align: top;\">\n\t\t\t\t<strong>Java Implementation<\/strong> (<strong><a href=\"https:\/\/info.calcofi.com\/wp-content\/uploads\/2014\/02\/CalCOFICoordCodeJava.zip\">Java Download<\/a><\/strong>): objects of the Java class CalcofiCoordConverter hold coordinates as either \u201clonglat\u201d or \u201ccalcofi.\u201d Coordinates may be retrieved using the \u201cgetCoords\u201d method. The current coordinate system may be retrieved using the \u201cgetProjection\u201d method. The \u201creproject\u201d method accepts either \u201clonglat\u201d or \u201ccalcofi \u201d as an argument and converts to the appropriate coordinate system.<\/td>\n<\/tr>\n<tr>\n<td style=\"vertical-align: top; width: 329px;\">\n<p>\n\t\t\t\t\tTo Convert Lat Lon to Line Sta<br \/>\n\t\t\t\t\t&gt;<span style=\"color: rgb(165, 42, 42);\">java TestCalcofiCoordConverter -121.15 <\/span><span style=\"color: rgb(165, 42, 42);\">34.15 longlat<\/span><br \/>\n\t\t\t\t\treturns:<br \/>\n\t\t\t\t\tOriginal coordinates<br \/>\n\t\t\t\t\tx -121.15<br \/>\n\t\t\t\t\ty 34.15<br \/>\n\t\t\t\t\tprojection longlat<br \/>\n\t\t\t\t\tNew coordinates<br \/>\n\t\t\t\t\tx 79.99999886102664<br \/>\n\t\t\t\t\ty 60.0000059182792<br \/>\n\t\t\t\t\tprojection calcofi<br \/>\n\t\t\t\t\tBacktransformed coordinates<br \/>\n\t\t\t\t\tx -121.15000054796204<br \/>\n\t\t\t\t\ty 34.15<br \/>\n\t\t\t\t\tprojection longlat<\/p>\n<\/td>\n<td style=\"vertical-align: top; width: 307px;\">\n\t\t\t\tTo Convert Line Sta to Lat Lon:<br \/>\n\t\t\t\t&gt;<span style=\"color: rgb(165, 42, 42);\"> java TestCalcofiCoordConverter 50 120 calcofi<\/span><br \/>\n\t\t\t\tOriginal coordinates<br \/>\n\t\t\t\tx 50.0<br \/>\n\t\t\t\ty 120.0<br \/>\n\t\t\t\tprojection calcofi<br \/>\n\t\t\t\tNew coordinates<br \/>\n\t\t\t\tx -129.2795443042271<br \/>\n\t\t\t\ty 37.34615242270663<br \/>\n\t\t\t\tprojection longlat<br \/>\n\t\t\t\tBacktransformed coordinates<br \/>\n\t\t\t\tx 49.999998777973516<br \/>\n\t\t\t\ty 120.00000634983587<br \/>\n\t\t\t\tprojection calcofi<\/td>\n<\/tr>\n<tr>\n<td colspan=\"2\">\n\t\t\t\t&nbsp;<\/td>\n<\/tr>\n<tr>\n<td colspan=\"2\">\n\t\t\t\t<strong>PERL Implementation (<a href=\"https:\/\/info.calcofi.com\/wp-content\/uploads\/2014\/02\/CalCOFICoordCodePerl.zip\">Perl Download<\/a>)<\/strong>: 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 \u201cUSER-MODIFIED SETTINGS\u201d can be changed to use different filenames and identify the direction of the conversion (\u201ccc2geo\u201d for CalCOFI station grid coordinates to geographic coordinates and \u201cgeo2cc\u201d for geographic coordinates to CalCOFI station grid coordinates).<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 329px; vertical-align: top;\">\n<p>\n\t\t\t\t\tContents for <strong>cc2geo_coords.in<\/strong>:<br \/>\n\t\t\t\t\tLINE,STATION<br \/>\n\t\t\t\t\t80.0,60.0<br \/>\n\t\t\t\t\t50.0,120.0<\/p>\n<p>\n\t\t\t\t\tContents for <strong>cc2geo_coords.out<\/strong>:<br \/>\n\t\t\t\t\tLINE,STATION,LAT_DD,LON_DD<br \/>\n\t\t\t\t\t80.0,60.0,34.1500,-121.1500<br \/>\n\t\t\t\t\t50.0,120.0,37.3462,-129.2795<\/p>\n<\/td>\n<td style=\"width: 307px; vertical-align: top;\">\n\t\t\t\tContents for <strong>geo2cc_coords.in:<\/strong><br \/>\n\t\t\t\tLATD,LATM,LATS,LATH,LOND,LONM,LONS,LONH<br \/>\n\t\t\t\t34,9,0,N,121,9,0,W<br \/>\n\t\t\t\t34.15,0,0,N,121.15,0,0,W<br \/>\n\t\t\t\t37,20.7692,0,N,129,16.7727,0,W<\/p>\n<p>\t\t\t\tContents for <strong>geo2cc_coords.out:<\/strong><br \/>\n\t\t\t\tLATD,LATM,LATS,LATH,LOND,LONM,LONS,LONH,LAT_DD,<br \/>\n\t\t\t\tLON_DD,LINE,STATION<br \/>\n\t\t\t\t34,9,0,N,121,9,0,W,34.15,-121.15,80.0000,60.0000<br \/>\n\t\t\t\t34.15,0,0,N,121.15,0,0,W,34.15,-121.15,80.0000,60.0000<br \/>\n\t\t\t\t37,20.7692,0,N,129,16.7727,0,W,37.3461533333333,<br \/>\n\t\t\t\t-129.279545,50.0000,120.0000<\/td>\n<\/tr>\n<tr>\n<td colspan=\"2\" style=\"width: 329px;\">\n\t\t\t\t&nbsp;<\/td>\n<\/tr>\n<tr>\n<td colspan=\"2\" style=\"width: 329px;\">\n\t\t\t\t<strong>Python Implementation (<a href=\"https:\/\/info.calcofi.com\/wp-content\/uploads\/2014\/02\/CalCOFICoordCodePython.zip\">Python Download<\/a>)<\/strong>: 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.<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 329px; vertical-align: top;\">\n\t\t\t\t&gt; line, station = latlontostation(-121.15, 34.15)<br \/>\n\t\t\t\t&gt; line<br \/>\n\t\t\t\t79.999998861026384<br \/>\n\t\t\t\t&gt; station<br \/>\n\t\t\t\t60.000005918280479<br \/>\n\t\t\t\t&gt; stationtolatlon(line, station)<br \/>\n\t\t\t\tarray([-121.15000055, 34.15 ])<\/p>\n<p>\t\t\t\t&gt; lon, lat = stationtolatlon(50, 120)<br \/>\n\t\t\t\t&gt; lon<br \/>\n\t\t\t\t-129.27954430422696<br \/>\n\t\t\t\t&gt; lat<br \/>\n\t\t\t\t37.346152422706631<br \/>\n\t\t\t\t&gt;latlontostation(lon, lat)<br \/>\n\t\t\t\tarray([ 49.99999878, 120.00000635])<\/td>\n<td style=\"width: 307px; vertical-align: top;\">\n<p>\n\t\t\t\t\tMultiple points may be converted equivalently using tuples:<br \/>\n\t\t\t\t\t&gt; stationtolatlon((80, 50), (60, 120))<br \/>\n\t\t\t\t\tlists:<br \/>\n\t\t\t\t\t&gt; stationtolatlon([80, 50], [60, 120])<br \/>\n\t\t\t\t\tor numpy arrays:<br \/>\n\t\t\t\t\t&gt; arr = numpy.array((80, 60, 50, 120))<br \/>\n\t\t\t\t\t&gt; arr.shape = (2, 2)<br \/>\n\t\t\t\t\t&gt; arr<br \/>\n\t\t\t\t\tarray([[ 80, 60],<br \/>\n\t\t\t\t\t[ 50, 120]])<br \/>\n\t\t\t\t\t&gt; stationtolatlon(arr)<\/p>\n<p>\n\t\t\t\t\tAll three of these examples return:<br \/>\n\t\t\t\t\tarray([[-121.15 , 34.15 ],<br \/>\n\t\t\t\t\t[-129.2795443 , 37.34615242]])<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td colspan=\"2\" style=\"width: 329px; vertical-align: top;\">\n\t\t\t\t&nbsp;<\/td>\n<\/tr>\n<tr>\n<td colspan=\"2\" style=\"width: 329px; vertical-align: top;\">\n<p>\n\t\t\t\t\t<strong>R Implementation (<a href=\"https:\/\/info.calcofi.com\/wp-content\/uploads\/2014\/02\/CalCOFICoordCodeR.zip\">R Download<\/a>): <\/strong>the R functions listed in Appendix IV work similar.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 329px; vertical-align: top;\">\n\t\t\t\t&gt; lineandstation &lt;- latlon.to.station(c(-121.15,34.15))<br \/>\n\t\t\t\t&gt; lineandstation<br \/>\n\t\t\t\tline station<br \/>\n\t\t\t\t[1,] 80 60.0000<\/p>\n<p>\t\t\t\t&gt; station.to.latlon(lineandstation)<br \/>\n\t\t\t\tlon lat<br \/>\n\t\t\t\tline -121.15 34.1<\/td>\n<td style=\"width: 307px; vertical-align: top;\">\n\t\t\t\t&gt; latlon &lt;- station.to.latlon(c(50, 120))<br \/>\n\t\t\t\t&gt; latlon<br \/>\n\t\t\t\tlon lat<br \/>\n\t\t\t\t[1,] -129.2795 37.3461<\/p>\n<p>\t\t\t\t&gt; latlon.to.station(latlon)<br \/>\n\t\t\t\tline station<br \/>\n\t\t\t\tlon 50 120<\/td>\n<\/tr>\n<tr>\n<td colspan=\"2\" style=\"width: 329px; vertical-align: top;\">\n\t\t\t\tThe R functions will accept matrices of two columns<br \/>\n\t\t\t\tto perform conversions on multiple points at the same<br \/>\n\t\t\t\ttime. For example,<br \/>\n\t\t\t\t&gt; mat &lt;- matrix(c(80, 50, 60, 120), 2, 2)<br \/>\n\t\t\t\t&gt; mat<br \/>\n\t\t\t\t[,1] [,2]<br \/>\n\t\t\t\t[1,] 80 60<br \/>\n\t\t\t\t[2,] 50 120<br \/>\n\t\t\t\t&gt; station.to.latlon(mat)<br \/>\n\t\t\t\tlon lat<br \/>\n\t\t\t\t[1,] -121.1500 34.15000<br \/>\n\t\t\t\t[2,] -129.2795 37.34615<br \/>\n\t\t\t\tBy default, R uses fewer significant digits than Python<br \/>\n\t\t\t\tor Java but this could be adjusted in the R options<\/td>\n<\/tr>\n<tr>\n<td colspan=\"2\" style=\"width: 329px; vertical-align: top;\">\n\t\t\t\t&nbsp;<\/td>\n<\/tr>\n<tr>\n<td colspan=\"2\" style=\"width: 329px; vertical-align: top;\">\n<p>\n\t\t\t\t\t<strong>MatLab Scripts<\/strong> (<a href=\"https:\/\/info.calcofi.com\/wp-content\/uploads\/2014\/02\/CalCOFILineStationMatLab.zip\">MatLab Download<\/a>) by Robert Thombley; gridlib.m<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 329px; vertical-align: top;\">\n<p>\n\t\t\t\t\t<span style=\"color: rgb(128, 0, 0);\">function [lat, lon] = cc2lat(li,st)<\/span><br \/>\n\t\t\t\t\tDESCRIPTION: Use this function to convert from calcofi grid coordinates to latitude and longitude. This uses a slightly modified (because the original is wrong) version of the CalCOFI gridding algorithm (Eber and Hewitt 1979) (Also see errata 2006).<\/p>\n<p>\n\t\t\t\t\tINPUT: The calcofi line and station values<br \/>\n\t\t\t\t\tOUTPUT: This function outputs a degree decimal latitude and longitude<br \/>\n\t\t\t\t\tASSUMPTIONS: All lat\/long and station values are from the Northwestern hemisphere and within the middle latitudes.<br \/>\n\t\t\t\t\tREFERENCE: Based on Weber &amp; Moore 2013; Eber and Hewitt 1979, Conversion Algorithms for the CalCOFI Station Grid<br \/>\n\t\t\t\t\tWRITTEN BY: Robert Thombley (2006), Scripps Institution of Oceanography, SIO-CalCOFI<br \/>\n\t\t\t\t\tMODIFIED BY: Augusto Valencia (2014), Universidad de Baja California-UABC (02Sep2014).<\/p>\n<\/td>\n<td style=\"width: 329px; vertical-align: top;\">\n\t\t\t\t<span style=\"color: rgb(128, 0, 0);\">function [line, sta] = lat2cc(la,lo)<\/span><br \/>\n\t\t\t\tDESCRIPTION: 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).&nbsp; This is the inverse of the function cc2lat.&nbsp; It is more complicated because this one requires some non-algebraic iteration.<br \/>\n\t\t\t\tINPUT: latitude and longitude values in decimal degrees to be converted<br \/>\n\t\t\t\tOUTPUT: This function outputs a line and station value<br \/>\n\t\t\t\tASSUMPTIONS: All lat\/long and station values are from the Northwestern hemisphere and within the middle latitudes.<br \/>\n\t\t\t\tREFERENCE: Based on Weber &amp; Moore 2013; Eber and Hewitt 1979, Conversion Algorithms for the CalCOFI Station Grid<br \/>\n\t\t\t\tWRITTEN BY: Robert Thombley (2006), Scripps Institution of Oceanography, SIO-CalCOFI<br \/>\n\t\t\t\tMODIFIED BY: Augusto Valencia (2014), Universidad de Baja California-UABC (02Sep2014).<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\n\t&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Corrected Conversion Algorithm for CalCOFI Station Grid And Their Implementation in Several Computer Languages by Edward Weber &amp; Thomas Moorem, NOAA Fisheries, 2013 CalCOFI Report v 54. Link to downloadable code (Java, Perl, Python &amp; R) file presented in the CalCOFI Report vol 54, pages 102-106. Matlab scripts by Robert Thombley, SIO-CalCOFI with Sep2014 error [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":768,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[19],"tags":[],"class_list":["post-776","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-methods"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/mindwander.com\/index.php\/wp-json\/wp\/v2\/posts\/776","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mindwander.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mindwander.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mindwander.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mindwander.com\/index.php\/wp-json\/wp\/v2\/comments?post=776"}],"version-history":[{"count":0,"href":"https:\/\/mindwander.com\/index.php\/wp-json\/wp\/v2\/posts\/776\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/mindwander.com\/index.php\/wp-json\/"}],"wp:attachment":[{"href":"https:\/\/mindwander.com\/index.php\/wp-json\/wp\/v2\/media?parent=776"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mindwander.com\/index.php\/wp-json\/wp\/v2\/categories?post=776"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mindwander.com\/index.php\/wp-json\/wp\/v2\/tags?post=776"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}