amp_mask_template_creator.py 1.5 KB

1234567891011121314151617181920212223242526272829
  1. import datetime
  2. import time
  3. import pandas as pd
  4. import numpy as np
  5. def amp_mask_template_creator(cluster, year, path_to_mask):
  6. """Создание excel файла за год, в котором прописывается шаблон амплитудной маски."""
  7. with pd.ExcelWriter(f'{path_to_mask}\\{cluster}cl_amp_mask_{year}.xlsx') as writer:
  8. for period in pd.period_range(start=datetime.date(year, 1, 1), end=datetime.date(year, 12, 31), freq='M'):
  9. start_month = datetime.date(period.year, period.month, 1)
  10. end_month = datetime.date(period.year + int(period.month / 12), ((period.month % 12) + 1),
  11. 1) - datetime.timedelta(days=1)
  12. daterange = [single_date.date() for single_date in pd.date_range(start_month, end_month)]
  13. amp_template = np.ones((len(daterange), 16))
  14. mask_amp = pd.DataFrame(amp_template.astype(int),
  15. columns=[f'amp{i}_mask' for i in range(1, 17)])
  16. mask_amp['date'] = daterange
  17. mask_amp = mask_amp[['date'] + [f'amp{i}_mask' for i in range(1, 17)]]
  18. mask_amp.to_excel(writer, sheet_name=str(period), index=False)
  19. if __name__ == "__main__":
  20. t1 = time.time_ns()
  21. amp_mask_template_creator(cluster=1, year=2022,
  22. path_to_mask="C:\\Users\\pad_z\\OneDrive\\Рабочий стол\\PrismaPassport\\amp_mask")
  23. print(f'time - {(time.time_ns() - t1) / 1e9}')