{"id":15627210,"url":"https://github.com/eggsyntax/crnscript","last_synced_at":"2025-03-29T17:41:48.722Z","repository":{"id":5378472,"uuid":"6565894","full_name":"eggsyntax/crnscript","owner":"eggsyntax","description":"Domain-specific language for CRN climate data (note: requires data access which is not publicly available)","archived":false,"fork":false,"pushed_at":"2012-11-06T17:16:54.000Z","size":35688,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-24T05:46:42.581Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/eggsyntax.png","metadata":{"files":{"readme":"README.txt","changelog":"Changelog","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-11-06T17:11:18.000Z","updated_at":"2013-04-30T16:58:21.000Z","dependencies_parsed_at":"2022-09-14T19:11:53.737Z","dependency_job_id":null,"html_url":"https://github.com/eggsyntax/crnscript","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eggsyntax%2Fcrnscript","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eggsyntax%2Fcrnscript/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eggsyntax%2Fcrnscript/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eggsyntax%2Fcrnscript/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eggsyntax","download_url":"https://codeload.github.com/eggsyntax/crnscript/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246223271,"owners_count":20743158,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-03T10:15:41.110Z","updated_at":"2025-03-29T17:41:48.698Z","avatar_url":"https://github.com/eggsyntax.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"****Working with crnscript:****\n\nThe crnscript project provides a turnkey environment for running python scripts or using an interactive\npython console with use of the CRN data access capabilities, domain objects, and utilities available from the \ncrnshared project. \n\n***Working with crnscript on a unix server:***\n\n- Log into one of the unix boxes (front is an excellent choice). If you don't already have access\nto a unix server, you'll want to put in a request at http://www3.ncdc.noaa.gov/itas/ . Check out \nthe project from source control ('svn co https://conman/svn-repos/CRN/crnscript/tags/crnscript-1.14 crnscript') \nand change into the newly created crnscript directory ('cd crnscript').  \n\n- Start X-Win on your desktop (if it's not already running). You may want to put it in your \nstartup directory. If you can't find it in your start menu, you may need to put in a helpdesk \nrequest (https://servicedesk) to have it installed.\n\n- Run the interactive python console: './crnscript'. Personally, I recommend leaving a crnscript\nwindow running at all times -- it makes it easy to reach for crnscript for quick questions.\n\n- You immediately have access to CRN resources. Let's try a few commands:\n\n\tstation = findStation(\"Barrow\")\n\tprint(station)\n\t\t\nfindStation will search a station based on the station string (the station string is what you see\nwhen you print the station, in this case \"Station[1007] AK Barrow 4 ENE (00F0B0,27516)Comm:E, OpStat: Y\"). \nYou can use the station id or the state/city/vector, for example. findStations, plural, will return a list of \nstations matching the input. So findStations(\"AZ\") would return a list of all Arizona stations.\n\n\tprint(station.latitude,station.longitude)\n\nImportantly, the returned station is not just an info string but a domain object with its own properties and methods\nsuch as latitude and longitude (try dir(station) to get a full list).\n\n\tstart = findDate(\"10/31/09 8:00\")\n\tend = findDate(\"10/31/09 10:00\")\n\nfindDate will accept a date string in most formats, a datetime id, \"now\", or variants like \"last Tuesday.\"\n\n\telements = findElements(\"precip\")\n\t\nfindElements() functions much like findStations(). findElements(), by default, first checks a number of predefined\nkeywords like \"temp\" and \"precip\" (you can see them all with showElements()). If a parameter is not one of these \nkeywords, findElements() searches the name, description, and element id of the elements (you can get a list of all\nelements, by the way, just by doing getAllElements(), and similarly you can get a list of stations with \ngetAllStations()). findElements() and findStations() both use smartcase -- if the search term is all lowercase, it \ndoes a case-insensitive search; otherwise it's case-sensitive. The element names are in all caps, so using an argument \nin all caps is an easy way of restricting the search to name. Also, if findElements() receives an integer input, \nit treats it as an element id. If you're familiar with regular expression syntax, findElements() and findStations() \naccept full regex (see http://docs.python.org/dev/howto/regex.html for details on regex in python).\n\n\tdata = getData(station,(start,end),element)\n\nHere we put together the parameters we've just obtained and use the getData() method to find the values and flags for \ncalculated precip for a few hours at the Barrow station. Any time you want to get values/flags\nfor some combination of stations, elements, and dates, it should be as simple as that. getData() is limited to\nretrieving 120,000 facts by default in order to avoid heavy impact on the database; if you need more, loop through\nseveral requests or speak with a crnscript developer about overriding this limit.\n\nActually, we can bypass the findStation, findDate, and findElement process if we'd rather, and just pass the \nequivalent parameters directly to getData(). So for example, we could simply say \n\n\tdata = getData(\"Barrow\",(\"2010110100\",\"now\"),\"temp\")\n\t\nand we would get equivalent results. Note that these parameters, and the findStations() and findElements() methods, are\nextremely forgiving about what they accept: you can hand them any sort of station/element ids, strings, domain objects,\nor mixed collections of any of the above.\n\n\tprintlist(data)\n\t\nprintlist() handles any of the return types from crnscript methods and prints them as a reasonably-formatted list. You\ncan format them differently using csv() or fixed(). csv() produces comma-separated output, suitable for copying and \npasting into Excel or other applications. fixed() prints the results in fixed-column format suitable for fortran. \nIn addition to printlist(), there are printfile(), graph(), histogram(), and scatter() functions. graph() produces \na basic time-series graph, histogram() produces a histogram, and scatter() produces a scatterplot with optional\nlinear regression. printfile(\"filename.txt\",data) prints to a file. \n\n\tshowFunctions() \n\t\nCall showFunctions() to get a list of all the functions you've seen so far, as well as other useful functions, along with\nbrief explanatory texts. You can also use help() for any of the crnscript functions (eg 'help(printlist)') \nto get information on it.\n\nReading the src/Examples.py file should give you all the info you need to handle common use cases. You may \nalso want to take a look at the rest of the example scripts in the src directory. See also QuickReference.png,\nwhich you may want to print out or otherwise keep handy.\n\n- Use Ctrl-D to exit the console\n\n- To run a python script instead of using the interactive console, just call, for example, \n'./crnscript src/HelloWorld.py'. You'll want to start your scripts with 'from crn import *' to \nprovide access to crnscript's capabilities. You can edit scripts by doing, for example,\n'gedit src/HelloWorld.py' (nice graphical editor that does syntax highlighting and runs over xwin) or\n'nano src/HelloWorld.py' (non-graphical editor). If you happen to be a member of the vi cult, see\nhttp://www.reddit.com/r/programming/comments/e9uvc/ultimate_vim_python_setup/ . You may wish to keep\nyour personal source files outside the crnscript directory to prevent them from being overwritten when\nyou update crnscript.\n\nMore information about the Python programming language can be found at http://www.python.org/. If you need further\nguidance, type \"import this\" in the interactive console.\n\n- Pro tip 1: one thing that's important to understand about crnscript is that some of its functions, notably\nmost of the dao methods, return a *Map*, aka a list whose members are key/value pairs. When working with a map, \nyou need to think about whether you want to work with the keys or the values (or both). Consider the following example:\n\n\t stations = stationDao.getStationsCurrentlyWithSmSt()\n\t \nstations now contains a map from integer (station id) to Station objects. To\nget a list of just the keys, use stations.keySet(). To get a list of just the Stations, use \nstations.values(). Python's default is to work with the keys, so if you were to say: for s in stations: print s, you\nwould get a list of integers. If for some reason you wanted to work with both simultaneously, you would use \nstations.entrySet().\n\nIt's a bit complicated, to be sure, but if you're ever unsure what you're working with, just do type(myVariable) to\nfind out. When in doubt, you'll probably want to work with values().\n\t \n- Pro tip 2: Rounding is something we try to be very careful with in CRN (see \nhttps://local.ncdc.noaa.gov/wiki/index.php/CRN:Rounding). crnscript is already set up to round properly (half-up), but\nthere are issues with binary floating point representation of precise decimal numbers. Python has a class which \navoids these issues (Decimal), and in general, if you need to be careful about precision and rounding, just cast\nyour numbers to Decimal (the value field of a Fact is already a Decimal) and use the quantize() method to round. \nHowever, there are a few pain points; in particular, if you use the comparison operators(\u003e,\u003c,=) to compare Decimals \nto non-Decimal numbers, you'll get some unexpected results. See \nhttp://docs.python.org/release/2.5.2/lib/decimal-faq.html and http://docs.python.org/library/decimal.html for details. \n\nIn general, just be cautious: if you're going to work with Decimals, work with *all* Decimals. If you're considering \nusing python for production situations where rounding is a factor, please unit test thoroughly. On the other hand, you can \nuse ordinary arithmetic operators with Decimal (+,-,*, etc), which makes it rather less painful than using java's BigDecimal.\nOn a related note, many values are returned from the database as strings, which give unexpected results when compared\nto numbers. If you're getting an odd result from a comparison, try casting the returned value to Decimal and see if\nthat fixes the problem.\n\n\n***Accessing underlying Data Access objects***\n\n- The commands you've seen so far are a layer of specialized crnscript methods. They overlay a shared layer of \ndata access objects and domain objects. The data access objects serve as a centralized way of asking questions of the \nCRN database, and they return domain objects which themselves have rich functionality. When you need information that \ncan't be obtained through the specialized methods shown above, you may want to begin using the daos directly \n(although it's valuable to try showFunctions() first, and check the examples shown in Examples.py -- there are \nrather more methods than have been shown so far!).\n\n\tshowDaos()\n\nThis is a method built into crnscript, and shows us the data access objects underlying crnscript. We observe that one \nof them is stationDao.\n\n\tdir(stationDao)\n\nThis uses Python's built-in dir() method to show what methods the stationDao object offers. More detail about each method \ncan be found in the javadocs (in crnscript/doc/crnshared/index.html). We observe that stationDao has a getStation method.\n\n\tstation = stationDao.getStation(1124)\n\nThis retrieves a station from the database using its station ID.\n\n\tprint(station)\n\nThis calls the station's print method, showing you the station's state, location, and vector and some other pertinent \ninfo.\n\n\tdir(station)\n\nAs you can see, the dir() method is extremely powerful and useful, and can be called on any object to show its available \nvariables and methods.\n\n\tstation.getLongName()\n\nThis calls one of the methods just shown in order to get the extended name of the station. Note that in the interactive \nconsole, the result of a method call is automatically printed, whereas in a script you'd need 'print station.getLongName()'.\n\n- You can call the showDaos(), showDomainObjects(), or showUtils() methods to get an idea of what you have at \nyour disposal.\n\n\n***Working with crnscript in Eclipse***\n\nThe rest of this document will probably only be of use to developers. Non-developers may wish to leave now and read\nExamples.py, which provides many more examples of using crnscript methods.\n\nWorking with crnscript on a *nix box is simplest and provides an interactive \nconsole, but working with crnscript in the Eclipse IDE is perhaps better for developers \ncreating substantial projects and includes syntax highlighting/code completion. Personally, I use\nboth simultaneously -- I develop scripts in Eclipse while simultaneously working with an \ninteractive console on front.\n\nRunning python scripts in eclipse (once pydev is installed) should be as easy as choosing Run/Run \nfrom the menu and selecting \"Jython Run.\" \n\nTo open an interactive console in Eclipse, choose the dropdown arrow farthest to the right on the console tab and choose\n\"Pydev Console.\" Click \"OK\" on any dialog boxes that come up. Type \"from crn import *\" as your first command to provide\naccess to crnscript functionality.\n\ncrnscript checkout in eclipse (this will vary by eclipse version):\n\n1. Ensure pydev is installed as an Eclipse plugin:\n\tHelp/Install New Software\n\tIn \"Work with\" put http://pydev.org/updates\n\tCheck \"PyDev\"\n\tClick \"Finish\"\n\tAllow Eclipse to restart.\n\n2. Check out the project (https://conman/svn-repos/CRN/crnscript/tags/crnscript-1.02) as a Java project.\n\n3. Right-click project, click Pydev/Set as pydev project (It needs both the Java and PyDev natures, \n\twhich is why we didn't just check it out as a PyDev project).\n\n4. Under project/properties:\n\n\tA. Under Java Build Path:\n\t\tUnder \"Libraries\", click \"Add JARs.\" Add all the top-level\n\t\t\tjars in lib.\n\t\tUnder \"Source\", click \"Add Folder\" and make sure both resources and src are checked\n\n\tB. Under PyDev - Interpreter/Grammar:\n\t\tChange project type from python to jython.\n\t\tClick link to configure an interpreter. Click \"new\". Set \n\t\t\tinterpreter name to \"crn-jython\". Browse for\n\t\t\texecutable and select lib/jython.jar. Click OK\n\t\t\tin the \"selection needed\" dialog box, and OK in the\n\t\t\tpreferences window.\n\t\tChange Interpreter from default to crn-jython.\n\t\n\tC. Under PyDev - PYTHONPATH:\n\t\tUnder \"source folders,\" click \"add source folder.\" Add src and resources.\n\t\tUnder \"External libraries\":\n\t\t\tClick \"add zip/jar/egg.\" Add each of the top-level files\n\t\t\t\tin lib.\n\t\t\tClick \"add source folder.\" Add bin.\n\n5. To verify that the project is running, run src/HelloWorld.py; it should produce a list of CRN stations.\n\nNote that all your python scripts should start with 'from crn import *'.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feggsyntax%2Fcrnscript","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feggsyntax%2Fcrnscript","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feggsyntax%2Fcrnscript/lists"}