Skip to content

Commit 6e336f8

Browse files
committed
Release 1.7.3 files
1 parent 7cabb76 commit 6e336f8

29 files changed

+313
-133
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Description: Support for all calendars as specified in the Climate and Forecast
1111
Climate Change (IPCC). This package specifically allows the user to work
1212
with any of the CF-compliant calendars (many of which are not compliant with
1313
POSIXt). The CF time coordinate is formally defined in the CF Metadata
14-
Conventions document available at <https://cfconventions.org/Data/cf-conventions/cf-conventions-1.13/cf-conventions.html#time-coordinate>.
14+
Conventions document available at <https://cf-convention.github.io/Data/cf-conventions/cf-conventions-1.13/cf-conventions.html#time-coordinate>.
1515
License: MIT + file LICENSE
1616
Encoding: UTF-8
1717
Roxygen: list(markdown = TRUE)

NEWS.md

Lines changed: 30 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Maintenance release
66
* Fields in `CFTime` and `CFClimatology` classes have been made private, corresponding active fields added.
77
* `CFClimatology` instances can now be extended with the `+` operator.
88
* When extending a `CFTime` or `CFClimatology` instance with another such instance using the `+` operator, bounds are preserved if both instances have bounds set.
9+
* Added method `CFTime$doy()` to calculate the day-of-year from offsets or supplied dates, using the calendar of the instance.
910
* Documentation updated.
1011

1112
# CFtime 1.7.2
@@ -46,17 +47,11 @@ Maintenance release
4647

4748
# CFtime 1.6.0
4849

49-
* New class `CFClimatology` to manage climatological statistics. Method
50-
`CFTime$factor()` with an `era` argument will now have a `CFClimatology`
51-
instance attached to the attribute "CFTime" of its return value.
52-
* New class `CFCalendarNone` for a calendar with no annual cycle. Such a
53-
calendar represents a single instant in time, which may be useful for
54-
experiments on a fixed moment during the year.
50+
* New class `CFClimatology` to manage climatological statistics. Method `CFTime$factor()` with an `era` argument will now have a `CFClimatology` instance attached to the attribute "CFTime" of its return value.
51+
* New class `CFCalendarNone` for a calendar with no annual cycle. Such a calendar represents a single instant in time, which may be useful for experiments on a fixed moment during the year.
5552
* `str()` for `CFTime` and `CFClimatology` gives compact information.
56-
* Fixed new `CFTime` instance for factor with a "day" or "dekad" period where
57-
the last factor level is not at the end of the year.
58-
* `CFTime$new()` with a single character string offset will generate only the
59-
single corresponding offset.
53+
* Fixed new `CFTime` instance for factor with a "day" or "dekad" period where the last factor level is not at the end of the year.
54+
* `CFTime$new()` with a single character string offset will generate only the single corresponding offset.
6055
* Test coverage near-complete.
6156
* Fixed inconsistent documentation for functions.
6257
* Minor code fixes.
@@ -70,128 +65,62 @@ single corresponding offset.
7065

7166
# CFtime 1.5.0
7267

73-
* Code is updated to align with the CF 1.12 release. Specifically, calendars
74-
`utc` and `tai` are added.
75-
* `standard` calendar now uses mixed Gregorian/Julian calendar as defined in the
76-
CF Metadata Conventions. `proleptic_gregorian` is now a separate calendar with
77-
its own code base.
68+
* Code is updated to align with the CF 1.12 release. Specifically, calendars `utc` and `tai` are added.
69+
* `standard` calendar now uses mixed Gregorian/Julian calendar as defined in the CF Metadata Conventions. `proleptic_gregorian` is now a separate calendar with its own code base.
7870
* Negative offsets from a calendar origin are allowed.
79-
* Code is refactored to R6. R6 class CFTime replaces S4 class CFtime (note the
80-
difference in case). S4 class CFdatum has been replaced by hierarchy of
81-
R6 CFCalendar classes, with various non-exported functions converted into
82-
methods of CFCalendar. The code is now much cleaner and easier to extend, such
83-
as with the two new calendars `utc` and `tai`.
84-
* ISO8601 timestamps can use a comma "," as decimal mark to separate a
85-
fractional part from a time element, in addition to the dot ".".
86-
* Do not drop degenerate dimension on bounds when only 1 offset is included in
87-
subsetting.
71+
* Code is refactored to R6. R6 class CFTime replaces S4 class CFtime (note the difference in case). S4 class CFdatum has been replaced by hierarchy of R6 CFCalendar classes, with various non-exported functions converted into methods of CFCalendar. The code is now much cleaner and easier to extend, such as with the two new calendars `utc` and `tai`.
72+
* ISO8601 timestamps can use a comma "," as decimal mark to separate a fractional part from a time element, in addition to the dot ".".
73+
* Do not drop degenerate dimension on bounds when only 1 offset is included in subsetting.
8874

8975
# CFtime 1.4.1
9076

91-
* Method `slab()` has an additional argument `rightmost.closed` to indicate if
92-
the upper extreme value should be included in the result.
93-
* Fixed bounds information on CFtime instances returned from methods `indexOf()`
94-
and `slab()`.
77+
* Method `slab()` has an additional argument `rightmost.closed` to indicate if the upper extreme value should be included in the result.
78+
* Fixed bounds information on CFtime instances returned from methods `indexOf()` and `slab()`.
9579
* Several minor code improvements.
9680

9781
# CFtime 1.4.0
9882

99-
* Bounds that define intervals around offsets can be associated with a CFtime
100-
instance and retrieved as raw offset values or as formatted timestamps.
101-
* Methods that subset a CF time series (e.g. `CFfactor()`, `cut()`, `slab()`)
102-
now have an attribute "CFtime" (among possible others) that describes the "time"
103-
dimension of the analysis result applying the subset. In other words, if CFtime
104-
instance 'Acf' describes the temporal dimension of data set 'A' and a factor 'Af'
105-
is generated from 'Acf', then `Bcf <- attr(Af, "CFtime")` describes the temporal
106-
dimension of the result of, say, `B <- apply(A, 1:2, tapply, Af, FUN)`.
107-
* New `indexOf()` method added that returns the indices of supplied timestamps
108-
in a CFtime instance, optionally with a fractional part. This can be used to
109-
extract specific time steps, or to interpolate between time steps using the
110-
fractional part, from the time dimension of the data set associated with the
111-
CFtime instance. A vector of indices (e.g. referring to slices of the data set)
112-
can also be supplied, in which case valid indices are returned, with the new
113-
CFtime instance.
114-
* New `cut()` method added to generate a factor, similar to `cut.POSIXt()` but with
115-
some differences in the arguments.
83+
* Bounds that define intervals around offsets can be associated with a CFtime instance and retrieved as raw offset values or as formatted timestamps.
84+
* Methods that subset a CF time series (e.g. `CFfactor()`, `cut()`, `slab()`) now have an attribute "CFtime" (among possible others) that describes the "time" dimension of the analysis result applying the subset. In other words, if CFtime instance 'Acf' describes the temporal dimension of data set 'A' and a factor 'Af' is generated from 'Acf', then `Bcf <- attr(Af, "CFtime")` describes the temporal dimension of the result of, say, `B <- apply(A, 1:2, tapply, Af, FUN)`.
85+
* New `indexOf()` method added that returns the indices of supplied timestamps in a CFtime instance, optionally with a fractional part. This can be used to extract specific time steps, or to interpolate between time steps using the fractional part, from the time dimension of the data set associated with the CFtime instance. A vector of indices (e.g. referring to slices of the data set) can also be supplied, in which case valid indices are returned, with the new CFtime instance.
86+
* New `cut()` method added to generate a factor, similar to `cut.POSIXt()` but with some differences in the arguments.
11687
* `CFfactor()` now supports a period "quarter", for calendar quarters.
117-
* `format()` method added that generates a character vector of timestamps for the
118-
offsets in a CFtime instance. The format is specified using the flags used in
119-
`strptime()`, with some limitations. In particular, locale-specific formatting is
120-
limited to month names and no weekday information can be generated. The `range()`
121-
method has a new "format" parameter to support the same functionality and timestamps
122-
can also be generated for the extremes of the bounds, if set.
123-
* `as_character()` and `length()` methods added that return a vector of timestamps
124-
or the number of offsets in a CFtime instance, respectively.
125-
* Several functions have been renamed (most notably `CFtimestamp()` to
126-
`as_timestamp()`, `CFcomplete()` to `is_complete()`, `CFrange()` to the standard
127-
generic method `range()`, and `CFsubset()` to `slab()`) to be more consistent
128-
with the R universe. The original functions are now flagged as being deprecated.
129-
Some datum functions (deep down where regular mortals do not dwell) have been
130-
deleted.
88+
* `format()` method added that generates a character vector of timestamps for the offsets in a CFtime instance. The format is specified using the flags used in `strptime()`, with some limitations. In particular, locale-specific formatting is limited to month names and no weekday information can be generated. The `range()` method has a new "format" parameter to support the same functionality and timestamps can also be generated for the extremes of the bounds, if set.
89+
* `as_character()` and `length()` methods added that return a vector of timestamps or the number of offsets in a CFtime instance, respectively.
90+
* Several functions have been renamed (most notably `CFtimestamp()` to `as_timestamp()`, `CFcomplete()` to `is_complete()`, `CFrange()` to the standard generic method `range()`, and `CFsubset()` to `slab()`) to be more consistent with the R universe. The original functions are now flagged as being deprecated. Some datum functions (deep down where regular mortals do not dwell) have been deleted.
13191
* Time zone designator "UTC" accepted when parsing timestamps to offsets.
13292
* Minor code fixes, see GitHub commits.
13393
* Documentation updated, with description of new functions.
13494

13595
# CFtime 1.3.0
13696

137-
* Two CFtime instances can be added if they have compatible calendars and units.
138-
The earlier origin is preserved in the result and offsets from the later instance
139-
are incremented by the appropriate amount. As before, in the result offsets are
140-
in the order of the specified CFtime instances.
141-
* A new function CFsubset() can be used to retrieve a logical vector that indicates
142-
which time steps in a CFtime instance fall between two timestamps. This is useful
143-
to slice data during reading from file or analysis.
144-
* Time zone information is managed at the level of the datum. If a vector of character
145-
timestamps is parsed and found to have different time zones, a warning is generated.
97+
* Two CFtime instances can be added if they have compatible calendars and units. The earlier origin is preserved in the result and offsets from the later instance are incremented by the appropriate amount. As before, in the result offsets are in the order of the specified CFtime instances.
98+
* A new function CFsubset() can be used to retrieve a logical vector that indicates which time steps in a CFtime instance fall between two timestamps. This is useful to slice data during reading from file or analysis.
99+
* Time zone information is managed at the level of the datum. If a vector of character timestamps is parsed and found to have different time zones, a warning is generated.
146100
* Much reduced memory footprint.
147101
* Minor code fixes, see GitHub commits.
148102
* Codecov.io test coverage monitoring added.
149103
* Documentation updated, with description of new functions.
150104

151105
# CFtime 1.2.0
152106

153-
* Datum units "years" and "months" added. While these units are discouraged by
154-
the CF Metadata Conventions due to their problematic definition, there are quite
155-
a few data sets out there that use these units nonetheless. For this reason,
156-
reading existing files with such datum units is supported (converting offsets to
157-
time elements is easy) but parsing timestamps is not (calculating offsets from
158-
time elements is possible but tedious and slow). Should there be a definite need,
159-
open an issue on GitHub and make a *very good* case why this functionality is
160-
required.
161-
* CFresolution() returns the average separation between elements in a time series,
162-
in units of the datum.
163-
* CFcomplete() indicates if the time series is complete, meaning that there are
164-
no gaps in the time series. This also works for time series with a somewhat
165-
variable length such as monthly data with a "days" datum unit. This works for
166-
all but the most exotic time dimension constructions.
167-
* CFtimestamp() produces a timestamp for all midnight values if the datum unit is
168-
"hours", "minutes" or "seconds". The "time" format has been removed. For "standard",
169-
"gregorian" and "proleptic_gregorian" calendars output can be generated as POSIXct
170-
by specifying the new argument `asPOSIX = TRUE` -- defaults to `FALSE`, the
171-
previous behaviour so the API is not broken.
107+
* Datum units "years" and "months" added. While these units are discouraged by the CF Metadata Conventions due to their problematic definition, there are quite a few data sets out there that use these units nonetheless. For this reason, reading existing files with such datum units is supported (converting offsets to time elements is easy) but parsing timestamps is not (calculating offsets from time elements is possible but tedious and slow). Should there be a definite need, open an issue on GitHub and make a *very good* case why this functionality is required.
108+
* CFresolution() returns the average separation between elements in a time series, in units of the datum.
109+
* CFcomplete() indicates if the time series is complete, meaning that there are no gaps in the time series. This also works for time series with a somewhat variable length such as monthly data with a "days" datum unit. This works for all but the most exotic time dimension constructions.
110+
* CFtimestamp() produces a timestamp for all midnight values if the datum unit is "hours", "minutes" or "seconds". The "time" format has been removed. For "standard", "gregorian" and "proleptic_gregorian" calendars output can be generated as POSIXct by specifying the new argument `asPOSIX = TRUE` -- defaults to `FALSE`, the previous behaviour so the API is not broken.
172111
* Minor documentation updates.
173112
* Assorted minor code fixes, see GitHub commits.
174113

175114
# CFtime 1.1.0
176115

177-
* CFtime() can now also be invoked with a vector of character timestamps as offsets, or
178-
with a single timestamp to create a complete time series from the datum to the
179-
indicated timestamp.
116+
* CFtime() can now also be invoked with a vector of character timestamps as offsets, or with a single timestamp to create a complete time series from the datum to the indicated timestamp.
180117
* CFtimestamp() can now automatically select the best format for the time series.
181-
* New CFfactor_units() and CFfactor_coverage() functions. CFfactor_units() will
182-
tell you how many time units compose every level of a factor. CFfactor_coverage()
183-
computes the actual or relative number of time units in the factor levels from the
184-
time series in a CFtime instance with which the factor was created. This will
185-
enable you to assess the completeness of your time series (and perhaps filter out
186-
factor levels below a certain coverage threshold) and it can be useful in computing
187-
absolute values from average values, as is often useful when computing anomalies.
118+
* New CFfactor_units() and CFfactor_coverage() functions. CFfactor_units() will tell you how many time units compose every level of a factor. CFfactor_coverage() computes the actual or relative number of time units in the factor levels from the time series in a CFtime instance with which the factor was created. This will enable you to assess the completeness of your time series (and perhaps filter out factor levels below a certain coverage threshold) and it can be useful in computing absolute values from average values, as is often useful when computing anomalies.
188119
* Global constants are now defined in a package environment, CFt.
189120
* Documentation expanded, updated and fixed.
190121
* Assorted minor code fixes, see GitHub commits.
191122

192123
# CFtime 1.0.0
193124

194-
* This version supports all CF Metadata Conventions calendars for use with climate
195-
projection data.
196-
* You can create timestamps from the offsets in the files and create factors that
197-
greatly simplify working with climate change data.
125+
* This version supports all CF Metadata Conventions calendars for use with climate projection data.
126+
* You can create timestamps from the offsets in the files and create factors that greatly simplify working with climate change data.

R/CFCalendar.R

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ NULL
2424
#' \item [`360_day`][CFCalendar360], all years have 360 days, divided over 12 months of 30 days.
2525
#' }
2626
#' @references
27-
#' https://cfconventions.org/Data/cf-conventions/cf-conventions-1.13/cf-conventions.html#calendar
27+
#' https://cf-convention.github.io/Data/cf-conventions/cf-conventions-1.13/cf-conventions.html#calendar
2828
#' @docType class
2929
CFCalendar <- R6::R6Class("CFCalendar",
3030
private = list(
@@ -325,6 +325,21 @@ CFCalendar <- R6::R6Class("CFCalendar",
325325
cap
326326
},
327327

328+
#' @description Retrieve the day-of-year number for the supplied
329+
#' `data.frame` of year, month and day, using this calendar. This method
330+
#' tests for leap years - calendars without leap years may override this
331+
#' method for efficiency.
332+
#' @param ymd `data.frame` with dates parsed into their parts in columns
333+
#' `year`, `month` and `day`. Any other columns are disregarded.
334+
#' @return Integer vector as long as argument `ymd` has rows with the
335+
#' day-of-year for each row.
336+
doy = function(ymd) {
337+
cum_month <- c(0L, 31L, 59L, 90L, 120L, 151L, 181L, 212L, 243L, 273L, 304L, 334L) # days in year before the month
338+
doy <- cum_month[ymd$month] + ymd$day
339+
doy <- ifelse(self$leap_year(ymd$year) & ymd$month > 2L, doy + 1L, doy)
340+
doy
341+
},
342+
328343
#' @description Decompose a vector of offsets, in units of the calendar, to
329344
#' their timestamp values. This adds a specified amount of time to the
330345
#' origin of a `CFTime` object.

R/CFCalendar360.R

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,16 @@ CFCalendar360 <- R6::R6Class("CFCalendar360",
5757
res
5858
},
5959

60+
#' @description Retrieve the day-of-year number for the supplied
61+
#' `data.frame` of year, month and day, using this calendar.
62+
#' @param ymd `data.frame` with dates parsed into their parts in columns
63+
#' `year`, `month` and `day`. Any other columns are disregarded.
64+
#' @return Integer vector as long as argument `ymd` has rows with the
65+
#' day-of-year for each row.
66+
doy = function(ymd) {
67+
(ymd$month - 1L) * 30L + ymd$day
68+
},
69+
6070
#' @description Calculate difference in days between a `data.frame` of time
6171
#' parts and the origin.
6272
#'

R/CFCalendar365.R

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,17 @@ CFCalendar365 <- R6::R6Class("CFCalendar365",
6262
res
6363
},
6464

65+
#' @description Retrieve the day-of-year number for the supplied
66+
#' `data.frame` of year, month and day, using this calendar.
67+
#' @param ymd `data.frame` with dates parsed into their parts in columns
68+
#' `year`, `month` and `day`. Any other columns are disregarded.
69+
#' @return Integer vector as long as argument `ymd` has rows with the
70+
#' day-of-year for each row.
71+
doy = function(ymd) {
72+
cum_month <- c(0L, 31L, 59L, 90L, 120L, 151L, 181L, 212L, 243L, 273L, 304L, 334L)
73+
cum_month[ymd$month] + ymd$day
74+
},
75+
6576
#' @description Calculate difference in days between a `data.frame` of time
6677
#' parts and the origin.
6778
#'

R/CFCalendar366.R

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,17 @@ CFCalendar366 <- R6::R6Class("CFCalendar366",
6262
res
6363
},
6464

65+
#' @description Retrieve the day-of-year number for the supplied
66+
#' `data.frame` of year, month and day, using this calendar.
67+
#' @param ymd `data.frame` with dates parsed into their parts in columns
68+
#' `year`, `month` and `day`. Any other columns are disregarded.
69+
#' @return Integer vector as long as argument `ymd` has rows with the
70+
#' day-of-year for each row.
71+
doy = function(ymd) {
72+
cum_month <- c(0L, 31L, 60L, 91L, 121L, 152L, 182L, 213L, 244L, 274L, 305L, 335L)
73+
cum_month[ymd$month] + ymd$day
74+
},
75+
6576
#' @description Calculate difference in days between a `data.frame` of time
6677
#' parts and the origin.
6778
#'

0 commit comments

Comments
 (0)