diff --git a/.gitignore b/.gitignore index 138866d..c833a2c 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,3 @@ .RData .Ruserdata inst/doc -docs diff --git a/docs/404.html b/docs/404.html new file mode 100644 index 0000000..0ad95e8 --- /dev/null +++ b/docs/404.html @@ -0,0 +1,93 @@ + + +
+ + + + +LICENSE.md
+ Version 2.0, January 2004 <http://www.apache.org/licenses/>
+“License” shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
+“Licensor” shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
+“Legal Entity” shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, “control” means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
+“You” (or “Your”) shall mean an individual or Legal Entity exercising permissions granted by this License.
+“Source” form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
+“Object” form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
+“Work” shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
+“Derivative Works” shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
+“Contribution” shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, “submitted” means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as “Not a Contribution.”
+“Contributor” shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
+Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
+Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
+You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
+You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
+Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
+This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
+Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
+In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
+While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
+END OF TERMS AND CONDITIONS
+To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets []
replaced with your own identifying information. (Don’t include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same “printed page” as the copyright notice for easier identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
In this article, we show an example of tracking features in an +outgoing longwave radiation field from the NWP model MEPS. We are going +to make use of the harpIO package to load the data and the +ggplot2 package, together with some expansions from the +harpVis package to plot the data.
+ +First we need to load the data using read_forecast()
+from the harpIO package. The data are downloaded from the open
+data Thredds server at the Norwegian Meteorological Institute.
There are a few steps we need to go through to ensure we read the
+data properly. First we’ll add the outgoing longwave parameter to the
+parameter definitions so that read_forecast()
knows what
+parameter to extract. The data are also negative for outgoing radiation
+so we multiply by -1
+my_params <- add_param_def(
+ "olr",
+ netcdf = new_netcdf_param("toa_outgoing_longwave_flux"),
+ func = function(x) x * -1
+)
Then we set the path and template for the file(s) to read, as well as +some information about the netcdf files.
+
+url <- "https://thredds.met.no/thredds/dodsC/meps25epsarchive"
+template <- "{YYYY}/{MM}/{DD}/{fcst_model}_sfc_{YYYY}{MM}{DD}T{HH}Z.ncml"
+file_opts <- netcdf_opts(
+ z_var = "top_of_atmosphere", ref_time_var = "forecast_reference_time"
+)
And now we can read the data…
+
+olr <- read_forecast(
+ dttm = 2024052700,
+ fcst_model = "meps_det",
+ parameter = "olr",
+ lead_time = seq(0, 23),
+ file_path = url,
+ file_template = template,
+ file_format = "netcdf",
+ file_format_opts = file_opts,
+ param_defs = my_params,
+ return_data = TRUE
+)
+#> Reading https://thredds.met.no/thredds/dodsC/meps25epsarchive/2024/05/27/meps_det_sfc_20240527T00Z.ncml
Feature detection is done using thresholds to identify contiguous +features in the field of interest at each time. This requires careful +selection of thresholds, so as a first step we will plot the OLR at each +time step.
+
+countries <- get_map(get_domain(olr$fcst), polygon = FALSE)
+ggplot() +
+ geom_georaster(
+ aes(geofield = fcst), olr,
+ upscale_factor = 8, upscale_method = "downsample"
+ ) +
+ geom_path(aes(x, y), countries, colour = "grey30") +
+ facet_wrap(~valid_dttm) +
+ scale_fill_viridis_c(bquote(OLR~"["*W.m^{-2}*"]"), direction = -1) +
+ coord_equal(expand = FALSE) +
+ theme_harp_map()
It looks like most of the interesting features are for OLR < ~180. +We can get a better idea by masking all values that are > 180, by +adding limits to the colour scale.
+
+countries <- get_map(get_domain(olr$fcst), polygon = FALSE)
+ggplot() +
+ geom_georaster(
+ aes(geofield = fcst), olr,
+ upscale_factor = 8, upscale_method = "downsample"
+ ) +
+ geom_path(aes(x, y), countries, colour = "grey30") +
+ facet_wrap(~valid_dttm) +
+ scale_fill_viridis_c(
+ bquote(OLR~"["*W.m^{-2}*"]"), direction = -1,
+ limits = c(NA, 180), na.value = "white"
+ ) +
+ coord_equal(expand = FALSE) +
+ theme_harp_map()
Using this information we will use thresholds of 180, 160 and 140 in
+the feature detection, setting the target to “min” since we want
+features to be identified that are less than the thresholds. Features
+are detected using detect_features_multithreshold()
that is
+a wrapper around tobac.feature_detection.feature_detection_multithreshold
+from the original Python package. We will only detect features that are
+at least 16 contiguous pixels in size, and use the “weighted_diff”
+method to set the position of the features.
+features <- detect_features_multithreshold(
+ olr,
+ thresholds = c(180, 160, 140),
+ data_col = fcst,
+ target = "min",
+ n_min_threshold = 16,
+ position_threshold = "weighted_diff"
+)
We can now plot the feature locations for each threshold and +time.
+
+ggplot(features, aes(projection_x_coordinate, projection_y_coordinate)) +
+ geom_path(aes(x, y), countries, colour = "grey30") +
+ geom_point(aes(colour = factor(threshold_value))) +
+ facet_wrap(~timestr) +
+ coord_equal(expand = FALSE) +
+ theme_harp_map() +
+ labs(colour = bquote(atop(OLR~Threshold,"["*W.m^{-2}*"]")))
Having run the feature detection, the next step is to associate
+regions with the identified features. This is done using
+segment_2d()
that is a wrapper around the tobac.segmentation.segmentation_2D
+function from the original Python package. Here a single threshold is
+needed, and we use the highest of the thresholds we used in the feature
+detection. segment_2d
returns a named list, but we can
+destructure using the %<-%
operator from the
+zeallot package.
+library(zeallot)
+c(segments, features) %<-% segment_2d(
+ features,
+ olr,
+ threshold = 180,
+ data_col = fcst,
+ target = "min"
+)
segments
is a data frame with a geolist coloumn
+that contains fields with a mask identifying the areas that are
+associated with each feature, while features
is the same as
+the output of the previous step, but with an extra column giving the
+number of cells associated with each feature. The segment masks can be
+overlayed on top of the original OLR data. Here we just show 4
+times.
+ggplot() +
+ geom_georaster(
+ aes(geofield = fcst), olr[11:14, ],
+ upscale_factor = 4, upscale_method = "downsample"
+ ) +
+ geom_geocontour(
+ aes(geofield = segmentation_mask), segments[11:14, ],
+ colour = "red"
+ ) +
+ geom_path(aes(x, y), countries, colour = "grey30") +
+ facet_wrap(~valid_dttm) +
+ scale_fill_viridis_c(direction = -1) +
+ coord_equal(expand = FALSE) +
+ theme_harp_map()
With the features identified, the tracking algorithm attempts to link
+these features in time to produce tracks. The tracking is computed with
+the link_tracks()
function that is a wrapper around tobac.tracking.linking_trackpy
+from the original Python package.
+tracks <- link_tracks(
+ features,
+ olr,
+ data_col = fcst,
+ v_max = 20,
+ stubs = 2,
+ subnetwork_size = 100,
+ adaptive_step = 0.95,
+ adaptive_stop = 0.2
+)
Some of the arguments in the call to link_tracks()
+require some experimentation, and are better explained in some of the tobac
+examples.
The tracks for each of the identified cells can easily be plotted. +For all tracks throughout the period this can be done making sure to +remove untracked cells (these are labelled -1).
+
+library(dplyr)
+countries <- get_map(get_domain(olr$fcst))
+ggplot(filter(tracks, cell > -1), aes(x, y)) +
+ geom_polygon(aes(group = group), countries, fill = "grey", colour = "grey30") +
+ geom_path(
+ aes(group = factor(cell), colour = factor(threshold_value)),
+ arrow = arrow(type = "open", angle = 30, length = unit(0.1, "cm"))
+ ) +
+ labs(colour = bquote(atop(OLR~threshold, "["*W.m^{-2}*"]"))) +
+ coord_equal(expand = FALSE) +
+ theme_harp_map()
We could then plot some statistics, such as the distribution of the +lifetimes of individual cells.
+ + +