Example #1
0
def ndcubesequence_3c_l_ln_lt_cax1(wcs_3d_lt_ln_l):
    common_axis = 1

    base_time1 = Time('2000-01-01', format='fits', scale='utc')
    gc1 = GlobalCoords()
    gc1.add('distance', 'custom:distance', 1 * u.m)
    cube1 = gen_ndcube_3d_l_ln_lt_ectime(wcs_3d_lt_ln_l, 1, base_time1, gc1)

    shape = cube1.data.shape
    base_time2 = base_time1 + TimeDelta([shape[common_axis] * 60],
                                        format='sec')
    gc2 = GlobalCoords()
    gc2.add('distance', 'custom:distance', 2 * u.m)
    gc2.add('global coord', 'custom:physical_type', 0 * u.pix)
    cube2 = gen_ndcube_3d_l_ln_lt_ectime(wcs_3d_lt_ln_l, 1, base_time2, gc2)
    cube2.data[:] *= 2

    base_time3 = base_time2 + TimeDelta([shape[common_axis] * 60],
                                        format='sec')
    gc3 = GlobalCoords()
    gc3.add('distance', 'custom:distance', 3 * u.m)
    cube3 = gen_ndcube_3d_l_ln_lt_ectime(wcs_3d_lt_ln_l, 1, base_time3, gc3)
    cube3.data[:] *= 3

    return NDCubeSequence([cube1, cube2, cube3], common_axis=common_axis)
Example #2
0
 def fromFile(cls, files: str) -> 'ViewerController':
     cubes = [NDCube(getdata(f), WCS(getheader(f))) for f in files]
     if len(cubes) == 1:
         cube = cubes[0]
     else:
         cube = NDCubeSequence(cubes)
     model = NDCubeModel(cube, files)
     return cls(model)
Example #3
0
def ndcubesequence_4c_ln_lt_l_cax1(ndcube_3d_ln_lt_l):
    cube1 = ndcube_3d_ln_lt_l
    cube2 = ndcube_3d_ln_lt_l
    cube3 = ndcube_3d_ln_lt_l
    cube4 = ndcube_3d_ln_lt_l
    cube2.data[:] *= 2
    cube3.data[:] *= 3
    cube4.data[:] *= 4
    return NDCubeSequence([cube1, cube2, cube3, cube4], common_axis=1)
Example #4
0
def ndcubesequence_4c_ln_lt_l(ndcube_3d_ln_lt_l):
    cube1 = ndcube_3d_ln_lt_l
    cube2 = ndcube_3d_ln_lt_l
    cube3 = ndcube_3d_ln_lt_l
    cube4 = ndcube_3d_ln_lt_l
    cube2.data[:] *= 2
    cube3.data[:] *= 3
    cube4.data[:] *= 4
    return NDCubeSequence([cube1, cube2, cube3, cube4])
Example #5
0
    'CUNIT3': 'deg',
    'CDELT3': 0.4,
    'CRPIX3': 2,
    'CRVAL3': 1,
    'NAXIS3': 2,
}

wt = WCS(header=ht, naxis=3)
wm = WCS(header=hm, naxis=3)

cube1 = NDCube(data, wt, missing_axis=[False, False, False, True])
cube2 = NDCube(data, wm)
cube3 = NDCube(data2, wt, missing_axis=[False, False, False, True])
cube4 = NDCube(data2, wm)

seq = NDCubeSequence([cube1, cube2, cube3, cube4], common_axis=0)
seq1 = NDCubeSequence([cube1, cube2, cube3, cube4])

map1 = cube2[:, :, 0].to_sunpy()
map2 = cube2[:, :, 1].to_sunpy()
map3 = cube2[:, :, 2].to_sunpy()
map4 = cube2[:, :, 3].to_sunpy()
mapcube_seq = NDCubeSequence([map1, map2, map3, map4], common_axis=0)


@pytest.mark.parametrize("test_input,expected", [
    (seq[0], NDCube),
    (seq[1], NDCube),
    (seq[2], NDCube),
    (seq[3], NDCube),
    (seq[0:1], NDCubeSequence),
Example #6
0
hm = {
    'CTYPE1': 'WAVE    ', 'CUNIT1': 'Angstrom', 'CDELT1': 0.2, 'CRPIX1': 0, 'CRVAL1': 10, 'NAXIS1': 4,
    'CTYPE2': 'HPLT-TAN', 'CUNIT2': 'deg', 'CDELT2': 0.5, 'CRPIX2': 2, 'CRVAL2': 0.5, 'NAXIS2': 3,
    'CTYPE3': 'HPLN-TAN', 'CUNIT3': 'deg', 'CDELT3': 0.4, 'CRPIX3': 2, 'CRVAL3': 1, 'NAXIS3': 2,
}

wt = WCS(header=ht, naxis=3)
wm = WCS(header=hm, naxis=3)

cube1 = NDCube(data, wcs=wt, missing_axis=[False, False, False, True])
cube2 = NDCube(data, wcs=wm)
cube3 = NDCube(data2, wcs=wt, missing_axis=[False, False, False, True])
cube4 = NDCube(data2, wcs=wm)

seq = NDCubeSequence([cube1, cube2, cube3, cube4], common_axis=0)
seq1 = NDCubeSequence([cube1, cube2, cube3, cube4])


@pytest.mark.parametrize("test_input,expected", [
    (seq[0], NDCube),
    (seq[1], NDCube),
    (seq[2], NDCube),
    (seq[3], NDCube),
    (seq[0:1], NDCubeSequence),
    (seq[1:3], NDCubeSequence),
    (seq[0:2], NDCubeSequence),
    (seq[slice(0, 2)], NDCubeSequence),
    (seq[slice(0, 3)], NDCubeSequence),
])
def test_slice_first_index_sequence(test_input, expected):
Example #7
0
    'CTYPE2': 'HPLN-TAN',
    'CUNIT2': 'deg',
    'CDELT2': 0.4,
    'CRPIX2': 2,
    'CRVAL2': 1,
    'NAXIS2': 3
}
input_wcs1 = astropy.wcs.WCS(wcs_input_dict1)

# Define cubes.
cube0 = NDCube(data0, input_wcs)
cube1 = NDCube(data1, input_wcs1)
cube2 = NDCube(data2, input_wcs)

# Define sequences.
sequence02 = NDCubeSequence([cube0, cube2])
sequence20 = NDCubeSequence([cube2, cube0])

# Define collections
aligned_axes = ((1, 2), (2, 0), (1, 2))
keys = ("cube0", "cube1", "cube2")
cube_collection = NDCollection([("cube0", cube0), ("cube1", cube1),
                                ("cube2", cube2)], aligned_axes)
seq_collection = NDCollection([("seq0", sequence02), ("seq1", sequence20)],
                              aligned_axes="all")


@pytest.mark.parametrize(
    "item,collection,expected",
    [(0, cube_collection,
      NDCollection([("cube0", cube0[:, 0]), ("cube1", cube1[:, :, 0]),
cube2_time_common = NDCube(
    data,
    wm,
    extra_coords=[('time', 1, [
        cube1_time_common.extra_coords["time"]["value"][-1] +
        datetime.timedelta(minutes=i) for i in range(1, data.shape[1] + 1)
    ])])

cube1_no_extra_coords = NDCube(data,
                               wt,
                               missing_axes=[False, False, False, True])
cube3_no_extra_coords = NDCube(data2,
                               wt,
                               missing_axes=[False, False, False, True])

seq = NDCubeSequence([cube1, cube2, cube3, cube4], common_axis=0)
seq_bad_common_axis = NDCubeSequence([cube1, cube2, cube3, cube4],
                                     common_axis=None)
seq_time_common = NDCubeSequence([cube1_time_common, cube2_time_common],
                                 common_axis=1)
seq1 = NDCubeSequence([cube1, cube2, cube3, cube4])
seq2 = NDCubeSequence([cube1, cube2_no_no, cube3_no_time, cube4])
seq3 = NDCubeSequence([cube1, cube2, cube3_diff_compatible_unit, cube4])
seq4 = NDCubeSequence([cube1, cube2, cube3_diff_incompatible_unit, cube4])
seq_no_extra_coords = NDCubeSequence(
    [cube1_no_extra_coords, cube3_no_extra_coords], common_axis=0)

nan_extra_coord = u.Quantity(range(4), unit=u.cm)
nan_extra_coord.value[1] = np.nan
nan_time_extra_coord = np.array([
    datetime.datetime(2000, 1, 1) + datetime.timedelta(minutes=i)
                    ('distance', None, u.Quantity(0, unit=u.cm)),
                    ('time', None, datetime.datetime(2000, 1, 1, 0, 0))
                ])

cubem3 = NDCube(data2,
                wm,
                extra_coords=[
                    ('pix', 0, u.Quantity(range(data.shape[0]), unit=u.pix)),
                    ('hi', 1, u.Quantity(range(data.shape[1]), unit=u.s)),
                    ('distance', None, u.Quantity(0, unit=u.cm)),
                    ('time', None, datetime.datetime(2000, 1, 1, 0, 0))
                ])

# Define some test NDCubeSequences.
common_axis = 0
seq = NDCubeSequence(data_list=[cube1, cube3, cube1, cube3],
                     common_axis=common_axis)

seq_no_common_axis = NDCubeSequence(data_list=[cube1, cube3, cube1, cube3])

seq_with_units = NDCubeSequence(data_list=[
    cube1_with_unit, cube3_with_unit, cube1_with_unit, cube3_with_unit
],
                                common_axis=common_axis)

seq_with_masks = NDCubeSequence(data_list=[
    cube1_with_mask, cube3_with_mask, cube1_with_mask, cube3_with_mask
],
                                common_axis=common_axis)

seq_with_unit0 = NDCubeSequence(
    data_list=[cube1_with_unit, cube3, cube1_with_unit, cube3],
Example #10
0
    data, wt, missing_axes=[False, False, False, True],
    extra_coords=[('time', 1, [datetime.datetime(2000, 1, 1) + datetime.timedelta(minutes=i)
                               for i in range(data.shape[1])])])

cube2_time_common = NDCube(data, wm, extra_coords=[
    ('time', 1,
     [cube1_time_common.extra_coords["time"]["value"][-1] + datetime.timedelta(minutes=i)
      for i in range(1, data.shape[1]+1)])])

cube1_no_extra_coords = NDCube(data, wt, missing_axes=[False, False, False, True])
cube3_no_extra_coords = NDCube(data2, wt, missing_axes=[False, False, False, True])

seq = NDCubeSequence([cube1, cube2, cube3, cube4], common_axis=0)
seq_bad_common_axis = NDCubeSequence([cube1, cube2, cube3, cube4], common_axis=None)
seq_time_common = NDCubeSequence([cube1_time_common, cube2_time_common], common_axis=1)
seq1 = NDCubeSequence([cube1, cube2, cube3, cube4])
seq2 = NDCubeSequence([cube1, cube2_no_no, cube3_no_time, cube4])
seq3 = NDCubeSequence([cube1, cube2, cube3_diff_compatible_unit, cube4])
seq4 = NDCubeSequence([cube1, cube2, cube3_diff_incompatible_unit, cube4])
seq_no_extra_coords = NDCubeSequence([cube1_no_extra_coords, cube3_no_extra_coords], common_axis=0)

nan_extra_coord = u.Quantity(range(4), unit=u.cm)
nan_extra_coord.value[1] = np.nan
nan_time_extra_coord = np.array([datetime.datetime(2000, 1, 1)+datetime.timedelta(minutes=i)
                                 for i in range(len(seq.data))])
nan_time_extra_coord[2] = np.nan


@pytest.mark.parametrize("test_input,expected", [
    (seq[0], NDCube),
    (seq[1], NDCube),