<jupyter_start><jupyter_text>**Warning** Work in progress notebook - only for testing purposes only of sunpy and nustar_pysolar<jupyter_code>from astropy.io import fits
import astropy.units as u

import matplotlib
import matplotlib.pyplot as plt
import matplotlib.colors as colors
from matplotlib.colors import LogNorm
%matplotlib inline
# %matplotlib notebook

import warnings
warnings.simplefilter('ignore')

from pylab import figure, cm
from astropy.coordinates import SkyCoord

import numpy as np

import nustar_pysolar as nustar

import sunpy.map

from scipy import ndimage

dirin=''
infile = 'nu90410111001A06_cl_sunpos.evt'

# Load in the evt
hdulist = fits.open(dirin+infile)
evtdata=hdulist[1].data
hdr = hdulist[1].header
hdulist.close()

print(hdr["ontime"])
import astropy.time
mjdref=hdr['MJDREFI']
tr = ['2018-09-28T18:50:00', '2018-09-28T18:52:00']
tim_ran = astropy.time.Time(tr, format='isot')

print(tim_ran.mjd)
print(mjdref)
at_ref=astropy.time.Time(mjdref,format='mjd')

print(at_ref.iso)
# number of days for time range since ref
print(tim_ran.mjd-mjdref)
# number of seconds for time range since ref
print(tim_ran.unix-at_ref.unix)
print(evtdata['time'][0])
# Map the filtered evt, into one corrected for livetime (so units count/s) 
# nustar_map = nustar.map.make_sunpy(cleanevt, hdr,norm_map=True)

# import nustar_pysolar as nustar
# import map
# import importlib
# importlib.reload(map)

# nmap = map.make_sunpy(cleanevt, hdr,norm_map=True)
nmap = nustar.map.make_sunpy(evtdata, hdr,norm_map=True)

nmap.peek()

print(nmap.meta)
# Filter the evt file
import nustar_filter
import importlib
importlib.reload(nustar_filter)

import astropy.time
tr = ['2018-09-28T18:49:00', '2018-09-28T18:49:30']
tim_ran = astropy.time.Time(tr, format='isot')

cleanevt = nustar_filter.event_filter(evtdata,fpm='A',energy_low=2.5, energy_high=5.0,\
                                      hdr=hdr,\
#                                       xy_range=[-1300,-500,-400,400],\
                                      time_range=tim_ran)

nmap = nustar.map.make_sunpy(cleanevt, hdr,norm_map=True)

print(evtdata['time'].min(),evtdata['time'].max())
print(cleanevt['time'].min(),cleanevt['time'].max())
bl = SkyCoord(-1300*u.arcsec, -300*u.arcsec, frame=nmap.coordinate_frame)
tr = SkyCoord(-500*u.arcsec, 500*u.arcsec, frame=nmap.coordinate_frame)
nms = nmap.submap(bl,tr)
fig = plt.figure(figsize=(9, 8))
nms.plot(colors.Normalize(vmin=1e-3,vmax=1e-1))


# print(len(evtdata),len(cleanevt))
# Filter the evt file
import nustar_filter
import importlib
importlib.reload(nustar_filter)


cleanevt = nustar_filter.event_filter(evtdata,fpm='A',energy_low=2.5, energy_high=10.0,\
                                      hdr=hdr,dets_id=[0,2])
print(len(evtdata),len(cleanevt))

nmap = nustar.map.make_sunpy(cleanevt, hdr,norm_map=True)

bl = SkyCoord(-1400*u.arcsec, -400*u.arcsec, frame=nmap.coordinate_frame)
tr = SkyCoord(-200*u.arcsec, 600*u.arcsec, frame=nmap.coordinate_frame)
nms = nmap.submap(bl,tr)
fig = plt.figure(figsize=(9, 8))
nms.plot(colors.Normalize(vmin=1e-3,vmax=1e-1))
plt.show()


print(nmap.meta['date-obs'][:len(nmap.meta['date-obs'])-4])
print(nmap.meta['ontime'])
print(evtdata['time'][0:10])<jupyter_output>[2.75856515e+08 2.75856515e+08 2.75856515e+08 2.75856515e+08
 2.75856515e+08 2.75856515e+08 2.75856515e+08 2.75856515e+08
 2.75856515e+08 2.75856515e+08]
{'fraction_non_alphanumeric': 0.1424341131181522, 'fraction_numerical': 0.07343796268877702, 'mean_word_length': 4.957671957671957, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '72963', 'license': 'MIT', 'n_tokens_mistral': 1493, 'n_tokens_neox': 1374, 'n_words': 230, 'path': 'python/nstest_sunpyv2.ipynb', 'repo_name': 'ianan/nustar_sac', 'size': '3377'}