Skip to content

Commit

Permalink
Merge branch 'master' into test_parfive_1.1_rc2
Browse files Browse the repository at this point in the history
  • Loading branch information
Raahul Singh committed Feb 26, 2020
2 parents b68100e + c6b4756 commit a5d4bd4
Show file tree
Hide file tree
Showing 27 changed files with 239 additions and 173 deletions.
7 changes: 3 additions & 4 deletions CONTRIBUTING.rst
Expand Up @@ -197,13 +197,12 @@ You will need to check two things:
We follow the `PEP8`_ style for all Python code and depending on your setup, you can use a `linter program <https://realpython.com/python-code-quality/#how-to-improve-python-code-quality>`_ to check your code.
For documentation, we follow the `numpydoc style <https://numpydoc.readthedocs.io/en/latest/format.html#docstring-standard>`_.

We provide more more detail about our :ref: `test suite and how to write tests <testing>`, and how to :ref: `create and style documentation <docs_guidelines>`.
We provide more more detail about our :ref:`test suite and how to write tests <testing>`, and how to :ref:`create and style documentation <docs_guidelines>`.

.. _pytest: https://docs.pytest.org/en/latest/

Send it back to us
^^^^^^^^^^^^^^^^^^

Once you have some changes you would like to submit, you will need to commit the changes.
This is a three stage process:

Expand All @@ -226,10 +225,10 @@ Please fill this in and title the pull request.
Now the final step is to press the green "Create pull request" button.

As soon as you do this, you will be greeted by a message from the "sunpy bot" as well as several continuous integration checks.
These are explained on our :ref: `Pull Request Review <pr_review>` page.
These are explained on our :ref:`Pull Request Review <pr_review>` page.
But what is important to know is that these run a series of tests to make sure that the changes do not cause any new errors.
We strongly recommend that any code changes you have had, follow the `PEP8`_ style and that you have ran the code locally to make sure any changes do not break any existing code.
We provide an overview on how to run the test suite :ref: `here <testing>`.
We provide an overview on how to run the test suite :ref:`here <testing>`.
Now we (the SunPy community) can review the code and offer suggestions and once we are happy, we can merge in the pull request.

If you do not have time to finish what you started on or ran out of time during a sprint and do not want to submit a pull request, you can create a git patch instead:
Expand Down
1 change: 1 addition & 0 deletions changelog/3776.doc.rst
@@ -0,0 +1 @@
Added an example for `~sunpy.map.GenericMap.world_to_pixel` function in the Units & Coordinates guide.
1 change: 1 addition & 0 deletions changelog/3818.feature.rst
@@ -0,0 +1 @@
Made skimage.transform import lazy to reduce import time of `sunpy.image.transform` by ~50%
1 change: 1 addition & 0 deletions changelog/3835.doc.rst
@@ -0,0 +1 @@
Changed padding value of an example in the example gallery to fix the overlap of titles and x-label axes.
1 change: 1 addition & 0 deletions changelog/3838.bugfix.1.rst
@@ -0,0 +1 @@
Add support for passing paths of type `pathlib.Path` in `sunpy.net.jsoc.JSOCClient.fetch`.
1 change: 1 addition & 0 deletions changelog/3838.bugfix.rst
@@ -0,0 +1 @@
Add explicit support for dealing with download urls for files, under 'as-is' protocol in `sunpy.net.jsoc.JSOCClient.get_request`.
12 changes: 9 additions & 3 deletions docs/guide/units-coordinates.rst
Expand Up @@ -222,7 +222,14 @@ Using Coordinates with SunPy Map
(-0.00406308, 0.04787238, 1.51846026e+11)>): (Tx, Ty) in arcsec
(100., 10.)>

This `~astropy.coordinates.SkyCoord` object could then be used to plot a point
The `~astropy.coordinates.SkyCoord` object can be converted to a PixelPair object
using `~sunpy.map.GenericMap.world_to_pixel`:

>>> pixel_obj = m.world_to_pixel(c) # doctest: +REMOTE_DATA
>>> pixel_obj # doctest: +REMOTE_DATA
PixelPair(x=<Quantity 551.7680511 pix>, y=<Quantity 515.18266871 pix>)

This `~astropy.coordinates.SkyCoord` object could also be used to plot a point
on top of the map:

>>> import matplotlib.pyplot as plt
Expand All @@ -231,5 +238,4 @@ Using Coordinates with SunPy Map
<matplotlib.image.AxesImage object at ...>
>>> _ = ax.plot_coord(c, 'o') # doctest: +REMOTE_DATA

For more information on coordinates see :ref:`sunpy-coordinates` section of
the :ref:`reference`.
For more information on coordinates see :ref:`sunpy-coordinates` section of the :ref:`reference`.
2 changes: 1 addition & 1 deletion examples/acquiring_data/2011_06_07_sampledata_overview.py
Expand Up @@ -78,7 +78,7 @@
aia_1600_map.plot(clip_interval=(0.5, 99.9)*u.percent)
aia_1600_map.draw_grid()

fig.tight_layout(pad=6.50)
fig.tight_layout(pad=8.50)
plt.show()

###############################################################################
Expand Down
81 changes: 48 additions & 33 deletions sunpy/CITATION.rst
Expand Up @@ -2,56 +2,71 @@
Acknowledging or Citing SunPy
*****************************

If you have used SunPy in your scientific work we would appreciate it if you would acknowledge it.
If you use SunPy in your scientific work, we would appreciate citing it in your publications.
The continued growth and development of SunPy is dependent on the community being aware of SunPy.

Publications
============
Citing SunPy in Publications
============================

Please add the following line within your methods, conclusion or acknowledgements sections:

*This research has made use of SunPy vX.Y (version citation), an open-source and free
community-developed solar data analysis Python package (citation).*
*This research has made use of SunPy vX.Y (software citation), an open-source and free
community-developed solar data analysis Python package (project citation).*

The citation should be to the `SunPy paper`_ and the version number should cite the specific `Zenodo DOI`_ for the version used in your work.
The project citation should be to the `SunPy paper`_, and the software citation should be the specific `Zenodo DOI`_ for the version used in your work.

.. code:: bibtex
@ARTICLE{2015CS&D....8a4009S,
author = {{SunPy Community}, T. and {Mumford}, S.~J. and {Christe}, S. and
{P{\'e}rez-Su{\'a}rez}, D. and {Ireland}, J. and {Shih}, A.~Y. and
{Inglis}, A.~R. and {Liedtke}, S. and {Hewett}, R.~J. and {Mayer}, F. and
{Hughitt}, K. and {Freij}, N. and {Meszaros}, T. and {Bennett}, S.~M. and
{Malocha}, M. and {Evans}, J. and {Agrawal}, A. and {Leonard}, A.~J. and
{Robitaille}, T.~P. and {Mampaey}, B. and {Iv{\'a}n Campos-Rozo}, J. and
{Kirk}, M.~S.},
title = "{SunPy{\mdash}Python for solar physics}",
journal = {Computational Science and Discovery},
archivePrefix = "arXiv",
eprint = {1505.02563},
primaryClass = "astro-ph.IM",
year = 2015,
month = jan,
volume = 8,
number = 1,
eid = {014009},
pages = {014009},
doi = {10.1088/1749-4699/8/1/014009},
adsurl = {http://adsabs.harvard.edu/abs/2015CS%26D....8a4009S},
adsnote = {Provided by the SAO/NASA Astrophysics Data System}
}
@ARTICLE{sunpy_community2020,
doi = {10.3847/1538-4357/ab4f7a},
url = {https://iopscience.iop.org/article/10.3847/1538-4357/ab4f7a},
author = {{The SunPy Community} and Barnes, Will T. and Bobra, Monica G. and Christe, Steven D. and Freij, Nabil and Hayes, Laura A. and Ireland, Jack and Mumford, Stuart and Perez-Suarez, David and Ryan, Daniel F. and Shih, Albert Y. and Chanda, Prateek and Glogowski, Kolja and Hewett, Russell and Hughitt, V. Keith and Hill, Andrew and Hiware, Kaustubh and Inglis, Andrew and Kirk, Michael S. F. and Konge, Sudarshan and Mason, James Paul and Maloney, Shane Anthony and Murray, Sophie A. and Panda, Asish and Park, Jongyeob and Pereira, Tiago M. D. and Reardon, Kevin and Savage, Sabrina and Sipőcz, Brigitta M. and Stansby, David and Jain, Yash and Taylor, Garrison and Yadav, Tannmay and Rajul, and Dang, Trung Kien},
title = {The SunPy Project: Open Source Development and Status of the Version 1.0 Core Package},
journal = {The Astrophysical Journal},
volume = {890},
issue = {1},
pages = {68-},
publisher = {American Astronomical Society},
year = {2020}
}
You can also get this information with ``sunpy.__citation__``.

Posters and talks
=================

Other SunPy publications
------------------------

The SunPy v1.0.8 code was reviewed by `The Journal of Open Source Software (JOSS) <https://joss.theoj.org/papers/10.21105/joss.01832>`__.

.. code:: bibtex
@ARTICLE{Mumford2020,
doi = {10.21105/joss.01832},
url = {https://doi.org/10.21105/joss.01832},
year = {2020},
publisher = {The Open Journal},
volume = {5},
number = {46},
pages = {1832},
author = {Stuart Mumford and Nabil Freij and Steven Christe and Jack Ireland and Florian Mayer and V. Hughitt and Albert Shih and Daniel Ryan and Simon Liedtke and David Pérez-Suárez and Pritish Chakraborty and Vishnunarayan K and Andrew Inglis and Punyaslok Pattnaik and Brigitta Sipőcz and Rishabh Sharma and Andrew Leonard and David Stansby and Russell Hewett and Alex Hamilton and Laura Hayes and Asish Panda and Matt Earnshaw and Nitin Choudhary and Ankit Kumar and Prateek Chanda and Md Haque and Michael Kirk and Michael Mueller and Sudarshan Konge and Rajul Srivastava and Yash Jain and Samuel Bennett and Ankit Baruah and Will Barnes and Michael Charlton and Shane Maloney and Nicky Chorley and Himanshu and Sanskar Modi and James Mason and Naman9639 and Jose Rozo and Larry Manley and Agneet Chatterjee and John Evans and Michael Malocha and Monica Bobra and Sourav Ghosh and Airmansmith97 and Dominik Stańczak and Ruben De Visscher and Shresth Verma and Ankit Agrawal and Dumindu Buddhika and Swapnil Sharma and Jongyeob Park and Matt Bates and Dhruv Goel and Garrison Taylor and Goran Cetusic and Jacob and Mateo Inchaurrandieta and Sally Dacie and Sanjeev Dubey and Deepankar Sharma and Erik Bray and Jai Rideout and Serge Zahniy and Tomas Meszaros and Abhigyan Bose and André Chicrala and Ankit and Chloé Guennou and Daniel D'Avella and Daniel Williams and Jordan Ballew and Nick Murphy and Priyank Lodha and Thomas Robitaille and Yash Krishan and Andrew Hill and Arthur Eigenbrot and Benjamin Mampaey and Bernhard Wiedemann and Carlos Molina and Duygu Keşkek and Ishtyaq Habib and Joseph Letts and Juanjo Bazán and Quinn Arbolante and Reid Gomillion and Yash Kothari and Yash Sharma and Abigail Stevens and Adrian Price-Whelan and Ambar Mehrotra and Arseniy Kustov and Brandon Stone and Trung Dang and Emmanuel Arias and Fionnlagh Dover and Freek Verstringe and Gulshan Kumar and Harsh Mathur and Igor Babuschkin and Jaylen Wimbish and Juan Buitrago-Casas and Kalpesh Krishna and Kaustubh Hiware and Manas Mangaonkar and Matthew Mendero and Mickaël Schoentgen and Norbert Gyenge and Ole Streicher and Rajasekhar Mekala and Rishabh Mishra and Shashank Srikanth and Sarthak Jain and Tannmay Yadav and Tessa Wilkinson and Tiago Pereira and Yudhik Agrawal and Jamescalixto and Yasintoda and Sophie Murray},
title = {SunPy: A Python package for Solar Physics},
journal = {Journal of Open Source Software}
}
A paper about version v0.5 of SunPy was published in `Computational Science & Discovery <https://iopscience.iop.org/article/10.1088/1749-4699/8/1/014009>`__.



Acknowledging SunPy in Posters and Talks
========================================

Please include the `Sunpy logo`_ on the title, conclusion slide, or about page.
For websites please link the image to `sunpy.org`_.
Other versions of the logo are available in the `sunpy-logo repository`_.

.. _SunPy paper: https://iopscience.iop.org/article/10.1088/1749-4699/8/1/014009
.. _SunPy paper: https://doi.org/10.3847/1538-4357/ab4f7a
.. _SunPy JOSS paper: https://doi.org/10.21105/joss.01832
.. _Sunpy logo: https://sunpy.org/about/#acknowledging
.. _sunpy.org: https://sunpy.org/
.. _sunpy-logo repository: https://github.com/sunpy/sunpy-logo/
Expand Down
13 changes: 8 additions & 5 deletions sunpy/__init__.py
Expand Up @@ -32,15 +32,18 @@ class UnsupportedPythonError(Exception):


def _get_bibtex():
import textwrap
# Set the bibtex entry to the article referenced in CITATION.rst
citation_file = os.path.join(os.path.dirname(__file__), 'CITATION.rst')

with open(citation_file, 'r') as citation:
refs = citation.read().split('@ARTICLE')[1:]
if len(refs) == 0:
return ''
bibtexreference = r"@ARTICLE{}".format(refs[0])
return bibtexreference
# Extract the first bibtex block:
ref = citation.read().partition(".. code:: bibtex\n\n")[2]
lines = ref.split("\n")
# Only read the lines which are indented
lines = lines[:[l.startswith(" ") for l in lines].index(False)]
ref = textwrap.dedent('\n'.join(lines))
return ref


__citation__ = __bibtex__ = _get_bibtex()
Expand Down
9 changes: 7 additions & 2 deletions sunpy/coordinates/ephemeris.py
Expand Up @@ -88,7 +88,7 @@ def get_body_heliographic_stonyhurst(body, time='now', observer=None):
emitted_time = obstime - light_travel_time

log.info(f"Apparent body location accounts for {light_travel_time.to('s').value:.2f}"
" seconds of light travel time")
" seconds of light travel time")

body_hgs = ICRS(body_icrs).transform_to(HGS(obstime=obstime))

Expand Down Expand Up @@ -221,7 +221,12 @@ def get_horizons_coord(body, time='now', id_type='majorbody'):
def _B0(time='now'):
"""
Return the B0 angle for the Sun at a specified time, which is the heliographic latitude of the
Sun-disk center as seen from Earth. The range of B0 is +/-7.23 degrees.
of the center of the disk of the Sun as seen from Earth. The range of B0 is +/-7.23 degrees.
Equivalent definitions include:
* The heliographic latitude of Earth
* The tilt of the solar North rotational axis toward Earth
Parameters
----------
Expand Down
25 changes: 11 additions & 14 deletions sunpy/image/transform.py
Expand Up @@ -8,15 +8,6 @@

from sunpy.util.exceptions import SunpyUserWarning

try:
import skimage.transform
scikit_image_not_found = False
except ImportError:
warnings.warn("scikit-image could not be imported. Image rotation will use scipy",
ImportWarning)
scikit_image_not_found = True


__all__ = ['affine_transform']


Expand Down Expand Up @@ -84,7 +75,7 @@ def affine_transform(image, rmatrix, order=3, scale=1.0, image_center=None,
algorithm to map the original to target pixel values.
"""
rmatrix = rmatrix / scale
array_center = (np.array(image.shape)[::-1]-1)/2.0
array_center = (np.array(image.shape)[::-1] - 1) / 2.0

# Make sure the image center is an array and is where it's supposed to be
if image_center is not None:
Expand All @@ -100,14 +91,20 @@ def affine_transform(image, rmatrix, order=3, scale=1.0, image_center=None,

displacement = np.dot(rmatrix, rot_center)
shift = image_center - displacement

if use_scipy or scikit_image_not_found:
if not use_scipy:
try:
import skimage.transform
except ImportError:
warnings.warn("scikit-image could not be imported. Image rotation will use scipy",
ImportWarning)
use_scipy = True
if use_scipy:
if np.any(np.isnan(image)):
warnings.warn("Setting NaNs to 0 for SciPy rotation.", SunpyUserWarning)
# Transform the image using the scipy affine transform
rotated_image = scipy.ndimage.interpolation.affine_transform(
np.nan_to_num(image).T, rmatrix, offset=shift, order=order,
mode='constant', cval=missing).T
np.nan_to_num(image).T, rmatrix, offset=shift, order=order,
mode='constant', cval=missing).T
else:
# Make the rotation matrix 3x3 to include translation of the image
skmatrix = np.zeros((3, 3))
Expand Down
4 changes: 3 additions & 1 deletion sunpy/map/mapbase.py
Expand Up @@ -452,7 +452,9 @@ def date(self):
time = self.meta.get('date-obs', None)
if time is None:
if self._default_time is None:
warnings.warn("Missing metadata for observation time: setting observation time to current time.",
warnings.warn("Missing metadata for observation time, "
"setting observation time to current time. "
"Set the 'DATE-OBS' FITS keyword to prevent this warning.",
SunpyUserWarning)
self._default_time = parse_time('now')
time = self._default_time
Expand Down
5 changes: 5 additions & 0 deletions sunpy/net/jsoc/attrs.py
Expand Up @@ -25,6 +25,11 @@ class Keys(SimpleAttr):
class PrimeKey(DataAttr):
"""
Prime Keys
Parameters
----------
label : str
value : str
"""
def __init__(self, label, value):
super().__init__()
Expand Down
16 changes: 12 additions & 4 deletions sunpy/net/jsoc/jsoc.py
Expand Up @@ -4,6 +4,7 @@
import urllib
import warnings
from collections.abc import Sequence
from pathlib import Path

import drms
import numpy as np
Expand Down Expand Up @@ -563,7 +564,10 @@ def get_request(self, requests, path=None, overwrite=False, progress=True,
if path is None:
default_dir = config.get("downloads", "download_dir")
path = os.path.join(default_dir, '{file}')
elif isinstance(path, str) and '{file}' not in path:
elif isinstance(path, Path):
path = str(path)

if isinstance(path, str) and '{file}' not in path:
path = os.path.join(path, '{file}')

paths = []
Expand Down Expand Up @@ -595,9 +599,13 @@ def get_request(self, requests, path=None, overwrite=False, progress=True,
urls = []
for request in requests:
if request.status == 0:
for index, data in request.data.iterrows():
url_dir = request.request_url + '/'
urls.append(urllib.parse.urljoin(url_dir, data['filename']))
if request.protocol == 'as-is':
urls.extend(list(request.urls.url))
else:
for index, data in request.data.iterrows():
url_dir = request.request_url + '/'
urls.append(urllib.parse.urljoin(url_dir, data['filename']))

if urls:
if progress:
print_message = "{0} URLs found for download. Full request totalling {1}MB"
Expand Down
13 changes: 13 additions & 0 deletions sunpy/net/jsoc/tests/test_jsoc.py
Expand Up @@ -330,3 +330,16 @@ def test_max_parallel_connections():

with pytest.warns(SunpyUserWarning):
client.fetch(responses, path=path, max_conn=5, max_splits=5)


def test_results_filenames_as_is(tmp_path):
responses = client.search(
a.Time('2014/1/1T1:00:36', '2014/1/1T01:01:38'),
a.jsoc.Series('hmi.M_45s'), a.jsoc.Notify('jsoc@cadair.com'),
a.jsoc.Protocol('as-is'))
assert len(responses) == 2
files = client.fetch(responses, path=tmp_path)
assert isinstance(files, Results)
assert len(files) == len(responses)
for hmiurl in files:
assert os.path.isfile(hmiurl)
10 changes: 5 additions & 5 deletions sunpy/timeseries/sources/eve.py
Expand Up @@ -76,14 +76,14 @@ def peek(self, title='EVE/ESP Level1', **kwargs):

figure = plt.figure()
axes = plt.gca()
axes = self.data.plot(ax=axes, subplots=True, sharex=True, **kwargs)
plt.xlim(self.data.index[0], self.data.index[-1])
axes = self.to_dataframe().plot(ax=axes, subplots=True, sharex=True, **kwargs)
plt.xlim(self.to_dataframe().index[0], self.to_dataframe().index[-1])

axes[0].set_title(title)
for i, ax in enumerate(axes):
ax.set_ylabel(names[i])
ax.legend(loc='upper right')
axes[-1].set_xlabel('Time (UT) ' + str(self.data.index[0])[0:11])
axes[-1].set_xlabel('Time (UT) ' + str(self.to_dataframe().index[0])[0:11])
axes[-1].xaxis.set_major_formatter(dates.DateFormatter('%H:%M'))
plt.tight_layout()
plt.subplots_adjust(hspace=0.05)
Expand Down Expand Up @@ -200,7 +200,7 @@ def peek(self, column=None, **kwargs):
figure = plt.figure()
# Choose title if none was specified
if "title" not in kwargs and column is None:
if len(self.data.columns) > 1:
if len(self.to_dataframe().columns) > 1:
kwargs['title'] = 'EVE (1 minute data)'
else:
if self._filename is not None:
Expand All @@ -212,7 +212,7 @@ def peek(self, column=None, **kwargs):
if column is None:
self.plot(**kwargs)
else:
data = self.data[column]
data = self.to_dataframe()[column]
if "title" not in kwargs:
kwargs['title'] = 'EVE ' + column.replace('_', ' ')
data.plot(**kwargs)
Expand Down

0 comments on commit a5d4bd4

Please sign in to comment.