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

Helper map header function #3083

Merged
merged 34 commits into from May 21, 2019

Conversation

Projects
6 participants
@hayesla
Copy link
Contributor

commented Apr 30, 2019

Description

A first pass at creating helper functionality for creating a Map header from Issue #2278

At the moment I've put it in maputils.py as meta_helper class object.
The object can be called through map.meta_helper .

It currently print the accepted meta keywords that is used in GenericMap to create a map, and describes what each keyword means.

For example

>>> from sunpy import map
>>> map.meta_helper.acceptable_meta_keywords()
cunit1  :  Units of the coordinate increments along naxis1 e.g. arcsec **required
cunit2  :  Units of the coordinate increments along naxis2 e.g. arcsec **required
crval1  :  Coordinate value at reference point on naxis1 **required
crval2  :  Coordinate value at reference point on naxis2 **required
cdelt1  :  Spatial scale of pixels for naxis1, i.e. coordinate increment at reference point
cdelt2  :  Spatial scale of pixels for naxis2, i.e. coordinate increment at reference point
.....

It can also check if a meta keyword is accepted

>>> map.meta_helper.acceptable_meta_keywords('crpix1')
crpix1  :  Pixel coordinate at reference point naxis1
>>> map.meta_helper.acceptable_meta_keywords('lalala')
lalala  is not in the accepted meta data required for sunpy.map.Map 

The class also has a utility function that can create a map header, stored in a MetaDict. This function can either take no keywords, and defaults to an Earth-based observer at current time (assuming cunit = arcsec), or can take a SkyCoord or sunpy.coordinates.frame as a reference point from which ctype, cunit, hglt/ln_obs, dsun_ref, rsun_ref and obstime can be pulled. It then can take optional crval, cdelt and crpix which are set to default 0, 1, center of data array if none are given.

For example

>>> from sunpy import map
>>> from sunpy.coordinates import frames
>>> from astropy.coordinates import SkyCoord
>>> from astropy import units as u
>>> import numpy as np

>>> data = np.random.rand(1024, 1024)
>>> header = map.meta_helper.make_header(data)
>>> header
MetaDict([('ctype1', 'HPLN-TAN'),
          ('ctype2', 'HPLT-TAN'),
          ('cunit1', 'arcsec'),
          ('cunit2', 'arcsec'),
          ('crpix1', 512.5),
          ('crpix2', 512.5),
          ('cdelt1', 1),
          ('cdelt2', 1),
          ('crval1', 0),
          ('crval2', 0),
          ('hgln_obs', 0.0),
          ('hglt_obs', 0.0),
          ('date_obs', '2019-04-30 19:29:47.129'),
          ('t_obs', '2019-04-30 19:29:47.129'),
          ('dsun_obs', 149597870700.0),
          ('rsun_obs', 959.2277285408243),
          ('rsun_ref', 695700000.0)])

or a SkyCoord or frame can be passed such that

>>> d = SkyCoord(0*u.arcsec, 0*u.arcsec, obstime="2017-08-01", observer = 'earth', frame=frames.Helioprojective)
>>> header = map.meta_helper.make_header(data, d)
>>> header
MetaDict([('ctype1', 'HPLN-TAN'),
          ('ctype2', 'HPLT-TAN'),
          ('cunit1', Unit("arcsec")),
          ('cunit2', Unit("arcsec")),
          ('crpix1', 512.5),
          ('crpix2', 512.5),
          ('cdelt1', 1),
          ('cdelt2', 1),
          ('crval1', 0),
          ('crval2', 0),
          ('hgln_obs', <Longitude 0. deg>),
          ('hglt_obs', <Latitude 5.78339799 deg>),
          ('date_obs',
           <Time object: scale='utc' format='isot' value=2017-08-01T00:00:00.000>),
          ('t_obs',
           <Time object: scale='utc' format='isot' value=2017-08-01T00:00:00.000>),
          ('dsun_obs', <Distance 1.51837236e+11 m>),
          ('rsun_obs', 945.0805956220959),
          ('rsun_ref', <Quantity 6.957e+08 m>)])

This is based on astropy.wcs.utils.celestial_frame_to_wcs. additonaly kwargs can be passed through make_map to define the metadict keywords

>>> header = map.meta_helper.make_header(data, d, crval = [100,100], cdelt = [10,10], exptime = 2, telescop = 'my_telescope', crota2 = -0.15)

I dont know if this is the type of functionality we want but it's a start I guess!

@pep8speaks

This comment has been minimized.

Copy link

commented Apr 30, 2019

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

Line 6:101: E501 line too long (118 > 100 characters)

Line 101:101: E501 line too long (103 > 100 characters)
Line 109:101: E501 line too long (102 > 100 characters)
Line 182:101: E501 line too long (103 > 100 characters)
Line 268:101: E501 line too long (108 > 100 characters)
Line 270:101: E501 line too long (108 > 100 characters)
Line 272:101: E501 line too long (108 > 100 characters)
Line 274:101: E501 line too long (108 > 100 characters)
Line 276:101: E501 line too long (108 > 100 characters)
Line 278:101: E501 line too long (108 > 100 characters)
Line 280:101: E501 line too long (108 > 100 characters)
Line 282:101: E501 line too long (107 > 100 characters)

Line 18:101: E501 line too long (119 > 100 characters)
Line 23:101: E501 line too long (123 > 100 characters)
Line 28:101: E501 line too long (124 > 100 characters)
Line 33:101: E501 line too long (117 > 100 characters)
Line 47:101: E501 line too long (128 > 100 characters)
Line 83:101: E501 line too long (107 > 100 characters)
Line 85:101: E501 line too long (109 > 100 characters)
Line 87:101: E501 line too long (108 > 100 characters)

Comment last updated at 2019-05-21 13:13:45 UTC
@sunpy-bot

This comment has been minimized.

Copy link

commented Apr 30, 2019

Thanks for the pull request @hayesla! Everything looks great!

Show resolved Hide resolved sunpy/map/maputils.py Outdated
Show resolved Hide resolved changelog/3083.feature.rst Outdated
Show resolved Hide resolved sunpy/map/maputils.py Outdated

@nabobalis nabobalis added this to the 1.0 milestone May 1, 2019

@nabobalis nabobalis added this to Release Blocking Items in SunPy 1.0 May 1, 2019

@ehsteve

This comment has been minimized.

Copy link
Member

commented May 2, 2019

@hayesla I think this is a great start! I would also recommend that this PR come with a guide (in addition to the normal documentation).

@nabobalis
Copy link
Contributor

left a comment

Sorry, probably the most list of pedantic things you will ever come across.

Show resolved Hide resolved sunpy/map/maputils.py Outdated
Show resolved Hide resolved sunpy/map/maputils.py Outdated
Show resolved Hide resolved sunpy/map/maputils.py Outdated
Show resolved Hide resolved sunpy/map/maputils.py Outdated
Show resolved Hide resolved sunpy/map/maputils.py Outdated
Show resolved Hide resolved sunpy/map/maputils.py Outdated
Show resolved Hide resolved sunpy/map/maputils.py Outdated
Show resolved Hide resolved sunpy/map/maputils.py Outdated
Show resolved Hide resolved sunpy/map/maputils.py Outdated
Show resolved Hide resolved sunpy/map/maputils.py Outdated
@nabobalis
Copy link
Contributor

left a comment

Sorry, probably the most list of pedantic things you will ever come across.

@Cadair

This comment has been minimized.

Copy link
Member

commented May 2, 2019

I think that it would be best to move this into it's own file (should maputils be a directory?) and drop the class (using the file to group all the parts).

I will go through the exact header logic tomorrow morning probably.

Show resolved Hide resolved changelog/3083.feature.rst Outdated
Show resolved Hide resolved sunpy/map/maputils.py Outdated
Show resolved Hide resolved sunpy/map/maputils.py Outdated
Show resolved Hide resolved sunpy/map/maputils.py Outdated
Show resolved Hide resolved sunpy/map/maputils.py Outdated
Show resolved Hide resolved sunpy/map/maputils.py Outdated
Show resolved Hide resolved sunpy/map/maputils.py Outdated
Show resolved Hide resolved sunpy/map/maputils.py Outdated
Show resolved Hide resolved sunpy/map/maputils.py Outdated
Show resolved Hide resolved sunpy/map/maputils.py Outdated

@hayesla hayesla force-pushed the hayesla:helper_map_function branch from 37b554d to 09b4f0a May 8, 2019

@hayesla hayesla force-pushed the hayesla:helper_map_function branch from 09b4f0a to 81b75b2 May 8, 2019

@Cadair
Copy link
Member

left a comment

Getting really close I think. Tests and a changelog please!

Show resolved Hide resolved sunpy/map/maphelper.py Outdated
Show resolved Hide resolved sunpy/map/maphelper.py Outdated
Show resolved Hide resolved sunpy/map/maphelper.py Outdated
Show resolved Hide resolved sunpy/map/maphelper.py Outdated

Cadair added some commits May 21, 2019

@Cadair

Cadair approved these changes May 21, 2019

Cadair added some commits May 21, 2019

@Cadair Cadair force-pushed the hayesla:helper_map_function branch from 222343c to a38c5e7 May 21, 2019

@Cadair Cadair merged commit a031c23 into sunpy:master May 21, 2019

16 checks passed

ci/circleci: 32bit Your tests passed on CircleCI!
Details
ci/circleci: egg-info-36 Your tests passed on CircleCI!
Details
ci/circleci: egg-info-37 Your tests passed on CircleCI!
Details
ci/circleci: figure-tests-36 Your tests passed on CircleCI!
Details
ci/circleci: html-docs Your tests passed on CircleCI!
Details
ci/circleci: pip-install Your tests passed on CircleCI!
Details
codecov/patch 98.01% of diff hit (target 90%)
Details
codecov/project 90.07% (+0.06%) compared to 106b0da
Details
giles Click details to preview the documentation build
Details
sunpy-bot All checks passed
sunpy.sunpy Build #20190521.16 succeeded
Details
sunpy.sunpy (Linux_36_Conda_offline) Linux_36_Conda_offline succeeded
Details
sunpy.sunpy (Linux_36_offline) Linux_36_offline succeeded
Details
sunpy.sunpy (Linux_37_online) Linux_37_online succeeded
Details
sunpy.sunpy (Windows_36_offline) Windows_36_offline succeeded
Details
sunpy.sunpy (macOS_37_offline) macOS_37_offline succeeded
Details

@Cadair Cadair moved this from Pre-Feature Freeze (2019-05-08) to Finished in SunPy 1.0 May 21, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.