opsimsummaryv2.utils
====================

.. py:module:: opsimsummaryv2.utils

.. autoapi-nested-parse::

   This module contains usefull functions.



Attributes
----------

.. autoapisummary::

   opsimsummaryv2.utils.use_geopandas


Functions
---------

.. autoapisummary::

   opsimsummaryv2.utils.compute_angle_sep
   opsimsummaryv2.utils.dataline
   opsimsummaryv2.utils.df_subdiviser
   opsimsummaryv2.utils.download_rubinlsst_baseline_dbfile
   opsimsummaryv2.utils.format_poly
   opsimsummaryv2.utils.host_joiner
   opsimsummaryv2.utils.host_resampler
   opsimsummaryv2.utils.read_SNANA_WGTMAP


Module Contents
---------------

.. py:function:: compute_angle_sep(ra_arr: numpy.array, dec_arr: numpy.array, ra: float, dec: float)

   Compute angle separation

   :param ra_arr: array of RA coords
   :type ra_arr: np.array
   :param dec_arr: array of Dec coords
   :type dec_arr: np.array
   :param ra: the RA coord of the reference angle with which compute the separation
   :type ra: float
   :param dec: the Dec coord of the reference angle with which compute the separation
   :type dec: float

   :returns: angle separation
   :rtype: np.array


.. py:function:: dataline(expMJD, ObsID, BAND, CCDgain, CCDnoise, SKYSIG, PSF, ZPT, ZPTNoise)

   Write a SIMLIB data line

   :param expMJD: Date of observation in MJD
   :type expMJD: float
   :param ObsID: ID of the observation
   :type ObsID: int
   :param BAND: Band used for the observation
   :type BAND: str
   :param CCDgain: CCd gain
   :type CCDgain: float
   :param CCDnoise: CCD noise
   :type CCDnoise: float
   :param SKYSIG: Sky noise error
   :type SKYSIG: float
   :param PSF: Point spread function sigma
   :type PSF: float
   :param ZPT: Zero point
   :type ZPT: float
   :param ZPTNoise: Zero point calibration error
   :type ZPTNoise: float

   :returns: A SIMLIB LIB entry line
   :rtype: str


.. py:function:: df_subdiviser(df, Nsub)

   Divide a dataframe into a list of sub-dataframne

   :param df: A pandas Dataframe to divide
   :type df: pandas.DataFrame
   :param Nsub: Number of subdivision
   :type Nsub: int

   :returns: A list of dataframme subdivisions.
   :rtype: list(pandas.DataFrame)


.. py:function:: download_rubinlsst_baseline_dbfile(version, output_dir=None)

   Download a specific versio  of Opsim output.

   :param version: The version of OpSim output to download.
   :type version: str
   :param output_dir: path of download, by default $SNANA_LSST_ROOT/simlibs/
   :type output_dir: str, optional

   :raises ValueError: _description_


.. py:function:: format_poly(poly)

   Fromat polygon that cross the 2 PI edge.

   :param poly: Polygon that represent fields
   :type poly: shapely.polygons

   :returns: Polygon that represent fields cutted on 2 PI edge.
   :rtype: shapely.MultiPolygons


.. py:function:: host_joiner(survey_fields, host)

   Use geopandas to match host in survey fields.

   :param survey_fields: Geodataframe describing survey fields
   :type survey_fields: geopandas.GeoDataFrame
   :param host: Dataframe that contains host informations
   :type host: pandas.DataFrame

   :returns: Datafrane containing host that are in field with their correspind GROUPID
   :rtype: pandas.DataFrame


.. py:function:: host_resampler(wgt_map_VAR, wgt_map_WGT, index, values, cdf_cut=0.95)

   Resample host according to a WGTMAP

   :param wgt_map_VAR: Variable of the WGTMAP
   :type wgt_map_VAR: numpy.array(float)
   :param wgt_map_WGT: Weight values of the WGTMAP
   :type wgt_map_WGT: numpy.array(float)
   :param index: Index of hosts
   :type index: numpy.array(int)
   :param values: Values of the Variable for host
   :type values: numpy.array(float)
   :param cdf_cut: A cut on the cdf to adjust , by default 0.95
   :type cdf_cut: float, optional

   :returns: _description_
   :rtype: _type_


.. py:function:: read_SNANA_WGTMAP(file)

   Read a SNANA HOSTLIB WGTMAP

   :param file: path to WGTMAP
   :type file: str

   :returns: list of varnames, WGTMAP as a dict
   :rtype: list(str), dict

   :raises ValueError: No WGT key


.. py:data:: use_geopandas
   :value: True


