-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ability to change date modes in time-series types (#30)
* [WIP] Old dates support in Time * [WIP] no errors in time module * [WIP] Refactoring for new time format * [WIP] New time format compiles * New time tests pass * Fantomas formatted * Time tests passing * Benchmarks run again * Annual mode and subsequently reworked dendro functions * Sunrise tests * Fix orchestrator with new timemodes * Basic time-series docs
- Loading branch information
Showing
42 changed files
with
1,742 additions
and
727 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
(** | ||
--- | ||
title: Time-Series and Time-Frames | ||
category: Components | ||
categoryindex: 4 | ||
index: 1 | ||
--- | ||
[]({{root}}/{{fsdocs-source-basename}}.fsx)  | ||
[]({{root}}/{{fsdocs-source-basename}}.ipynb) | ||
*) | ||
|
||
(*** condition: prepare ***) | ||
#nowarn "211" | ||
#r "../src/Bristlecone/bin/Debug/netstandard2.0/Bristlecone.dll" | ||
(*** condition: fsx ***) | ||
#if FSX | ||
#r "nuget: Bristlecone,{{fsdocs-package-version}}" | ||
#endif // FSX | ||
(*** condition: ipynb ***) | ||
#if IPYNB | ||
#r "nuget: Bristlecone,{{fsdocs-package-version}}" | ||
#endif // IPYNB | ||
|
||
(** | ||
Time-series and time-frames | ||
======================== | ||
Bristlecone includes core representations of time-series,, time-frames, and | ||
time indexes. | ||
A key concept is the date mode. Bristlecone supports using different modes of measuring | ||
time, from simple `DateTime` representation (calendar time) to various dating methods | ||
commonly used in long-term ecology and archaeology. | ||
The time-related types are included in the `Bristlecone.Time` module: | ||
*) | ||
|
||
open System | ||
open Bristlecone | ||
open Bristlecone.Time | ||
|
||
(*** | ||
## Time Series | ||
A time-series is a representation of data ordered in time by the date | ||
of observation. | ||
### From calendar-date observations | ||
Time-series may be created from date-time observations using built-in .NET | ||
types and the `TimeSeries.fromNeoObservations` function: | ||
*) | ||
|
||
let someObservations = [ | ||
2.1, DateTime(2020, 03, 21) | ||
5.4, DateTime(2020, 03, 22) | ||
-54.2, DateTime(2020, 03, 23) | ||
] | ||
|
||
let ts = TimeSeries.fromNeoObservations someObservations | ||
(*** include-value: ts ***) | ||
|
||
(** | ||
### From radiocarbon dates | ||
As an example of an alternative date format, uncalibrated radiocarbon dates | ||
may be used as follows: | ||
*) | ||
|
||
let someDatedValues = [ | ||
1654, DatingMethods.Radiocarbon 345<``BP (radiocarbon)``> | ||
982, DatingMethods.Radiocarbon -2<``BP (radiocarbon)``> | ||
5433, DatingMethods.Radiocarbon 1023<``BP (radiocarbon)``> | ||
] | ||
|
||
let tsRadiocarbon = TimeSeries.fromObservations DateMode.radiocarbonDateMode someDatedValues | ||
(*** include-value: tsRadiocarbon ***) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,58 @@ | ||
namespace Bristlecone.Data | ||
|
||
open Bristlecone | ||
open Bristlecone.Time | ||
open Bristlecone.Dendro | ||
|
||
module PlantIndividual = | ||
|
||
open FSharp.Data | ||
|
||
type RingWidthData = CsvProvider<"data-types/ring-width.csv"> | ||
type EnvironmentVariableData = CsvProvider<"data-types/env-variable.csv"> | ||
|
||
let loadRingWidths (fileName: string) = | ||
let data = RingWidthData.Load fileName | ||
|
||
data.Rows | ||
|> Seq.groupBy (fun row -> row.``Plant Code``) | ||
|> Seq.map (fun (code, rows) -> | ||
let growth = | ||
open Bristlecone | ||
open Bristlecone.Time | ||
open Bristlecone.Dendro | ||
open Bristlecone.Dendro.Units | ||
|
||
/// Load plant-specific time-series from CSV files. | ||
module Csv = | ||
|
||
open FSharp.Data | ||
|
||
type RingWidthData = CsvProvider<"data-types/ring-width.csv"> | ||
type EnvironmentVariableData = CsvProvider<"data-types/env-variable.csv"> | ||
|
||
/// <summary>Load ring widths from a CSV file that contains 'Year', 'Plant Code', | ||
/// and 'Increment (mm)' columns.</summary> | ||
/// <param name="csvFileName">The file to load</param> | ||
/// <returns>A plant individual containing the growth series.</returns> | ||
let loadRingWidths (csvFileName: string) = | ||
let data = RingWidthData.Load csvFileName | ||
|
||
data.Rows | ||
|> Seq.groupBy (fun row -> row.``Plant Code``) | ||
|> Seq.map (fun (code, rows) -> | ||
let growth = | ||
rows | ||
|> Seq.sortBy (fun i -> i.Year) | ||
|> Seq.map (fun i -> | ||
(float i.``Increment (mm)`` * 1.<millimetre / year>, i.Year * 1<year> |> DatingMethods.Annual)) | ||
|> TimeSeries.fromObservations DateMode.annualDateMode | ||
|> GrowthSeries.Absolute | ||
|> PlantIndividual.PlantGrowth.RingWidth | ||
|
||
{ Identifier = code |> ShortCode.create |> Option.get | ||
Growth = growth | ||
InternalControls = [] |> Map.ofList | ||
Environment = [] |> Map.ofList } | ||
: PlantIndividual.PlantIndividual<DatingMethods.Annual, int<year>, int<year>>) | ||
|> Seq.toList | ||
|
||
/// <summary>Load plant-specific environmental time-series from | ||
/// a CSV file, where all time-series are specified in a single CSV.</summary> | ||
/// <param name="fileName">The CSV file to load from.</param> | ||
/// <returns>A map of time-series by their plant individual.</returns> | ||
let loadPlantSpecificEnvironments (fileName: string) = | ||
let data = EnvironmentVariableData.Load fileName | ||
|
||
data.Rows | ||
|> Seq.groupBy (fun row -> row.``Plant Code``) | ||
|> Seq.map (fun (code, rows) -> | ||
code, | ||
rows | ||
|> Seq.sortBy (fun i -> i.Date) | ||
|> Seq.map (fun i -> (float i.``Increment (mm)`` * 1.<mm>, i.Date)) | ||
|> TimeSeries.fromObservations | ||
|> GrowthSeries.Absolute | ||
|> PlantIndividual.RingWidth | ||
|
||
{ Identifier = code |> ShortCode.create |> Option.get | ||
Growth = growth | ||
InternalControls = [] |> Map.ofList | ||
Environment = [] |> Map.ofList } | ||
: PlantIndividual.PlantIndividual) | ||
|> Seq.toList | ||
|
||
let loadLocalEnvironmentVariable (fileName: string) = | ||
let data = EnvironmentVariableData.Load fileName | ||
|
||
data.Rows | ||
|> Seq.groupBy (fun row -> row.``Plant Code``) | ||
|> Seq.map (fun (code, rows) -> | ||
code, | ||
rows | ||
|> Seq.map (fun i -> float i.Predictor, i.Date) | ||
|> TimeSeries.fromObservations) | ||
|> Seq.toList | ||
|> Seq.map (fun i -> float i.Predictor, i.Year * 1<year> |> DatingMethods.Annual) | ||
|> TimeSeries.fromObservations DateMode.annualDateMode) | ||
|> Seq.toList |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.