-
Notifications
You must be signed in to change notification settings - Fork 10
39 add fuv dark monitors #73
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
dzhuliya
wants to merge
26
commits into
master
Choose a base branch
from
39-add-fuv-dark-monitors
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
4918b0b
Added FUVA LEFT monitor, changes to filesystem & monitor_helper
dzhuliya 5a7acde
Merge branch '46-add-tests' into 39-add-fuv-dark-monitors
dzhuliya e906982
Merge remote-tracking branch 'origin/master' into 39-add-fuv-dark-mon…
dzhuliya df5666f
small changes to imports - doesn't work yet don't merge
dzhuliya f58151d
Merge branch 'master' into 39-add-fuv-dark-monitors
dzhuliya 4fcb7ee
dark_data_models now works
dzhuliya c6fae09
Merge branch 'master' of /Users/dashtamirova/cosmo with conflicts.
dzhuliya 3324df1
Merge branch 'master' into 39-add-fuv-dark-monitors
dzhuliya af0a0e0
add cy27 directory
dzhuliya 95f750d
draft that worked once upon a time
dzhuliya 0d65787
Merge remote-tracking branch 'origin/master'
dzhuliya 2fd7265
Merge branch 'master' into 39-add-fuv-dark-monitors
dzhuliya 95b14fb
draft that worked once upon a time
dzhuliya c1ab365
draft for fuva left that worked once upon a time
dzhuliya 149178e
draft for fuva left that worked once upon a time
dzhuliya 67fb6bd
DRAFT: updated and added darkdatamodel to datamodels
dzhuliya 8935d21
fixed the issue with dark counts clustering at zero
dzhuliya 9f4c12c
updated subdir_pattern now find_files works
dzhuliya 17e66d6
added FUVA bottom monitor
dzhuliya 7a011e6
Merge remote-tracking branch 'origin/master'
dzhuliya 49b9a16
Merge branch 'master' into 39-add-fuv-dark-monitors
dzhuliya 2e4abc0
updated output location in yaml for myself
dzhuliya b5a4c15
added the rest of the FUV dark monitors
dzhuliya c2a05c4
added the rest of the FUV dark monitors
dzhuliya c6242ed
updated some docstrings. all dark monitors work
dzhuliya 5f5ce5f
working monitors yay
dzhuliya File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| import pandas as pd | ||
| import os | ||
| from glob import glob | ||
| from monitorframe.datamodel import BaseDataModel | ||
|
|
||
| from ..filesystem import find_files, data_from_exposures | ||
| from .. import SETTINGS | ||
|
|
||
| FILES_SOURCE = SETTINGS['filesystem']['source'] | ||
|
|
||
|
|
||
| class DarkDataModel(BaseDataModel): | ||
| cosmo_layout = False | ||
| program_id = ['15771', '15533/', '14940/', '14520/', '14436/', '13968/', '13521/', '13121/', '12716/', '12423/', | ||
| '11895/'] | ||
| # subdir_pattern = '?????' | ||
|
|
||
| def get_new_data(self): | ||
| header_request = { | ||
| 0: ['ROOTNAME', 'SEGMENT'], | ||
| 1: ['EXPTIME', 'EXPSTART'] | ||
| } | ||
|
|
||
| table_request = { | ||
| 1: ['PHA', 'XCORR', 'YCORR', 'TIME'], | ||
| 3: ['TIME', 'LATITUDE', 'LONGITUDE'] | ||
| } | ||
|
|
||
| files = [] | ||
|
|
||
| for prog_id in self.program_id: | ||
|
|
||
| new_files_source = os.path.join(FILES_SOURCE, prog_id) | ||
| files += find_files('*corrtag*', data_dir=new_files_source) | ||
|
|
||
| if self.model is not None: | ||
| currently_ingested = [item.FILENAME for item in self.model.select(self.model.FILENAME)] | ||
|
|
||
| for file in currently_ingested: | ||
| files.remove(file) | ||
|
|
||
| if not files: # No new files | ||
| return pd.DataFrame() | ||
|
|
||
| data_results = data_from_exposures( | ||
| files, | ||
| header_request=header_request, | ||
| table_request=table_request | ||
| ) | ||
|
|
||
| return data_results | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,156 @@ | ||
| from typing import Any | ||
|
|
||
| import numpy as np | ||
| import plotly.graph_objs as go | ||
| import pandas as pd | ||
|
|
||
| from itertools import repeat | ||
|
|
||
| from monitorframe.monitor import BaseMonitor | ||
| from .data_models import FUVDarkDataModel | ||
| from ..monitor_helpers import explode_df, absolute_time | ||
| from .. import SETTINGS | ||
|
|
||
| COS_MONITORING = SETTINGS['output'] | ||
|
|
||
|
|
||
| def dark_filter(df_row, filter_pha, location): | ||
| good_pha = (2, 23) | ||
| time_step = 25 | ||
| time_bins = df_row['TIME_3'][::time_step] | ||
| lat = df_row['LATITUDE'][::time_step][:-1] | ||
| lon = df_row['LONGITUDE'][::time_step][:-1] | ||
| event_df = df_row[['SEGMENT', 'XCORR', 'YCORR', 'PHA', 'TIME']].to_frame().T | ||
| event_df = explode_df(event_df, ['XCORR', 'YCORR', 'PHA', 'TIME']) | ||
| npix = (location[1] - location[0]) * (location[3] - location[2]) | ||
| index = np.where((event_df['XCORR'] > location[0]) & | ||
| (event_df['XCORR'] < location[1]) & | ||
| (event_df['YCORR'] > location[2]) & | ||
| (event_df['YCORR'] < location[3])) | ||
| filtered_row = event_df.iloc[index].reset_index(drop=True) | ||
|
|
||
| if filter_pha: | ||
| filtered_row = filtered_row[(filtered_row['PHA'] > good_pha[0]) & (filtered_row['PHA'] < good_pha[1])] | ||
|
|
||
| counts = np.histogram(filtered_row.TIME, bins=time_bins)[0] | ||
|
|
||
| date = absolute_time( | ||
| expstart=list(repeat(df_row['EXPSTART'], len(time_bins))), time=time_bins.tolist() | ||
| ).to_datetime()[:-1] | ||
|
|
||
| dark_rate = counts / npix / time_step | ||
|
|
||
| return pd.DataFrame({'segment': df_row['SEGMENT'], 'darks': [dark_rate], 'date': [date], | ||
| 'ROOTNAME': df_row['ROOTNAME']}) | ||
|
|
||
|
|
||
| class FUVDarkMonitor(BaseMonitor): | ||
| """Abstracted FUV Dark Monitor. Not meant to be used directly but rather inherited by specific segment and region | ||
| dark monitors""" | ||
| labels = ['ROOTNAME'] | ||
| output = COS_MONITORING | ||
| docs = "https://spacetelescope.github.io/cosmo/monitors.html#fuv-dark-rate-monitors" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just remember to name the section like that when you write the documentation, otherwise the link won't work 😆 |
||
| segment = None | ||
| location = None | ||
| plottype = 'scatter' | ||
| x = 'date' | ||
| y = 'darks' | ||
|
|
||
| def get_data(self) -> Any: | ||
| filtered_rows = [] | ||
| for _, row in self.model.new_data.iterrows(): | ||
| if row.EXPSTART == 0: | ||
| continue | ||
| if row.SEGMENT == self.segment: | ||
| filtered_rows.append(dark_filter(row, True, self.location)) | ||
| filtered_df = pd.concat(filtered_rows).reset_index(drop=True) | ||
|
|
||
| return explode_df(filtered_df, ['darks', 'date']) | ||
|
|
||
| def store_results(self): | ||
| # TODO: Define results to store | ||
| pass | ||
|
|
||
| def track(self): | ||
| # TODO: Define something to track | ||
| pass | ||
|
|
||
|
|
||
| class FUVABottomDarkMonitor(FUVDarkMonitor): | ||
| """FUVA dark monitor for bottom edge""" | ||
| data_model = FUVDarkDataModel | ||
| segment = 'FUVA' | ||
| location = (1060, 15250, 296, 375) | ||
| name = f'FUVA Dark Monitor - Bottom' | ||
|
|
||
|
|
||
| class FUVALeftDarkMonitor(FUVDarkMonitor): | ||
| """FUVA dark monitor for left edge""" | ||
| name = 'FUVA Dark Monitor - Left' | ||
| data_model = FUVDarkDataModel | ||
| segment = 'FUVA' | ||
| location = (1060, 1260, 296, 734) | ||
|
|
||
|
|
||
| class FUVATopDarkMonitor(FUVDarkMonitor): | ||
| """FUVA dark monitor for top edge""" | ||
| name = 'FUVA Dark Monitor - Top' | ||
| data_model = FUVDarkDataModel | ||
| segment = 'FUVA' | ||
| location = (1060, 15250, 660, 734) | ||
|
|
||
|
|
||
| class FUVARightDarkMonitor(FUVDarkMonitor): | ||
| """FUVA dark monitor for right edge""" | ||
| name = 'FUVA Dark Monitor - Right' | ||
| data_model = FUVDarkDataModel | ||
| segment = 'FUVA' | ||
| location = (15119, 15250, 296, 734) | ||
|
|
||
|
|
||
| class FUVAInnerDarkMonitor(FUVDarkMonitor): | ||
| """FUVA dark monitor for inner region""" | ||
| name = 'FUVA Dark Monitor - Inner' | ||
| data_model = FUVDarkDataModel | ||
| segment = 'FUVA' | ||
| location = (1260, 15119, 375, 660) | ||
|
|
||
|
|
||
| class FUVBBottomDarkMonitor(FUVDarkMonitor): | ||
| """FUVB dark monitor for bottom edge""" | ||
| name = 'FUVB Dark Monitor - Bottom' | ||
| data_model = FUVDarkDataModel | ||
| segment = 'FUVB' | ||
| location = (809, 15182, 360, 405) | ||
|
|
||
|
|
||
| class FUVBLeftDarkMonitor(FUVDarkMonitor): | ||
| """FUVB dark monitor for left edge""" | ||
| name = 'FUVB Dark Monitor - Left' | ||
| data_model = FUVDarkDataModel | ||
| segment = 'FUVB' | ||
| location = (809, 1000, 360, 785) | ||
|
|
||
|
|
||
| class FUVBTopDarkMonitor(FUVDarkMonitor): | ||
| """FUVB dark monitor for top edge""" | ||
| name = 'FUVB Dark Monitor - Top' | ||
| data_model = FUVDarkDataModel | ||
| segment = 'FUVB' | ||
| location = (809, 15182, 740, 785) | ||
|
|
||
|
|
||
| class FUVBRightDarkMonitor(FUVDarkMonitor): | ||
| """FUVB dark monitor for right edge""" | ||
| name = 'FUVB Dark Monitor - Right' | ||
| data_model = FUVDarkDataModel | ||
| segment = 'FUVB' | ||
| location = (14990, 15182, 360, 785) | ||
|
|
||
|
|
||
| class FUVBInnerDarkMonitor(FUVDarkMonitor): | ||
| """FUVB dark monitor for inner region""" | ||
| name = 'FUVB Dark Monitor - Inner' | ||
| data_model = FUVDarkDataModel | ||
| segment = 'FUVB' | ||
| location = (1000, 14990, 405, 740) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.