Tempscat Files ============== Let's imagine an institution called *Tempscat* intended to collect data about whether conditions all around Catalonia. *Tempscat* composed of a central station (aka *TCentral*) connected to a network of *Tempscat Municipal Stations* (aka *TMuni*) located in many towns in Catalonia that send information about the whether variables in that spot. Let's focus on the temperature variable. Each *TMuni* is constantly measuring the temperature and computes the average temperature for every hour. This information is sent in lots of several hours to the *TCentral*. Therefore *TCentral* receives a number of messages from each *TMuni* throughout the day, collects them all and produces a daily file with all the measures received that day. This is a `csv` file (Comma Separated Values) whose format is as follows: each line has the town name followed by several float numbers all separated by ``','``. Each town usually appears in several lines since the *TCentral* in that town send severals lots throughout the day. For example the file :download:`temp_11-1-2026.csv ` contains information about the temperature from three towns collected in lots of 6 hours: .. literalinclude:: temp_11-1-2026.csv :language: python Since the communication system is not perfect, some temperature values might be corrupted and include characters that cannot be interpreted as a numeric value. For instance, notice in the above example that line 7 contains and character ``'E'``, ine 11 contains the character ``'o'`` and line 12 contains the caracter ``'A'``. Anything that cannot be interpreted as numeric value (either float or integer) should be **disregarded**. Given a file like this, we wish to compile its information to produce a file with the daily minimum and maximum temperatures for each town. This ought to be a CSV file with the following format: #. the town name (:class:`str`) #. the minimum temperature (:class:`float`) #. the maximum temperature (:class:`float`) #. the number of valid temperature measures (:class:`int`) #. the valid temperature measures (sequence of :class:`float`) For example, the output expected from the above file would be the file :download:`tempminmax_11-1-2026.csv `: .. literalinclude:: tempminmax_11-1-2026.csv :language: python Notice that ``Barcelona`` has 24 valid measures whereas ``La Cellera de Ter`` has 23 and ``Sort`` has only 22, due to the invalid characters found in the input file. To this purpose you are asked to deliver the following Python function in the module :mod:`tempscat` (file :file:`tempscat.py`): .. py:function:: temp_join(in_filename, out_filename) such that **given** - `in_filename`, a :class:`str` with the filename of a file with the temperatures of one day as described above - `out_filename`, a :class:`str` with the name of the output file as described above **returns** an :class:`int` with the number of municipalites processed **produces** a file named `out_filename` with the format and compiled info from the info `in_filename` as described above. .. note:: The implement this function here you have a code snippet and a recommendation: - To chech whether a value read from the file is a valid numeric value you can used the file :download:`is_float.py `. You can download it and either import or copy into your code file. - It is recommended to store the temperatures for each town coming from several lines of `in_filename` into a **dictionary** where the key is the town name and the value is the list of processed, numeric temperatures for that town name. Doctests are available in the file :download:`temp_join.test`. The file to pass these doctests are available at: - :download:`temp_11-1-2026.csv ` - :download:`temp_bcn_11-1-2026.csv ` - :download:`temp_12-1-2026.csv ` - :download:`temp_13-1-2026.csv ` - :download:`temp_14-1-2026.csv `