OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

time stamps not calculated correctly

  • Thread starter Thread starter naiyaluna
  • Start date Start date
N

naiyaluna

Guest
I am trying to plot displacement (y axis) against time- a years worth of data and showing every hour on the x axis. My time, for some reason, is just not coming through the script correctly. My min and max of time are the same negatuve value. I will include my script below- if there are any ideas, please let me know.

Code:
#changing to HOURS instead of minutes
rawTime = pd.to_datetime(data.iloc[3:, 0], format='%Y/%m/%d %H:%M', errors='coerce')
#deltaTime = (rawTime - rawTime.iloc[0]).astype(np.int64) / (1e9 * 3600)

# Remove any NaN values that resulted from the conversion
raw_time = rawTime.dropna().reset_index(drop=True)

# Calculate deltaTime in hours from the first timestamp
deltaTime = (raw_time - raw_time.iloc[0]).astype('timedelta64[h]')
deltaTime = deltaTime.reset_index(drop=True).rename('Time')

print(deltaTime)

#name generation for instruments- only going up to 29 because after that it is all NAN
names = ["GeoFlex" + str(i) for i in range(1,29,1)]

#pulling indexed data- this is from Myra
tiltX = data.iloc[4:57447, range(6, 118, 4)].set_axis([names], axis="columns")
tiltY = data.iloc[4:57447, range(7, 119, 4)].set_axis([names], axis="columns")

#removing NaN values without changing index
tiltXWithoutNaN = tiltX.join(deltaTime).dropna().astype(float)
tiltYWithoutNaN = tiltY.join(deltaTime).dropna().astype(float)

# Renaming the deltaTime Series to avoid column name conflicts-ChatGPT
deltaTime = deltaTime.reset_index(drop=True).rename('Time')

#calculations for displacement (equations provided by GeoFlex documentation)
displacementMagnitudeX = (tiltXWithoutNaN.iloc[:,0:30]*0.6).diff(axis=0).dropna().join(deltaTime).rename(columns={"Column1":"Time"})
displacementMagnitudeY = (tiltYWithoutNaN.iloc[:,0:30]*0.6).diff(axis=0).dropna().join(deltaTime).rename(columns={"Column1":"Time"})

# Calculating displacementTotal using Pythagorean theorem
displacementTotal = pd.DataFrame(np.sqrt((
        abs(displacementMagnitudeX.iloc[:, 0:30])**2) + (
        abs(displacementMagnitudeY.iloc[:, 0:30])**2)))

#extracting time- Chat GPT 
time_column = displacementMagnitudeX['Time']

# Adding the 'Time' column directly to the result
displacementTotal['Time'] = time_column.values

#some good ol pythagorean- keep this tagged, didn't work previously 
#displacementTotal = pd.DataFrame(np.sqrt((
       # abs(displacementMagnitudeX.iloc[:,0:30])**2)+(
       # abs(displacementMagnitudeY.iloc[:,0:30])**2))).join(deltaTime).rename(columns={"Column1":"Time"})

#plotting
plt.rcParams.update({'font.size': 7})
fig = plt.figure(layout='constrained')
spec = fig.add_gridspec(2,2)

#plot1
ax3 = fig.add_subplot(spec[0,:])
ax3.plot(displacementTotal.iloc[:,29],displacementTotal.iloc[:,0:5], ls=':', linewidth='0.7')
ax3.axis([0,9000,0,1])
ax3.set_xlabel("Time[hours]")
ax3.set_ylabel("Magnitude of Displacement of Sensor [mm]")
ax3.set_title("Fig 1: Seismogram")

I am trying to keep displacement values aligned with time and it just isn't working
<p>I am trying to plot displacement (y axis) against time- a years worth of data and showing every hour on the x axis. My time, for some reason, is just not coming through the script correctly. My min and max of time are the same negatuve value. I will include my script below- if there are any ideas, please let me know.</p>
<pre><code>#changing to HOURS instead of minutes
rawTime = pd.to_datetime(data.iloc[3:, 0], format='%Y/%m/%d %H:%M', errors='coerce')
#deltaTime = (rawTime - rawTime.iloc[0]).astype(np.int64) / (1e9 * 3600)

# Remove any NaN values that resulted from the conversion
raw_time = rawTime.dropna().reset_index(drop=True)

# Calculate deltaTime in hours from the first timestamp
deltaTime = (raw_time - raw_time.iloc[0]).astype('timedelta64[h]')
deltaTime = deltaTime.reset_index(drop=True).rename('Time')

print(deltaTime)

#name generation for instruments- only going up to 29 because after that it is all NAN
names = ["GeoFlex" + str(i) for i in range(1,29,1)]

#pulling indexed data- this is from Myra
tiltX = data.iloc[4:57447, range(6, 118, 4)].set_axis([names], axis="columns")
tiltY = data.iloc[4:57447, range(7, 119, 4)].set_axis([names], axis="columns")

#removing NaN values without changing index
tiltXWithoutNaN = tiltX.join(deltaTime).dropna().astype(float)
tiltYWithoutNaN = tiltY.join(deltaTime).dropna().astype(float)

# Renaming the deltaTime Series to avoid column name conflicts-ChatGPT
deltaTime = deltaTime.reset_index(drop=True).rename('Time')

#calculations for displacement (equations provided by GeoFlex documentation)
displacementMagnitudeX = (tiltXWithoutNaN.iloc[:,0:30]*0.6).diff(axis=0).dropna().join(deltaTime).rename(columns={"Column1":"Time"})
displacementMagnitudeY = (tiltYWithoutNaN.iloc[:,0:30]*0.6).diff(axis=0).dropna().join(deltaTime).rename(columns={"Column1":"Time"})

# Calculating displacementTotal using Pythagorean theorem
displacementTotal = pd.DataFrame(np.sqrt((
abs(displacementMagnitudeX.iloc[:, 0:30])**2) + (
abs(displacementMagnitudeY.iloc[:, 0:30])**2)))

#extracting time- Chat GPT
time_column = displacementMagnitudeX['Time']

# Adding the 'Time' column directly to the result
displacementTotal['Time'] = time_column.values

#some good ol pythagorean- keep this tagged, didn't work previously
#displacementTotal = pd.DataFrame(np.sqrt((
# abs(displacementMagnitudeX.iloc[:,0:30])**2)+(
# abs(displacementMagnitudeY.iloc[:,0:30])**2))).join(deltaTime).rename(columns={"Column1":"Time"})

#plotting
plt.rcParams.update({'font.size': 7})
fig = plt.figure(layout='constrained')
spec = fig.add_gridspec(2,2)

#plot1
ax3 = fig.add_subplot(spec[0,:])
ax3.plot(displacementTotal.iloc[:,29],displacementTotal.iloc[:,0:5], ls=':', linewidth='0.7')
ax3.axis([0,9000,0,1])
ax3.set_xlabel("Time[hours]")
ax3.set_ylabel("Magnitude of Displacement of Sensor [mm]")
ax3.set_title("Fig 1: Seismogram")
</code></pre>
<p>I am trying to keep displacement values aligned with time and it just isn't working</p>
 

Latest posts

Online statistics

Members online
0
Guests online
2
Total visitors
2
Top