|
| 1 | +import os |
| 2 | +import pandas as pd |
| 3 | +import sys |
| 4 | +import numpy as np |
| 5 | +from .constants import * |
| 6 | +from .io import * |
| 7 | + |
| 8 | +__all__ = ['WeatherData'] |
| 9 | + |
| 10 | +SeeingFile = os.path.join(example_data_dir, 'SeeingPachon.txt') |
| 11 | +CloudFile = os.path.join(example_data_dir, 'CloudTololo.txt') |
| 12 | + |
| 13 | +class WeatherData(object): |
| 14 | + """ |
| 15 | + Class to provide Seeing and Cloud fraction as a function of time. |
| 16 | + """ |
| 17 | + def __init__(self, |
| 18 | + seeingHistory, |
| 19 | + cloudHistory, |
| 20 | + startDate=None, |
| 21 | + endDate=None): |
| 22 | + """ |
| 23 | + Parameters |
| 24 | + ---------- |
| 25 | + SeeingHistory : `pandas.DataFrame` with the following columns |
| 26 | + 'days', |
| 27 | + CloudHistory: |
| 28 | + """ |
| 29 | + |
| 30 | + self.cloudHistory = None |
| 31 | + self.seeingHistory = seeingHistory |
| 32 | + self.startDate = startDate |
| 33 | + |
| 34 | + @classmethod |
| 35 | + def fromTxtFiles(cls, |
| 36 | + SeeingTxtFile=SeeingFile, |
| 37 | + CloudTxtFile=CloudFile): |
| 38 | + """ |
| 39 | + build the class from txt files that are being used in OpSim |
| 40 | +
|
| 41 | + Parameters |
| 42 | + ---------- |
| 43 | +
|
| 44 | + Returns |
| 45 | + ------- |
| 46 | + """ |
| 47 | + seeingHistory = pd.read_csv(SeeingTxtFile, delim_whitespace=True) |
| 48 | + stripLeadingPoundFromHeaders(seeingHistory) |
| 49 | + |
| 50 | + # seeingHistory.rename(columns={seeingHistory.columns[0]: |
| 51 | + # seeingHistory.columns[0][1:]}, |
| 52 | + # inplace=True) |
| 53 | + |
| 54 | + seeingHistory['days'] = seeingHistory['s_date'] / DAY_IN_SEC |
| 55 | + seeingColNames = ['days', 'seeing'] |
| 56 | + |
| 57 | + cloudHistory = pd.read_csv(CloudTxtFile, delim_whitespace=True) |
| 58 | + stripLeadingPoundFromHeaders(cloudHistory) |
| 59 | + |
| 60 | + cloudHistory['days'] = cloudHistory['c_date'] / DAY_IN_SEC |
| 61 | + cloudHistory.rename(columns={'cloud', 'cloudFraction'}, inplace=True) |
| 62 | + cloudColNames = ['days', 'cloud'] |
| 63 | + |
| 64 | + return cls(seeingHistory=seeingHistory[seeingColNames], |
| 65 | + cloudHistory=cloudHistory) |
| 66 | + |
| 67 | + def seeing(self, times, startDate=None, method='linearInterp'): |
| 68 | + """ |
| 69 | + """ |
| 70 | + if startDate is None: |
| 71 | + startDate = self.startDate |
| 72 | + if startDate is None: |
| 73 | + raise ValueError('startDate must be provided as an attribute or\ |
| 74 | + as a parameter to the method\n') |
| 75 | + |
| 76 | + native_times = self.seeingHistory.days.values - startDate |
| 77 | + native_seeing = self.seeingHistory.seeing.values |
| 78 | + |
| 79 | + if method == 'linearInterp': |
| 80 | + return np.interp(times, native_times, native_seeing, period=max(native_times)) |
| 81 | + else: |
| 82 | + raise ValueError('method not implemented \n') |
| 83 | + |
0 commit comments