Skip to content

Commit 8f8804b

Browse files
committed
Added code to be able to interpolate both seeing and cloud data
modified: .gitignore modified to keep ipython_notebook_checkpoints out of examples modified: obscond/__init__.py for new imports new file: MANIFEST.in new file: obscond/constants.py package wide constants new file: obscond/historicalWeatherData.py contains code to use historical data to provide interpolated values of seeing and cloud fraction new file: obscond/io.py Helper module for io modified: setup.py Added statements
1 parent cf8d402 commit 8f8804b

File tree

7 files changed

+118
-2
lines changed

7 files changed

+118
-2
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,4 @@ target/
6060

6161
#Ipython Notebook
6262
.ipynb_checkpoints
63+
examples/.ipynb_checkpoints

MANIFEST.in

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
include example_data/*.md
2+
include example_data/*.txt
3+

obscond/__init__.py

+6
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
11
import palpy as pal
2+
import os
3+
from .io import *
4+
from .historicalWeatherData import *
5+
from .constants import *
26
#from .version import __version__
7+
dirname = os.path.dirname(os.path.abspath(__file__))
8+
example_data_dir = os.path.join(dirname, 'example_data')

obscond/constants.py

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import os
2+
__all__ = ['example_data_dir', 'DAY_IN_SEC']
3+
dirname = os.path.dirname(os.path.abspath(__file__))
4+
example_data_dir = os.path.join(dirname, 'example_data')
5+
DAY_IN_SEC = 24.0 * 60. * 60

obscond/historicalWeatherData.py

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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+

obscond/io.py

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
__all__=['stripLeadingPoundFromHeaders']
3+
4+
def stripLeadingPoundFromHeaders(df):
5+
"""
6+
on using `pandas.read_csv` on csv files with the header commented out with
7+
a '#', The '#' is often added to the name of the the first column. This
8+
function removes this pound in place.
9+
10+
Parameters
11+
----------
12+
df : `pandas.dataFrame`
13+
14+
Returns
15+
-------
16+
None
17+
"""
18+
df.rename(columns={df.columns[0]:df.columns[0][1:]}, inplace=True)

setup.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
# Assign to __version__
1616
__version__ = versionRegExp.findall(s)[0]
1717

18-
setup(name='ObsCond',
18+
setup(name='obscond',
1919
version=__version__,
2020
description='Interpolating Observing Conditions from historic data',
2121
packages=['obscond'],
2222
package_dir={'obscond': 'obscond'},
23-
package_data={'obscond': ['obscond/example_data/*.txt', 'obscond/example_data/*.md']},
23+
package_data={'obscond': ['example_data/*.txt', 'example_data/*.md']},
2424
include_package_data=True
2525
)

0 commit comments

Comments
 (0)