|
10 | 10 | * Property: European Space Agency (ESA)
|
11 | 11 | * Developed by: Elecnor Deimos
|
12 | 12 | * Author: C. Álvaro Arroyo Parejo
|
13 |
| -* Issue: 1.4.0 |
14 |
| -* Date: 02-11-2021 |
| 13 | +* Issue: 2.1.0 |
| 14 | +* Date: 01-03-2021 |
15 | 15 | * Purpose: Module which request and parse list data from ESA NEOCC
|
16 | 16 | * Module: tabs.py
|
17 | 17 | * History:
|
|
48 | 48 | Orb_type attribute added in tab *orbit_properties*.\n
|
49 | 49 | Bug fix in tab *observations*.\n
|
50 | 50 | Adding redundancy for tab *summary* parsing.
|
| 51 | +2.0.0 21-01-2022 Prepare module for Astroquery integration |
| 52 | +2.1.0 01-03-2022 Remove *parse* dependency |
51 | 53 | ======== =========== =====================================================
|
52 | 54 |
|
53 |
| -© Copyright [European Space Agency][2021] |
| 55 | +© Copyright [European Space Agency][2022] |
54 | 56 | All rights reserved
|
55 | 57 | """
|
56 | 58 |
|
|
60 | 62 | import re
|
61 | 63 | from datetime import datetime, timedelta
|
62 | 64 | import pandas as pd
|
63 |
| -from parse import parse |
64 | 65 | import requests
|
65 | 66 | from bs4 import BeautifulSoup
|
66 | 67 | from astroquery.esa.neocc import conf
|
@@ -299,16 +300,21 @@ def _get_footer(data_obj):
|
299 | 300 |
|
300 | 301 | # Drop NaN values if necessary
|
301 | 302 | df_txt = df_txt.dropna(how='all')
|
302 |
| - # Template for observations data |
303 |
| - parse_txt_obs = "Based on {total} optical observations "\ |
304 |
| - "(of which {rejected} are rejected as "\ |
305 |
| - "outliers)" |
306 |
| - # Parse required data for attributes |
307 |
| - obs = parse(parse_txt_obs, df_txt.iloc[-7-j][0].split(' and')[0]) |
308 |
| - # Template for date of observations |
309 |
| - parse_txt_arc = 'from {start} to {end}.' |
310 |
| - # Parse required data for attributes |
311 |
| - arc = parse(parse_txt_arc, df_txt.iloc[-6-j][0]) |
| 303 | + # Template for observations data: |
| 304 | + # Based on {total} optical observations (of which {rejected} |
| 305 | + # are rejected as outliers) |
| 306 | + obs_total = df_txt.iloc[-7-j][0].split('on ')[1].\ |
| 307 | + split('optical')[0].strip() |
| 308 | + obs_rejected = df_txt.iloc[-7-j][0].split('which ')[1].\ |
| 309 | + split('are')[0].strip() |
| 310 | + obs = [obs_total, obs_rejected] |
| 311 | + # Template for date of observations: from {start} to {end}. |
| 312 | + arc_start = df_txt.iloc[-6-j][0].split('from ')[1].\ |
| 313 | + split('to ')[0].strip() |
| 314 | + arc_end = df_txt.iloc[-6-j][0].split('to ')[1].\ |
| 315 | + split('.')[0] + '.' + df_txt.iloc[-6-j][0].\ |
| 316 | + split('to ')[1].split('.')[1] |
| 317 | + arc = [arc_start, arc_end] |
312 | 318 | # Computation date
|
313 | 319 | comp = df_txt.iloc[-1-j][0].split('=')[2].strip()
|
314 | 320 | # Get information text
|
@@ -732,29 +738,21 @@ def _get_head_obs(df_d):
|
732 | 738 | Root Mean Square for magnitude.
|
733 | 739 | """
|
734 | 740 | df_head = pd.read_csv(df_d, nrows=4, header=None)
|
735 |
| - # Template for version |
736 |
| - parse_ver = 'version = {ver}' |
737 |
| - # Parse required data for attributes |
738 |
| - ver = parse(parse_ver, df_head[0][0]) |
739 |
| - ver = float(ver['ver']) |
740 |
| - # Template for errmod |
741 |
| - parse_err = "errmod = '{err}'" |
742 |
| - # Parse required data for attributes |
743 |
| - err = parse(parse_err, df_head[0][1]) |
744 |
| - err = err['err'] |
745 |
| - # Template for RMSast |
746 |
| - parse_ast = "RMSast = {ast}" |
747 |
| - # Parse required data for attributes |
748 |
| - ast = parse(parse_ast, df_head[0][2]) |
749 |
| - ast = float(ast['ast']) |
750 |
| - # Template for RMSast |
751 |
| - parse_mag = "RMSmag = {mag}" |
752 |
| - # Parse required data for attributes |
753 |
| - mag = parse(parse_mag, df_head[0][3]) |
754 |
| - if mag is None: |
| 741 | + # Template for version: version = {ver} |
| 742 | + ver = df_head.iloc[0][0].split('=')[1].strip() |
| 743 | + ver = float(ver) |
| 744 | + # Template for errmod: errmod = '{err}' |
| 745 | + err = df_head.iloc[1][0].split("'")[1].strip() |
| 746 | + # Template for RMSast: RMSast = {ast} |
| 747 | + ast = df_head.iloc[2][0].split('=')[1].strip() |
| 748 | + ast = float(ast) |
| 749 | + # Template for RMSast: RMSmag = {mag} |
| 750 | + mag = df_head.iloc[3][0] |
| 751 | + if mag == 'END_OF_HEADER': |
755 | 752 | mag = 'No data for RMSmag'
|
756 | 753 | else:
|
757 |
| - mag = float(mag['mag']) |
| 754 | + mag = float(df_head.iloc[3][0].split('=')[1].strip()) |
| 755 | + |
758 | 756 |
|
759 | 757 | return ver, err, ast, mag
|
760 | 758 |
|
@@ -1351,23 +1349,16 @@ def _get_head_orb(data_obj):
|
1351 | 1349 | df_info_d = io.StringIO(data_obj.decode('utf-8'))
|
1352 | 1350 | # Read as txt file
|
1353 | 1351 | df_info = pd.read_fwf(df_info_d, nrows=3, header=None)
|
1354 |
| - # Template for format data |
1355 |
| - parse_format = "format = '{format}' ! file format" |
1356 |
| - # Parse required data for attributes |
1357 |
| - format_txt = parse(parse_format, df_info.iloc[0][0]) |
1358 |
| - form = format_txt['format'] |
1359 |
| - # Template for record type |
1360 |
| - parse_rectype = "rectype = '{rectype}' !"\ |
1361 |
| - " record type (1L/ML)" |
1362 |
| - # Parse required data for attributes |
1363 |
| - rectype = parse(parse_rectype, df_info.iloc[1][0]) |
1364 |
| - rectype = rectype['rectype'] |
1365 |
| - # Template for reference system |
1366 |
| - parse_refsys = "refsys = {refsys} !"\ |
1367 |
| - " default reference system" |
1368 |
| - # Parse required data for attributes |
1369 |
| - refsys = parse(parse_refsys, df_info.iloc[2][0]) |
1370 |
| - refsys = refsys['refsys'] |
| 1352 | + # Template for format data: |
| 1353 | + # format = '{format}' ! file format |
| 1354 | + format_txt = df_info.iloc[0][0].split("'")[1].strip() |
| 1355 | + form = format_txt |
| 1356 | + # Template for record type: |
| 1357 | + # rectype = '{rectype}' ! record type (1L/ML) |
| 1358 | + rectype = df_info.iloc[1][0].split("'")[1].strip() |
| 1359 | + # Template for reference system: |
| 1360 | + # refsys = {refsys} ! default reference system" |
| 1361 | + refsys = df_info.iloc[2][0].split("=")[1].split("!")[0].strip() |
1371 | 1362 |
|
1372 | 1363 | return form, rectype, refsys
|
1373 | 1364 |
|
@@ -1827,26 +1818,17 @@ def _get_head_ephem(data_obj):
|
1827 | 1818 | """
|
1828 | 1819 | data_d = io.StringIO(data_obj.decode('utf-8'))
|
1829 | 1820 | head_ephe = pd.read_fwf(data_d, nrows=5, header=None)
|
1830 |
| - # Template for observatory |
1831 |
| - parse_obs = 'Observatory: {observatory}' |
1832 |
| - # Parse required data for attributes |
1833 |
| - obs = parse(parse_obs, head_ephe[0][1]) |
1834 |
| - obs = obs['observatory'] |
1835 |
| - # Template for initial date |
1836 |
| - parse_idate = 'Initial Date: {init_date}' |
1837 |
| - # Parse required data for attributes |
1838 |
| - idate = parse(parse_idate, head_ephe[0][2]) |
1839 |
| - idate = idate['init_date'] |
1840 |
| - # Template for initial date |
1841 |
| - parse_fdate = 'Final Date: {final_date}' |
1842 |
| - # Parse required data for attributes |
1843 |
| - fdate = parse(parse_fdate, head_ephe[0][3]) |
1844 |
| - fdate = fdate['final_date'] |
1845 |
| - # Template for initial date |
1846 |
| - parse_step = 'Time step: {step}' |
1847 |
| - # Parse required data for attributes |
1848 |
| - tstep = parse(parse_step, head_ephe[0][4]) |
1849 |
| - tstep = tstep['step'] |
| 1821 | + # Template for observatory: Observatory: {observatory} |
| 1822 | + obs = head_ephe.iloc[1][0].split(':')[1].strip() |
| 1823 | + # Template for initial date: Initial Date: {init_date} |
| 1824 | + idate = head_ephe.iloc[2][0].split(':')[1].strip() + ':' +\ |
| 1825 | + head_ephe.iloc[2][0].split(':')[2].strip() |
| 1826 | + # Template for initial date: Final Date: {final_date} |
| 1827 | + fdate = head_ephe.iloc[3][0].split(':')[1].strip() + ':' +\ |
| 1828 | + head_ephe.iloc[3][0].split(':')[2].strip() |
| 1829 | + # Template for initial date: Time step: {step} |
| 1830 | + tstep = head_ephe.iloc[4][0].split(':')[1].strip() |
| 1831 | + |
1850 | 1832 |
|
1851 | 1833 | return obs, idate, fdate, tstep
|
1852 | 1834 |
|
|
0 commit comments