Date as a filter in vector format on GEE - google-earth-engine

I want to use date as a filter in zone on GEE script and I want to add start and end date as date filter. I need to add start date and end date in here. But vectors format is different from Raster format. Can you help me please?
Map.addLayer(latest_radd_alert.select('Date'), {min:20001,max:21200,palette:['eb1677','f6f5ff', '0000FF']}, 'RADD alert date')
var year21sel = latest_radd_alert.select('Date');
var zones = year21sel.gt(20001).add(year21sel.gt(21001));
zones = zones.updateMask(zones.neq(0));' enter code'

Related

When writing a DateTime value using openxlsx, a "x" is written followed by DateTime value in the next row instead of just the DateTime value

I would like to write DateTime values to an excel sheet using openxlsx. When I try to do this, instead of just the DateTime value, I get a lowercase "x" on one row followed by the DateTime in the subsequent row. This occurs whether I use write.xlsx or writeData. I also tried converting the DateTime using as.POSIXlt or as.POSIXct, converting the date with timezone specified or not, and get the same result.
The UTC DateTime values are coming from a PerkinElmer microplate reader file.
Below is a code snippet that gives me this result. Any advice or help is appreciated, Thanks!
library(openxlsx)
library(lubridate)
date <- as_datetime("2022-04-07T22:15:08+0000", tz = "America/Los_Angeles")
options(openxlsx.datetimeFormat = "yyyy-mm-dd hh:mm:ss")
write.xlsx(date,"test.xlsx",overwrite = TRUE)
The documentation of write.xlsx says in section Arguments that x is (my emphasis)
A data.frame or a (named) list of objects that can be handled by writeData() or writeDataTable() to write to file.
So apparently an atomic vector is first coerced to data.frame and since the data argument name is x, so is its column header.
This also happens when writing a named list date_list <- list(date = date). A workbook with a sheet named date is created and the data in it has a column header x.

How to use the start function in ts in R when date and time are included?

I am exporting data from a CSV file that has two columns. One has time and the other has power.
The time columns has the time in two different formats: mm-dd-yy hh:mm:ss AM and mm/dd/yy hh:mm:ss 24h format. I was trying to use ts(x, start = c(?,), end = c(?,)), where x is the timeseries and ? and * are the inputs I need to write to tell R where to start but I don't know what I should write.
Can someone help?
dates13 = power_use_replaced$ï..time
Ac13 = power_use_replaced$power
AC13 = ts(Ac13, frequency = 7, start = as.Date(dates13[1],format="%d-%m-%y"),
end = as.Date(dates13[length(Ac13)],format="%d-%m-%y"))
This is one way. power_use_replaced is the data frame

R - Shiny Won't Let Me Convert Serial Dates

I have a data frame in Shiny that has separate columns for the month and year. I have been trying to turn this into a date object.
yearData=2013
monthData=1
dateData = ymd(paste(yearData, monthData, "01", sep="-")
This returns the proper date object if I run it in the R console (01-01-2013), but when I run the same code in Shiny it for some reason converts it to the serial date (15706). I've tried to troubleshoot this:
#This converts the serial date to a character string in the date format,
#"2013/01/01"
dateData2 = format(as.Date(dateData, origin = "1970-01-01"), "%Y/%m/%d")
#This then converts it back to a proper date object
dateData3 = as.Date(dateData2)
Again, if I try this in the R console, I have no problem converting a serial date into a date object. However, when I run it in Shiny, it once again converts dateData3 back into a serial date.
Here's a screenshot of what Shiny is returning when I run that same code
Does anybody have any suggestions on some other methods I could try to convert the serial date in Shiny into a date object?
It sounds like the date object is being converted when the table is being rendered.
dateData4 <- as.character(dateData3)
This is what I do before I render a table or write it to a csv.

Unable to grab dates into a column

While using quantmod and scraping GOOGLE stock prices I want the dates and it is showing the dates but unable to subset the dates.
library(quantmod)
start <- as.Date("2017-01-01")
end <- as.Date("2017-11-01")
getSymbols("GOOGL", src = "yahoo", from = start, to = end)
Snapshot:
What should I do?
The xts class (a superset of the zoo class which stores the time data as rownames rather than in numeric columns) has a method for "[" that can be used. It parses dates as characters and uses "/" to separate the ends of intervals:
G.subset <- GOOGL["2017-01-01/2017-11-01"]
Read more at:
?`[.xts`
?xts
The time values are accessible with the index function.

Using functions with dplyr to parse dates

I have code in R which is manipulating timestamps with dyplr
The code is below
In essence, we send out an email at a certain time and get a response - if any. I wanted to extract a number of attributes from both the sent and response items.
There are 3 countries involved and they have time stamps set up differently
So for example UK has a timestamp like: 2015-03-11 09:32:51, where as the other two countries have time stamps like 02/03/2015 08:02
I have created the code below based on my studying of dplyr and i wish to create a function out of it but im getting errors
udf_parsedates <- function(strFormat)
{
Email <- Email %>%
mutate(Email.dtm = parse_date_time(SMS.Date,strFormat),
Email.Hour = as.numeric(format(SMS.dtm,"%H")),
Email.Dow = wday(SMS.dtm, label=TRUE, abbr=FALSE),
Rep.dtm = parse_date_time(Reply.Date,strFormat),
Rep.Hour = as.numeric(format(Rep.dtm,"%H")),
Rep.Dow = wday(Rep.dtm, label=TRUE, abbr=FALSE),
ResponseTime.Hours = as.numeric(difftime(Rep.dtm, SMS.dtm, units="hours")))
}
# Find hour and DOW of the Email
if(Email$dest_ctry == 'GB') {udf_parsedates("%Y-%m-%d %H:%M:%S")
} else if (SMS$dest_ctry == 'IT') {udf_parsedates("%Y/%m/%d %H:%M")
} else if (SMS$dest_ctry == 'ES') {udf_parsedates("%Y/%m/%d %H:%M")}
The mutate works fine outside of the function but im trying to learn to integrate and re-use code so i would like to use functions to do this. Any help would be greatly appreciated
If it were me, I'd try to create a column that shows the date format, and then use and ifelse to apply to correct transformation into a POSIXct object
This line in your mutate call will generate the date format
date_format = ifelse(grepl("\\d{4}-\\d{2}-\\d{2} ", SMS.Date), "ymd", "mdy")

Resources