Skip to content

Commit 37bbda9

Browse files
author
Alvaro Arroyo Parejo
committed
update dates and chage log, remove parse dependency, refactor parse code
1 parent 4bfdb8c commit 37bbda9

File tree

5 files changed

+100
-101
lines changed

5 files changed

+100
-101
lines changed

docs/esa/neocc.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,26 @@ Visit `Interfacing with the Pandas Package <https://docs.astropy.org/en/stable/t
589589
ESANEOCC Change Log
590590
##########################################
591591

592+
==============================
593+
Version 2.1
594+
==============================
595+
596+
----------------------
597+
Changes
598+
----------------------
599+
600+
* Remove *parse* library dependency for Astroquery integration.
601+
602+
==============================
603+
Version 2.0
604+
==============================
605+
606+
----------------------
607+
Changes
608+
----------------------
609+
610+
* Configuration and file layout changes to start the Astroquery integration.
611+
592612
==============================
593613
Version 1.4
594614
==============================

esa/neocc/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
European Space Agency (ESA)
77
88
Created on 16 Jun. 2021
9-
Last update 02 Nov. 2021
9+
Last update 01 Mar. 2022
1010
1111
"""
1212
import os

esa/neocc/core.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
* Property: European Space Agency (ESA)
1010
* Developed by: Elecnor Deimos
1111
* Author: C. Álvaro Arroyo Parejo
12-
* Issue: 1.4.0
13-
* Date: 02-11-2021
12+
* Issue: 2.1.0
13+
* Date: 01-03-2021
1414
* Purpose: Main module which gets NEAs data from https://neo.ssa.esa.int/
1515
* Module: core.py
1616
* History:
@@ -35,10 +35,12 @@
3535
1.4.0 29-10-2021 Adding new docstrings.\n
3636
Change method for obtaining physical
3737
properties
38+
2.0.0 21-01-2022 Prepare module for Astroquery integration
39+
2.1.0 01-03-2022 Remove *parse* dependency
3840
======== =========== ============================================
3941
4042
41-
© Copyright [European Space Agency][2021]
43+
© Copyright [European Space Agency][2022]
4244
All rights reserved
4345
"""
4446

esa/neocc/lists.py

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
* Property: European Space Agency (ESA)
88
* Developed by: Elecnor Deimos
99
* Author: C. Álvaro Arroyo Parejo
10-
* Issue: 1.4.0
11-
* Date: 02-11-2021
10+
* Issue: 2.1.0
11+
* Date: 01-03-2021
1212
* Purpose: Module which request and parse list data from ESA NEOCC
1313
* Module: lists.py
1414
* History:
@@ -29,16 +29,17 @@
2929
1.4.0 29-10-2021 Adding Catalogue of NEAS (current date
3030
and middle arc).\n
3131
Update docstrings.
32+
2.0.0 21-01-2022 Prepare module for Astroquery integration
33+
2.1.0 01-03-2022 Remove *parse* dependency
3234
======== =========== ==========================================
3335
34-
© Copyright [European Space Agency][2021]
36+
© Copyright [European Space Agency][2022]
3537
All rights reserved
3638
"""
3739

3840
import io
3941
from datetime import timedelta
4042
import pandas as pd
41-
from parse import parse
4243
import requests
4344
from astroquery.esa.neocc import conf
4445

@@ -505,29 +506,22 @@ def parse_neo_catalogue(data_byte_d):
505506
data_byte_d.seek(0)
506507
# Read the header
507508
neocc_head = pd.read_fwf(data_byte_d, header=None, nrows=4)
508-
# Template for format data
509-
parse_format = "format = '{format}' ! file format"
510-
# Parse required data for attributes
511-
format_txt = parse(parse_format, neocc_head.iloc[0][0])
512-
neocc_lst.form = format_txt['format']
513-
# Template for record type
514-
parse_rectype = "rectype = '{rectype}' !"\
515-
" record type (1L/ML)"
516-
# Parse required data for attributes
517-
rectype = parse(parse_rectype, neocc_head.iloc[1][0])
518-
neocc_lst.rectype = rectype['rectype']
509+
# Template for format data:
510+
# format = '{format}' ! file format
511+
format_txt = neocc_head.iloc[0][0].split("'")[1].strip()
512+
neocc_lst.form = format_txt
513+
# Template for record type:
514+
# rectype = '{rectype}' ! record type (1L/ML)
515+
rectype = neocc_head.iloc[1][0].split("'")[1].strip()
516+
neocc_lst.rectype = rectype
519517
# Template for type of orbital element
520-
parse_elem = "elem = '{elem}' ! "\
521-
"type of orbital elements"
522-
# Parse required data for attributes
523-
elem = parse(parse_elem, neocc_head.iloc[2][0])
524-
neocc_lst.elem = elem['elem']
518+
# elem = '{elem}' ! type of orbital elements
519+
elem = neocc_head.iloc[2][0].split("'")[1].strip()
520+
neocc_lst.elem = elem
525521
# Template for reference system
526-
parse_refsys = "refsys = {refsys} !"\
527-
" default reference system"
528-
# Parse required data for attributes
529-
refsys = parse(parse_refsys, neocc_head.iloc[3][0])
530-
neocc_lst.refsys = refsys['refsys']
522+
# refsys = {refsys} ! default reference system
523+
refsys = neocc_head.iloc[3][0].split("=")[1].split("!")[0].strip()
524+
neocc_lst.refsys = refsys
531525
neocc_lst.help = ('These catalogues represent the list of '
532526
'Keplerian orbit for each asteroid in the '
533527
'input list at mean epoch and at current epoch.'
@@ -546,3 +540,4 @@ def parse_neo_catalogue(data_byte_d):
546540

547541

548542
return neocc_lst
543+

esa/neocc/tabs.py

Lines changed: 54 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
* Property: European Space Agency (ESA)
1111
* Developed by: Elecnor Deimos
1212
* 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
1515
* Purpose: Module which request and parse list data from ESA NEOCC
1616
* Module: tabs.py
1717
* History:
@@ -48,9 +48,11 @@
4848
Orb_type attribute added in tab *orbit_properties*.\n
4949
Bug fix in tab *observations*.\n
5050
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
5153
======== =========== =====================================================
5254
53-
© Copyright [European Space Agency][2021]
55+
© Copyright [European Space Agency][2022]
5456
All rights reserved
5557
"""
5658

@@ -60,7 +62,6 @@
6062
import re
6163
from datetime import datetime, timedelta
6264
import pandas as pd
63-
from parse import parse
6465
import requests
6566
from bs4 import BeautifulSoup
6667
from astroquery.esa.neocc import conf
@@ -299,16 +300,21 @@ def _get_footer(data_obj):
299300

300301
# Drop NaN values if necessary
301302
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]
312318
# Computation date
313319
comp = df_txt.iloc[-1-j][0].split('=')[2].strip()
314320
# Get information text
@@ -732,29 +738,21 @@ def _get_head_obs(df_d):
732738
Root Mean Square for magnitude.
733739
"""
734740
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':
755752
mag = 'No data for RMSmag'
756753
else:
757-
mag = float(mag['mag'])
754+
mag = float(df_head.iloc[3][0].split('=')[1].strip())
755+
758756

759757
return ver, err, ast, mag
760758

@@ -1351,23 +1349,16 @@ def _get_head_orb(data_obj):
13511349
df_info_d = io.StringIO(data_obj.decode('utf-8'))
13521350
# Read as txt file
13531351
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()
13711362

13721363
return form, rectype, refsys
13731364

@@ -1827,26 +1818,17 @@ def _get_head_ephem(data_obj):
18271818
"""
18281819
data_d = io.StringIO(data_obj.decode('utf-8'))
18291820
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+
18501832

18511833
return obs, idate, fdate, tstep
18521834

0 commit comments

Comments
 (0)