r function for classifying calendar dates as spring or neap tide - package

I want to classify each calendar day from 2005-2025 as spring or neap tide. Is there another function or package to do this?
Spring tide also known as king tide is when the tides are most extreme (higher high tides and lower low tides). Spring tide occurs during the full moon and new moon. Neap tide is the less extreme tides encourage during the half moon phases (waxing and waning moon). I am using this website to determine when the lunar cycle is https://www.calendar-12.com/moon_phases/2022#:~:text=Dates%20of%20Moon%20Phases%20in%202022%20Year%20,%2001%3A42%20PM%20%2028%20more%20rows%20. I also tried using the lunar package to figure out when the dates of the lunar phase are, but ran into issues getting this to work, namely I keep getting the error of an invalid trim argument, but I have already coerced the dates to be in a date format, so I'm not sure why that is happening.
The lunar cycle generally changes the moon phases every week, but there is variation. Typically whenever the moon phase would be spring tide, I will assign three days on either side of the date of the full or new moon to be spring tide days. Days assigned to neap tide are three days on either side of the half moon. Sometimes I have to give or take a day for either assignment when the moon phase change is not exactly 7 days.
So far I have only coded each day by hand in excel (physically typed the word spring or neap in a new column in excel beside the calendar date), but I have 20 years of data to do this for and wanted to find a way to automate it in R. That's why I wondered if a package existed.
Thanks for the help.
What I want my data to look like. In the example, May 8 is a half moon, May 16th is a full moon, May 22nd is a half moon, and May 30th is a new moon.
Code I tried.
dates <- format(seq(as.Date("2005-01-01"), as.Date("2025-01-01"), by="days"), format="%m/%d/%Y")
as.vector(dates)
library(lunar)
lunar.phase(dates, name = TRUE)

Related

Add predictor to model quantile function in Tableau

Does anyone know how to get a model quantile function to project into future using a predictor variable/measure? I have support ticket volume I'm trying to predict using previous months and another measure.
MODEL_QUANTILE(0.5,SUM(Volume),ATTR(DATETRUNC('month',[fiscal date])),SUM(Time / User (min)]))
If I take out the last predictor (Time/User) it produces a smooth curve into future, but only gives me until this month if I have it in. Both measures stop at this month, and I've tried "Infer Properties from Missing Values" and "Extend Date Range"

How to create a calendar event that repeats weekly for three months every year?

I want to be reminded about something every week every winter. Is that possible to achieve using the ical-/webcal-standard and Google Calender, Apple Calendar/iCal, Android Calender or similar?
(I searched quite extensively for which subdomain this questioned belonged to but the results were inconclusive, with a slight predominance for SO)
It's definitely possible with RFC 5545 recurrence rules.
You can create a WEEKLY RRULE that recurs in specific months only, like so:
FREQ=WEEKLY;BYDAY=MO;BYMONTH=1,2,12
The occurrences of this rule are all Mondays in January, February and December.
Check out the first 100 instances of such an event at http://recurrence-expansion-service.appspot.com/reaas?dtstart=20160104&rrule=FREQ%3DWEEKLY%3BBYDAY%3DMO%3BBYMONTH%3D1%2C2%2C12&skip=&max_instances=100&expansion_window_end=21000104&rfc2445=1
Changing the rule to DAILY would yield the same results, but might be more compatible with actual implementations.
However, I think most calendar UIs don't provide this level of control over recurrence rules.
update:
To create an all day event starting on Dec 15 2015 and recur on the same day of week use:
DTSTART;VALUE=DATE:20151215
RRULE:FREQ=WEEKLY;BYMONTH=1,2,12
The rule doesn't include March itself. To include March just append ,3 to the rule.

How to get last year's same week data in SOLR

How do I get last years same week data?
I used fq=trans_date:[NOW-1YEAR/DAY-7DAY TO NOW-1YEAR/DAY] on date field which will give me last 7 days data for last year. But that approach doesn't take into account calender weeks.
It's probably easier to calculate the boundaries for your week number last year in the frontend and then query Solr with the date interval. That way you can get the behavior you want regarding sundays/mondays as well.
Solr does not provide a nice way to do this.
It would be really cool if you could do fq=trans_date:[NOW-1YEAR/WEEK TO NOW-1YEAR/WEEK] but this is not supported.
Nevertheless, you could create a quick function using php or javascript using each language's native Date operators and get the Week number from today to produce start and end points to feed solr in a query like [1995-12-31T23:59:59.999Z TO 2007-03-06T00:00:00Z].

How does NOW/DAY in a Solr query work?

I am trying to figure out why Solr thinks an doc is in the past. My query is set up to use
published:[* TO NOW/DAY]
The doc I am hoping it will find has a published date of
2012-04-30T04:00:00Z
Current Solr server time is Mon Apr 30 18:26:47 EDT 2012. My understanding says that the document should have been found by now, which makes me think the NOW/DAY doesn't work the way I think it does. Does anybody know how the NOW/DAY evaluates dates and why when Solr is not finding my doc when I add that stipulation?
NOW/DAY means take the actual date time and round it to the day (leaving out the time). Of course if the actual date is 2012-04-30, any hour, the result is 2012-04-30T00:00:00Z.
Try just using NOW. I suspect that NOW/DAY is equal to 2012-04-30T00:00:00Z.
NOW/DAY rounds down to midnight last night. If you want the midnight of current day change with NOW+1DAY/DAY.
Date Math Syntax
Date math expressions consist either adding some
quantity of time in a specified unit, or rounding the current time by
a specified unit. expressions can be chained and are evaluated left to
right.
For example: this represents a point in time two months from
now:
NOW+2MONTHS
This is one day ago:
NOW-1DAY
A slash is used to indicate rounding. This represents the beginning of the current hour:
NOW/HOUR
The following example computes (with millisecond precision)
the point in time six months and three days into the future and then
rounds that time to the beginning of that day:
NOW+6MONTHS+3DAYS/DAY
Note that while date math is most commonly used relative to NOW it can
be applied to any fixed moment in time as well:
1972-05-20T17:33:18.772Z+6MONTHS+3DAYS/DAY
Quoted from Apache Solr Reference Guide - Working with Dates

Hide weekends on WPF toolkit chart

I am making a small app that plots financial price data and since the finance markets are closed on the weekends, I have no data for those days. By default the chart, found in the new WPF Toolkit, shows a large gap between Friday and following Monday and this behaviour is not acceptable. I am trying to figure out a way to "hide" the weekend gaps but can't seem to find any good solutions. So far, I figured that I would have to overload the standard DateTime struct (how?) which will be able to recognize and skip weekends and holidays. I am looking for suggestions and/or pointers before I start down that slippery slope.
Some more details:
I am given a wide range of data - currently daily closing prices on NYSE. I am using the DayTimeAxis to plot the independent variable of LineSeries which is of type DateTime. It currently simply plots all the prices, one day at a time - and that's where the devil is, it shows wider gaps due to lack of data for Saturdays and Sundays and some major holidays.
I will eventually have to show more detailed (hourly, minute) chart once data becomes available, but the problem will remain if the user will want to view hourly data for some Friday and the following Monday.
After much playing around with various options, I ended up using the CategoryAxis instead of DateTimeAxis. It treats each day as a category without inferring the relationship between the days.
The data can still be kept as DateTime objects for any necessary calculations and you just have to worry about the ToString (that's what CategoryAxis to label each category). Or just throw them all in as strings - technically calculations are done on the data points, not the array of dates so not much of a loss here...
If you will plot candlestick or ohlc you can't go with toolkit (you can but it will be VERY unpleasant) if you are open to use component use visifire's the one you may go. if you can't figure it out with that send a sample code please.
Completely off the top of my head, so I'm not sure how feasible this would be, but could you possibly set up a value converter on the Width property of the data point that would return "Auto" on a weekday and 0 for a weekend?

Resources