• 潮差


    import eofs
    from eofs.standard import Eof
    import pandas as pd
    import numpy as np
    import glob
    import datetime
    from matplotlib import pyplot as plt
    import copy
    import re
    import time
    from pylab import *
    import matplotlib.dates as mdate
    import matplotlib.patches as patches
    import matplotlib.ticker as ticker
    import xarray as ax
    import copy
    import geopandas as gpd
    from pykrige.ok import OrdinaryKriging
    from pykrige.kriging_tools import write_asc_grid
    import pykrige.kriging_tools as kt
    from matplotlib.colors import LinearSegmentedColormap
    from matplotlib.patches import Path, PathPatch
    from shapely.geometry import LineString
    from cartopy.mpl.ticker import LongitudeFormatter, LatitudeFormatter
    from cartopy.mpl.ticker import LongitudeFormatter, LatitudeFormatter
    from sklearn.linear_model import LinearRegression
    import heapq
    from typing import *

    time_parse1 = lambda date: datetime.datetime.strptime(date, '%Y/%m/%d %H:%M')

    df = pd.read_csv('./water_level_nanmen_1.csv',parse_dates=['date'],date_parser=time_parse1,encoding='utf-8')
    print(df)
    helper = pd.DataFrame({'date': pd.date_range(df['date'].min(), df['date'].max(), freq='5T')})
    df1 = pd.merge(df,helper,on = 'date',how='outer').sort_values('date')
    df1.reset_index(drop=True,inplace=True)
    time_1 = pd.Series(list(df1['date']))

    dt =list(copy.deepcopy(df1['water_level']))
    dy = pd.Series(dt,index=time_1)
    dy= dy.resample('5T').mean()
    dy1 =dy.interpolate(method='spline', order=3)
    # # print(dy1)
    dty = pd.DataFrame(dy1,columns=['water_level'])
    dty.to_csv('./nanmen_five.csv')
    wt = dty['water_level']


    df = pd.DataFrame({'B': [-10, 1, 2, 5, 4]},
    index = [pd.Timestamp('20130101 09:00:00'),
    pd.Timestamp('20130101 09:00:02'),
    pd.Timestamp('20130101 09:00:03'),
    pd.Timestamp('20130101 09:00:05'),
    pd.Timestamp('20130101 09:00:06')])

    class Solution:
    def minSlidingWindow(self, nums: List[int], k: int) -> List[int]:
    n = len(nums)
    # 注意 Python 默认的优先队列是小根堆
    # 将数组中的元素取反 5 -> -5 1 -> -1;此时:-5 < -1;5就可以排到1上面了。
    q = [(nums[i], i) for i in range(k)]
    heapq.heapify(q)
    ans1 = [q[0][0]]
    # print(ans)
    for i in range(k, n):
    heapq.heappush(q, (nums[i], i)) #右移一个
    #不断地移除堆顶的元素,直到堆顶的元素确实出现在滑动窗口中
    while q[0][1] <= i - k:
    heapq.heappop(q)
    ans1.append(q[0][0])

    return ans1

    def maxSlidingWindow(self, nums: List[int], k: int) -> List[int]:
    n = len(nums)
    # 注意 Python 默认的优先队列是小根堆
    # 将数组中的元素取反 5 -> -5 1 -> -1;此时:-5 < -1;5就可以排到1上面了。
    q = [(-nums[i], i) for i in range(k)]
    heapq.heapify(q)

    ans = [-q[0][0]]
    for i in range(k, n):
    heapq.heappush(q, (-nums[i], i)) # 右移一个
    # 不断地移除堆顶的元素,直到堆顶的元素确实出现在滑动窗口中
    while q[0][1] <= i - k:
    heapq.heappop(q)
    ans.append(-q[0][0])

    return ans



    #
    ans1 = Solution()
    # # nums = input()
    # # nums = [int(i) for i in nums.split()]
    # # k = int(input())
    # nums = [1,3,-1,-3,5,3,6,7]
    # k = 3
    # nums = df['B']
    # k= 2

    nums = wt
    k =324

    # print(k)
    # print(nums)

    tu = pd.Series(ans1.minSlidingWindow(nums,k))
    ti= pd.Series(ans1.maxSlidingWindow(nums,k))
    tp = ti-tu
    tpo = pd.DataFrame(tp)
    tpo.to_csv('./142.csv')





  • 相关阅读:
    zhcon安装过程记录
    diff和patch配合使用(转载备用)
    Linux /etc/passwd 和 /etc/group 文件格式
    APT 常用功能
    Linux邮件服务器架构
    出现segment fault 错误的几种原因
    位运算
    Linux启动过程中几个重要配置文件的执行过程
    2016-2017 ACM-ICPC, South Pacific Regional Contest (SPPC 16)
    Codeforces Round #439 (Div. 2) 题解
  • 原文地址:https://www.cnblogs.com/chenyun-delft3d/p/14688202.html
Copyright © 2020-2023  润新知