19 Apr 2024 |
ayshih | .pixel_to_world() converts to the world coordinates of the FITS file, which in HMI's case is helioprojective coordinates | 13:43:59 |
ayshih | You should be able to literally replace the arcsec_coord = ... statement in your notebook cell with mine and go from there | 13:44:50 |
ayshih | But, if it's somehow helpful, here's my example from the beginning:
>>> import astropy.units as u
>>> import sunpy.map
>>> from sunpy.data.sample import HMI_LOS_IMAGE
>>> hmi_map = sunpy.map.Map(HMI_LOS_IMAGE)
>>> arcsec_coord = hmi_map.pixel_to_world(600*u.pix, 300*u.pix)
>>> print(arcsec_coord)
<SkyCoord (Helioprojective: obstime=2011-06-07T06:32:11.000, rsun=696000.0 km, observer=<HeliographicStonyhurst Coordinate (obstime=2011-06-07T06:32:11.000, rsun=696000.0 km): (lon, lat, radius) in (deg, deg, m)
(0.07430567, 0.048537, 1.51846024e+11)>): (Tx, Ty) in arcsec
(-182.22906643, 426.71390943)>
>>> print(arcsec_coord.heliographic_stonyhurst)
<SkyCoord (HeliographicStonyhurst: obstime=2011-06-07T06:32:11.000, rsun=696000.0 km): (lon, lat, radius) in (deg, deg, m)
(-12.34153662, 26.76145867, 6.96e+08)>
| 13:47:12 |
mnedal | I'm trying to plot the PFSS solution for that date but I'm getting this error about a missing key. Here's the code and the error below:
import numpy as np
import pfsspy
from pfsspy import coords, tracing
import sunpy.map
from sunpy.net import Fido, attrs as a
import astropy.units as u
import astropy.constants as const
from astropy.coordinates import SkyCoord
gong_result = Fido.search(a.Time('2021-09-18 12:00:00', '2021-09-18 13:00:00'), a.Instrument('GONG'))
gong = Fido.fetch(gong_result, path='./{instrument}/{file}')
gong_map = sunpy.map.Map(gong)
nrho = 35
rss = 2.5
pfss_in = pfsspy.Input(gong_map, nrho, rss)
pfss_out = pfsspy.pfss(pfss_in)
num_footpoints_lat = 40
num_footpoints_lon = 60
lat = np.linspace(np.radians(-75), np.radians(75), num_footpoints_lat, endpoint=False)
lon = np.linspace(np.radians(0), np.radians(365), num_footpoints_lon, endpoint=False)
lat, lon = np.meshgrid(lat, lon, indexing='ij')
lat, lon = lat.ravel()*u.rad, lon.ravel()*u.rad
r = 1.2*const.R_sun
seeds = SkyCoord(lon, lat, r, frame=pfss_out.coordinate_frame)
tracer = tracing.FortranTracer()
flines = tracer.trace(seeds, pfss_out)
Files Downloaded: 0%| | 0/1 [00:00<?, ?file/s]
INFO: Missing metadata for solar radius: assuming the standard radius of the photosphere. [sunpy.map.mapbase]
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
Cell In[3], line 31
29 seeds = SkyCoord(lon, lat, r, frame=pfss_out.coordinate_frame)
30 tracer = tracing.FortranTracer()
---> 31 flines = tracer.trace(seeds, pfss_out)
File ~/.conda/envs/solo8/lib/python3.9/site-packages/pfsspy/tracing.py:151, in FortranTracer.trace(self, seeds, output)
148 self.tracer.max_steps = int(4 * output.grid.nr / self.step_size)
150 self.validate_seeds(seeds)
--> 151 x, y, z = self.coords_to_xyz(seeds, output)
152 r, lat, phi = astrocoords.cartesian_to_spherical(x, y, z)
154 # Force 360deg wrapping
File ~/.conda/envs/solo8/lib/python3.9/site-packages/pfsspy/tracing.py:66, in Tracer.coords_to_xyz(seeds, output)
63 lon = seeds.lon
64 # Note we want 0deg longitude to be a point on the LH side of the map,
65 # but _lon0 is center of map, so offset by 180deg
---> 66 lon -= output._lon0 - 180 * u.deg
67 x, y, z = astrocoords.spherical_to_cartesian(
68 seeds.radius, seeds.lat, lon)
69 x = x.to_value(const.R_sun)
File ~/.conda/envs/solo8/lib/python3.9/site-packages/pfsspy/output.py:58, in Output._lon0(self)
54 @property
55 def _lon0(self):
56 """Longitude offset of the map."""
57 return (self.input_map.meta['crval1'] *
---> 58 u.Unit(self.input_map.meta['cunit1']))
File ~/.conda/envs/solo8/lib/python3.9/site-packages/sunpy/util/metadata.py:167, in MetaDict.__getitem__(self, key)
163 def __getitem__(self, key):
164 """
165 Override ``[]`` indexing.
166 """
--> 167 return OrderedDict.__getitem__(self, key.lower())
KeyError: 'cunit1'
I tested it with different dates and times and I still get the same error.
sunpy: 5.1.2
pfsspy: 1.2.0
python 3.9.13
| 13:59:49 |
mnedal | * I'm trying to plot the PFSS solution for that date but I'm getting this error about a missing key. Here's the code and the error below:
import numpy as np
import pfsspy
from pfsspy import coords, tracing
import sunpy.map
from sunpy.net import Fido, attrs as a
import astropy.units as u
import astropy.constants as const
from astropy.coordinates import SkyCoord
gong_result = Fido.search(a.Time('2021-09-18 12:00:00', '2021-09-18 13:00:00'), a.Instrument('GONG'))
gong = Fido.fetch(gong_result, path='./{instrument}/{file}')
gong_map = sunpy.map.Map(gong)
nrho = 35
rss = 2.5
pfss_in = pfsspy.Input(gong_map, nrho, rss)
pfss_out = pfsspy.pfss(pfss_in)
num_footpoints_lat = 40
num_footpoints_lon = 60
lat = np.linspace(np.radians(-75), np.radians(75), num_footpoints_lat, endpoint=False)
lon = np.linspace(np.radians(0), np.radians(365), num_footpoints_lon, endpoint=False)
lat, lon = np.meshgrid(lat, lon, indexing='ij')
lat, lon = lat.ravel()*u.rad, lon.ravel()*u.rad
r = 1.2*const.R_sun
seeds = SkyCoord(lon, lat, r, frame=pfss_out.coordinate_frame)
tracer = tracing.FortranTracer()
flines = tracer.trace(seeds, pfss_out)
Files Downloaded: 0%| | 0/1 [00:00<?, ?file/s]
INFO: Missing metadata for solar radius: assuming the standard radius of the photosphere. [sunpy.map.mapbase]
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
Cell In[3], line 31
29 seeds = SkyCoord(lon, lat, r, frame=pfss_out.coordinate_frame)
30 tracer = tracing.FortranTracer()
---> 31 flines = tracer.trace(seeds, pfss_out)
File ~/.conda/envs/solo8/lib/python3.9/site-packages/pfsspy/tracing.py:151, in FortranTracer.trace(self, seeds, output)
148 self.tracer.max_steps = int(4 * output.grid.nr / self.step_size)
150 self.validate_seeds(seeds)
--> 151 x, y, z = self.coords_to_xyz(seeds, output)
152 r, lat, phi = astrocoords.cartesian_to_spherical(x, y, z)
154 # Force 360deg wrapping
File ~/.conda/envs/solo8/lib/python3.9/site-packages/pfsspy/tracing.py:66, in Tracer.coords_to_xyz(seeds, output)
63 lon = seeds.lon
64 # Note we want 0deg longitude to be a point on the LH side of the map,
65 # but _lon0 is center of map, so offset by 180deg
---> 66 lon -= output._lon0 - 180 * u.deg
67 x, y, z = astrocoords.spherical_to_cartesian(
68 seeds.radius, seeds.lat, lon)
69 x = x.to_value(const.R_sun)
File ~/.conda/envs/solo8/lib/python3.9/site-packages/pfsspy/output.py:58, in Output._lon0(self)
54 @property
55 def _lon0(self):
56 """Longitude offset of the map."""
57 return (self.input_map.meta['crval1'] *
---> 58 u.Unit(self.input_map.meta['cunit1']))
File ~/.conda/envs/solo8/lib/python3.9/site-packages/sunpy/util/metadata.py:167, in MetaDict.__getitem__(self, key)
163 def __getitem__(self, key):
164 """
165 Override ``[]`` indexing.
166 """
--> 167 return OrderedDict.__getitem__(self, key.lower())
KeyError: 'cunit1'
I tested it with different dates and times and I still get the same error. Is there a way to fix it?
sunpy: 5.1.2
pfsspy: 1.2.0
python 3.9.13
| 14:00:59 |
fresnels | In reply to @ayshih:matrix.org
But, if it's somehow helpful, here's my example from the beginning:
>>> import astropy.units as u
>>> import sunpy.map
>>> from sunpy.data.sample import HMI_LOS_IMAGE
>>> hmi_map = sunpy.map.Map(HMI_LOS_IMAGE)
>>> arcsec_coord = hmi_map.pixel_to_world(600*u.pix, 300*u.pix)
>>> print(arcsec_coord)
<SkyCoord (Helioprojective: obstime=2011-06-07T06:32:11.000, rsun=696000.0 km, observer=<HeliographicStonyhurst Coordinate (obstime=2011-06-07T06:32:11.000, rsun=696000.0 km): (lon, lat, radius) in (deg, deg, m)
(0.07430567, 0.048537, 1.51846024e+11)>): (Tx, Ty) in arcsec
(-182.22906643, 426.71390943)>
>>> print(arcsec_coord.heliographic_stonyhurst)
<SkyCoord (HeliographicStonyhurst: obstime=2011-06-07T06:32:11.000, rsun=696000.0 km): (lon, lat, radius) in (deg, deg, m)
(-12.34153662, 26.76145867, 6.96e+08)>
Thanks! Now I understand it better. One more question, in line 10. where can I get the list for available keywords like the .heliographic_stonyhurst that is used here. It looks slightly different from sunpy.coordinates.frames | 14:18:07 |
alasdairwilson | you just mean this? :
https://docs.sunpy.org/en/stable/generated/api/sunpy.coordinates.HeliographicStonyhurst.html | 14:19:08 |
ayshih | In reply to @fresnels:matrix.org Thanks! Now I understand it better. One more question, in line 10. where can I get the list for available keywords like the .heliographic_stonyhurst that is used here. It looks slightly different from sunpy.coordinates.frames In most cases, that way of specifying the destination frame is simply all lowercase of the class name. For historical reasons, heliographic_stonyhurst and heliographic_carrington have an additional underscore. In our transform graph (https://docs.sunpy.org/en/stable/reference/coordinates/index.html#module-sunpy.coordinates), you can see the "string" names for each of the coordinate frames as the second line in each oval (you may need to increase the magnification in your web browser) | 14:22:39 |
ayshih | You can alternatively specify arcsec_coord.transform_to(sunpy.coordinates.frames.HeliographicStonyhurst) , and then you don't have to be aware of the sneaky underscore | 14:24:04 |
Cadair | snneaaaaakkkk | 15:16:57 |
Cadair | yeah the underscore is my bad ;) | 15:16:59 |
Nabobalis | In reply to @mohamednedal:matrix.org
I'm trying to plot the PFSS solution for that date but I'm getting this error about a missing key. Here's the code and the error below:
import numpy as np
import pfsspy
from pfsspy import coords, tracing
import sunpy.map
from sunpy.net import Fido, attrs as a
import astropy.units as u
import astropy.constants as const
from astropy.coordinates import SkyCoord
gong_result = Fido.search(a.Time('2021-09-18 12:00:00', '2021-09-18 13:00:00'), a.Instrument('GONG'))
gong = Fido.fetch(gong_result, path='./{instrument}/{file}')
gong_map = sunpy.map.Map(gong)
nrho = 35
rss = 2.5
pfss_in = pfsspy.Input(gong_map, nrho, rss)
pfss_out = pfsspy.pfss(pfss_in)
num_footpoints_lat = 40
num_footpoints_lon = 60
lat = np.linspace(np.radians(-75), np.radians(75), num_footpoints_lat, endpoint=False)
lon = np.linspace(np.radians(0), np.radians(365), num_footpoints_lon, endpoint=False)
lat, lon = np.meshgrid(lat, lon, indexing='ij')
lat, lon = lat.ravel()*u.rad, lon.ravel()*u.rad
r = 1.2*const.R_sun
seeds = SkyCoord(lon, lat, r, frame=pfss_out.coordinate_frame)
tracer = tracing.FortranTracer()
flines = tracer.trace(seeds, pfss_out)
Files Downloaded: 0%| | 0/1 [00:00<?, ?file/s]
INFO: Missing metadata for solar radius: assuming the standard radius of the photosphere. [sunpy.map.mapbase]
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
Cell In[3], line 31
29 seeds = SkyCoord(lon, lat, r, frame=pfss_out.coordinate_frame)
30 tracer = tracing.FortranTracer()
---> 31 flines = tracer.trace(seeds, pfss_out)
File ~/.conda/envs/solo8/lib/python3.9/site-packages/pfsspy/tracing.py:151, in FortranTracer.trace(self, seeds, output)
148 self.tracer.max_steps = int(4 * output.grid.nr / self.step_size)
150 self.validate_seeds(seeds)
--> 151 x, y, z = self.coords_to_xyz(seeds, output)
152 r, lat, phi = astrocoords.cartesian_to_spherical(x, y, z)
154 # Force 360deg wrapping
File ~/.conda/envs/solo8/lib/python3.9/site-packages/pfsspy/tracing.py:66, in Tracer.coords_to_xyz(seeds, output)
63 lon = seeds.lon
64 # Note we want 0deg longitude to be a point on the LH side of the map,
65 # but _lon0 is center of map, so offset by 180deg
---> 66 lon -= output._lon0 - 180 * u.deg
67 x, y, z = astrocoords.spherical_to_cartesian(
68 seeds.radius, seeds.lat, lon)
69 x = x.to_value(const.R_sun)
File ~/.conda/envs/solo8/lib/python3.9/site-packages/pfsspy/output.py:58, in Output._lon0(self)
54 @property
55 def _lon0(self):
56 """Longitude offset of the map."""
57 return (self.input_map.meta['crval1'] *
---> 58 u.Unit(self.input_map.meta['cunit1']))
File ~/.conda/envs/solo8/lib/python3.9/site-packages/sunpy/util/metadata.py:167, in MetaDict.__getitem__(self, key)
163 def __getitem__(self, key):
164 """
165 Override ``[]`` indexing.
166 """
--> 167 return OrderedDict.__getitem__(self, key.lower())
KeyError: 'cunit1'
I tested it with different dates and times and I still get the same error. Is there a way to fix it?
sunpy: 5.1.2
pfsspy: 1.2.0
python 3.9.13
pfsspy is no longer maintained and we broke it with some changes in sunpy 5.1, the sunpy project is spinning up a replacement https://github.com/sunpy/sunkit-magex, Cadair what is the status of that? | 15:29:57 |
Cadair | errr | 15:32:13 |
mnedal | In reply to @Nabobalis:matrix.org pfsspy is no longer maintained and we broke it with some changes in sunpy 5.1, the sunpy project is spinning up a replacement https://github.com/sunpy/sunkit-magex, Cadair what is the status of that? I tried to install sunkit-magex from this website in a virtual environment and I got this error message:
ERROR: Could not find a version that satisfies the requirement sunkit-magex (from versions: none) ERROR: No matching distribution found for sunkit-magex
| 18:49:43 |
mnedal | In reply to @Nabobalis:matrix.org pfsspy is no longer maintained and we broke it with some changes in sunpy 5.1, the sunpy project is spinning up a replacement https://github.com/sunpy/sunkit-magex, Cadair what is the status of that? * I tried to install sunkit-magex from this website in a virtual environment and I got this error message:
ERROR: Could not find a version that satisfies the requirement sunkit-magex (from versions: none)
ERROR: No matching distribution found for sunkit-magex
| 18:50:00 |
Nabobalis | Its not released yet, that is why. | 18:50:44 |
Nabobalis | * Its not released yet, that is why you can't install it. | 18:50:55 |
alasdairwilson | You can install from the git repo though | 18:50:56 |
Nabobalis | True | 18:51:12 |
Nabobalis | * True, you can do that | 18:51:15 |
mnedal | In reply to @alasdairwilson:matrix.org You can install from the git repo though Ok, got it. Thank you | 18:51:19 |
alasdairwilson | Jury download the .exe... I mean "pip install git+urlofrepo" or clone the repo and do "pip install -e ." In the folder. | 18:53:38 |
alasdairwilson | * Just download the .exe... I mean "pip install git+urlofrepo" or clone the repo and do "pip install -e ." In the folder. | 18:53:57 |
alasdairwilson | And report back if it works haha cause not sure how many have tested it. | 18:54:36 |
Nabobalis | In reply to @alasdairwilson:matrix.org Just download the .exe... I mean "pip install git+urlofrepo" or clone the repo and do "pip install -e ." In the folder. NOT_A_VIRUS.EXE i think explains it self pretty nicely under the release page | 18:57:49 |
| wtbarnes set a profile picture. | 22:13:36 |
| wtbarnes changed their profile picture. | 22:14:14 |
20 Apr 2024 |
mnedal | Download image.png | 00:29:50 |
mnedal | It works!! Thank you 😃🙌 | 00:30:06 |
Cadair | That's good to know! | 05:41:31 |