;+ ; ; PROJECT: ; RHESSI ; ; NAME: ; read_messenger_pds_csv_data ; ; PURPOSE: ; Read MESSENGER solar data and times from a cvs format file, compute drm, and ; return data and associated values. Normally we read the MESSENGER data from .dat and .lbl file, but ; for data that isn't available yet publically, Richard Starr made an XLS spreadsheet which I converted ; to CVS. This is called from OSPEX in spex_any_specfile::read_data when spex_specfilel has been set ; to a messenger cvs file, and the user has set o->spex_file_reader='read_messenger_pds_csv' ; ; ; CATEGORY: ; SPEX ; ; CALLING SEQUENCE: ; read_messenger_pds_csv_data, FILES=files, data_str=data_str[, ERR_CODE=err_code, ; ERR_MSG=err_msg, _REF_EXTRA=_ref_extra $ ; verbose=verbose ; ; INPUT KEYWORDS: ; FILES - Name of messenger .dat file to read. Corresponding .lbl file must be in the same directory. ; verbose - if set, print information about filtering. Default is 0. ; ; OUTPUT KEYWORDS: ; data_str - structure containing the information read from the file (see ; structure definition at end of code for fields in structure) ; err_code - 0 / 1 means no error / error ; err_msg - string containing error message. Blank if none. ; ; EXAMPLE: ; Can be called standalone: ; read_messenger_pds_csv,files='xrs2007152.dat', data_str=data_str ; or, called from within OSPEX to load MESSENGER data ; ; Written: 9-Oct-2013, Kim Tolbert ; ; Modification History: ; 9-oct-2014, Kim. Extracted from messenger_read_pds ; 24-Nov-2014, Kim. Renamed to read_messenger_pds_csv_data from read_messenger_pds_csv because spex_any_specfile is now ; generalized to read any data type. Set spex_file_reader parameter to 'read_messenger_pds_csv', the '_data' will ; automatically be appended. ; ; ;- ;------------------------------------------------------------------------------ pro read_messenger_pds_csv_data, FILES=files, data_str=data_str, ERR_CODE=err_code,$ ERR_MSG=err_msg, _REF_EXTRA=_ref_extra, $ verbose=verbose checkvar, verbose, 0 checkvar, no_filter, 0 orbit_date = anytim('4-mar-2011') ; first day of Mercury Orbit temp_change_date = anytim('5-march-2012') temp_cutoff = [19., 2.] ; valid maximum temperature for before/after temp_change_date ; These are times that weren't caught by any of our eclipse, etc filters, but are clearly bad data bad_times = [[' 3-Sep-2012 07:51:41.327', ' 3-Sep-2012 08:01:01.327'], $ ['20-Sep-2012 07:54:57.355', '20-Sep-2012 08:14:57.355'], $ ['20-Sep-2012 15:56:39.355', '20-Sep-2012 16:14:39.355'], $ ['21-Sep-2012 07:58:37.072', '21-Sep-2012 08:11:17.072'], $ ['21-Sep-2012 15:47:57.072', '21-Sep-2012 16:17:57.072']] bad_times = anytim(bad_times) fcount = 0 If is_string( files ) then file = file_search(/fully_qualify_path, files, count=fcount) if fcount eq 0 then begin err_code=1 err_msg = 'No MESSENGER spectrum file selected.' return endif Catch, err_code IF err_code ne 0 then begin catch, /cancel print,!error_state.msg err_msg = 'Error reading MESSENGER file ' + file[0] message,/continue, err_msg return endif a = rd_tfile(files[0], delim=',', /auto) if n_elements(a[*,0]) ne 234 then message,'This probably is not a MESSENGER CSV file: ' + files[0] met = reform(long(a[0,*])) message, 'NOTE: CURRENTLY ASSUMES 1-sep-2014, CHANGE THIS IF READING A DIFFERENT DAY OF DATA !!!!!!!!!!!!!!!!!!!!!!!!!!!', /cont ut = anytim('1-sep-2014 ' +reform( a[1,*])) int_time = reform(fix(a[2,*])) ut_edges = transpose([[ut], [ut+int_time]]) data = float(a[3:*,*]) ; get corrections for times and area to Earth view messenger_dist_correct, intime=ut[0], time_offset=time_offset, area_factor=area_factor ut_edges = ut_edges + time_offset data_str = -1 err_code = 0 err_msg = '' atten_states = -1 ; get drm, energy edges and area ;drm = messenger_drm(ein2=ct_edges, area=area) ;richard schwartz, 17-feb-2014, use new drm computation with possible offset in keV defsysv, '!messenger_drm_params', value, exist = have_drm_params if have_drm_params then begin value = !messenger_drm_params if have_tag( value, 'offset') then offset = value.offset if have_tag( value, 'fwhm' ) then fwhm = value.fwhm endif drm = messenger_use_resp_calc( edges_in = ph_edges, edges_out = ct_edges, area = area, fwhm=fwhm, offset=offset, zout = zout ) area = area * area_factor ; correct to Earth view data = data[zout,*] nt = n_elements(data[0,*]) nen = n_elements(data[*,0]) ut_width = get_edges(ut_edges, /width) ; livetime estimate is width of time bin minus 16 microsec for each count in all energies ltimes = transpose( rebin(ut_width - .000016 * total(data,1), nt, nen)) data_name = 'MESSENGER' title = 'MESSENGER SPECTRUM' units = 'counts' data_str = { $ START_TIME: anytim(ut_edges[0],/vms), $ ;start time of data in sec rel to 79/1/1 END_TIME: anytim(ut_edges[1,nt-1], /vms), $ ;end time of data in sec rel to 79/1/1 RCOUNTS: data, $ ; SOLAR_MON_SPECTRUM_23_253 - xrs data (nenergy, ntime) ERCOUNTS: sqrt(data), $ ; error in xrs data (nenergy, ntime) UT_EDGES: ut_edges, $ ;edges of time bins of xrs data in sec rel to 79/1/1 (2,ntime) UNITS: units, $ ; 'counts' AREA: area, $ ; detector area corrected to Earth view LTIME: ltimes, $ ;live times in seconds (nenergy, ntime) CT_EDGES: ct_edges, $ ;edges of energy bins in keV (2,nenergy) data_name: data_name, $ ; instrument/satellite name 'MESSENGER' TITLE: title, $ ; label for data 'MESSENGER SPECTRUM' RESPFILE: {drm: drm, edges_in: ph_edges, edges_out: ct_edges }, $ ; DRM matrix, ras added edges, 17-feb-2014 detused: 'XRS', $ ; label for detector name for main data in RCOUNTS atten_states: atten_states, $ ; -1, not used int_time: int_time, $ ; integration time in seconds deconvolved: 0, $ pseudo_livetime: 0, $ xyoffset: [0.,0.] $ } END