Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

draft nuv dark monitor. help. #156

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
64 changes: 61 additions & 3 deletions cosmo/monitors/data_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,12 +217,13 @@ def get_new_data(self):
'YCORR'
],
3: [
'TIME',
'LATITUDE',
'LONGITUDE'
'LONGITUDE',
'DARKRATE'
]

}
# TODO: add gross counts, don't need PHA, lat or long right now

# any special data requests
# TODO: add spt support for temp, sun_lat, sun_long
Expand All @@ -235,7 +236,6 @@ def get_new_data(self):
for program in program_ids:
new_files_source = os.path.join(FILES_SOURCE, program)
subfiles = glob(os.path.join(new_files_source, "*corrtag*"))
# TODO: figure out why this wasn't working with find_files()
files += subfiles

if not files: # No new files
Expand All @@ -247,3 +247,61 @@ def get_new_data(self):
table_request=table_request)

return data_results


class CorrtagDataModel(BaseDataModel):
"""Datamodel for all NUV Dark files."""
files_source = FILES_SOURCE
subdir_pattern = '?????'

def get_new_data(self):
header_request = {
0: ['ROOTNAME'],
1: [
'EXPSTART',
'EXPTIME',
'EXPTYPE',
'DETECTOR'
]
}

table_request = {
1: [
'TIME',
'XCORR',
'YCORR'
],
3: [
'LATITUDE',
'LONGITUDE'
]

}
cmagness marked this conversation as resolved.
Show resolved Hide resolved
# TODO: add gross counts, don't need PHA, lat or long right now

# any special data requests
# TODO: add spt support for temp, sun_lat, sun_long
# TODO: is this a good place to add solar data scraping in the future?

# this is temporary to find the files from the dark programs until
# we can add the dark files to the monitor_data database
# files = []
# program_ids = ['15776/']
# for program in program_ids:
# new_files_source = os.path.join(FILES_SOURCE, program)
# subfiles = glob(os.path.join(new_files_source, "*corrtag*"))
# # TODO: figure out why this wasn't working with find_files()
# files += subfiles

files = find_files('*corrtag*', data_dir=self.files_source,
subdir_pattern=self.subdir_pattern)

if not files: # No new files
return pd.DataFrame()

# need to add any other keywords that need to be set
data_results = data_from_exposures(files,
header_request=header_request,
table_request=table_request)

return data_results
37 changes: 28 additions & 9 deletions cosmo/monitors/nuv_dark_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,29 @@ def get_data(self):
# access data, perform any filtering required for analysis
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# access data, perform any filtering required for analysis
"""access data, perform any filtering required for analysis"""

data = self.model.new_data
dark_rate_column = []
dec_year_column = []

xlim = [0, 1024]
ylim = [0, 1024]

# parallelize, this is going to get bad when looking at a lot of data
cmagness marked this conversation as resolved.
Show resolved Hide resolved
for index, row in data.iterrows():
subdf = pd.DataFrame({
"TIME": row["TIME"], "XCORR": row["XCORR"],
"YCORR": row["YCORR"]
"EXPSTART": row["EXPSTART"], "TIME": row["TIME"],
"XCORR": row["XCORR"], "YCORR": row["YCORR"],
"TIME_3": row["TIME_3"]
})
filtered = subdf.where(
(subdf["XCORR"] > xlim[0]) & (subdf["XCORR"] < xlim[1]) & (
subdf["YCORR"] > ylim[0]) & (
subdf["YCORR"] < ylim[1]))
cmagness marked this conversation as resolved.
Show resolved Hide resolved
dark_rate = self.calculate_dark_rate(filtered, xlim, ylim)
dark_rate_column.append(dark_rate)
dark_rate_array, dec_year_array = self.calculate_dark_rate(
filtered, xlim, ylim)
dark_rate_column.append(dark_rate_array)
dec_year_column.append(dec_year_array)

data["DARK_RATE"] = dark_rate_column
data["DECIMAL_YEAR"] = dec_year_column

return data

Expand All @@ -59,19 +64,33 @@ def calculate_dark_rate(self, dataframe, xlim, ylim):

counts = np.histogram(dataframe["TIME"], bins=time_bins)[0]
npix = float((xlim[1] - xlim[0]) * (ylim[1] - ylim[0]))
dark_rate = np.median(counts / npix / timestep)
# what is going on with the whole histogram, ok to use median?

return dark_rate
dark_rate_array = counts / npix / timestep
# save the whole histogram in time bins, and then plot each of them

# make a decimal year array corresponding to the time bins of the
# dark rates
# do this with the expstart (mjd) and time array from the timeline
# extension
mjd_conversion_factor = 1.15741e-5
# taking the expstart, binning the time array by the timestep,
# removing the last element in the array (bin by front edge),
# and then multiplying by the conversion factor
mjd_array = dataframe["EXPSTART"] + dataframe["TIME_3"][::timestep][
:-1] * mjd_conversion_factor
mjd_array = Time(mjd_array, format='mjd')
cmagness marked this conversation as resolved.
Show resolved Hide resolved
dec_year_array = mjd_array.decimalyear

return dark_rate_array, dec_year_array

def track(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The track method should return some sort of quantity (scalar, dataframe, etc), not execute plotting

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep that is the end goal, don't worry. once the histogram is working correctly it will get the rates from the histogram and return those

# track something. perhaps current dark rate?
cmagness marked this conversation as resolved.
Show resolved Hide resolved
pass

def plot(self):
# do some plots

pass

def store_results(self):
# need to store results if not going in the database
pass
pass