How to do a second interpolation in python

2024/11/15 0:28:00

I did my first interpolation with numpy.polyfit() and numpy.polyval() for 50 longitude values for a full satellite orbit.

Now, I just want to look at a window of 0-4.5 degrees longitude and do a second interpolation so that I have 6,000 points for longitude in the window.

I need to use the equation/curve from the first interpolation to create the second one because there is only one point in the window range. I'm not sure how to do the second interpolation.

Inputs:

lon = [-109.73105744378498, -104.28690174554579, -99.2435132929552, -94.48533149079628, -89.91054414962821, -85.42671400689177, -80.94616150449806, -76.38135021210172, -71.6402674905218, -66.62178379632216, -61.21120467960157, -55.27684029674759, -48.66970878028004, -41.23083703244677, -32.813881865289346, -23.332386757370532, -12.832819226213942, -1.5659455609661785, 10.008077792630402, 21.33116444634303, 31.92601575632583, 41.51883213364072, 50.04498630545507, 57.58103957109249, 64.26993028992476, 70.2708323505337, 75.73441871754586, 80.7944079829813, 85.56734813043659, 90.1558676264546, 94.65309120129724, 99.14730128118617, 103.72658922048785, 108.48349841714494, 113.51966824008079, 118.95024882101737, 124.9072309203375, 131.5395221402974, 139.00523971191907, 147.44847902856114, 156.95146022590976, 167.46163867248032, 178.72228750873975, -169.72898181991064, -158.44642409799974, -147.8993300787564, -138.35373014113995, -129.86955508919888, -122.36868103811106, -115.70852432245486]myOrbitJ2000Time = [ 20027712.,  20027713.,  20027714.,  20027715.,  20027716.,20027717.,  20027718.,  20027719.,  20027720.,  20027721.,20027722.,  20027723.,  20027724.,  20027725.,  20027726.,20027727.,  20027728.,  20027729.,  20027730.,  20027731.,20027732.,  20027733.,  20027734.,  20027735.,  20027736.,20027737.,  20027738.,  20027739.,  20027740.,  20027741.,20027742.,  20027743.,  20027744.,  20027745.,  20027746.,20027747.,  20027748.,  20027749.,  20027750.,  20027751.,20027752.,  20027753.,  20027754.,  20027755.,  20027756.,20027757.,  20027758.,  20027759.,  20027760.,  20027761.]

Code:

deg = 30 #polynomial degree for fit
fittime = myOrbitJ2000Time - myOrbitJ2000Time[0]'Longitude Interpolation'
fitLon = np.polyfit(fittime, lon, deg)   #gets fit coefficients
polyval_lon = np.polyval(fitLon,fittime) #interp.s to get actual values'Get Longitude values for a window of 0-4.5 deg Longitude'
lonwindow =[]for i in range(len(polyval_lon)):if 0 < polyval_lon[i] < 4.5:         # get lon vals in windowlonwindow.append(polyval_lon[i]) #append lon valslonwindow = np.array(lonwindow)
Answer

First, generate the polynomial fit coefficients using the old time (x-axis) values, and interpolated longitude (y-axis) values.

import numpy as np  
import matplotlib.pyplot as pltpoly_deg = 3 #degree of the polynomial fit
polynomial_fit_coeff = np.polyfit(original_times, interp_lon, poly_deg)

Next, use np.linspace() to generate arbitrary time values based on the number of desire points in the window.

start = 0
stop = 4
num_points = 6000
arbitrary_time = np.linspace(start, stop, num_points)

Finally, use the fit coefficients and the arbitrary time to get the actual interpolated longitude (y-axis) values and plot.

lon_intrp_2 = np.polyval(polynomial_fit_coeff, arbitrary_time)plt.plot(arbitrary_time, lon_intrp_2, 'r') #interpolated window as a red curve
plt.plot(myOrbitJ2000Time, lon, '.') #original data plotted as points
https://en.xdnf.cn/q/119336.html

Related Q&A

How can I filter an ms-access databse, using QSqlTableModel and QLineEdit?

Im building a GUI that allows users to search information in a ms access database (yup. It has to be the ms access) The user has a textfield where he can type his search and the Tableview should update…

Python regex - Replace single quotes and brackets

Id like to replace quantities with name then a square bracket and a single quote with the contents inside. So, from this: RSQ(name[BAKD DK], name[A DKJ])to this:RSQ(BAKD DK, A DKJ)

Python unexpected EOF while parsing (python2.7)

Heres my python code. Could someone show me whats wrong with it? I try to learn an algorithm on solving 24 - point game. But I really dont know why this program has an error.from __future__ import div…

Call a function in repl without brackets

Would like to know if there is a way to call a function in python in repl just with the function name. $ python -i interace.py >>> load 834.png >>> sharpen >>> saverather tha…

how to work on a exist session in selenium with python?

I want to fill some field of a webpage and then send a request to it but this website has a very powerful login page to avoid sending requests for login from a robot so I cant log in with selenium bu…

how to find similarity between many strings and plot it

I have a xls file with one column and 10000 strings I want to do few things 1- make a heatmap or a cluster figure shows the similarity percentage between each string with another one.In order to find …

Python and Variable Scope

So I am recently new to Python, but I seem to be able to program some stuff and get it working. However Ive been trying to expand my knowledge of how things work in the language, and putting this simp…

How to check if element is orthogonally adjacent (next to) to existing elements?

Im trying to make a simple game where a building placed in a nested list must be next to another building. The problem I face is that if the building was placed at the sides, I cant use for loops to ch…

How to add new column(header) to a csv file from command line arguments

The output of the following code:-import datetime import csv file_name=sample.txt with open(file_name,rb) as f: reader = csv.reader(f,delimiter=",") …

Pattern matching and replacing in Python

Im trying to take a string that can be anything like "Hello here is a [URL]www.url.com[/URL] and its great." and be able to extract whatever is between [URL] and [/URL] and then modify the st…