Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add -Fe for step-up sampling in sample1d #7488

Merged
merged 9 commits into from Jun 2, 2023
Merged

Add -Fe for step-up sampling in sample1d #7488

merged 9 commits into from Jun 2, 2023

Conversation

PaulWessel
Copy link
Member

See the forum post for details. This interpolator keeps the previous value until we pass a new input node and then we step up to that value.

@Esteban82, I think this reproduces your example but I do not know if it is generally correct since I only tested it on yours.

See the forum post for details.  This interpolator keeps the previous value until we pass a new input node and then we step up to that value.
@PaulWessel PaulWessel added the new feature PR that implements a new feature or capability in GMT label Jun 1, 2023
@PaulWessel PaulWessel added this to the 6.5.0 milestone Jun 1, 2023
@PaulWessel PaulWessel requested a review from Esteban82 June 1, 2023 21:15
@PaulWessel PaulWessel self-assigned this Jun 1, 2023
@@ -1358,8 +1358,8 @@ GMT_LOCAL bool gmtsupport_is_penstyle (char *word) {
if (n == 0) return (false);

if (!strncmp (word, "dotdash", 7U) || !strncmp (word, "dashdot", 7U) \
|| !strncmp (word, "dash", 4U) || !strncmp (word, "dot", 3U) \
|| !strncmp (word, "solid", 5U)) return (true);
|| !strncmp (word, "dash", 4U) || !strncmp (word, "dot", 3U) \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't replace those spaces by tabs. Using the spaces like that is the only way of keep the alignment with the first character after the parentesis.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, it was an auto think. I will fix it.

@@ -10323,7 +10338,7 @@ GMT_LOCAL unsigned int gmtsupport_contour_old_T_parser (struct GMT_CTRL *GMT, ch
}
else {
GMT_Report (GMT->parent, GMT_MSG_ERROR,
"Option -T: Give low and high labels either as :LH or :<low>,<high>.\n");
"Option -T: Give low and high labels either as :LH or :<low>,<high>.\n");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Likewise here and below.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did a few more but dont want to go over all of this manually. As you know I am not in favour of 80character screens so feel these break-the-line adds longer code and more opportunities for tab/space shits.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's has nothing to do about the the line width but only on a good alignment with above line. Tee price of indenting with tabs is that we must do a mix of tabs and spaces to keep that alignment.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want to revert some of these then no problem, go right ahead.

@Esteban82
Copy link
Member

Great Paul!! I test it. It works. But I found a bug when the input has two records

cat << EOF | gmt sample1d xy.txt -I1 -Fe
1	1
5   4
EOF
Output:
1       1
2       1
3       1
4       1
5       1

@PaulWessel
Copy link
Member Author

OK, I was checking for the first point first but need to do the end first, then first, then the rest. Now works, I think?

@Esteban82 Esteban82 merged commit 4944984 into master Jun 2, 2023
6 checks passed
@Esteban82 Esteban82 deleted the step-curve branch June 2, 2023 11:52
@Esteban82
Copy link
Member

I found a new issue.

cat << EOF | gmt sample1d -I2 -Fe -Am
1	1
3   3
7   4
EOF
output:
2       1
4       3
6       4   # here I would expect 3.

@Esteban82
Copy link
Member

With the GMT_Splines.sh also found some issues. Maybe the sames (see #7490).
Here is the figure.

GMT_splines

gmt sample1d t.txt -Fe -T0.5
0       0
0.5     0
1       1
1.5     1
2       1.25
2.5     1.25
3       1.25
3.5     1.25
4       1.5
4.5     2
5       2
5.5     2
6       2.5

@PaulWessel
Copy link
Member Author

-Fe requires monotonously increasing data but this data set is not that, so not an appropriate test

@Esteban82
Copy link
Member

Ok, I see. So, would I need to pre process my data with another tool?

@PaulWessel
Copy link
Member Author

Well, it only make sense for cumulative data since we step up

@Esteban82
Copy link
Member

In the case of the forum, yes, it is cumulative. But it might not be always the case specially with dates.

@PaulWessel
Copy link
Member Author

Perhaps you can give me some examples of how -Fe would work on regular data such as in GMT_splines.sh. I approached the problem as specific to cumulative data, or at least a monotonically increasing data set, but presumably we could do something similar for monotonically decreasing data. Not sure what expectation is for other data sets though.

@Esteban82
Copy link
Member

This is a simple animation that I want to make. Look at the labels.

Messi.mp4

When I interpolate the data (with sample1d -Fe) I got this table.
There are some issues:

  • Why the list doesn't start at 19-01 as in the dataset? It does if the first data is 2004-01-18.
  • In the last record says 5 ahead of time (14-Feb) when in the data table it says 16-Feb.

times.txt:

2004-01-21T00:00:00	1
2004-01-24T00:00:00	1
2004-01-27T00:00:00	1
2004-01-30T00:00:00	2
2004-02-02T00:00:00	2
2004-02-05T00:00:00	2
2004-02-08T00:00:00	2
2004-02-11T00:00:00	2
2004-02-14T00:00:00	5

Full script

#!/usr/bin/env bash
# Data
cat << EOF > Accumulated_Goals.txt
2004-01-19 1
2004-01-28 2
2004-02-16 5
EOF

gmt sample1d Accumulated_Goals.txt -fT --TIME_UNIT=d -I3 -Fe > times.txt

# 	2. Set up main script
cat << EOF > main.sh
gmt begin
	gmt basemap -Rd -JW24c -Bf -Y0 -X0
gmt end
EOF

gmt movie main.sh -Cfhd -Ttimes.txt -NMessi -Ml,png -Vi -Zs -Fmp4 -Lc0+jTR+o0.3/0.3+gwhite+h+r \
	-Lc1+jTL+o0.3/0.3+gwhite+h+r

@PaulWessel
Copy link
Member Author

I guess 19 is not a multiple of 3, but 21 is. Remember, you are stepping every 3 and nodes are always a multiple of the increment.

@Esteban82
Copy link
Member

I guess 19 is not a multiple of 3, but 21 is. Remember, you are stepping every 3 and nodes are always a multiple of the increment.

Ok, thanks, I didn't know that. Altough with dates it doesn't make much sense to have steps that are multiple of the increment.

@maxrjones maxrjones added the add-changelog Add PR to the changelog label Dec 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
add-changelog Add PR to the changelog new feature PR that implements a new feature or capability in GMT
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants