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

Add a new filter for Blazar and BLLac #165

Merged
merged 2 commits into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
71 changes: 71 additions & 0 deletions fink_filters/filter_blazar/filter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Copyright 2023 AstroLab Software
# Author: Julien Peloton
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from pyspark.sql.functions import pandas_udf, PandasUDFType
from pyspark.sql.types import BooleanType

from fink_filters.tester import spark_unit_tests

import pandas as pd

from typing import Any

@pandas_udf(BooleanType(), PandasUDFType.SCALAR)
def blazar(cdsxmatch: Any) -> pd.Series:
""" Return alerts identified as Blazar or BLLac by the xmatch module.

Parameters
----------
cdsxmatch: Spark DataFrame Column
Column containing the cross-match values

Returns
----------
out: pandas.Series of bool
Return a Pandas DataFrame with the appropriate flag:
false for bad alert, and true for good alert.

Examples
----------
>>> from fink_utils.spark.utils import apply_user_defined_filter
>>> df = spark.read.format('parquet').load('datatest')
>>> f = 'fink_filters.filter_blazar.filter.blazar'
>>> df = apply_user_defined_filter(df, f)
>>> print(df.count())
10

>>> df.groupby('cdsxmatch').count().show()
+----------------+-----+
| cdsxmatch|count|
+----------------+-----+
|Blazar_Candidate| 3|
| BLLac| 4|
| Blazar| 3|
+----------------+-----+
<BLANKLINE>

"""
# Include new taxonomy
classes = ['Blazar', 'Blazar_Candidate', 'BLLac', 'BLLac_Candidate']
mask = cdsxmatch.isin(classes)

return pd.Series(mask)


if __name__ == "__main__":
""" Execute the test suite """

# Run the test suite
globs = globals()
spark_unit_tests(globs)
Loading