|
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 |
| -======== =========== ===================================================== |
| 51 | +2.0.0 21-01-2022 Prepare module for Astroquery integration |
| 52 | +2.1.0 01-03-2022 Remove *parse* dependency |
52 | 53 |
|
53 |
| -© Copyright [European Space Agency][2021] |
| 54 | +© Copyright [European Space Agency][2022] |
54 | 55 | All rights reserved
|
55 | 56 | """
|
56 | 57 |
|
|
60 | 61 | import re
|
61 | 62 | from datetime import datetime, timedelta
|
62 | 63 | import pandas as pd
|
63 |
| -from parse import parse |
64 | 64 | import requests
|
65 | 65 | from bs4 import BeautifulSoup
|
66 | 66 | from astroquery.esa.neocc import conf
|
@@ -299,16 +299,21 @@ def _get_footer(data_obj):
|
299 | 299 |
|
300 | 300 | # Drop NaN values if necessary
|
301 | 301 | 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]) |
| 302 | + # Template for observations data: |
| 303 | + # Based on {total} optical observations (of which {rejected} |
| 304 | + # are rejected as outliers) |
| 305 | + obs_total = df_txt.iloc[-7-j][0].split('on ')[1].\ |
| 306 | + split('optical')[0].strip() |
| 307 | + obs_rejected = df_txt.iloc[-7-j][0].split('which ')[1].\ |
| 308 | + split('are')[0].strip() |
| 309 | + obs = [obs_total, obs_rejected] |
| 310 | + # Template for date of observations: from {start} to {end}. |
| 311 | + arc_start = df_txt.iloc[-6-j][0].split('from ')[1].\ |
| 312 | + split('to ')[0].strip() |
| 313 | + arc_end = df_txt.iloc[-6-j][0].split('to ')[1].\ |
| 314 | + split('.')[0] + '.' + df_txt.iloc[-6-j][0].\ |
| 315 | + split('to ')[1].split('.')[1] |
| 316 | + arc = [arc_start, arc_end] |
312 | 317 | # Computation date
|
313 | 318 | comp = df_txt.iloc[-1-j][0].split('=')[2].strip()
|
314 | 319 | # Get information text
|
@@ -429,18 +434,18 @@ def _impacts_parser(self, data_obj):
|
429 | 434 | footer = self._get_footer(data_obj)
|
430 | 435 | # Assign parsed data to attributes
|
431 | 436 | # Change format to datetime and show in isoformat()
|
432 |
| - arc_start = footer[1]['start'].split('.') |
| 437 | + arc_start = footer[1][0].split('.') |
433 | 438 | arc_start = datetime.strptime(arc_start[0], '%Y/%m/%d') +\
|
434 | 439 | timedelta(float(arc_start[1])/1e3)
|
435 | 440 | self.arc_start = arc_start.isoformat()
|
436 | 441 | # Change format to datetime and show in isoformat()
|
437 |
| - arc_end = footer[1]['end'].split('.') |
| 442 | + arc_end = footer[1][1].split('.') |
438 | 443 | arc_end = datetime.strptime(arc_end[0], '%Y/%m/%d') +\
|
439 | 444 | timedelta(float(arc_end[1])/1e3)
|
440 | 445 | self.arc_end = arc_end.isoformat()
|
441 |
| - self.observation_accepted = int(footer[0]['total']) - \ |
442 |
| - int(footer[0]['rejected']) |
443 |
| - self.observation_rejected = int(footer[0]['rejected']) |
| 446 | + self.observation_accepted = int(footer[0][0]) - \ |
| 447 | + int(footer[0][1]) |
| 448 | + self.observation_rejected = int(footer[0][1]) |
444 | 449 | self.computation = footer[2]
|
445 | 450 | self.additional_note = footer[4]
|
446 | 451 | # Assign info text from pandas
|
@@ -614,7 +619,6 @@ def _phys_prop_parser(self, data_obj):
|
614 | 619 | # Initialize index
|
615 | 620 | index = 0
|
616 | 621 | if len(df_check.columns) > 4:
|
617 |
| - # rest = len(df_check.columns) - 4 |
618 | 622 | # Iterate over each element in last col to find
|
619 | 623 | # rows with additional elements separated by commas
|
620 | 624 | for element in df_check.iloc[:, -1]:
|
@@ -732,29 +736,21 @@ def _get_head_obs(df_d):
|
732 | 736 | Root Mean Square for magnitude.
|
733 | 737 | """
|
734 | 738 | 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: |
| 739 | + # Template for version: version = {ver} |
| 740 | + ver = df_head.iloc[0][0].split('=')[1].strip() |
| 741 | + ver = float(ver) |
| 742 | + # Template for errmod: errmod = '{err}' |
| 743 | + err = df_head.iloc[1][0].split("'")[1].strip() |
| 744 | + # Template for RMSast: RMSast = {ast} |
| 745 | + ast = df_head.iloc[2][0].split('=')[1].strip() |
| 746 | + ast = float(ast) |
| 747 | + # Template for RMSast: RMSmag = {mag} |
| 748 | + mag = df_head.iloc[3][0] |
| 749 | + if mag == 'END_OF_HEADER': |
755 | 750 | mag = 'No data for RMSmag'
|
756 | 751 | else:
|
757 |
| - mag = float(mag['mag']) |
| 752 | + mag = float(df_head.iloc[3][0].split('=')[1].strip()) |
| 753 | + |
758 | 754 |
|
759 | 755 | return ver, err, ast, mag
|
760 | 756 |
|
@@ -1351,23 +1347,16 @@ def _get_head_orb(data_obj):
|
1351 | 1347 | df_info_d = io.StringIO(data_obj.decode('utf-8'))
|
1352 | 1348 | # Read as txt file
|
1353 | 1349 | 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'] |
| 1350 | + # Template for format data: |
| 1351 | + # format = '{format}' ! file format |
| 1352 | + format_txt = df_info.iloc[0][0].split("'")[1].strip() |
| 1353 | + form = format_txt |
| 1354 | + # Template for record type: |
| 1355 | + # rectype = '{rectype}' ! record type (1L/ML) |
| 1356 | + rectype = df_info.iloc[1][0].split("'")[1].strip() |
| 1357 | + # Template for reference system: |
| 1358 | + # refsys = {refsys} ! default reference system" |
| 1359 | + refsys = df_info.iloc[2][0].split("=")[1].split("!")[0].strip() |
1371 | 1360 |
|
1372 | 1361 | return form, rectype, refsys
|
1373 | 1362 |
|
@@ -1827,26 +1816,17 @@ def _get_head_ephem(data_obj):
|
1827 | 1816 | """
|
1828 | 1817 | data_d = io.StringIO(data_obj.decode('utf-8'))
|
1829 | 1818 | 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'] |
| 1819 | + # Template for observatory: Observatory: {observatory} |
| 1820 | + obs = head_ephe.iloc[1][0].split(':')[1].strip() |
| 1821 | + # Template for initial date: Initial Date: {init_date} |
| 1822 | + idate = head_ephe.iloc[2][0].split(':')[1].strip() + ':' +\ |
| 1823 | + head_ephe.iloc[2][0].split(':')[2].strip() |
| 1824 | + # Template for initial date: Final Date: {final_date} |
| 1825 | + fdate = head_ephe.iloc[3][0].split(':')[1].strip() + ':' +\ |
| 1826 | + head_ephe.iloc[3][0].split(':')[2].strip() |
| 1827 | + # Template for initial date: Time step: {step} |
| 1828 | + tstep = head_ephe.iloc[4][0].split(':')[1].strip() |
| 1829 | + |
1850 | 1830 |
|
1851 | 1831 | return obs, idate, fdate, tstep
|
1852 | 1832 |
|
|
0 commit comments