def identity_gwcs_3d_temporal(): """ A simple 1-1 gwcs that converts from pixels to arcseconds """ identity = (TwoDScale(1 * u.arcsec / u.pixel) & m.Multiply(1 * u.s / u.pixel)) sky_frame = cf.CelestialFrame( axes_order=(0, 1), name='helioprojective', reference_frame=Helioprojective(obstime="2018-01-01"), axes_names=("longitude", "latitude"), unit=(u.arcsec, u.arcsec), axis_physical_types=("custom:pos.helioprojective.lon", "custom:pos.helioprojective.lat")) time_frame = cf.TemporalFrame(Time("2020-01-01T00:00", format="isot", scale="utc"), axes_order=(2, ), unit=u.s) frame = cf.CompositeFrame([sky_frame, time_frame]) detector_frame = cf.CoordinateFrame(name="detector", naxes=3, axes_order=(0, 1, 2), axes_type=("pixel", "pixel", "pixel"), axes_names=("x", "y", "z"), unit=(u.pix, u.pix, u.pix)) wcs = gwcs.wcs.WCS(forward_transform=identity, output_frame=frame, input_frame=detector_frame) wcs.pixel_shape = (10, 20, 30) wcs.array_shape = wcs.pixel_shape[::-1] return wcs
def identity_gwcs_4d(): """ A simple 1-1 gwcs that converts from pixels to arcseconds """ identity = (m.Multiply(1 * u.arcsec / u.pixel) & m.Multiply(1 * u.arcsec / u.pixel) & m.Multiply(1 * u.nm / u.pixel) & m.Multiply(1 * u.nm / u.pixel)) sky_frame = cf.CelestialFrame( axes_order=(0, 1), name='helioprojective', reference_frame=Helioprojective(obstime="2018-01-01")) wave_frame = cf.SpectralFrame(axes_order=(2, ), unit=u.nm) time_frame = cf.TemporalFrame(axes_order=(3, ), unit=u.s) frame = cf.CompositeFrame([sky_frame, wave_frame, time_frame]) detector_frame = cf.CoordinateFrame(name="detector", naxes=4, axes_order=(0, 1, 2, 3), axes_type=("pixel", "pixel", "pixel", "pixel"), axes_names=("x", "y", "z", "s"), unit=(u.pix, u.pix, u.pix, u.pix)) return gwcs.wcs.WCS(forward_transform=identity, output_frame=frame, input_frame=detector_frame)
def frame(self): """ Generate the Frame for this LookupTable. """ return cf.TemporalFrame(self.reference_time, unit=u.s, axes_names=self.names, name="TemporalFrame")
def make_temporal(self): """ Add a temporal axes to the builder. """ name = self.header[f'DWNAME{self.n}'] self._frames.append( cf.TemporalFrame(axes_order=(self._i, ), name=name, axes_names=(name, ), unit=self.get_units(self._i), reference_time=Time(self.header['DATE-BGN']))) self._transforms.append( time_model_from_date_obs( [e['DATE-OBS'] for e in self.slice_headers], self.header['DATE-BGN'])) self._i += 1
def _from_time(self, lookup_tables, mesh=False, names=None, physical_types=None, **kwargs): if len(lookup_tables) > 1: raise ValueError("Can only parse one time lookup table.") time = lookup_tables[0] deltas = (time[1:] - time[0]).to(u.s) deltas = deltas.insert(0, 0 * u.s) def _generate_time_lookup(deltas): return self._model_from_quantity((deltas, )) frame = cf.TemporalFrame(lookup_tables[0][0], unit=u.s, axes_names=names, name="TemporalFrame") return DelayedLookupTable(deltas, _generate_time_lookup, mesh), frame
def main(): path = Path('~/sunpy/data/jsocflare/').expanduser() files = glob.glob(str(path / '*.fits')) # requestid = 'JSOC_20180831_1097' requestid = None if not files: if requestid: c = JSOCClient() filesd = c.get_request(requestid, path=str(path), overwrite=False).wait() files = [] for f in filesd.values(): files.append(f['path']) else: results = Fido.search( a.jsoc.Time('2017-09-06T12:00:00', '2017-09-06T12:02:00'), a.jsoc.Series('aia.lev1_euv_12s'), a.jsoc.Segment('image'), a.jsoc.Notify("*****@*****.**")) print(results) files = Fido.fetch(results, path=str(path)) files.sort() files = np.array(files) # For each image get: # the index inds = [] # the time times = [] # the dt from the first image seconds = [] # the wavelength waves = [] for i, filepath in enumerate(files): with fits.open(filepath) as hdul: header = hdul[1].header time = parse_time(header['DATE-OBS']) if i == 0: root_header = header start_time = time inds.append(i) times.append(time) seconds.append((time - start_time).total_seconds()) waves.append(header['WAVELNTH']) # Construct an array and sort it by wavelength and time arr = np.array((inds, seconds, waves)).T sorter = np.lexsort((arr[:, 1], arr[:, 2])) # Using this double-sorted array get the list indicies list_sorter = np.array(arr[sorter][:, 0], dtype=int) # Calculate the desired shape of the output array n_waves = len(list(set(waves))) shape = (n_waves, len(files) // n_waves) # Construct a 2D array of filenames cube = files[list_sorter].reshape(shape) # Extract a list of coordinates in time and wavelength # this assumes all wavelength images are taken at the same time time_coords = np.array([t.isoformat() for t in times])[list_sorter].reshape(shape)[0, :] wave_coords = np.array(waves)[list_sorter].reshape(shape)[:, 0] smap0 = sunpy.map.Map(files[0]) spatial = map_to_transform(smap0) timemodel = generate_lookup_table(lookup_table=seconds[:shape[1]] * u.s) wavemodel = generate_lookup_table(lookup_table=waves[:shape[0]] * u.AA) hcubemodel = spatial & timemodel & wavemodel wave_frame = cf.SpectralFrame(axes_order=(3, ), unit=u.AA, name="wavelength", axes_names=("wavelength", )) time_frame = cf.TemporalFrame(axes_order=(2, ), unit=u.s, reference_time=Time(time_coords[0]), name="time", axes_names=("time", )) sky_frame = cf.CelestialFrame(axes_order=(0, 1), name='helioprojective', reference_frame=smap0.coordinate_frame, axes_names=("helioprojective longitude", "helioprojective latitude")) sky_frame = cf.CompositeFrame([sky_frame, time_frame, wave_frame]) detector_frame = cf.CoordinateFrame(name="detector", naxes=4, axes_order=(0, 1, 2, 3), axes_type=("pixel", "pixel", "pixel", "pixel"), axes_names=("x", "y", "time", "wavelength"), unit=(u.pix, u.pix, u.pix, u.pix)) wcs = gwcs.wcs.WCS(forward_transform=hcubemodel, input_frame=detector_frame, output_frame=sky_frame) print(repr(wcs)) print(wcs(*[1 * u.pix] * 4, with_units=True)) ea = references_from_filenames(cube, relative_to=str(path)) tree = { 'gwcs': wcs, 'dataset': ea, } with asdf.AsdfFile(tree) as ff: # ff.write_to("test.asdf") filename = str(path / "aia_{}.asdf".format(time_coords[0])) ff.write_to(filename) print("Saved to : {}".format(filename)) # import sys; sys.exit(0) from dkist.dataset import Dataset ds = Dataset.from_directory(str(path)) print(repr(ds)) print(repr(ds.wcs)) print(ds.wcs(*[1 * u.pix] * 4, with_units=True))
def main(): path = Path('~/Git/DKIST/dkist/dkist/data/test/EIT').expanduser() files = glob.glob(str(path / '*.fits')) files.sort() files = np.array(files) # For each image get: # the index inds = [] # the time times = [] # the dt from the first image seconds = [] headers = [] for i, filepath in enumerate(files): with fits.open(filepath) as hdul: header = hdul[0].header headers.append(dict(header)) time = parse_time(header['DATE-OBS']) if i == 0: start_time = time inds.append(i) times.append(time) seconds.append((time - start_time).to(u.s)) # Extract a list of coordinates in time and wavelength # this assumes all wavelength images are taken at the same time time_coords = np.array([str(t.isot) for t in times]) smap0 = sunpy.map.Map(files[0]) spatial = map_to_transform(smap0) timemodel = LookupTable(lookup_table=seconds * u.s) hcubemodel = spatial & timemodel sky_frame = cf.CelestialFrame(axes_order=(0, 1), name='helioprojective', reference_frame=smap0.coordinate_frame, axes_names=("helioprojective longitude", "helioprojective latitude")) time_frame = cf.TemporalFrame(axes_order=(2, ), unit=u.s, reference_time=Time(time_coords[0]), axes_names=("time", )) sky_frame = cf.CompositeFrame([sky_frame, time_frame], name="world") detector_frame = cf.CoordinateFrame(name="detector", naxes=3, axes_order=(0, 1, 2), axes_type=("pixel", "pixel", "pixel"), axes_names=("x", "y", "z"), unit=(u.pix, u.pix, u.pix)) wcs = gwcs.wcs.WCS(forward_transform=hcubemodel, input_frame=detector_frame, output_frame=sky_frame) print(repr(wcs)) print(wcs(*[1 * u.pix] * 4, with_units=True)) ea = references_from_filenames(files, relative_to=str(path)) tree = { 'wcs': wcs, 'data': ea, 'headers': table_from_headers(headers), 'meta': generate_datset_inventory_from_headers(headers, "eit_test_dataset.asdf") } with asdf.AsdfFile(tree) as ff: filename = path / "eit_test_dataset.asdf" ff.write_to(filename) print("Saved to : {}".format(filename))