Last active
March 1, 2018 20:38
-
-
Save migueldvb/8aa5c1c192be0b6d29467b19724145e5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
from bs4 import BeautifulSoup | |
import requests | |
import pandas as pd | |
url = 'http://www.cadc-ccda.hia-iha.nrc-cnrc.gc.ca/cadcbin/ssos/ssosclf.pl?lang=en&object=7968&search=bynameCADC&epoch1=&epoch2=&eellipse=&eunits=arcseconds&extres=no&xyres=no' | |
html = requests.get(url) | |
soup = BeautifulSoup(html.content, 'html.parser') | |
table = soup.find_all('table')[0] | |
df = pd.read_html(str(table), header=0)[0] | |
# exclude WISE data | |
df = df[~(df['Telescope/Instrument'] == 'WISE')] | |
# convert to datetime objects | |
df['datetime'] = pd.to_datetime(df['Date/Time'], format="%Y-%m-%d %H:%M:%S") | |
# groupby UT day and aggregate | |
df = df.groupby([df['datetime'].dt.date]).agg({'Exptime': ['sum', 'count'], | |
'Telescope/Instrument': 'unique', | |
'Filter': 'unique', | |
'Image target': 'unique' | |
}).reset_index() | |
# flatten column hierarchy | |
df.columns = [' '.join(col).strip() for col in df.columns.values] | |
# cut on exposure time | |
df = df[(df['Exptime sum'] > 3600) & (df['Exptime count'] >= 5)] | |
pd.options.display.width = 500 | |
print(df) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output