<jupyter_start><jupyter_text>Check the new T2 TNS selector, then try to get the client to work with all the config updates..<jupyter_code>import os
%load_ext ampel_quick_import
%qi DevAmpelContext DictSecretProvider AmpelLogger T2Processor ChannelModel AlertConsumer TarAlertLoader ChannelModel AbsAlertFilter T3Processor TransientInfoPrinter
# See other sample notebooks for path to download
ALERT_ARCHIVE = "/home/jnordin/data/ztfalerts/ztf_public_20180731_nostars.tar.gz"
AMPEL_CONF = "/home/jnordin/github/ampelv71/ampel_conf.yaml"
secrets = DictSecretProvider( {'slack/ztf_general/jno':None,
                              'mongo/logger':{},
                              'mongo/writer':{},
                               'fritz/jvs/ampelbot': None,
                               'desi/skyportal/jno': None
                               'tns/jnordin': None,
                               'extcats/reader' : {},
                               'lco/jnordin':None,
                              })
ctx = DevAmpelContext.load(
    config_file_path = AMPEL_CONF,
    db_prefix = "TNSTest",
    purge_db = True,
    secrets = secrets,
)
# First channel, general look combined with SNGuess
ctx.add_channel(
    name="TNS1",
    access=['ZTF', 'ZTF_PUB']
)
cat_conf = { 'catalogs' : {
             'SDSS_spec' : {
                 'use' : 'extcats',
                 'catq_kwargs' : {
                     'ra_key' : 'ra',
                     'dec_key' : 'dec',
                 },
                 'rs_arcsec' : 10,
                 'keys_to_append' : ['z','bptclass','subclass'],
                 'pre_filter' : None,
                 'post_filter' : None,
             },
             'milliquas' : {
                 'use' : 'extcats',
                 'catq_kwargs' : {
                     'ra_key' : 'ra',
                     'dec_key' : 'dec',
                 },
                 'rs_arcsec' : 3,
                 'keys_to_append' : ['broad_type', 'name', 'redshift', 'qso_prob'],
                 'pre_filter' : None,
                 'post_filter' : None,
             }
        },
        'extcats' : {
            'auth' : {'key' : 'extcats/reader'},
            'max_time' : 300.0            
        }
}
extcat_config_id = ctx.add_config_id( cat_conf )
print(extcat_config_id)
tnseval_conf = {
    "t2_dependency": [
        {
            "unit": "T2CatalogMatch",
            "config": extcat_config_id,
            "link_override": {
                "pps": "last"
                }
        }
    ]
}
tnseval_config_id = ctx.add_config_id( tnseval_conf )
print(tnseval_config_id)
ap = AlertConsumer(
    context = ctx,
    process_name = "ipyton_notebook_test",
    supplier = "ZiAlertSupplier",
    log_profile = "debug",
    directives = [
        {
            "channel": "TNS1", 
            "filter": {"unit": "SimpleDecentFilter","config": {
#                                                                "min_drb":0.995,
                                                                "min_rb":0.3,
                                                                "min_ndet":3,
                                                                "min_tspan":0.02,
                                                                "max_tspan" : 999,
                                                                "min_gal_lat" : 14
                                                              }
                        },
            "stock_update": "ZiStockIngester",
            't0_add': {
                "ingester": "ZiAlertContentIngester",
                "t1_combine": [
                    {
                        "ingester": "PhotoCompoundIngester",
                        "config": {"combiner": "ZiT1Combiner"},
                        "t2_compute": {
                            "ingester": "PhotoT2Ingester",
                            "config": {"tags": ["ZTF"]},
                            "units": [
                                {'unit': 'T2TNSEval',
                                 'config': tnseval_config_id
                                },
                                {'unit': 'T2BrightSNProb'
                                },
                            ]
                        }
                    }
                ],
                "t2_compute": {
                    'unit': 'DualPointT2Ingester',
                    'config': {'tags': ['ZTF']},
                    'units': [
                        {
                            'unit': 'T2CatalogMatch', 
                            'config' : extcat_config_id,
                            "ingest": {'eligible': {'pps': 'first'}}
                        }
                    ],
                },

            }
        }
    ]
)
ap.set_loader(TarAlertLoader(ALERT_ARCHIVE))
ap.set_iter_max(20)
ap.run()
t2p = T2Processor(context=ctx, process_name="T2Processor_test", log_profile="debug")
t2p.run()
t3p = T3Processor(
    context=ctx,
    process_name = "T3Processor_test",
    log_profile = "default", # debug
    channel = "TNS1",
    directives = [ {
        "context": [
            {"unit": "T3AddLastRunTime"},
            {"unit": "T3AddAlertsNumber"}
        ],
        "select": {
            "unit": "T3FilteringStockSelector",
            "config": {
                "created": {"after": {"match_type": "time_delta", "days": -400000}},
                'tag': {'with': "ZTF", 'without': 'HAS_ERROR'},
                't2_filter':  {
                    'unit': 'T2TNSEval',
                    'match': {'tns_candidate':True },
                }, 
            }
        },
        "load": {
            "unit": "T3SimpleDataLoader",
            "config": {
                "directives": ["TRANSIENT", "T2RECORD"],
            }

        },
        "run": {
            "unit": "T3UnitRunner",
            "config": {
                "directives": [
                      {
                            "project": {
                                "unit": "T3ChannelProjector",
                                "config": {
                                    "channel": "TNS1"
                                }
                            },
                            "execute": [
                                {"unit": "TransientInfoPrinter"},
                                {
                                    "unit": "TNSTalker",
                                    "config": {
                                        "tns_api_key": {
                                            "key":"tns/jnordin",
                                        },
                                        "sandbox":True,
                                        "submit_tns":True,
                                    },
                                },
                            ]

                      }
                ]
            }
        }
    } ]
)

t3p.run()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11520670714079213, 'fraction_numerical': 0.010985834056085574, 'mean_word_length': 0.9187465335551858, 'pattern_counts': {'":': 56, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 26, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '393546', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 1891, 'n_tokens_neox': 1774, 'n_words': 276, 'path': 'notebooks/test_TNS.ipynb', 'repo_name': 'mafn/Ampel-HU-astro', 'size': '6918'}