Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Dastcom5 Service #115

Open
wants to merge 16 commits into
base: main
Choose a base branch
from

Conversation

shreyasbapat
Copy link

@shreyasbapat shreyasbapat commented Feb 27, 2019

As discussed in chats of astroquery: https://astropy.slack.com/archives/C8U8VGQFM/p1549754624034000

And from a PR in astroquery: astropy/astroquery#1339

I am adding this module here.

cc @Juanlu001

@pep8speaks
Copy link

pep8speaks commented Feb 27, 2019

Hello @shreyasbapat! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

Line 355:32: E231 missing whitespace after ','
Line 356:29: E231 missing whitespace after ','
Line 357:31: E231 missing whitespace after ','
Line 358:31: E231 missing whitespace after ','
Line 359:32: E231 missing whitespace after ','
Line 360:32: E231 missing whitespace after ','
Line 361:29: E231 missing whitespace after ','
Line 362:26: E231 missing whitespace after ','
Line 366:1: E302 expected 2 blank lines, found 1

Comment last updated at 2020-07-22 20:39:45 UTC

@astrojuanlu
Copy link

(In case the Slack message is lost: https://matrix.to/#/!DdazxkLDTPnBLekbbL:openastronomy.org/$15497546251785GFeBH:openastronomy.org?via=cadair.com&via=openastronomy.org&via=matrix.org)

@astrojuanlu
Copy link

@shreyasbapat please fix the PEP8 errors.

@shreyasbapat
Copy link
Author

@Juanlu001 I am also working on tests. Will push both of them together

@mommermi mommermi self-assigned this Feb 28, 2019
@mommermi mommermi added the data label Feb 28, 2019
@mommermi mommermi self-requested a review February 28, 2019 16:43
@mommermi
Copy link
Member

Thanks for providing this PR! A few things that I would like to see discussed/changed/added before I proceed with an in-depth review:

  • sbpy.data.Orbit handles orbits, so that would be a natural place for dastcom5. However, given the rather complex structure of the code makes it hard to integrate into the existing Orbit class. The current convention is to only have high-level functionality (basically wrappers) in Orbit, such as Orbit.from_horizons or Orbit.from_mpc. Would it be possible to add the current dastcom5 submodule as sbpy.data.utils.dastcom5 and then provide a Orbit.from_dastcom5 wrapper?
  • The output of the wrapper function should be an Orbit object, which allows it to be used in other sbpy functionality. Functions to convert a astropy.table.Table to Orbit exists in the parent class DataClass.from_table.
  • we try to avoid pandas and use astropy.table functionality instead. It seems to me that pandas is only used to concatenate tables and order data. This can easily be done on the astropy.table.Table objects or even the resulting Orbit object.
  • Could you also please add some examples to the docstrings and write a bit of text for docs/sbpy/data.rst?

Thanks!

@shreyasbapat
Copy link
Author

Sure @mommermi . Thanks for a quick response. I will keep you updated as I complete all the requirements.

@shreyasbapat
Copy link
Author

shreyasbapat commented Mar 8, 2019

I have created the checklist for reference.

  • sbpy.data.Orbit handles orbits, so that would be a natural place for dastcom5. However, given the rather complex structure of the code makes it hard to integrate into the existing Orbit class. The current convention is to only have high-level functionality (basically wrappers) in Orbit, such as Orbit.from_horizons or Orbit.from_mpc. Would it be possible to add the current dastcom5 submodule as sbpy.data.utils.dastcom5 and then provide a Orbit.from_dastcom5 wrapper?

  • The output of the wrapper function should be an Orbit object, which allows it to be used in other sbpy functionality. Functions to convert a astropy.table.Table to Orbit exists in the parent class DataClass.from_table.

  • we try to avoid pandas and use astropy.table functionality instead. It seems to me that pandas is only used to concatenate tables and order data. This can easily be done on the astropy.table.Table objects or even the resulting Orbit object.

  • Could you also please add some examples to the docstrings and write a bit of text for docs/sbpy/data.rst?

@shreyasbapat
Copy link
Author

@mommermi I have done everything that was asked!

@mommermi
Copy link
Member

Thanks, @shreyasbapat ! I will work on the review as soon as possible!

Copy link
Member

@mommermi mommermi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this! I have a handful of comments and suggestions to make this compatible with the sbpy API:

  1. please move the module from sbpy.utils to sbpy.data.utils
  2. please add some examples to the docstrings of the individual functions and methods
  3. in their current state, the return values of most functions are not very useful and not compatible with other sbpy functionality; please make sure that each function returns some derivative of sbpy.data.DataClass where the data is split into columns, each of which uses the corresponding astropy.units unit (see detailed review comments and the wiki: https://github.com/NASA-Planetary-Science/sbpy/wiki)

sbpy/utils/dastcom5_README.txt Outdated Show resolved Hide resolved
return body_data


def download_dastcom5():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the download function, but I would suggest a few minor things:

  • during download and in addition to showing the download progress, could you add a line saying: 'downloading current DASTCOM5 database' or something similar?
  • can you add a keyword parameter update that allows to overwrite the local version of the database?
  • instead of downloading the files into ~/.sbpy, can you download them into data_archive in the sbpy directory?
  • in order to save space, please delete the zip file once it is unpacked

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update will mean removing the version user has and downloading completely newer version? I didn't understand.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, sorry if I was unclear. By 'update' I mean to overwrite the existing local version with the latest available version.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of downloading the files into ~/.sbpy, can you download them into data_archive in the sbpy directory

Won't the users installing it from pip find it difficult to access the database? I think it is fine if someone is cloning the repository somewhere and then runs pip install -e .. Otherwise in my opinion, it won't be good?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I don't think we should assume that the sbpy directory is writable.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, so will we use ~/.sbpy as the location of the database? ~/sbpy/dastcom5/?

Copy link
Author

@shreyasbapat shreyasbapat Apr 11, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes @mommermi
/.sbpy/dastcom5/

Database with custom dtype.

"""
with open(AST_DB_PATH, "rb") as f:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that there is some kind of timestamp in the database; can you issue a warning if the local database is older than 7 days? The same applies to the comet database.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where do you see the timestamp? I am unable to find it :/

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might have mistaken Epoch as a timestamp. Should we use this?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think using epoch is a good idea for giving out warnings.

sbpy/data/orbit.py Show resolved Hide resolved
sbpy/data/orbit.py Show resolved Hide resolved
return data


def orbit_from_name(name):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both this function and orbit_from_record lack a parser function. Right now, all the data is stored in a single column of an astropy.table object, which is not very useful. Please split up the data into columns in a useful way; have a look at https://sbpy.readthedocs.io/en/latest/fieldnames.html and the documentation of astroquery.jplhorizons/astroquery.sbdb to get an idea of meaningful column names for the different properties that are already being used within sbpy. Finally, please use the corresponding astropy.units for each column.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please elaborate a little by what you mean by parser? Sorry that I am unable to understand. Will it be on the top of these pre-existing functions and return the required table?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, exactly. Right now, the functions return single-columns tables. These tables are not really useful as the data are unstructured. A parser function would read in these rows and split them into the individual columns. Does this make sense?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got it!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this function still return a table?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added. Please review what name it should have. I have added a function with a wierd name :/

return records


def string_record_from_name(name):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this function should be mentioned in the documentation

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure

return lines


def read_headers():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does this function do? What are 'headers'?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The HEADERS of the database

for line in inF:
if re.search(r"\b" + name.casefold() + r"\b", line.casefold()):
lines.append(line)
return lines
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please turn this output into a sbpy.data.DataClass object with corresponding column names.

return ast_header, com_header


def read_record(record):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't get this function to work. It fails with

File ".../sbpy/utils/dastcom5.py", line 502, in read_record
f.seek(phis_rec, os.SEEK_SET)

This function would be potentially useful and could output as sbpy.data.Phys object.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will work on it

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is already being used in orbit_from_record 😅

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This error pops when the record is not there in the database. Please try with :

read_record(1636)

which is for atira

@shreyasbapat
Copy link
Author

@mommermi I am facing issues in pip installing the package.

Failed building wheel for synphot
  Running setup.py clean for synphot
Failed to build synphot

Is this my environment problem?
Also, I seem to not find a place to report this bug

@astrojuanlu
Copy link

Failed to build synphot

I just did pip install git+https://github.com/NASA-Planetary-Science/sbpy.git on Linux + Python 3.7 and worked just fine.

@astrojuanlu
Copy link

Also, I seem to not find a place to report this bug

https://github.com/spacetelescope/synphot_refactor

@mommermi
Copy link
Member

mommermi commented May 6, 2019

@shreyasbapat: have you tried installing synphot separately with: pip install synphot?

@shreyasbapat
Copy link
Author

I am sorry for leaving this for long! I will finish this up asap!

@shreyasbapat
Copy link
Author

Finally, a good rebase. I will finish the PR in a day.

.travis.yml Outdated Show resolved Hide resolved
@mkelley
Copy link
Member

mkelley commented Feb 24, 2020

@shreyasbapat @Juanlu001 The test needs to be skipped or marked as remote, probably the latter? Append "# doctest: +REMOTE_DATA" to the lines that need remote data. https://docs.astropy.org/en/stable/development/testguide.html#working-with-data-files

@shreyasbapat
Copy link
Author

Sure. I will do so.

@shreyasbapat
Copy link
Author

@mkelley The # doctest: +REMOTE_DATA is for usage in docs right? What if I had a test which is to test if my download happens, can I skip the whole test in Travis?

@mommermi
Copy link
Member

If you have a doctest that checks if your download succeeded, I think it's legitimate to skip it. However, in that case, you should have a dedicated test on the module level that checks for this.

@mkelley
Copy link
Member

mkelley commented Apr 8, 2020

@shreyasbapat @mommermi I don't think the download should ever happen in the documentation. The files are too large. If there were a way to do a mock download, that would be OK.

@shreyasbapat
Copy link
Author

True. I will try to get the ticks green this weekend.

@astrojuanlu
Copy link

astrojuanlu commented Apr 15, 2020

In case it's relevant for this PR, we fixed a bug in the original code poliastro/poliastro#902

@shreyasbapat
Copy link
Author

shreyasbapat commented Apr 15, 2020 via email

@shreyasbapat
Copy link
Author

In case it's relevant for this PR, we fixed a bug in the original code poliastro/poliastro#902

Fixing this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants