Giter VIP home page Giter VIP logo

rwl's Introduction

Read Tucson rwl files in Javascript

Parses Tucson rwl ring width text for Javascript

An in-depth description of the Tucson rwl format can be found here

Installation

npm install rwl

Usage

Node

import rwl from 'rwl';

const fs = require('fs');
const rwl = require('rwl');

fs.readFile('./example.rwl', 'utf8', (err,data)=>{
    let dendroData = rwl(data);
    ...
})

In the browser

<script>

const res = fetch('./my-rwl.rwl')
const data = await res.text();
const dendroData = rwl(data); 
... 
</script>

API Reference

rwl(text)

Returns an JSON object of the parsed Tucson rwl text

Parameters

  • rwlText string input string of Tucson rwl file
  • options object optional configuration parameters
    • options.metadata boolean default false if true parses metadata from rwl file and returns in output JSON
    • options.formatDates boolean default true if true returns year as JavaScript Date, if false returns year as number. e.g. 1724-01-01T00:00:00.000Z or 1724

Output

JSON Schema of output:

{
    "$schema": "http://json-schema.org/draft-06/schema#",
    "title": "Tucson rwl file",
    "description": "rwl file format in JSON",
    "type": "object",
    "properties": {
        "metadata": {
            "type": "object",
            "properties": {
                "siteId": {
                    "description": "Unique identifier for collection site",
                    "type": "string"
                },
                "siteName": {
                    "description": "Full name of collection site",
                    "type": "string"
                },
                "speciesCode": {
                    "description": "Three or Four letter species code",
                    "type": "string",
                },
                "species": {
                      "description": "Full name of species",
                    "type": "string",
                },
                "state" : {
                    "description": "State or country where samples where collected",
                    "type": "string",
                },
                "elevation": {
                    "description": "Elevation in meters of the site",
                    "type": "number",
                },
                "lngLat": {
                    "description": "longitude latitude pair of site coordinates",
                    "type": "array",
                    "items": {
                        "type": "number"
                    }
                },
                "firstYear":{
                    "description": "First year of series",
                    "type": "number",
                },
                "lastYear":{
                    "description": "Last year of series",
                    "type": "number",
                },
                "leadInvestigator":{
                    "description": "Full name of lead investigator",
                    "type": "string",
                }
            }
        },
        "series": {
            "description": "array of measurement objects each representing a ring width measurement for a given year"
            "type": "array",
            "items": {
              "description": "object representing a ring width measurement for a given year",
              "type": "object",
              "required": ["year", "width"],
              "properties": {
                "year": {
                  "description": "year of measurement, either as year as an integer or ISO 8601 date string",
                  "type": ["number", "string"]
                },
                "width": {
                  "description": "measurement width in millimeters",
                  "type": "number"
                }
              }
            },
            "minItems": 1
        }
    },
    "required": [ "series" ]
}

Outputs measurements to mm (millimeters) convertered to 1/100th millimeter, i.e. 0.01mm or microns, i.e. 0.001mm, depending on the stop value provided.


Note about metadata:

Tucson rwl metadata is not consistently implemented across software and sometimes seems to be manually input by users. There is a specification for metadata in Tucson rwl but unfortunately it seems it is rarely followed. For this reason this library defaults to not including the file metadata, just series data. With the optional options.metadata flag set to true rwl will include metadata in the output JSON but cannot guarantee its accuracy due to the inconsistent implementation in the wild.

rwl's People

Contributors

russbiggs avatar

Watchers

 avatar  avatar

Forkers

vs-genn

rwl's Issues

Handle different coordinate pairs

coordinate pairs seem to come in many possible variations such as:

  • 4652N01101E
  • +4652-01101
  • N4652E01101
  • 4652-01101
  • 465201101
  • 4652 01101

it would be good to be able to try to handle as many, if not all, of these

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.